27def isCleanupOperation(env):
28 return env.GetOption(
'clean')
31 """ this is a hack: SCons does all configure tests even if only
32 the help message is requested. SCons doesn't export the
33 help option for retrieval by env.GetOption(),
34 so we scan the commandline directly.
36 return '-h' in sys.argv
or '--help' in sys.argv
41 """ convenience wrapper: scan the given subtree, which is relative
42 to the current SConscript, and find all source files.
48SRCPATTERNS = [
'*.c',
'*.cpp',
'*.cc']
51 """ first expand (possible) wildcards and filter out non-dirs.
52 Then scan the given subtree for source filenames
53 (python generator function)
56 for (d,_,files)
in os.walk(root):
59 for f
in fnmatch.filter(files, p):
60 yield os.path.join(d,f)
65 """ helper: expand shell wildcards and filter the resulting list,
66 so that it only contains existing directories
68 isDirectory =
lambda f: os.path.isdir(f)
and os.path.exists(f)
69 roots = glob.glob(roots)
70 return (d
for d
in roots
if isDirectory(d) )
75 """ find possible source tree roots, starting with the given location.
76 When delving down from the initial location(s), a source tree is defined
77 as a directory containing source files and possibly further sub directories.
78 After having initially expanded the given location with #globRootdirs, each
79 directory is examined depth first, until encountering a directory containing
80 source files, which then yields a result. Especially, this can be used to traverse
81 an organisational directory structure and find out all possible source trees
82 to be built into packages, plugins, individual tool executables etc.
83 @return: the relative path names of all source root dirs found (generator function).
86 if isSrcDir (directory,patterns):
89 for result
in findSrcTrees (str(directory)+
'/*'):
94 """ helper: investigate the given (relative) path
95 @param patterns: list of wildcards to define what counts as "source file"
96 @return: True if it's a directory containing any source file
98 if not os.path.isdir(path):
102 if glob.glob(path+
'/'+p):
108 """ extract directory name without leading path,
109 or without the explicitly given basePrefix
111 d = os.path.realpath(d)
112 if not os.path.isdir(d):
113 d,_ = os.path.split(d)
115 basePrefix = os.path.realpath(basePrefix)
118 _, name = os.path.split(d)
124 if path.startswith(prefix):
125 path = path[len(prefix):]
131 """ investigate the given source directory to identify all contained source trees.
132 @return: a list of build nodes defining a plugin for each of these source trees.
144 """ evaluate and verify an option, which may point at a command.
145 besides specifying a path, the option may read True, yes or 1,
146 denoting that the system default for this command should be used.
147 @return: True, if the key has been expanded and validated,
148 False, if this failed and the key was removed
151 if not env.get(optID):
return False
155 if val==
'True' or val==
'true' or val==
'yes' or val==
'1' or val == 1 :
157 print(
"WARNING: no default for %s, please specify a full path." % optID)
161 val = env.WhereIs(cmdName)
163 print(
"WARNING: %s not found, please specify a full path" % cmdName)
167 if not os.path.isfile(val):
168 val = env.WhereIs(val)
170 if val
and os.path.isfile(val):
181 """ a set of properties with record style access.
182 Record is a dictionary, but the elements can be accessed
183 conveniently as if they where object fields
187 defaults.update(props)
189 dict.__init__(self,props)
192 if key==
'__get__' or key==
'__set__':
194 return self.setdefault(key)
201 """ extracts the directory configuration values.
202 For sake of simplicity, paths and directories are defined
203 immediately as global variables in the SConstruct. This helper
204 extracts from the given dict the variables matching some magical
205 pattern and returns them wrapped into a Record for convenient access
207 def relevantPathDefs (mapping):
208 for (k,v)
in mapping.items():
209 if (k.startswith(
'src')
or k.startswith(
'build')
or k.startswith(
'install'))
and Util.is_String(v):
211 if not v.endswith(
'/'): v +=
'/'
214 return dict(relevantPathDefs(localDefs))
a set of properties with record style access.
__setattr__(self, key, val)
__init__(self, defaults=None, **props)
srcSubtree(tree, **args)
convenience wrapper: scan the given subtree, which is relative to the current SConscript,...
isHelpRequest()
this is a hack: SCons does all configure tests even if only the help message is requested.
extract_localPathDefs(localDefs)
extracts the directory configuration values.
stripPrefix(path, prefix)
isSrcDir(path, patterns=SRCPATTERNS)
helper: investigate the given (relative) path
checkCommandOption(env, optID, val=None, cmdName=None)
evaluate and verify an option, which may point at a command.
globRootdirs(roots)
helper: expand shell wildcards and filter the resulting list, so that it only contains existing direc...
getDirname(d, basePrefix=None)
extract directory name without leading path, or without the explicitly given basePrefix
scanSubtree(roots, patterns=SRCPATTERNS)
first expand (possible) wildcards and filter out non-dirs.
createPlugins(env, directory, **kw)
investigate the given source directory to identify all contained source trees.
findSrcTrees(location, patterns=SRCPATTERNS)
find possible source tree roots, starting with the given location.