| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2008, Google Inc. | 2 # Copyright 2008, Google Inc. |
| 3 # All rights reserved. | 3 # All rights reserved. |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 of an environment, it should instead go in a tool in site_tools and be invoked | 35 of an environment, it should instead go in a tool in site_tools and be invoked |
| 36 for the target environment. | 36 for the target environment. |
| 37 """ | 37 """ |
| 38 | 38 |
| 39 import __builtin__ | 39 import __builtin__ |
| 40 import sys | 40 import sys |
| 41 import SCons | 41 import SCons |
| 42 | 42 |
| 43 | 43 |
| 44 # List of target groups for printing help; modified by AddTargetGroup(); used | 44 # List of target groups for printing help; modified by AddTargetGroup(); used |
| 45 # by BuildComponents(). | 45 # by BuildEnvironments(). |
| 46 __target_groups = {} | 46 __target_groups = {} |
| 47 | 47 |
| 48 | 48 |
| 49 def _HostPlatform(): | 49 def _HostPlatform(): |
| 50 """Returns the current host platform. | 50 """Returns the current host platform. |
| 51 | 51 |
| 52 That is, the platform we're actually running SCons on. You shouldn't use | 52 That is, the platform we're actually running SCons on. You shouldn't use |
| 53 this inside your SConscript files; instead, include the appropriate | 53 this inside your SConscript files; instead, include the appropriate |
| 54 target_platform tool for your environments. When you call BuildComponents(), | 54 target_platform tool for your environments. When you call |
| 55 only environments with the current host platform will be built. | 55 BuildEnvironments(), only environments with the current host platform will be |
| 56 built. |
| 56 | 57 |
| 57 Returns: | 58 Returns: |
| 58 The host platform name - one of ('WINDOWS', 'LINUX', 'MAC'). | 59 The host platform name - one of ('WINDOWS', 'LINUX', 'MAC'). |
| 59 """ | 60 """ |
| 60 | 61 |
| 61 platform_map = { | 62 platform_map = { |
| 62 'win32': 'WINDOWS', | 63 'win32': 'WINDOWS', |
| 63 'cygwin': 'WINDOWS', | 64 'cygwin': 'WINDOWS', |
| 64 'linux': 'LINUX', | 65 'linux': 'LINUX', |
| 65 'linux2': 'LINUX', | 66 'linux2': 'LINUX', |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 help_text = '' | 173 help_text = '' |
| 173 | 174 |
| 174 for alias, description in __target_groups.items(): | 175 for alias, description in __target_groups.items(): |
| 175 items = map(str, SCons.Script.Alias(alias)[0].sources) | 176 items = map(str, SCons.Script.Alias(alias)[0].sources) |
| 176 # Remove duplicates from multiple environments | 177 # Remove duplicates from multiple environments |
| 177 items = list(set(items)) | 178 items = list(set(items)) |
| 178 | 179 |
| 179 if items: | 180 if items: |
| 180 colwidth = max(map(len, items)) + 2 | 181 colwidth = max(map(len, items)) + 2 |
| 181 cols = 77 / colwidth | 182 cols = 77 / colwidth |
| 183 if cols < 1: |
| 184 cols = 1 # If target names are really long, one per line |
| 182 rows = (len(items) + cols - 1) / cols | 185 rows = (len(items) + cols - 1) / cols |
| 183 items.sort() | 186 items.sort() |
| 184 if xml_help: | 187 if xml_help: |
| 185 help_text += '<target_group name="%s">\n' % alias | 188 help_text += '<target_group name="%s">\n' % alias |
| 186 for i in items: | 189 for i in items: |
| 187 help_text += ' <build_target name="%s"/>\n' % i | 190 help_text += ' <build_target name="%s"/>\n' % i |
| 188 help_text += '</target_group>\n' | 191 help_text += '</target_group>\n' |
| 189 else: | 192 else: |
| 190 help_text += '\nThe following %s:' % description | 193 help_text += '\nThe following %s:' % description |
| 191 for row in range(0, rows): | 194 for row in range(0, rows): |
| 192 help_text += '\n ' | 195 help_text += '\n ' |
| 193 for i in range(row, len(items), rows): | 196 for i in range(row, len(items), rows): |
| 194 help_text += '%-*s' % (colwidth, items[i]) | 197 help_text += '%-*s' % (colwidth, items[i]) |
| 195 help_text += '\n %s (do all of the above)\n' % alias | 198 help_text += '\n %s (do all of the above)\n' % alias |
| 196 | 199 |
| 197 SCons.Script.Help(help_text) | 200 SCons.Script.Help(help_text) |
| 198 | 201 |
| 199 #------------------------------------------------------------------------------ | 202 #------------------------------------------------------------------------------ |
| 200 | 203 |
| 201 | 204 |
| 202 def BuildComponents(environments): | 205 def BuildEnvironments(environments): |
| 203 """Build a collection of components under a collection of environments. | 206 """Build a collection of SConscripts under a collection of environments. |
| 204 | 207 |
| 205 Only environments with HOST_PLATFORMS containing the platform specified by | 208 Only environments with HOST_PLATFORMS containing the platform specified by |
| 206 --host-platform (or the native host platform, if --host-platform was not | 209 --host-platform (or the native host platform, if --host-platform was not |
| 207 specified) will be matched. | 210 specified) will be matched. |
| 208 | 211 |
| 209 Each matching environment is checked against the modes passed to the --mode | 212 Each matching environment is checked against the modes passed to the --mode |
| 210 command line argument (or 'default', if no mode(s) were specified). If any | 213 command line argument (or 'default', if no mode(s) were specified). If any |
| 211 of the modes match the environment's BUILD_TYPE or any of the environment's | 214 of the modes match the environment's BUILD_TYPE or any of the environment's |
| 212 BUILD_GROUPS, all the BUILD_COMPONENTS and BUILD_SCONSCRIPTS in that | 215 BUILD_GROUPS, all the BUILD_SCONSCRIPTS (and for legacy reasons, |
| 213 environment will be built. | 216 BUILD_COMPONENTS) in that environment will be built. |
| 214 | 217 |
| 215 Args: | 218 Args: |
| 216 environments: List of SCons environments. | 219 environments: List of SCons environments. |
| 220 |
| 221 Returns: |
| 222 List of environments which were actually evaluated (built). |
| 217 """ | 223 """ |
| 218 # Get options | 224 # Get options |
| 219 xml_help = SCons.Script.GetOption('xml_help') | 225 xml_help = SCons.Script.GetOption('xml_help') |
| 220 build_modes = SCons.Script.GetOption('build_mode') | 226 build_modes = SCons.Script.GetOption('build_mode') |
| 221 # TODO(rspangler): Remove support legacy MODE= argument, once everyone has | 227 # TODO(rspangler): Remove support legacy MODE= argument, once everyone has |
| 222 # transitioned to --mode. | 228 # transitioned to --mode. |
| 223 legacy_mode_option = SCons.Script.ARGUMENTS.get('MODE') | 229 legacy_mode_option = SCons.Script.ARGUMENTS.get('MODE') |
| 224 if legacy_mode_option: | 230 if legacy_mode_option: |
| 225 build_modes = legacy_mode_option | 231 build_modes = legacy_mode_option |
| 226 build_modes = build_modes.split(',') | 232 build_modes = build_modes.split(',') |
| 227 | 233 |
| 228 host_platform = SCons.Script.GetOption('host_platform') | 234 host_platform = SCons.Script.GetOption('host_platform') |
| 229 if not host_platform: | 235 if not host_platform: |
| 230 host_platform = _HostPlatform() | 236 host_platform = _HostPlatform() |
| 231 | 237 |
| 232 # Check build modes | 238 # Check build modes |
| 233 _CheckBuildModes(build_modes, environments, host_platform) | 239 _CheckBuildModes(build_modes, environments, host_platform) |
| 234 | 240 |
| 235 if xml_help: | 241 if xml_help: |
| 236 SCons.Script.Help('<help_from_sconscripts>\n<![CDATA[\n') | 242 SCons.Script.Help('<help_from_sconscripts>\n<![CDATA[\n') |
| 237 | 243 |
| 244 environments_to_evaluate = [] |
| 238 for e in environments: | 245 for e in environments: |
| 239 if not e.Overlap(e['HOST_PLATFORMS'], [host_platform, '*']): | 246 if not e.Overlap(e['HOST_PLATFORMS'], [host_platform, '*']): |
| 240 continue # Environment requires a host platform which isn't us | 247 continue # Environment requires a host platform which isn't us |
| 241 | 248 |
| 242 if e.Overlap([e['BUILD_TYPE'], e['BUILD_GROUPS']], build_modes): | 249 if e.Overlap([e['BUILD_TYPE'], e['BUILD_GROUPS']], build_modes): |
| 243 # Set up for deferred functions and published resources | 250 environments_to_evaluate.append(e) |
| 244 e._InitializeComponentBuilders() | |
| 245 e._InitializeDefer() | |
| 246 e._InitializePublish() | |
| 247 | 251 |
| 248 # Read SConscript for each component | 252 for e in environments_to_evaluate: |
| 249 # TODO(rspangler): Remove BUILD_COMPONENTS once all projects have | 253 # Set up for deferred functions and published resources |
| 250 # transitioned to the BUILD_SCONSCRIPTS nomenclature. | 254 e._InitializeComponentBuilders() |
| 251 for c in e.get('BUILD_COMPONENTS', []) + e.get('BUILD_SCONSCRIPTS', []): | 255 e._InitializeDefer() |
| 252 # Clone the environment so components can't interfere with each other | 256 e._InitializePublish() |
| 253 ec = e.Clone() | |
| 254 | 257 |
| 255 if ec.Entry(c).isdir(): | 258 # Read SConscript for each component |
| 256 # The component is a directory, so assume it contains a SConscript | 259 # TODO(rspangler): Remove BUILD_COMPONENTS once all projects have |
| 257 # file. | 260 # transitioned to the BUILD_SCONSCRIPTS nomenclature. |
| 258 c_dir = ec.Dir(c) | 261 for c in e.get('BUILD_COMPONENTS', []) + e.get('BUILD_SCONSCRIPTS', []): |
| 262 # Clone the environment so components can't interfere with each other |
| 263 ec = e.Clone() |
| 259 | 264 |
| 260 # Use 'build.scons' as the default filename, but if that doesn't | 265 if ec.Entry(c).isdir(): |
| 261 # exist, fall back to 'SConscript'. | 266 # The component is a directory, so assume it contains a SConscript |
| 262 c_script = c_dir.File('build.scons') | 267 # file. |
| 263 if not c_script.exists(): | 268 c_dir = ec.Dir(c) |
| 264 c_script = c_dir.File('SConscript') | |
| 265 else: | |
| 266 # The component is a SConscript file. | |
| 267 c_script = ec.File(c) | |
| 268 c_dir = c_script.dir | |
| 269 | 269 |
| 270 ec.SConscript(c_script, | 270 # Use 'build.scons' as the default filename, but if that doesn't |
| 271 build_dir='$OBJ_ROOT/' + str(c_dir), | 271 # exist, fall back to 'SConscript'. |
| 272 exports={'env': ec}, | 272 c_script = c_dir.File('build.scons') |
| 273 duplicate=0) | 273 if not c_script.exists(): |
| 274 c_script = c_dir.File('SConscript') |
| 275 else: |
| 276 # The component is a SConscript file. |
| 277 c_script = ec.File(c) |
| 278 c_dir = c_script.dir |
| 274 | 279 |
| 275 # Execute deferred functions | 280 ec.SConscript(c_script, |
| 276 e._ExecuteDefer() | 281 build_dir='$OBJ_ROOT/' + str(c_dir), |
| 282 exports={'env': ec}, |
| 283 duplicate=0) |
| 284 |
| 285 # Execute deferred functions |
| 286 e._ExecuteDefer() |
| 277 | 287 |
| 278 if xml_help: | 288 if xml_help: |
| 279 SCons.Script.Help(']]>\n</help_from_sconscripts>\n') | 289 SCons.Script.Help(']]>\n</help_from_sconscripts>\n') |
| 280 | 290 |
| 281 _AddTargetHelp() | 291 _AddTargetHelp() |
| 282 | 292 |
| 283 # End final help tag | 293 # End final help tag |
| 284 if xml_help: | 294 if xml_help: |
| 285 SCons.Script.Help('</help>\n') | 295 SCons.Script.Help('</help>\n') |
| 286 | 296 |
| 297 # Return list of environments actually evaluated |
| 298 return environments_to_evaluate |
| 299 |
| 287 | 300 |
| 288 #------------------------------------------------------------------------------ | 301 #------------------------------------------------------------------------------ |
| 289 | 302 |
| 290 | 303 |
| 291 def _ToolExists(): | 304 def _ToolExists(): |
| 292 """Replacement for SCons tool module exists() function, if one isn't present. | 305 """Replacement for SCons tool module exists() function, if one isn't present. |
| 293 | 306 |
| 294 Returns: | 307 Returns: |
| 295 True. This enables modules which always exist not to need to include a | 308 True. This enables modules which always exist not to need to include a |
| 296 dummy exists() function. | 309 dummy exists() function. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 to use the wrong tools for your actual platform. | 371 to use the wrong tools for your actual platform. |
| 359 --site-path=DIRLIST Comma-separated list of additional site | 372 --site-path=DIRLIST Comma-separated list of additional site |
| 360 directory paths; each is processed as if passed | 373 directory paths; each is processed as if passed |
| 361 to --site-dir. | 374 to --site-dir. |
| 362 --xml-help Print help in XML format. | 375 --xml-help Print help in XML format. |
| 363 ''' | 376 ''' |
| 364 | 377 |
| 365 def SiteInitMain(): | 378 def SiteInitMain(): |
| 366 """Main code executed in site_init.""" | 379 """Main code executed in site_init.""" |
| 367 | 380 |
| 381 # Bail out if we've been here before. This is needed to handle the case where |
| 382 # this site_init.py has been dropped into a project directory. |
| 383 if hasattr(__builtin__, 'BuildEnvironments'): |
| 384 return |
| 385 |
| 368 # Let people use new global methods directly. | 386 # Let people use new global methods directly. |
| 369 __builtin__.AddSiteDir = AddSiteDir | 387 __builtin__.AddSiteDir = AddSiteDir |
| 370 __builtin__.BuildComponents = BuildComponents | 388 __builtin__.BuildEnvironments = BuildEnvironments |
| 371 __builtin__.AddTargetGroup = AddTargetGroup | 389 __builtin__.AddTargetGroup = AddTargetGroup |
| 390 # Legacy method names |
| 391 # TODO(rspangler): Remove these once they're no longer used anywhere. |
| 392 __builtin__.BuildComponents = BuildEnvironments |
| 393 |
| 372 | 394 |
| 373 # Set list of default tools for component_setup | 395 # Set list of default tools for component_setup |
| 374 __builtin__.component_setup_tools = [ | 396 __builtin__.component_setup_tools = [ |
| 375 'command_output', | 397 'command_output', |
| 376 'component_bits', | 398 'component_bits', |
| 377 'component_builders', | 399 'component_builders', |
| 378 'concat_source', | 400 'concat_source', |
| 379 'defer', | 401 'defer', |
| 380 'environment_tools', | 402 'environment_tools', |
| 381 'publish', | 403 'publish', |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 454 |
| 433 # Since our site dir was specified on the SCons command line, SCons will | 455 # Since our site dir was specified on the SCons command line, SCons will |
| 434 # normally only look at our site dir. Add back checking for project-local | 456 # normally only look at our site dir. Add back checking for project-local |
| 435 # site_scons directories. | 457 # site_scons directories. |
| 436 if not SCons.Script.GetOption('no_site_dir'): | 458 if not SCons.Script.GetOption('no_site_dir'): |
| 437 SCons.Script.Main._load_site_scons_dir( | 459 SCons.Script.Main._load_site_scons_dir( |
| 438 SCons.Node.FS.get_default_fs().SConstruct_dir, None) | 460 SCons.Node.FS.get_default_fs().SConstruct_dir, None) |
| 439 | 461 |
| 440 # Run main code | 462 # Run main code |
| 441 SiteInitMain() | 463 SiteInitMain() |
| OLD | NEW |