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.
14
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
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__ = "src/engine/SCons/Tool/rpm.py 3842 2008/12/20 22:59:52 scons"
49
def get_cmd(source, env):
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.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].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,
74
output = handle.stdout.read()
75
status = handle.wait()
78
raise SCons.Errors.BuildError( node=target[0],
80
filename=str(target[0]) )
82
# XXX: assume that LC_ALL=c is set while running rpmbuild
83
output_files = re.compile( 'Wrote: (.*)' ).findall( output )
85
for output, input in zip( output_files, target ):
86
rpm_output = os.path.basename(output)
87
expected = os.path.basename(input.get_path())
89
assert expected == rpm_output, "got %s but expected %s" % (rpm_output, expected)
90
shutil.copy( output, input.abspath )
93
# cleanup before leaving.
98
def string_rpm(target, source, env):
100
return env['RPMCOMSTR']
102
return get_cmd(source, env)
104
rpmAction = SCons.Action.Action(build_rpm, string_rpm)
106
RpmBuilder = SCons.Builder.Builder(action = SCons.Action.Action('$RPMCOM', '$RPMCOMSTR'),
107
source_scanner = SCons.Defaults.DirScanner,
108
suffix = '$RPMSUFFIX')
113
"""Add Builders and construction variables for rpm to an Environment."""
115
bld = env['BUILDERS']['Rpm']
118
env['BUILDERS']['Rpm'] = bld
120
env.SetDefault(RPM = 'LC_ALL=c rpmbuild')
121
env.SetDefault(RPMFLAGS = SCons.Util.CLVar('-ta'))
122
env.SetDefault(RPMCOM = rpmAction)
123
env.SetDefault(RPMSUFFIX = '.rpm')
126
return env.Detect('rpmbuild')