1 """SCons.Tool.Packaging.ipk
5 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 __revision__ = "src/engine/SCons/Tool/packaging/ipk.py 3842 2008/12/20 22:59:52 scons"
33 from SCons.Tool.packaging import stripinstallbuilder, putintopackageroot
35 def package(env, target, source, PACKAGEROOT, NAME, VERSION, DESCRIPTION,
36 SUMMARY, X_IPK_PRIORITY, X_IPK_SECTION, SOURCE_URL,
37 X_IPK_MAINTAINER, X_IPK_DEPENDS, **kw):
38 """ this function prepares the packageroot directory for packaging with the
41 SCons.Tool.Tool('ipkg').generate(env)
43 # setup the Ipkg builder
44 bld = env['BUILDERS']['Ipkg']
45 target, source = stripinstallbuilder(target, source, env)
46 target, source = putintopackageroot(target, source, env, PACKAGEROOT)
48 # This should be overridable from the construction environment,
49 # which it is by using ARCHITECTURE=.
50 # Guessing based on what os.uname() returns at least allows it
51 # to work for both i386 and x86_64 Linux systems.
58 buildarchitecture = os.uname()[4]
59 buildarchitecture = archmap.get(buildarchitecture, buildarchitecture)
61 if kw.has_key('ARCHITECTURE'):
62 buildarchitecture = kw['ARCHITECTURE']
64 # setup the kw to contain the mandatory arguments to this fucntion.
65 # do this before calling any builder or setup function
69 del kw['source'], kw['target'], kw['env']
71 # generate the specfile
72 specfile = gen_ipk_dir(PACKAGEROOT, source, env, kw)
74 # override the default target.
75 if str(target[0])=="%s-%s"%(NAME, VERSION):
76 target=[ "%s_%s_%s.ipk"%(NAME, VERSION, buildarchitecture) ]
78 # now apply the Ipkg builder
79 return apply(bld, [env, target, specfile], kw)
81 def gen_ipk_dir(proot, source, env, kw):
82 # make sure the packageroot is a Dir object.
83 if SCons.Util.is_String(proot): proot=env.Dir(proot)
85 # create the specfile builder
86 s_bld=SCons.Builder.Builder(
87 action = build_specfiles,
90 # create the specfile targets
92 control=proot.Dir('CONTROL')
93 spec_target.append(control.File('control'))
94 spec_target.append(control.File('conffiles'))
95 spec_target.append(control.File('postrm'))
96 spec_target.append(control.File('prerm'))
97 spec_target.append(control.File('postinst'))
98 spec_target.append(control.File('preinst'))
100 # apply the builder to the specfile targets
101 apply(s_bld, [env, spec_target, source], kw)
103 # the packageroot directory does now contain the specfiles.
106 def build_specfiles(source, target, env):
107 """ filter the targets for the needed files and use the variables in env
108 to create the specfile.
111 # At first we care for the CONTROL/control file, which is the main file for ipk.
113 # For this we need to open multiple files in random order, so we store into
114 # a dict so they can be easily accessed.
118 def open_file(needle, haystack):
120 return opened_files[needle]
122 file=filter(lambda x: x.get_path().rfind(needle)!=-1, haystack)[0]
123 opened_files[needle]=open(file.abspath, 'w')
124 return opened_files[needle]
126 control_file=open_file('control', target)
128 if not env.has_key('X_IPK_DESCRIPTION'):
129 env['X_IPK_DESCRIPTION']="%s\n %s"%(env['SUMMARY'],
130 env['DESCRIPTION'].replace('\n', '\n '))
136 Priority: $X_IPK_PRIORITY
137 Section: $X_IPK_SECTION
139 Architecture: $ARCHITECTURE
140 Maintainer: $X_IPK_MAINTAINER
141 Depends: $X_IPK_DEPENDS
142 Description: $X_IPK_DESCRIPTION
145 control_file.write(env.subst(content))
148 # now handle the various other files, which purpose it is to set post-,
149 # pre-scripts and mark files as config files.
151 # We do so by filtering the source files for files which are marked with
152 # the "config" tag and afterwards we do the same for x_ipk_postrm,
153 # x_ipk_prerm, x_ipk_postinst and x_ipk_preinst tags.
155 # The first one will write the name of the file into the file
156 # CONTROL/configfiles, the latter add the content of the x_ipk_* variable
157 # into the same named file.
159 for f in [x for x in source if 'PACKAGING_CONFIG' in dir(x)]:
160 config=open_file('conffiles')
161 config.write(f.PACKAGING_INSTALL_LOCATION)
164 for str in 'POSTRM PRERM POSTINST PREINST'.split():
165 name="PACKAGING_X_IPK_%s"%str
166 for f in [x for x in source if name in dir(x)]:
171 # close all opened files
172 for f in opened_files.values():
175 # call a user specified function
176 if env.has_key('CHANGE_SPECFILE'):
177 content += env['CHANGE_SPECFILE'](target)