OLD | NEW |
(Empty) | |
| 1 """SCons.Tool.rpm |
| 2 |
| 3 Tool-specific initialization for rpm. |
| 4 |
| 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() |
| 7 selection method. |
| 8 |
| 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. |
| 11 """ |
| 12 |
| 13 # |
| 14 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S
Cons Foundation |
| 15 # |
| 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: |
| 23 # |
| 24 # The above copyright notice and this permission notice shall be included |
| 25 # in all copies or substantial portions of the Software. |
| 26 # |
| 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. |
| 34 # |
| 35 |
| 36 __revision__ = "src/engine/SCons/Tool/rpm.py 5134 2010/08/16 23:02:40 bdeegan" |
| 37 |
| 38 import os |
| 39 import re |
| 40 import shutil |
| 41 import subprocess |
| 42 |
| 43 import SCons.Builder |
| 44 import SCons.Node.FS |
| 45 import SCons.Util |
| 46 import SCons.Action |
| 47 import SCons.Defaults |
| 48 |
| 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 ) |
| 55 |
| 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): |
| 60 shutil.rmtree(tmpdir) |
| 61 |
| 62 # now create the mandatory rpm directory structure. |
| 63 for d in ['RPMS', 'SRPMS', 'SPECS', 'BUILD']: |
| 64 os.makedirs( os.path.join( tmpdir, d ) ) |
| 65 |
| 66 # set the topdir as an rpmflag. |
| 67 env.Prepend( RPMFLAGS = '--define \'_topdir %s\'' % tmpdir ) |
| 68 |
| 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, |
| 73 shell=True) |
| 74 output = handle.stdout.read() |
| 75 status = handle.wait() |
| 76 |
| 77 if status: |
| 78 raise SCons.Errors.BuildError( node=target[0], |
| 79 errstr=output, |
| 80 filename=str(target[0]) ) |
| 81 else: |
| 82 # XXX: assume that LC_ALL=c is set while running rpmbuild |
| 83 output_files = re.compile( 'Wrote: (.*)' ).findall( output ) |
| 84 |
| 85 for output, input in zip( output_files, target ): |
| 86 rpm_output = os.path.basename(output) |
| 87 expected = os.path.basename(input.get_path()) |
| 88 |
| 89 assert expected == rpm_output, "got %s but expected %s" % (rpm_outpu
t, expected) |
| 90 shutil.copy( output, input.abspath ) |
| 91 |
| 92 |
| 93 # cleanup before leaving. |
| 94 shutil.rmtree(tmpdir) |
| 95 |
| 96 return status |
| 97 |
| 98 def string_rpm(target, source, env): |
| 99 try: |
| 100 return env['RPMCOMSTR'] |
| 101 except KeyError: |
| 102 return get_cmd(source, env) |
| 103 |
| 104 rpmAction = SCons.Action.Action(build_rpm, string_rpm) |
| 105 |
| 106 RpmBuilder = SCons.Builder.Builder(action = SCons.Action.Action('$RPMCOM', '$RPM
COMSTR'), |
| 107 source_scanner = SCons.Defaults.DirScanner, |
| 108 suffix = '$RPMSUFFIX') |
| 109 |
| 110 |
| 111 |
| 112 def generate(env): |
| 113 """Add Builders and construction variables for rpm to an Environment.""" |
| 114 try: |
| 115 bld = env['BUILDERS']['Rpm'] |
| 116 except KeyError: |
| 117 bld = RpmBuilder |
| 118 env['BUILDERS']['Rpm'] = bld |
| 119 |
| 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') |
| 124 |
| 125 def exists(env): |
| 126 return env.Detect('rpmbuild') |
| 127 |
| 128 # Local Variables: |
| 129 # tab-width:4 |
| 130 # indent-tabs-mode:nil |
| 131 # End: |
| 132 # vim: set expandtab tabstop=4 shiftwidth=4: |
OLD | NEW |