Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: site_scons/site_tools/component_builders.py

Issue 8117: Pulling in latest software construction toolkit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « site_scons/site_tools/component_bits.py ('k') | site_scons/site_tools/concat_source.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 Returns: 112 Returns:
113 A modified clone of the environment. 113 A modified clone of the environment.
114 """ 114 """
115 # Clone environment so we can modify it 115 # Clone environment so we can modify it
116 env = env.Clone() 116 env = env.Clone()
117 117
118 # Add all keyword arguments to the environment 118 # Add all keyword arguments to the environment
119 for k, v in kwargs.items(): 119 for k, v in kwargs.items():
120 env[k] = v 120 env[k] = v
121 121
122 # Add compiler flags for included headers, if any
123 env['INCLUDES'] = env.Flatten(env.subst_list(['$INCLUDES']))
124 for h in env['INCLUDES']:
125 env.Append(CCFLAGS = ['${CCFLAG_INCLUDE}%s' % h])
126
122 # Call platform-specific component setup function, if any 127 # Call platform-specific component setup function, if any
123 if env.get('COMPONENT_PLATFORM_SETUP'): 128 if env.get('COMPONENT_PLATFORM_SETUP'):
124 env['COMPONENT_PLATFORM_SETUP'](env, builder_name) 129 env['COMPONENT_PLATFORM_SETUP'](env, builder_name)
125 130
126 # Return the modified environment 131 # Return the modified environment
127 return env 132 return env
128 133
129 #------------------------------------------------------------------------------ 134 #------------------------------------------------------------------------------
130 135
131 # TODO(rspangler): Should be possible to refactor programs, test programs, 136 # TODO(rspangler): Should be possible to refactor programs, test programs,
132 # libs to all publish as packages, for simplicity and code reuse. 137 # libs to all publish as packages, for simplicity and code reuse.
133 138
134 139
135 def ComponentPackageDeferred(env): 140 def ComponentPackageDeferred(env):
136 """Deferred build steps for component package. 141 """Deferred build steps for component package.
137 142
138 Args: 143 Args:
139 env: Environment from ComponentPackage(). 144 env: Environment from ComponentPackage().
140 145
141 Sets up the aliases to build the package. 146 Sets up the aliases to build the package.
142 """ 147 """
143 package_name = env['PACKAGE_NAME'] 148 package_name = env['PACKAGE_NAME']
144 149
145 # Install program and resources 150 # Install program and resources
146 all_outputs = [] 151 all_outputs = []
147 components = _RetrieveComponents(package_name, 152 filter = env.Flatten(env.subst_list('$COMPONENT_PACKAGE_FILTER'))
148 env.get('COMPONENT_PACKAGE_FILTER')) 153 components = _RetrieveComponents(package_name, filter)
149 for resource, dest_dir in env.get('COMPONENT_PACKAGE_RESOURCES').items(): 154 for resource, dest_dir in env.get('COMPONENT_PACKAGE_RESOURCES').items():
150 all_outputs += env.ReplicatePublished(dest_dir, components, resource) 155 all_outputs += env.ReplicatePublished(dest_dir, components, resource)
151 156
152 # Add installed program and resources to the alias 157 # Add installed program and resources to the alias
153 env.Alias(package_name, all_outputs) 158 env.Alias(package_name, all_outputs)
154 159
155 160
156 def ComponentPackage(self, package_name, dest_dir, **kwargs): 161 def ComponentPackage(self, package_name, dest_dir, **kwargs):
157 """Pseudo-builder for package containing other components. 162 """Pseudo-builder for package containing other components.
158 163
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 Passthrough return code from env.StaticLibrary() or env.SharedLibrary(). 208 Passthrough return code from env.StaticLibrary() or env.SharedLibrary().
204 209
205 TODO(rspangler): Perhaps this should be a generator builder, so it can take 210 TODO(rspangler): Perhaps this should be a generator builder, so it can take
206 a list of inputs and return a list of outputs? 211 a list of inputs and return a list of outputs?
207 """ 212 """
208 # Clone and modify environment 213 # Clone and modify environment
209 env = _ComponentPlatformSetup(self, 'ComponentObject', **kwargs) 214 env = _ComponentPlatformSetup(self, 'ComponentObject', **kwargs)
210 215
211 # Make appropriate object type 216 # Make appropriate object type
212 if env.get('COMPONENT_STATIC'): 217 if env.get('COMPONENT_STATIC'):
213 return env.StaticObject(*args, **kwargs) 218 o = env.StaticObject(*args, **kwargs)
214 else: 219 else:
215 return env.SharedObject(*args, **kwargs) 220 o = env.SharedObject(*args, **kwargs)
221
222 # Add dependencies on includes
223 env.Depends(o, env['INCLUDES'])
224
225 return o
216 226
217 #------------------------------------------------------------------------------ 227 #------------------------------------------------------------------------------
218 228
219 229
220 def ComponentLibrary(self, lib_name, *args, **kwargs): 230 def ComponentLibrary(self, lib_name, *args, **kwargs):
221 """Pseudo-builder for library to handle platform-dependent type. 231 """Pseudo-builder for library to handle platform-dependent type.
222 232
223 Args: 233 Args:
224 self: Environment in which we were called. 234 self: Environment in which we were called.
225 lib_name: Library name. 235 lib_name: Library name.
226 args: Positional arguments. 236 args: Positional arguments.
227 kwargs: Keyword arguments. 237 kwargs: Keyword arguments.
228 238
229 Returns: 239 Returns:
230 Passthrough return code from env.StaticLibrary() or env.SharedLibrary(). 240 Passthrough return code from env.StaticLibrary() or env.SharedLibrary().
231 """ 241 """
232 # Clone and modify environment 242 # Clone and modify environment
233 env = _ComponentPlatformSetup(self, 'ComponentLibrary', **kwargs) 243 env = _ComponentPlatformSetup(self, 'ComponentLibrary', **kwargs)
234 244
235 # Make appropriate library type 245 # Make appropriate library type
236 if env.get('COMPONENT_STATIC'): 246 if env.get('COMPONENT_STATIC'):
237 lib_outputs = env.StaticLibrary(lib_name, *args, **kwargs) 247 lib_outputs = env.StaticLibrary(lib_name, *args, **kwargs)
238 else: 248 else:
239 lib_outputs = env.SharedLibrary(lib_name, *args, **kwargs) 249 lib_outputs = env.SharedLibrary(lib_name, *args, **kwargs)
240 250
251 # Add dependencies on includes
252 env.Depends(lib_outputs, env['INCLUDES'])
253
241 # Scan library outputs for files we need to link against this library, and 254 # Scan library outputs for files we need to link against this library, and
242 # files we need to run executables linked against this library. 255 # files we need to run executables linked against this library.
243 need_for_link = [] 256 need_for_link = []
244 need_for_debug = [] 257 need_for_debug = []
245 need_for_run = [] 258 need_for_run = []
246 for o in lib_outputs: 259 for o in lib_outputs:
247 if o.suffix in env['COMPONENT_LIBRARY_LINK_SUFFIXES']: 260 if o.suffix in env['COMPONENT_LIBRARY_LINK_SUFFIXES']:
248 need_for_link.append(o) 261 need_for_link.append(o)
249 if o.suffix in env['COMPONENT_LIBRARY_DEBUG_SUFFIXES']: 262 if o.suffix in env['COMPONENT_LIBRARY_DEBUG_SUFFIXES']:
250 need_for_debug.append(o) 263 need_for_debug.append(o)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 313
301 # Add an alias for running the test in the test directory, if there's a test 314 # Add an alias for running the test in the test directory, if there's a test
302 # command line. 315 # command line.
303 if env.get('COMPONENT_TEST_CMDLINE'): 316 if env.get('COMPONENT_TEST_CMDLINE'):
304 # Test program is the first run resource we replicated. 317 # Test program is the first run resource we replicated.
305 test_program = env.ReplicatePublished('$TESTS_DIR', prog_name, 'run') 318 test_program = env.ReplicatePublished('$TESTS_DIR', prog_name, 'run')
306 env.Replace( 319 env.Replace(
307 COMMAND_OUTPUT_CMDLINE=env['COMPONENT_TEST_CMDLINE'], 320 COMMAND_OUTPUT_CMDLINE=env['COMPONENT_TEST_CMDLINE'],
308 COMMAND_OUTPUT_RUN_DIR='$TESTS_DIR', 321 COMMAND_OUTPUT_RUN_DIR='$TESTS_DIR',
309 ) 322 )
310 test_out = env.CommandOutput( 323 test_out_name = '$TEST_OUTPUT_DIR/${PROGRAM_BASENAME}.out.txt'
311 '$TEST_OUTPUT_DIR/${PROGRAM_BASENAME}.out.txt', test_program) 324 if (env.GetOption('component_test_retest')
325 and env.File(test_out_name).exists()):
326 # Delete old test results, so test will rerun.
327 env.Execute(SCons.Script.Delete(test_out_name))
328
329 # Set timeout based on test size
330 timeout = env.get('COMPONENT_TEST_TIMEOUT')
331 if type(timeout) is dict:
332 timeout = timeout.get(env.get('COMPONENT_TEST_SIZE'))
333 if timeout:
334 env['COMMAND_OUTPUT_TIMEOUT'] = timeout
335
336 # 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
338 # env.File() we created in the if statement above, SCons would still think
339 # it exists and not rerun the test.
340 test_out = env.CommandOutput(test_out_name, test_program)
341
312 # Running the test requires the test and its libs copied to the tests dir 342 # Running the test requires the test and its libs copied to the tests dir
313 env.Depends(test_out, all_outputs) 343 env.Depends(test_out, all_outputs)
314 env.ComponentTestOutput('run_' + prog_name, test_out) 344 env.ComponentTestOutput('run_' + prog_name, test_out)
315 345
316 346
317 def ComponentTestProgram(self, prog_name, *args, **kwargs): 347 def ComponentTestProgram(self, prog_name, *args, **kwargs):
318 """Pseudo-builder for test program to handle platform-dependent type. 348 """Pseudo-builder for test program to handle platform-dependent type.
319 349
320 Args: 350 Args:
321 self: Environment in which we were called. 351 self: Environment in which we were called.
322 prog_name: Test program name. 352 prog_name: Test program name.
323 args: Positional arguments. 353 args: Positional arguments.
324 kwargs: Keyword arguments. 354 kwargs: Keyword arguments.
325 355
326 Returns: 356 Returns:
327 Output node list from env.Program(). 357 Output node list from env.Program().
328 358
329 TODO(rspangler): Should have some sort of support for S/M/L categorization 359 TODO(rspangler): Should have some sort of support for S/M/L categorization
330 """ 360 """
331 # Clone and modify environment 361 # Clone and modify environment
332 env = _ComponentPlatformSetup(self, 'ComponentTestProgram', **kwargs) 362 env = _ComponentPlatformSetup(self, 'ComponentTestProgram', **kwargs)
333 363
334 env['PROGRAM_BASENAME'] = prog_name 364 env['PROGRAM_BASENAME'] = prog_name
335 env['PROGRAM_NAME'] = '$PROGPREFIX$PROGRAM_BASENAME$PROGSUFFIX' 365 env['PROGRAM_NAME'] = '$PROGPREFIX$PROGRAM_BASENAME$PROGSUFFIX'
336 366
337 # Call env.Program() 367 # Call env.Program()
338 out_nodes = env.Program(prog_name, *args, **kwargs) 368 out_nodes = env.Program(prog_name, *args, **kwargs)
339 369
370 # Add dependencies on includes
371 env.Depends(out_nodes, env['INCLUDES'])
372
340 # Publish output 373 # Publish output
341 env.Publish(prog_name, 'run', out_nodes[0]) 374 env.Publish(prog_name, 'run', out_nodes[0])
342 env.Publish(prog_name, 'debug', out_nodes[1:]) 375 env.Publish(prog_name, 'debug', out_nodes[1:])
343 376
344 # Add an alias to build the program to the right groups 377 # Add an alias to build the program to the right groups
345 a = env.Alias(prog_name, out_nodes) 378 a = env.Alias(prog_name, out_nodes)
346 for group in env['COMPONENT_TEST_PROGRAM_GROUPS']: 379 for group in env['COMPONENT_TEST_PROGRAM_GROUPS']:
347 SCons.Script.Alias(group, a) 380 SCons.Script.Alias(group, a)
348 381
349 # Store list of components for this program 382 # Store list of components for this program
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 Output node list from env.Program(). 424 Output node list from env.Program().
392 """ 425 """
393 # Clone and modify environment 426 # Clone and modify environment
394 env = _ComponentPlatformSetup(self, 'ComponentProgram', **kwargs) 427 env = _ComponentPlatformSetup(self, 'ComponentProgram', **kwargs)
395 428
396 env['PROGRAM_BASENAME'] = prog_name 429 env['PROGRAM_BASENAME'] = prog_name
397 430
398 # Call env.Program() 431 # Call env.Program()
399 out_nodes = env.Program(prog_name, *args, **kwargs) 432 out_nodes = env.Program(prog_name, *args, **kwargs)
400 433
434 # Add dependencies on includes
435 env.Depends(out_nodes, env['INCLUDES'])
436
401 # Publish output 437 # Publish output
402 env.Publish(prog_name, 'run', out_nodes[0]) 438 env.Publish(prog_name, 'run', out_nodes[0])
403 env.Publish(prog_name, 'debug', out_nodes[1:]) 439 env.Publish(prog_name, 'debug', out_nodes[1:])
404 440
405 # Add an alias to build the program to the right groups 441 # Add an alias to build the program to the right groups
406 a = env.Alias(prog_name, out_nodes) 442 a = env.Alias(prog_name, out_nodes)
407 for group in env['COMPONENT_PROGRAM_GROUPS']: 443 for group in env['COMPONENT_PROGRAM_GROUPS']:
408 SCons.Script.Alias(group, a) 444 SCons.Script.Alias(group, a)
409 445
410 # Store list of components for this program 446 # Store list of components for this program
(...skipping 13 matching lines...) Expand all
424 460
425 Args: 461 Args:
426 self: Environment in which we were called. 462 self: Environment in which we were called.
427 test_name: Test name. 463 test_name: Test name.
428 nodes: List of files/Nodes output by the test. 464 nodes: List of files/Nodes output by the test.
429 465
430 Returns: 466 Returns:
431 Passthrough return code from env.Alias(). 467 Passthrough return code from env.Alias().
432 """ 468 """
433 469
434 # Add an alias for the test outputs, and add it to the right groups 470 # Add an alias for the test output
435 a = self.Alias(test_name, nodes) 471 a = self.Alias(test_name, nodes)
436 for group in self['COMPONENT_TEST_OUTPUT_GROUPS']: 472
473 groups = self.get('COMPONENT_TEST_OUTPUT_GROUPS')
474 if not groups:
475 # Output group not explicitly specified, so automatically add to groups
476 if self.get('COMPONENT_TEST_ENABLED'):
477 # Enabled tests go in all tests, and their size category
478 groups = ['run_all_tests']
479 if self.get('COMPONENT_TEST_SIZE'):
480 groups.append(self.subst('run_${COMPONENT_TEST_SIZE}_tests'))
481 else:
482 # Disabled tests only go in their group
483 groups = ['run_disabled_tests']
484
485 for group in groups:
437 SCons.Script.Alias(group, a) 486 SCons.Script.Alias(group, a)
438 487
439 # Return the output node 488 # Return the output node
440 return a 489 return a
441 490
442 #------------------------------------------------------------------------------ 491 #------------------------------------------------------------------------------
443 492
444 493
445 def generate(env): 494 def generate(env):
446 # NOTE: SCons requires the use of this name, which fails gpylint. 495 # NOTE: SCons requires the use of this name, which fails gpylint.
447 """SCons entry point for this tool.""" 496 """SCons entry point for this tool."""
448 497
449 env.Replace( 498 env.Replace(
450 COMPONENT_LIBRARY_DIR='$TARGET_ROOT/lib', 499 COMPONENT_LIBRARY_DIR='$TARGET_ROOT/lib',
451 STAGING_DIR='$TARGET_ROOT/staging', 500 STAGING_DIR='$TARGET_ROOT/staging',
452 TESTS_DIR='$TARGET_ROOT/tests', 501 TESTS_DIR='$TARGET_ROOT/tests',
453 TEST_OUTPUT_DIR='$TARGET_ROOT/test_output', 502 TEST_OUTPUT_DIR='$TARGET_ROOT/test_output',
454 # Default command line for a test is just the name of the file. 503 # Default command line for a test is just the name of the file.
455 # TODO(rspangler): Why doesn't the following work: 504 # TODO(rspangler): Why doesn't the following work:
456 # COMPONENT_TEST_CMDLINE='${SOURCE.abspath}', 505 # COMPONENT_TEST_CMDLINE='${SOURCE.abspath}',
457 # (it generates a SCons error) 506 # (it generates a SCons error)
458 COMPONENT_TEST_CMDLINE='${PROGRAM_NAME}', 507 COMPONENT_TEST_CMDLINE='${PROGRAM_NAME}',
459 COMPONENT_STATIC=True, # Static linking is a sensible default. 508 # Default test size is large
509 COMPONENT_TEST_SIZE='large',
510 # Default timeouts for component tests
511 COMPONENT_TEST_TIMEOUT={'large':900, 'medium':450, 'small':180},
512 # Tests are enabled by default
513 COMPONENT_TEST_ENABLED=True,
514 # Static linking is a sensible default
515 COMPONENT_STATIC=True,
460 # Don't publish libraries to the staging dir by themselves by default. 516 # Don't publish libraries to the staging dir by themselves by default.
461 COMPONENT_LIBRARY_PUBLISH=False, 517 COMPONENT_LIBRARY_PUBLISH=False,
462 ) 518 )
463 env.Append( 519 env.Append(
464 LIBPATH=['$COMPONENT_LIBRARY_DIR'], 520 LIBPATH=['$COMPONENT_LIBRARY_DIR'],
465 RPATH=['$COMPONENT_LIBRARY_DIR'], 521 RPATH=['$COMPONENT_LIBRARY_DIR'],
466 522
467 # Default alias groups for component builders 523 # Default alias groups for component builders
468 COMPONENT_PACKAGE_GROUPS=['all_packages'], 524 COMPONENT_PACKAGE_GROUPS=['all_packages'],
469 COMPONENT_LIBRARY_GROUPS=['all_libraries'], 525 COMPONENT_LIBRARY_GROUPS=['all_libraries'],
470 COMPONENT_PROGRAM_GROUPS=['all_programs'], 526 COMPONENT_PROGRAM_GROUPS=['all_programs'],
471 COMPONENT_TEST_PROGRAM_GROUPS=['all_test_programs'], 527 COMPONENT_TEST_PROGRAM_GROUPS=['all_test_programs'],
472 COMPONENT_TEST_OUTPUT_GROUPS=['run_all_tests'],
473 528
474 # Additional components whose resources should be copied into program 529 # Additional components whose resources should be copied into program
475 # directories, in addition to those from LIBS and the program itself. 530 # directories, in addition to those from LIBS and the program itself.
476 LIBS=[], 531 LIBS=[],
477 COMPONENTS=[], 532 COMPONENTS=[],
478 533
479 # Dicts of what resources should go in each destination directory for 534 # Dicts of what resources should go in each destination directory for
480 # programs and test programs. 535 # programs and test programs.
481 COMPONENT_PACKAGE_RESOURCES={ 536 COMPONENT_PACKAGE_RESOURCES={
482 'run': '$PACKAGE_DIR', 537 'run': '$PACKAGE_DIR',
483 'debug': '$PACKAGE_DIR', 538 'debug': '$PACKAGE_DIR',
484 }, 539 },
485 COMPONENT_PROGRAM_RESOURCES={ 540 COMPONENT_PROGRAM_RESOURCES={
486 'run': '$STAGING_DIR', 541 'run': '$STAGING_DIR',
487 'debug': '$STAGING_DIR', 542 'debug': '$STAGING_DIR',
488 }, 543 },
489 COMPONENT_TEST_RESOURCES={ 544 COMPONENT_TEST_RESOURCES={
490 'run': '$TESTS_DIR', 545 'run': '$TESTS_DIR',
491 'debug': '$TESTS_DIR', 546 'debug': '$TESTS_DIR',
492 'test_input': '$TESTS_DIR', 547 'test_input': '$TESTS_DIR',
493 }, 548 },
494 ) 549 )
495 550
551 # Add command line option for retest
552 SCons.Script.AddOption(
553 '--retest',
554 dest='component_test_retest',
555 action='store_true',
556 help='force all tests to rerun')
557 SCons.Script.Help(' --retest '
558 'Rerun specified tests, ignoring cached results.\n')
559
496 # Add our pseudo-builder methods 560 # Add our pseudo-builder methods
497 env.AddMethod(_InitializeComponentBuilders) 561 env.AddMethod(_InitializeComponentBuilders)
498 env.AddMethod(_StoreComponents) 562 env.AddMethod(_StoreComponents)
499 env.AddMethod(ComponentPackage) 563 env.AddMethod(ComponentPackage)
500 env.AddMethod(ComponentObject) 564 env.AddMethod(ComponentObject)
501 env.AddMethod(ComponentLibrary) 565 env.AddMethod(ComponentLibrary)
502 env.AddMethod(ComponentProgram) 566 env.AddMethod(ComponentProgram)
503 env.AddMethod(ComponentTestProgram) 567 env.AddMethod(ComponentTestProgram)
504 env.AddMethod(ComponentTestOutput) 568 env.AddMethod(ComponentTestOutput)
505 569
506 # Add our target groups 570 # Add our target groups
507 AddTargetGroup('all_libraries', 'libraries can be built') 571 AddTargetGroup('all_libraries', 'libraries can be built')
508 AddTargetGroup('all_programs', 'programs can be built') 572 AddTargetGroup('all_programs', 'programs can be built')
509 AddTargetGroup('all_test_programs', 'tests can be built') 573 AddTargetGroup('all_test_programs', 'tests can be built')
510 AddTargetGroup('all_packages', 'packages can be built') 574 AddTargetGroup('all_packages', 'packages can be built')
511 AddTargetGroup('run_all_tests', 'tests can be run') 575 AddTargetGroup('run_all_tests', 'tests can be run')
576 AddTargetGroup('run_disabled_tests', 'tests are disabled')
577 AddTargetGroup('run_small_tests', 'small tests can be run')
578 AddTargetGroup('run_medium_tests', 'medium tests can be run')
579 AddTargetGroup('run_large_tests', 'large tests can be run')
580
OLDNEW
« no previous file with comments | « site_scons/site_tools/component_bits.py ('k') | site_scons/site_tools/concat_source.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698