3 Tool-specific initialization for rpm.
5 There normally shouldn't be any need to import this module directly.
6 It will usually be imported through the generic SCons.Tool.Tool()
9 The rpm tool calls the rpmbuild command. The first and only argument should a
10 tar.gz consisting of the source file and a specfile.
16 # Permission is hereby granted, free of charge, to any person obtaining
17 # a copy of this software and associated documentation files (the
18 # "Software"), to deal in the Software without restriction, including
19 # without limitation the rights to use, copy, modify, merge, publish,
20 # distribute, sublicense, and/or sell copies of the Software, and to
21 # permit persons to whom the Software is furnished to do so, subject to
22 # the following conditions:
24 # The above copyright notice and this permission notice shall be included
25 # in all copies or substantial portions of the Software.
27 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
28 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
29 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 __revision__
= "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
49 def get_cmd(source
, env
) -> str:
50 tar_file_with_included_specfile
= source
51 if SCons
.Util
.is_List(source
):
52 tar_file_with_included_specfile
= source
[0]
53 return "%s %s %s"%(env
['RPM'], env
['RPMFLAGS'],
54 tar_file_with_included_specfile
.get_abspath())
56 def build_rpm(target
, source
, env
):
57 # create a temporary rpm build root.
58 tmpdir
= os
.path
.join(os
.path
.dirname(target
[0].get_abspath()), 'rpmtemp')
59 if os
.path
.exists(tmpdir
):
62 # now create the mandatory rpm directory structure.
63 for d
in ['RPMS', 'SRPMS', 'SPECS', 'BUILD']:
64 os
.makedirs(os
.path
.join(tmpdir
, d
))
66 # set the topdir as an rpmflag.
67 env
.Prepend(RPMFLAGS
= '--define \'_topdir %s\'' % tmpdir
)
69 # now call rpmbuild to create the rpm package.
70 handle
= subprocess
.Popen(get_cmd(source
, env
),
71 stdout
=subprocess
.PIPE
,
72 stderr
=subprocess
.STDOUT
,
75 output
= SCons
.Util
.to_str(handle
.stdout
.read())
76 status
= handle
.wait()
79 raise SCons
.Errors
.BuildError(node
=target
[0],
81 filename
=str(target
[0]))
83 # XXX: assume that LC_ALL=C is set while running rpmbuild
84 output_files
= re
.compile('Wrote: (.*)').findall(output
)
86 for output
, input in zip(output_files
, target
):
87 rpm_output
= os
.path
.basename(output
)
88 expected
= os
.path
.basename(input.get_path())
90 assert expected
== rpm_output
, "got %s but expected %s" % (rpm_output
, expected
)
91 shutil
.copy(output
, input.get_abspath())
94 # cleanup before leaving.
99 def string_rpm(target
, source
, env
):
101 return env
['RPMCOMSTR']
103 return get_cmd(source
, env
)
105 rpmAction
= SCons
.Action
.Action(build_rpm
, string_rpm
)
107 RpmBuilder
= SCons
.Builder
.Builder(action
= SCons
.Action
.Action('$RPMCOM', '$RPMCOMSTR'),
108 source_scanner
= SCons
.Defaults
.DirScanner
,
109 suffix
= '$RPMSUFFIX')
113 def generate(env
) -> None:
114 """Add Builders and construction variables for rpm to an Environment."""
116 bld
= env
['BUILDERS']['Rpm']
119 env
['BUILDERS']['Rpm'] = bld
121 env
.SetDefault(RPM
= 'LC_ALL=C rpmbuild')
122 env
.SetDefault(RPMFLAGS
= SCons
.Util
.CLVar('-ta'))
123 env
.SetDefault(RPMCOM
= rpmAction
)
124 env
.SetDefault(RPMSUFFIX
= '.rpm')
127 return env
.Detect('rpmbuild')
131 # indent-tabs-mode:nil
133 # vim: set expandtab tabstop=4 shiftwidth=4: