29 from SCons
import Util
36 def isCleanupOperation(env):
37 return env.GetOption(
'clean')
40 """ this is a hack: SCons does all configure tests even if only 41 the help message is requested. SCons doesn't export the 42 help option for retrieval by env.GetOption(), 43 so we scan the commandline directly. 45 return '-h' in sys.argv
or '--help' in sys.argv
49 def srcSubtree(tree, **args):
50 """ convenience wrapper: scan the given subtree, which is relative 51 to the current SConscript, and find all source files. 53 return list(scanSubtree(tree, **args))
57 SRCPATTERNS = [
'*.c',
'*.cpp',
'*.cc']
59 def scanSubtree(roots, patterns=SRCPATTERNS):
60 """ first expand (possible) wildcards and filter out non-dirs. 61 Then scan the given subtree for source filenames 62 (python generator function) 64 for root
in globRootdirs(roots):
65 for (d,_,files)
in os.walk(root):
66 d = stripPrefix(d,
'./')
68 for f
in fnmatch.filter(files, p):
69 yield os.path.join(d,f)
73 def globRootdirs(roots):
74 """ helper: expand shell wildcards and filter the resulting list, 75 so that it only contains existing directories 77 isDirectory =
lambda f: os.path.isdir(f)
and os.path.exists(f)
78 roots = glob.glob(roots)
79 return (d
for d
in roots
if isDirectory(d) )
83 def findSrcTrees(location, patterns=SRCPATTERNS):
84 """ find possible source tree roots, starting with the given location. 85 When delving down from the initial location(s), a source tree is defined 86 as a directory containing source files and possibly further sub directories. 87 After having initially expanded the given location with #globRootdirs, each 88 directory is examined depth first, until encountering a directory containing 89 source files, which then yields a result. Especially, this can be used to traverse 90 an organisational directory structure and find out all possible source trees 91 to be built into packages, plugins, individual tool executables etc. 92 @return: the relative path names of all source root dirs found (generator function). 94 for directory
in globRootdirs(location):
95 if isSrcDir (directory,patterns):
98 for result
in findSrcTrees (str(directory)+
'/*'):
102 def isSrcDir(path, patterns=SRCPATTERNS):
103 """ helper: investigate the given (relative) path 104 @param patterns: list of wildcards to define what counts as "source file" 105 @return: True if it's a directory containing any source file 107 if not os.path.isdir(path):
111 if glob.glob(path+
'/'+p):
116 def filterNodes(nlist, removeName=None):
117 """ filter out scons build nodes using the given criteria. 118 removeName: if set, remove all nodes with this srcname 121 predicate =
lambda n :
not fnmatch.fnmatch(os.path.basename(str(n[0])), removeName)
123 predicate =
lambda n :
True 125 return filter(predicate, nlist)
129 def getDirname (d, basePrefix=None):
130 """ extract directory name without leading path, 131 or without the explicitly given basePrefix 133 d = os.path.realpath(d)
134 if not os.path.isdir(d):
135 d,_ = os.path.split(d)
137 basePrefix = os.path.realpath(basePrefix)
138 name = stripPrefix(str(d), basePrefix)
140 _, name = os.path.split(d)
145 def stripPrefix(path, prefix):
146 if path.startswith(prefix):
147 path = path[len(prefix):]
152 def createPlugins(env, directory, **kw):
153 """ investigate the given source directory to identify all contained source trees. 154 @return: a list of build nodes defining a plugin for each of these source trees. 156 return [env.LumieraPlugin( getDirname(tree)
160 for tree
in findSrcTrees(directory)
165 def checkCommandOption(env, optID, val=None, cmdName=None):
166 """ evaluate and verify an option, which may point at a command. 167 besides specifying a path, the option may read True, yes or 1, 168 denoting that the system default for this command should be used. 169 @return: True, if the key has been expanded and validated, 170 False, if this failed and the key was removed 173 if not env.get(optID):
return False 177 if val==
'True' or val==
'true' or val==
'yes' or val==
'1' or val == 1 :
179 print "WARNING: no default for %s, please specify a full path." % optID
183 val = env.WhereIs(cmdName)
185 print "WARNING: %s not found, please specify a full path" % cmdName
189 if not os.path.isfile(val):
190 val = env.WhereIs(val)
192 if val
and os.path.isfile(val):
203 """ a set of properties with record style access. 204 Record is a dictionary, but the elements can be accessed 205 conveniently as if they where object fields 207 def __init__(self, defaults=None, **props):
209 defaults.update(props)
211 dict.__init__(self,props)
213 def __getattr__(self,key):
214 if key==
'__get__' or key==
'__set__':
216 return self.setdefault(key)
218 def __setattr__(self,key,val):
222 def extract_localPathDefs (localDefs):
223 """ extracts the directory configuration values. 224 For sake of simplicity, paths and directories are defined 225 immediately as global variables in the SConstruct. This helper 226 extracts from the given dict the variables matching some magical 227 pattern and returns them wrapped into a Record for convenient access 229 def relevantPathDefs (mapping):
230 for (k,v)
in mapping.items():
231 if (k.startswith(
'src')
or k.startswith(
'build')
or k.startswith(
'install'))
and Util.is_String(v):
233 if not v.endswith(
'/'): v +=
'/' 236 return dict(relevantPathDefs(localDefs))
bool filter(Placement< DummyMO > const &candidate)
a filter predicate to pick some objects from a resultset.