summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Tool/packaging/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/Tool/packaging/__init__.py')
-rw-r--r--src/engine/SCons/Tool/packaging/__init__.py187
1 files changed, 77 insertions, 110 deletions
diff --git a/src/engine/SCons/Tool/packaging/__init__.py b/src/engine/SCons/Tool/packaging/__init__.py
index e8f6a09..72bbff0 100644
--- a/src/engine/SCons/Tool/packaging/__init__.py
+++ b/src/engine/SCons/Tool/packaging/__init__.py
@@ -32,6 +32,7 @@ import SCons.Environment
from SCons.Options import *
from SCons.Errors import *
from SCons.Util import is_List, make_path_relative
+from SCons.Warnings import warn, Warning
import os, imp
import SCons.Defaults
@@ -96,7 +97,11 @@ def Package(env, target=None, source=None, **kw):
try: kw['PACKAGETYPE']=env['PACKAGETYPE']
except KeyError: pass
- if not kw.has_key('PACKAGETYPE') or kw['PACKAGETYPE']==None:
+ if not kw.get('PACKAGETYPE'):
+ from SCons.Script import GetOption
+ kw['PACKAGETYPE'] = GetOption('package_type')
+
+ if kw['PACKAGETYPE'] == None:
if env['BUILDERS'].has_key('Tar'):
kw['PACKAGETYPE']='targz'
elif env['BUILDERS'].has_key('Zip'):
@@ -175,76 +180,48 @@ def Package(env, target=None, source=None, **kw):
targets.extend(env.Alias( 'package', targets ))
return targets
-def build_source(ss, sources):
- for s in ss:
- if s.__class__==SCons.Node.FS.Dir:
- build_source(s.all_children())
- elif not s.has_builder() and s.__class__==SCons.Node.FS.File:
- sources.append(s)
- else:
- build_source(s.sources)
-
-def FindSourceFiles(env, target=None, source=None ):
- """ returns a list of all children of the target nodes, which have no
- children. This selects all leaves of the DAG that gets build by SCons for
- handling dependencies.
- """
- if target==None: target = '.'
-
- nodes = env.arg2nodes(target, env.fs.Entry)
-
- sources = []
- for node in nodes:
- build_source(node.all_children(), sources)
-
- # now strip the build_node from the sources by calling the srcnode
- # function
- def get_final_srcnode(file):
- srcnode = file.srcnode()
- while srcnode != file.srcnode():
- srcnode = file.srcnode()
- return srcnode
-
- # get the final srcnode for all nodes, this means stripping any
- # attached build node.
- map( get_final_srcnode, sources )
-
- # remove duplicates
- return list(set(sources))
-
-def FindInstalledFiles(env, source=[], target=[]):
- """ returns the list of all targets of the Install and InstallAs Builder.
- """
- from SCons.Tool import install
- return install._INSTALLED_FILES
-
#
# SCons tool initialization functions
#
+
+added = None
+
def generate(env):
+ from SCons.Script import AddOption
+ global added
+ if not added:
+ added = 1
+ AddOption('--package-type',
+ dest='package_type',
+ default=None,
+ type="string",
+ action="store",
+ help='The type of package to create.')
+
try:
env['BUILDERS']['Package']
env['BUILDERS']['Tag']
- env['BUILDERS']['FindSourceFiles']
- env['BUILDERS']['FindInstalledFiles']
except KeyError:
env['BUILDERS']['Package'] = Package
env['BUILDERS']['Tag'] = Tag
- env['BUILDERS']['FindSourceFiles'] = FindSourceFiles
- env['BUILDERS']['FindInstalledFiles'] = FindInstalledFiles
def exists(env):
return 1
+# XXX
def options(opts):
opts.AddOptions(
- EnumOption( [ 'PACKAGETYPE', '--package-type' ],
+ EnumOption( 'PACKAGETYPE',
'the type of package to create.',
None, allowed_values=map( str, __all__ ),
ignorecase=2
)
)
+#
+# Internal utility functions
+#
+
def copy_attr(f1, f2):
""" copies the special packaging file attributes from f1 to f2.
"""
@@ -254,79 +231,69 @@ def copy_attr(f1, f2):
pattrs = filter(copyit, dir(f1))
for attr in pattrs:
setattr(f2, attr, getattr(f1, attr))
-#
-# Emitter functions which are reused by the various packagers
-#
-def packageroot_emitter(pkg_root, honor_install_location=1):
- """ creates the packageroot emitter.
-
- The package root emitter uses the CopyAs builder to copy all source files
- to the directory given in pkg_root.
+def putintopackageroot(target, source, env, pkgroot, honor_install_location=1):
+ """ Uses the CopyAs builder to copy all source files to the directory given
+ in pkgroot.
If honor_install_location is set and the copied source file has an
PACKAGING_INSTALL_LOCATION attribute, the PACKAGING_INSTALL_LOCATION is
- used as the new name of the source file under pkg_root.
+ used as the new name of the source file under pkgroot.
- The source file will not be copied if it is already under the the pkg_root
+ The source file will not be copied if it is already under the the pkgroot
directory.
All attributes of the source file will be copied to the new file.
"""
- def package_root_emitter(target, source, env, pkg_root=pkg_root, honor_install_location=honor_install_location):
- pkgroot = pkg_root
- # make sure the packageroot is a Dir object.
- if SCons.Util.is_String(pkgroot): pkgroot=env.Dir(pkgroot)
-
- def copy_file_to_pkg_root(file, env=env, pkgroot=pkgroot, honor_install_location=honor_install_location):
- if file.is_under(pkgroot):
- return file
- else:
- if hasattr(file, 'PACKAGING_INSTALL_LOCATION') and\
- honor_install_location:
- new_name=make_path_relative(file.PACKAGING_INSTALL_LOCATION)
- else:
- new_name=make_path_relative(file.get_path())
+ # make sure the packageroot is a Dir object.
+ if SCons.Util.is_String(pkgroot): pkgroot=env.Dir(pkgroot)
+ if not SCons.Util.is_List(source): source=[source]
- new_file=pkgroot.File(new_name)
- new_file=env.CopyAs(new_file, file)[0]
+ new_source = []
+ for file in source:
+ if SCons.Util.is_String(file): file = env.File(file)
- copy_attr(file, new_file)
+ if file.is_under(pkgroot):
+ new_source.append(file)
+ else:
+ if hasattr(file, 'PACKAGING_INSTALL_LOCATION') and\
+ honor_install_location:
+ new_name=make_path_relative(file.PACKAGING_INSTALL_LOCATION)
+ else:
+ new_name=make_path_relative(file.get_path())
- return new_file
- return (target, map(copy_file_to_pkg_root, source))
- return package_root_emitter
+ new_file=pkgroot.File(new_name)
+ new_file=env.CopyAs(new_file, file)[0]
+ copy_attr(file, new_file)
+ new_source.append(new_file)
-from SCons.Warnings import warn, Warning
+ return (target, new_source)
-def stripinstall_emitter():
- """ create the a emitter which:
- * strips of the Install Builder of the source target, and stores the
- install location as the "PACKAGING_INSTALL_LOCATION" of the given source
- File object. This effectively avoids having to execute the Install
- Action while storing the needed install location.
- * warns about files that are mangled by this emitter which have no
- Install Builder.
+def stripinstallbuilder(target, source, env):
+ """ strips the install builder action from the source list and stores
+ the final installation location as the "PACKAGING_INSTALL_LOCATION" of
+ the source of the source file. This effectively removes the final installed
+ files from the source list while remembering the installation location.
+
+ It also warns about files which have no install builder attached.
"""
- def strip_install_emitter(target, source, env):
- def has_no_install_location(file):
- return not (file.has_builder() and\
- hasattr(file.builder, 'name') and\
- (file.builder.name=="InstallBuilder" or\
- file.builder.name=="InstallAsBuilder"))
-
- if len(filter(has_no_install_location, source)):
- warn(Warning, "there are file to package which have no\
- InstallBuilder attached, this might lead to irreproducible packages")
-
- n_source=[]
- for s in source:
- if has_no_install_location(s):
- n_source.append(s)
- else:
- for ss in s.sources:
- n_source.append(ss)
- copy_attr(s, ss)
- setattr(ss, 'PACKAGING_INSTALL_LOCATION', s.get_path())
+ def has_no_install_location(file):
+ return not (file.has_builder() and\
+ hasattr(file.builder, 'name') and\
+ (file.builder.name=="InstallBuilder" or\
+ file.builder.name=="InstallAsBuilder"))
+
+ if len(filter(has_no_install_location, source)):
+ warn(Warning, "there are files to package which have no\
+ InstallBuilder attached, this might lead to irreproducible packages")
+
+ n_source=[]
+ for s in source:
+ if has_no_install_location(s):
+ n_source.append(s)
+ else:
+ for ss in s.sources:
+ n_source.append(ss)
+ copy_attr(s, ss)
+ setattr(ss, 'PACKAGING_INSTALL_LOCATION', s.get_path())
- return (target, n_source)
- return strip_install_emitter
+ return (target, n_source)