| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 """Software construction toolkit builders for SCons.""" | 31 """Software construction toolkit builders for SCons.""" |
| 32 | 32 |
| 33 | 33 |
| 34 import SCons | 34 import SCons |
| 35 | 35 |
| 36 | 36 |
| 37 __component_list = {} | 37 __component_list = {} |
| 38 | 38 |
| 39 | 39 |
| 40 def _InitializeComponentBuilders(self): | 40 def _InitializeComponentBuilders(env): |
| 41 """Re-initializes component builders module. | 41 """Re-initializes component builders module. |
| 42 | 42 |
| 43 Args: | 43 Args: |
| 44 self: Parent environment. | 44 env: Environment context |
| 45 """ | 45 """ |
| 46 self = self # Silence gpylint | 46 env = env # Silence gpylint |
| 47 | 47 |
| 48 __component_list.clear() | 48 __component_list.clear() |
| 49 | 49 |
| 50 | 50 |
| 51 def _RetrieveComponents(component_name, filter_components=None): | 51 def _RetrieveComponents(component_name, filter_components=None): |
| 52 """Get the list of all components required by the specified component. | 52 """Get the list of all components required by the specified component. |
| 53 | 53 |
| 54 Args: | 54 Args: |
| 55 component_name: Name of the base component. | 55 component_name: Name of the base component. |
| 56 filter_components: List of components NOT to include. | 56 filter_components: List of components NOT to include. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 ) | 180 ) |
| 181 | 181 |
| 182 # Add an empty alias for the package and add it to the right groups | 182 # Add an empty alias for the package and add it to the right groups |
| 183 a = env.Alias(package_name, []) | 183 a = env.Alias(package_name, []) |
| 184 for group in env['COMPONENT_PACKAGE_GROUPS']: | 184 for group in env['COMPONENT_PACKAGE_GROUPS']: |
| 185 SCons.Script.Alias(group, a) | 185 SCons.Script.Alias(group, a) |
| 186 | 186 |
| 187 # Store list of components for this program | 187 # Store list of components for this program |
| 188 env._StoreComponents(package_name) | 188 env._StoreComponents(package_name) |
| 189 | 189 |
| 190 # Let component_targets know this target is available in the current mode |
| 191 env.SetTargetProperty(package_name, TARGET_PATH=dest_dir) |
| 192 |
| 190 # Set up deferred call to replicate resources | 193 # Set up deferred call to replicate resources |
| 191 env.Defer(ComponentPackageDeferred) | 194 env.Defer(ComponentPackageDeferred) |
| 192 | 195 |
| 193 # Return the alias, since it's the only node we have | 196 # Return the alias, since it's the only node we have |
| 194 return a | 197 return a |
| 195 | 198 |
| 196 #------------------------------------------------------------------------------ | 199 #------------------------------------------------------------------------------ |
| 197 | 200 |
| 198 | 201 |
| 199 def ComponentObject(self, *args, **kwargs): | 202 def ComponentObject(self, *args, **kwargs): |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 if o.suffix in env['COMPONENT_LIBRARY_LINK_SUFFIXES']: | 263 if o.suffix in env['COMPONENT_LIBRARY_LINK_SUFFIXES']: |
| 261 need_for_link.append(o) | 264 need_for_link.append(o) |
| 262 if o.suffix in env['COMPONENT_LIBRARY_DEBUG_SUFFIXES']: | 265 if o.suffix in env['COMPONENT_LIBRARY_DEBUG_SUFFIXES']: |
| 263 need_for_debug.append(o) | 266 need_for_debug.append(o) |
| 264 if o.suffix == env['SHLIBSUFFIX']: | 267 if o.suffix == env['SHLIBSUFFIX']: |
| 265 need_for_run.append(o) | 268 need_for_run.append(o) |
| 266 all_outputs = lib_outputs | 269 all_outputs = lib_outputs |
| 267 | 270 |
| 268 # Install library in intermediate directory, so other libs and programs can | 271 # Install library in intermediate directory, so other libs and programs can |
| 269 # link against it | 272 # link against it |
| 270 all_outputs += env.Replicate('$COMPONENT_LIBRARY_DIR', need_for_link) | 273 all_outputs += env.Replicate('$LIB_DIR', need_for_link) |
| 271 | 274 |
| 272 # Publish output | 275 # Publish output |
| 273 env.Publish(lib_name, 'run', need_for_run) | 276 env.Publish(lib_name, 'run', need_for_run) |
| 274 env.Publish(lib_name, 'debug', need_for_debug) | 277 env.Publish(lib_name, 'debug', need_for_debug) |
| 275 | 278 |
| 276 # Add an alias to build and copy the library, and add it to the right groups | 279 # Add an alias to build and copy the library, and add it to the right groups |
| 277 a = self.Alias(lib_name, all_outputs) | 280 a = self.Alias(lib_name, all_outputs) |
| 278 for group in env['COMPONENT_LIBRARY_GROUPS']: | 281 for group in env['COMPONENT_LIBRARY_GROUPS']: |
| 279 SCons.Script.Alias(group, a) | 282 SCons.Script.Alias(group, a) |
| 280 | 283 |
| 281 # Store list of components for this library | 284 # Store list of components for this library |
| 282 env._StoreComponents(lib_name) | 285 env._StoreComponents(lib_name) |
| 283 | 286 |
| 287 # Let component_targets know this target is available in the current mode. |
| 288 env.SetTargetProperty(lib_name, TARGET_PATH=lib_outputs[0]) |
| 289 |
| 284 # If library should publish itself, publish as if it was a program | 290 # If library should publish itself, publish as if it was a program |
| 285 if env.get('COMPONENT_LIBRARY_PUBLISH'): | 291 if env.get('COMPONENT_LIBRARY_PUBLISH'): |
| 286 env['PROGRAM_BASENAME'] = lib_name | 292 env['PROGRAM_BASENAME'] = lib_name |
| 287 env.Defer(ComponentProgramDeferred) | 293 env.Defer(ComponentProgramDeferred) |
| 288 | 294 |
| 289 # Return the library outputs | 295 # Return the library outputs |
| 290 return lib_outputs | 296 return lib_outputs |
| 291 | 297 |
| 292 #------------------------------------------------------------------------------ | 298 #------------------------------------------------------------------------------ |
| 293 | 299 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 # Run the test. Note that we need to refer to the file by name, so that | 342 # Run the test. Note that we need to refer to the file by name, so that |
| 337 # SCons will recreate the file node after we've deleted it; if we used the | 343 # SCons will recreate the file node after we've deleted it; if we used the |
| 338 # env.File() we created in the if statement above, SCons would still think | 344 # env.File() we created in the if statement above, SCons would still think |
| 339 # it exists and not rerun the test. | 345 # it exists and not rerun the test. |
| 340 test_out = env.CommandOutput(test_out_name, test_program) | 346 test_out = env.CommandOutput(test_out_name, test_program) |
| 341 | 347 |
| 342 # Running the test requires the test and its libs copied to the tests dir | 348 # Running the test requires the test and its libs copied to the tests dir |
| 343 env.Depends(test_out, all_outputs) | 349 env.Depends(test_out, all_outputs) |
| 344 env.ComponentTestOutput('run_' + prog_name, test_out) | 350 env.ComponentTestOutput('run_' + prog_name, test_out) |
| 345 | 351 |
| 352 # Add target properties |
| 353 env.SetTargetProperty( |
| 354 prog_name, |
| 355 # The copy of the program we care about is the one in the tests dir |
| 356 EXE='$TESTS_DIR/$PROGRAM_NAME', |
| 357 RUN_TARGET='run_' + prog_name, |
| 358 RUN_CMDLINE='$COMPONENT_TEST_CMDLINE', |
| 359 RUN_DIR='$TESTS_DIR', |
| 360 TARGET_PATH='$TESTS_DIR/$PROGRAM_NAME', |
| 361 ) |
| 362 |
| 346 | 363 |
| 347 def ComponentTestProgram(self, prog_name, *args, **kwargs): | 364 def ComponentTestProgram(self, prog_name, *args, **kwargs): |
| 348 """Pseudo-builder for test program to handle platform-dependent type. | 365 """Pseudo-builder for test program to handle platform-dependent type. |
| 349 | 366 |
| 350 Args: | 367 Args: |
| 351 self: Environment in which we were called. | 368 self: Environment in which we were called. |
| 352 prog_name: Test program name. | 369 prog_name: Test program name. |
| 353 args: Positional arguments. | 370 args: Positional arguments. |
| 354 kwargs: Keyword arguments. | 371 kwargs: Keyword arguments. |
| 355 | 372 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 375 env.Publish(prog_name, 'debug', out_nodes[1:]) | 392 env.Publish(prog_name, 'debug', out_nodes[1:]) |
| 376 | 393 |
| 377 # Add an alias to build the program to the right groups | 394 # Add an alias to build the program to the right groups |
| 378 a = env.Alias(prog_name, out_nodes) | 395 a = env.Alias(prog_name, out_nodes) |
| 379 for group in env['COMPONENT_TEST_PROGRAM_GROUPS']: | 396 for group in env['COMPONENT_TEST_PROGRAM_GROUPS']: |
| 380 SCons.Script.Alias(group, a) | 397 SCons.Script.Alias(group, a) |
| 381 | 398 |
| 382 # Store list of components for this program | 399 # Store list of components for this program |
| 383 env._StoreComponents(prog_name) | 400 env._StoreComponents(prog_name) |
| 384 | 401 |
| 402 # Let component_targets know this target is available in the current mode |
| 403 env.SetTargetProperty(prog_name, TARGET_PATH=out_nodes[0]) |
| 404 |
| 385 # Set up deferred call to replicate resources and run test | 405 # Set up deferred call to replicate resources and run test |
| 386 env.Defer(ComponentTestProgramDeferred) | 406 env.Defer(ComponentTestProgramDeferred) |
| 387 | 407 |
| 388 # Return the output node | 408 # Return the output node |
| 389 return out_nodes | 409 return out_nodes |
| 390 | 410 |
| 391 #------------------------------------------------------------------------------ | 411 #------------------------------------------------------------------------------ |
| 392 | 412 |
| 393 | 413 |
| 394 def ComponentProgramDeferred(env): | 414 def ComponentProgramDeferred(env): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 env.Publish(prog_name, 'debug', out_nodes[1:]) | 459 env.Publish(prog_name, 'debug', out_nodes[1:]) |
| 440 | 460 |
| 441 # Add an alias to build the program to the right groups | 461 # Add an alias to build the program to the right groups |
| 442 a = env.Alias(prog_name, out_nodes) | 462 a = env.Alias(prog_name, out_nodes) |
| 443 for group in env['COMPONENT_PROGRAM_GROUPS']: | 463 for group in env['COMPONENT_PROGRAM_GROUPS']: |
| 444 SCons.Script.Alias(group, a) | 464 SCons.Script.Alias(group, a) |
| 445 | 465 |
| 446 # Store list of components for this program | 466 # Store list of components for this program |
| 447 env._StoreComponents(prog_name) | 467 env._StoreComponents(prog_name) |
| 448 | 468 |
| 469 # Let component_targets know this target is available in the current mode |
| 470 env.SetTargetProperty(prog_name) |
| 471 |
| 449 # Set up deferred call to replicate resources | 472 # Set up deferred call to replicate resources |
| 450 env.Defer(ComponentProgramDeferred) | 473 env.Defer(ComponentProgramDeferred) |
| 451 | 474 |
| 452 # Return the output nodes | 475 # Return the output nodes |
| 453 return out_nodes | 476 return out_nodes |
| 454 | 477 |
| 455 #------------------------------------------------------------------------------ | 478 #------------------------------------------------------------------------------ |
| 456 | 479 |
| 457 | 480 |
| 458 def ComponentTestOutput(self, test_name, nodes): | 481 def ComponentTestOutput(self, test_name, nodes): |
| (...skipping 19 matching lines...) Expand all Loading... |
| 478 groups = ['run_all_tests'] | 501 groups = ['run_all_tests'] |
| 479 if self.get('COMPONENT_TEST_SIZE'): | 502 if self.get('COMPONENT_TEST_SIZE'): |
| 480 groups.append(self.subst('run_${COMPONENT_TEST_SIZE}_tests')) | 503 groups.append(self.subst('run_${COMPONENT_TEST_SIZE}_tests')) |
| 481 else: | 504 else: |
| 482 # Disabled tests only go in their group | 505 # Disabled tests only go in their group |
| 483 groups = ['run_disabled_tests'] | 506 groups = ['run_disabled_tests'] |
| 484 | 507 |
| 485 for group in groups: | 508 for group in groups: |
| 486 SCons.Script.Alias(group, a) | 509 SCons.Script.Alias(group, a) |
| 487 | 510 |
| 511 # Let component_targets know this target is available in the current mode |
| 512 self.SetTargetProperty(test_name, TARGET_PATH=nodes[0]) |
| 513 |
| 488 # Return the output node | 514 # Return the output node |
| 489 return a | 515 return a |
| 490 | 516 |
| 491 #------------------------------------------------------------------------------ | 517 #------------------------------------------------------------------------------ |
| 492 | 518 |
| 493 | 519 |
| 494 def generate(env): | 520 def generate(env): |
| 495 # NOTE: SCons requires the use of this name, which fails gpylint. | 521 # NOTE: SCons requires the use of this name, which fails gpylint. |
| 496 """SCons entry point for this tool.""" | 522 """SCons entry point for this tool.""" |
| 497 | 523 |
| 498 env.Replace( | 524 env.Replace( |
| 499 COMPONENT_LIBRARY_DIR='$TARGET_ROOT/lib', | 525 LIB_DIR='$TARGET_ROOT/lib', |
| 526 # TODO(rspangler): Remove legacy COMPONENT_LIBRARY_DIR, once all users |
| 527 # have transitioned to LIB_DIR |
| 528 COMPONENT_LIBRARY_DIR='$LIB_DIR', |
| 500 STAGING_DIR='$TARGET_ROOT/staging', | 529 STAGING_DIR='$TARGET_ROOT/staging', |
| 501 TESTS_DIR='$TARGET_ROOT/tests', | 530 TESTS_DIR='$TARGET_ROOT/tests', |
| 502 TEST_OUTPUT_DIR='$TARGET_ROOT/test_output', | 531 TEST_OUTPUT_DIR='$TARGET_ROOT/test_output', |
| 503 # Default command line for a test is just the name of the file. | 532 # Default command line for a test is just the name of the file. |
| 504 # TODO(rspangler): Why doesn't the following work: | 533 # TODO(rspangler): Why doesn't the following work: |
| 505 # COMPONENT_TEST_CMDLINE='${SOURCE.abspath}', | 534 # COMPONENT_TEST_CMDLINE='${SOURCE.abspath}', |
| 506 # (it generates a SCons error) | 535 # (it generates a SCons error) |
| 507 COMPONENT_TEST_CMDLINE='${PROGRAM_NAME}', | 536 COMPONENT_TEST_CMDLINE='${PROGRAM_NAME}', |
| 508 # Default test size is large | 537 # Default test size is large |
| 509 COMPONENT_TEST_SIZE='large', | 538 COMPONENT_TEST_SIZE='large', |
| 510 # Default timeouts for component tests | 539 # Default timeouts for component tests |
| 511 COMPONENT_TEST_TIMEOUT={'large':900, 'medium':450, 'small':180}, | 540 COMPONENT_TEST_TIMEOUT={'large': 900, 'medium': 450, 'small': 180}, |
| 512 # Tests are enabled by default | 541 # Tests are enabled by default |
| 513 COMPONENT_TEST_ENABLED=True, | 542 COMPONENT_TEST_ENABLED=True, |
| 514 # Static linking is a sensible default | 543 # Static linking is a sensible default |
| 515 COMPONENT_STATIC=True, | 544 COMPONENT_STATIC=True, |
| 516 # Don't publish libraries to the staging dir by themselves by default. | 545 # Don't publish libraries to the staging dir by themselves by default. |
| 517 COMPONENT_LIBRARY_PUBLISH=False, | 546 COMPONENT_LIBRARY_PUBLISH=False, |
| 518 ) | 547 ) |
| 519 env.Append( | 548 env.Append( |
| 520 LIBPATH=['$COMPONENT_LIBRARY_DIR'], | 549 LIBPATH=['$LIB_DIR'], |
| 521 RPATH=['$COMPONENT_LIBRARY_DIR'], | 550 RPATH=['$LIB_DIR'], |
| 522 | 551 |
| 523 # Default alias groups for component builders | 552 # Default alias groups for component builders |
| 524 COMPONENT_PACKAGE_GROUPS=['all_packages'], | 553 COMPONENT_PACKAGE_GROUPS=['all_packages'], |
| 525 COMPONENT_LIBRARY_GROUPS=['all_libraries'], | 554 COMPONENT_LIBRARY_GROUPS=['all_libraries'], |
| 526 COMPONENT_PROGRAM_GROUPS=['all_programs'], | 555 COMPONENT_PROGRAM_GROUPS=['all_programs'], |
| 527 COMPONENT_TEST_PROGRAM_GROUPS=['all_test_programs'], | 556 COMPONENT_TEST_PROGRAM_GROUPS=['all_test_programs'], |
| 528 | 557 |
| 529 # Additional components whose resources should be copied into program | 558 # Additional components whose resources should be copied into program |
| 530 # directories, in addition to those from LIBS and the program itself. | 559 # directories, in addition to those from LIBS and the program itself. |
| 531 LIBS=[], | 560 LIBS=[], |
| (...skipping 18 matching lines...) Expand all Loading... |
| 550 | 579 |
| 551 # Add command line option for retest | 580 # Add command line option for retest |
| 552 SCons.Script.AddOption( | 581 SCons.Script.AddOption( |
| 553 '--retest', | 582 '--retest', |
| 554 dest='component_test_retest', | 583 dest='component_test_retest', |
| 555 action='store_true', | 584 action='store_true', |
| 556 help='force all tests to rerun') | 585 help='force all tests to rerun') |
| 557 SCons.Script.Help(' --retest ' | 586 SCons.Script.Help(' --retest ' |
| 558 'Rerun specified tests, ignoring cached results.\n') | 587 'Rerun specified tests, ignoring cached results.\n') |
| 559 | 588 |
| 589 # Defer per-environment initialization, but do before building SConscripts |
| 590 env.Defer(_InitializeComponentBuilders) |
| 591 env.Defer('BuildEnvironmentSConscripts', after=_InitializeComponentBuilders) |
| 592 |
| 560 # Add our pseudo-builder methods | 593 # Add our pseudo-builder methods |
| 561 env.AddMethod(_InitializeComponentBuilders) | |
| 562 env.AddMethod(_StoreComponents) | 594 env.AddMethod(_StoreComponents) |
| 563 env.AddMethod(ComponentPackage) | 595 env.AddMethod(ComponentPackage) |
| 564 env.AddMethod(ComponentObject) | 596 env.AddMethod(ComponentObject) |
| 565 env.AddMethod(ComponentLibrary) | 597 env.AddMethod(ComponentLibrary) |
| 566 env.AddMethod(ComponentProgram) | 598 env.AddMethod(ComponentProgram) |
| 567 env.AddMethod(ComponentTestProgram) | 599 env.AddMethod(ComponentTestProgram) |
| 568 env.AddMethod(ComponentTestOutput) | 600 env.AddMethod(ComponentTestOutput) |
| 569 | 601 |
| 570 # Add our target groups | 602 # Add our target groups |
| 571 AddTargetGroup('all_libraries', 'libraries can be built') | 603 AddTargetGroup('all_libraries', 'libraries can be built') |
| 572 AddTargetGroup('all_programs', 'programs can be built') | 604 AddTargetGroup('all_programs', 'programs can be built') |
| 573 AddTargetGroup('all_test_programs', 'tests can be built') | 605 AddTargetGroup('all_test_programs', 'tests can be built') |
| 574 AddTargetGroup('all_packages', 'packages can be built') | 606 AddTargetGroup('all_packages', 'packages can be built') |
| 575 AddTargetGroup('run_all_tests', 'tests can be run') | 607 AddTargetGroup('run_all_tests', 'tests can be run') |
| 576 AddTargetGroup('run_disabled_tests', 'tests are disabled') | 608 AddTargetGroup('run_disabled_tests', 'tests are disabled') |
| 577 AddTargetGroup('run_small_tests', 'small tests can be run') | 609 AddTargetGroup('run_small_tests', 'small tests can be run') |
| 578 AddTargetGroup('run_medium_tests', 'medium tests can be run') | 610 AddTargetGroup('run_medium_tests', 'medium tests can be run') |
| 579 AddTargetGroup('run_large_tests', 'large tests can be run') | 611 AddTargetGroup('run_large_tests', 'large tests can be run') |
| 580 | 612 |
| OLD | NEW |