1 # This file is generated; do not edit. 2 3 __doc__ = ''' 4 Wrapper configuration for building this entire "solution," 5 including all the specific targets in various *.scons files. 6 ''' 7 8 import os 9 import sys 10 11 import SCons.Environment 12 import SCons.Util 13 14 def GetProcessorCount(): 15 ''' 16 Detects the number of CPUs on the system. Adapted form: 17 http://codeliberates.blogspot.com/2008/05/detecting-cpuscores-in-python.html 18 ''' 19 # Linux, Unix and Mac OS X: 20 if hasattr(os, 'sysconf'): 21 if os.sysconf_names.has_key('SC_NPROCESSORS_ONLN'): 22 # Linux and Unix or Mac OS X with python >= 2.5: 23 return os.sysconf('SC_NPROCESSORS_ONLN') 24 else: # Mac OS X with Python < 2.5: 25 return int(os.popen2("sysctl -n hw.ncpu")[1].read()) 26 # Windows: 27 if os.environ.has_key('NUMBER_OF_PROCESSORS'): 28 return max(int(os.environ.get('NUMBER_OF_PROCESSORS', '1')), 1) 29 return 1 # Default 30 31 # Support PROGRESS= to show progress in different ways. 32 p = ARGUMENTS.get('PROGRESS') 33 if p == 'spinner': 34 Progress(['/\r', '|\r', '\\\r', '-\r'], 35 interval=5, 36 file=open('/dev/tty', 'w')) 37 elif p == 'name': 38 Progress('$TARGET\r', overwrite=True, file=open('/dev/tty', 'w')) 39 40 # Set the default -j value based on the number of processors. 41 SetOption('num_jobs', GetProcessorCount() + 1) 42 43 # Have SCons use its cached dependency information. 44 SetOption('implicit_cache', 1) 45 46 # Only re-calculate MD5 checksums if a timestamp has changed. 47 Decider('MD5-timestamp') 48 49 # Since we set the -j value by default, suppress SCons warnings about being 50 # unable to support parallel build on versions of Python with no threading. 51 default_warnings = ['no-no-parallel-support'] 52 SetOption('warn', default_warnings + GetOption('warn')) 53 54 AddOption('--mode', nargs=1, dest='conf_list', default=[], 55 action='append', help='Configuration to build.') 56 57 AddOption('--verbose', dest='verbose', default=False, 58 action='store_true', help='Verbose command-line output.') 59 60 61 # 62 sconscript_file_map = dict( 63 sdch = 'sdch.scons', 64 ) 65 66 class LoadTarget: 67 ''' 68 Class for deciding if a given target sconscript is to be included 69 based on a list of included target names, optionally prefixed with '-' 70 to exclude a target name. 71 ''' 72 def __init__(self, load): 73 ''' 74 Initialize a class with a list of names for possible loading. 75 76 Arguments: 77 load: list of elements in the LOAD= specification 78 ''' 79 self.included = set([c for c in load if not c.startswith('-')]) 80 self.excluded = set([c[1:] for c in load if c.startswith('-')]) 81 82 if not self.included: 83 self.included = set(['all']) 84 85 def __call__(self, target): 86 ''' 87 Returns True if the specified target's sconscript file should be 88 loaded, based on the initialized included and excluded lists. 89 ''' 90 return (target in self.included or 91 ('all' in self.included and not target in self.excluded)) 92 93 if 'LOAD' in ARGUMENTS: 94 load = ARGUMENTS['LOAD'].split(',') 95 else: 96 load = [] 97 load_target = LoadTarget(load) 98 99 sconscript_files = [] 100 for target, sconscript in sconscript_file_map.iteritems(): 101 if load_target(target): 102 sconscript_files.append(sconscript) 103 104 105 target_alias_list= [] 106 107 conf_list = GetOption('conf_list') 108 if conf_list: 109 # In case the same --mode= value was specified multiple times. 110 conf_list = list(set(conf_list)) 111 else: 112 conf_list = ['Debug'] 113 114 sconsbuild_dir = Dir('../sconsbuild') 115 116 117 def FilterOut(self, **kw): 118 kw = SCons.Environment.copy_non_reserved_keywords(kw) 119 for key, val in kw.items(): 120 envval = self.get(key, None) 121 if envval is None: 122 # No existing variable in the environment, so nothing to delete. 123 continue 124 125 for vremove in val: 126 # Use while not if, so we can handle duplicates. 127 while vremove in envval: 128 envval.remove(vremove) 129 130 self[key] = envval 131 132 # TODO(sgk): SCons.Environment.Append() has much more logic to deal 133 # with various types of values. We should handle all those cases in here 134 # too. (If variable is a dict, etc.) 135 136 137 non_compilable_suffixes = { 138 'LINUX' : set([ 139 '.bdic', 140 '.css', 141 '.dat', 142 '.fragment', 143 '.gperf', 144 '.h', 145 '.hh', 146 '.hpp', 147 '.html', 148 '.hxx', 149 '.idl', 150 '.in', 151 '.in0', 152 '.in1', 153 '.js', 154 '.mk', 155 '.rc', 156 '.sigs', 157 '', 158 ]), 159 'WINDOWS' : set([ 160 '.h', 161 '.hh', 162 '.hpp', 163 '.dat', 164 '.idl', 165 '.in', 166 '.in0', 167 '.in1', 168 ]), 169 } 170 171 def compilable(env, file): 172 base, ext = os.path.splitext(str(file)) 173 if ext in non_compilable_suffixes[env['TARGET_PLATFORM']]: 174 return False 175 return True 176 177 def compilable_files(env, sources): 178 return [x for x in sources if compilable(env, x)] 179 180 def GypProgram(env, target, source, *args, **kw): 181 source = compilable_files(env, source) 182 result = env.Program('$TOP_BUILDDIR/' + str(target), source, *args, **kw) 183 if env.get('INCREMENTAL'): 184 env.Precious(result) 185 return result 186 187 def GypTestProgram(env, target, source, *args, **kw): 188 source = compilable_files(env, source) 189 result = env.Program('$TOP_BUILDDIR/' + str(target), source, *args, **kw) 190 if env.get('INCREMENTAL'): 191 env.Precious(*result) 192 return result 193 194 def GypLibrary(env, target, source, *args, **kw): 195 source = compilable_files(env, source) 196 result = env.Library('$LIB_DIR/' + str(target), source, *args, **kw) 197 return result 198 199 def GypLoadableModule(env, target, source, *args, **kw): 200 source = compilable_files(env, source) 201 result = env.LoadableModule('$TOP_BUILDDIR/' + str(target), source, *args, 202 **kw) 203 return result 204 205 def GypStaticLibrary(env, target, source, *args, **kw): 206 source = compilable_files(env, source) 207 result = env.StaticLibrary('$LIB_DIR/' + str(target), source, *args, **kw) 208 return result 209 210 def GypSharedLibrary(env, target, source, *args, **kw): 211 source = compilable_files(env, source) 212 result = env.SharedLibrary('$LIB_DIR/' + str(target), source, *args, **kw) 213 if env.get('INCREMENTAL'): 214 env.Precious(result) 215 return result 216 217 def add_gyp_methods(env): 218 env.AddMethod(GypProgram) 219 env.AddMethod(GypTestProgram) 220 env.AddMethod(GypLibrary) 221 env.AddMethod(GypLoadableModule) 222 env.AddMethod(GypStaticLibrary) 223 env.AddMethod(GypSharedLibrary) 224 225 env.AddMethod(FilterOut) 226 227 env.AddMethod(compilable) 228 229 230 base_env = Environment( 231 tools = ['ar', 'as', 'gcc', 'g++', 'gnulink', 'chromium_builders'], 232 INTERMEDIATE_DIR='$OBJ_DIR/${COMPONENT_NAME}/_${TARGET_NAME}_intermediate', 233 LIB_DIR='$TOP_BUILDDIR/lib', 234 OBJ_DIR='$TOP_BUILDDIR/obj', 235 SCONSBUILD_DIR=sconsbuild_dir.abspath, 236 SHARED_INTERMEDIATE_DIR='$OBJ_DIR/_global_intermediate', 237 SRC_DIR=Dir('..'), 238 TARGET_PLATFORM='LINUX', 239 TOP_BUILDDIR='$SCONSBUILD_DIR/$CONFIG_NAME', 240 LIBPATH=['$LIB_DIR'], 241 ) 242 243 if not GetOption('verbose'): 244 base_env.SetDefault( 245 ARCOMSTR='Creating library $TARGET', 246 ASCOMSTR='Assembling $TARGET', 247 CCCOMSTR='Compiling $TARGET', 248 CONCATSOURCECOMSTR='ConcatSource $TARGET', 249 CXXCOMSTR='Compiling $TARGET', 250 LDMODULECOMSTR='Building loadable module $TARGET', 251 LINKCOMSTR='Linking $TARGET', 252 MANIFESTCOMSTR='Updating manifest for $TARGET', 253 MIDLCOMSTR='Compiling IDL $TARGET', 254 PCHCOMSTR='Precompiling $TARGET', 255 RANLIBCOMSTR='Indexing $TARGET', 256 RCCOMSTR='Compiling resource $TARGET', 257 SHCCCOMSTR='Compiling $TARGET', 258 SHCXXCOMSTR='Compiling $TARGET', 259 SHLINKCOMSTR='Linking $TARGET', 260 SHMANIFESTCOMSTR='Updating manifest for $TARGET', 261 ) 262 263 add_gyp_methods(base_env) 264 265 for conf in conf_list: 266 env = base_env.Clone(CONFIG_NAME=conf) 267 SConsignFile(env.File('$TOP_BUILDDIR/.sconsign').abspath) 268 for sconscript in sconscript_files: 269 target_alias = env.SConscript(sconscript, exports=['env']) 270 if target_alias: 271 target_alias_list.extend(target_alias) 272 273 Default(Alias('all', target_alias_list)) 274 275 help_fmt = ''' 276 Usage: hammer [SCONS_OPTIONS] [VARIABLES] [TARGET] ... 277 278 Local command-line build options: 279 --mode=CONFIG Configuration to build: 280 --mode=Debug [default] 281 --mode=Release 282 --verbose Print actual executed command lines. 283 284 Supported command-line build variables: 285 LOAD=[module,...] Comma-separated list of components to load in the 286 dependency graph ('-' prefix excludes) 287 PROGRESS=type Display a progress indicator: 288 name: print each evaluated target name 289 spinner: print a spinner every 5 targets 290 291 The following TARGET names can also be used as LOAD= module names: 292 293 %s 294 ''' 295 296 if GetOption('help'): 297 def columnar_text(items, width=78, indent=2, sep=2): 298 result = [] 299 colwidth = max(map(len, items)) + sep 300 cols = (width - indent) / colwidth 301 if cols < 1: 302 cols = 1 303 rows = (len(items) + cols - 1) / cols 304 indent = '%*s' % (indent, '') 305 sep = indent 306 for row in xrange(0, rows): 307 result.append(sep) 308 for i in xrange(row, len(items), rows): 309 result.append('%-*s' % (colwidth, items[i])) 310 sep = '\n' + indent 311 result.append('\n') 312 return ''.join(result) 313 314 load_list = set(sconscript_file_map.keys()) 315 target_aliases = set(map(str, target_alias_list)) 316 317 common = load_list and target_aliases 318 load_only = load_list - common 319 target_only = target_aliases - common 320 help_text = [help_fmt % columnar_text(sorted(list(common)))] 321 if target_only: 322 fmt = "The following are additional TARGET names:\n\n%s\n" 323 help_text.append(fmt % columnar_text(sorted(list(target_only)))) 324 if load_only: 325 fmt = "The following are additional LOAD= module names:\n\n%s\n" 326 help_text.append(fmt % columnar_text(sorted(list(load_only)))) 327 Help(''.join(help_text)) 328