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

Side by Side Diff: pylib/gyp/__init__.py

Issue 10911082: Load target build files in parallel using Python multiprocessing. (Closed) Base URL: http://git.chromium.org/external/gyp.git@master
Patch Set: Switch to docstrings, move LoadTargetBuildFileCallback inside ParallelState. Created 8 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
« no previous file with comments | « no previous file | pylib/gyp/input.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/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (c) 2012 Google Inc. All rights reserved. 3 # Copyright (c) 2012 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import copy 7 import copy
8 import gyp.input 8 import gyp.input
9 import optparse 9 import optparse
10 import os.path 10 import os.path
(...skipping 28 matching lines...) Expand all
39 extension = '.gyp' 39 extension = '.gyp'
40 files = os.listdir(os.getcwd()) 40 files = os.listdir(os.getcwd())
41 build_files = [] 41 build_files = []
42 for file in files: 42 for file in files:
43 if file.endswith(extension): 43 if file.endswith(extension):
44 build_files.append(file) 44 build_files.append(file)
45 return build_files 45 return build_files
46 46
47 47
48 def Load(build_files, format, default_variables={}, 48 def Load(build_files, format, default_variables={},
49 includes=[], depth='.', params=None, check=False, circular_check=True): 49 includes=[], depth='.', params=None, check=False,
50 circular_check=True, parallel=False):
50 """ 51 """
51 Loads one or more specified build files. 52 Loads one or more specified build files.
52 default_variables and includes will be copied before use. 53 default_variables and includes will be copied before use.
53 Returns the generator for the specified format and the 54 Returns the generator for the specified format and the
54 data returned by loading the specified build files. 55 data returned by loading the specified build files.
55 """ 56 """
56 if params is None: 57 if params is None:
57 params = {} 58 params = {}
58 59
59 flavor = None 60 flavor = None
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 getattr(generator, 'generator_supports_multiple_toolsets', False), 118 getattr(generator, 'generator_supports_multiple_toolsets', False),
118 'generator_wants_static_library_dependencies_adjusted': 119 'generator_wants_static_library_dependencies_adjusted':
119 getattr(generator, 120 getattr(generator,
120 'generator_wants_static_library_dependencies_adjusted', True), 121 'generator_wants_static_library_dependencies_adjusted', True),
121 'generator_wants_sorted_dependencies': 122 'generator_wants_sorted_dependencies':
122 getattr(generator, 'generator_wants_sorted_dependencies', False), 123 getattr(generator, 'generator_wants_sorted_dependencies', False),
123 } 124 }
124 125
125 # Process the input specific to this generator. 126 # Process the input specific to this generator.
126 result = gyp.input.Load(build_files, default_variables, includes[:], 127 result = gyp.input.Load(build_files, default_variables, includes[:],
127 depth, generator_input_info, check, circular_check) 128 depth, generator_input_info, check, circular_check,
129 parallel)
128 return [generator] + result 130 return [generator] + result
129 131
130 def NameValueListToDict(name_value_list): 132 def NameValueListToDict(name_value_list):
131 """ 133 """
132 Takes an array of strings of the form 'NAME=VALUE' and creates a dictionary 134 Takes an array of strings of the form 'NAME=VALUE' and creates a dictionary
133 of the pairs. If a string is simply NAME, then the value in the dictionary 135 of the pairs. If a string is simply NAME, then the value in the dictionary
134 is set to True. If VALUE can be converted to an integer, it is. 136 is set to True. If VALUE can be converted to an integer, it is.
135 """ 137 """
136 result = { } 138 result = { }
137 for item in name_value_list: 139 for item in name_value_list:
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 help='sets generator flag FLAG to VAL') 306 help='sets generator flag FLAG to VAL')
305 parser.add_option('--generator-output', dest='generator_output', 307 parser.add_option('--generator-output', dest='generator_output',
306 action='store', default=None, metavar='DIR', type='path', 308 action='store', default=None, metavar='DIR', type='path',
307 env_name='GYP_GENERATOR_OUTPUT', 309 env_name='GYP_GENERATOR_OUTPUT',
308 help='puts generated build files under DIR') 310 help='puts generated build files under DIR')
309 parser.add_option('--ignore-environment', dest='use_environment', 311 parser.add_option('--ignore-environment', dest='use_environment',
310 action='store_false', default=True, regenerate=False, 312 action='store_false', default=True, regenerate=False,
311 help='do not read options from environment variables') 313 help='do not read options from environment variables')
312 parser.add_option('--check', dest='check', action='store_true', 314 parser.add_option('--check', dest='check', action='store_true',
313 help='check format of gyp files') 315 help='check format of gyp files')
316 parser.add_option('--parallel', action='store_true',
317 env_name='GYP_PARALLEL',
318 help='Use multiprocessing for speed (experimental)')
314 parser.add_option('--toplevel-dir', dest='toplevel_dir', action='store', 319 parser.add_option('--toplevel-dir', dest='toplevel_dir', action='store',
315 default=None, metavar='DIR', type='path', 320 default=None, metavar='DIR', type='path',
316 help='directory to use as the root of the source tree') 321 help='directory to use as the root of the source tree')
317 parser.add_option('--build', dest='configs', action='append', 322 parser.add_option('--build', dest='configs', action='append',
318 help='configuration for build after project generation') 323 help='configuration for build after project generation')
319 # --no-circular-check disables the check for circular relationships between 324 # --no-circular-check disables the check for circular relationships between
320 # .gyp files. These relationships should not exist, but they've only been 325 # .gyp files. These relationships should not exist, but they've only been
321 # observed to be harmful with the Xcode generator. Chromium's .gyp files 326 # observed to be harmful with the Xcode generator. Chromium's .gyp files
322 # currently have some circular relationships on non-Mac platforms, so this 327 # currently have some circular relationships on non-Mac platforms, so this
323 # option allows the strict behavior to be used on Macs and the lenient 328 # option allows the strict behavior to be used on Macs and the lenient
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 elif sys.platform in ('win32', 'cygwin'): 368 elif sys.platform in ('win32', 'cygwin'):
364 options.formats = ['msvs'] 369 options.formats = ['msvs']
365 else: 370 else:
366 options.formats = ['make'] 371 options.formats = ['make']
367 372
368 if not options.generator_output and options.use_environment: 373 if not options.generator_output and options.use_environment:
369 g_o = os.environ.get('GYP_GENERATOR_OUTPUT') 374 g_o = os.environ.get('GYP_GENERATOR_OUTPUT')
370 if g_o: 375 if g_o:
371 options.generator_output = g_o 376 options.generator_output = g_o
372 377
378 if not options.parallel and options.use_environment:
379 options.parallel = bool(os.environ.get('GYP_PARALLEL'))
380
373 for mode in options.debug: 381 for mode in options.debug:
374 gyp.debug[mode] = 1 382 gyp.debug[mode] = 1
375 383
376 # Do an extra check to avoid work when we're not debugging. 384 # Do an extra check to avoid work when we're not debugging.
377 if DEBUG_GENERAL in gyp.debug.keys(): 385 if DEBUG_GENERAL in gyp.debug.keys():
378 DebugOutput(DEBUG_GENERAL, 'running with these options:') 386 DebugOutput(DEBUG_GENERAL, 'running with these options:')
379 for option, value in sorted(options.__dict__.items()): 387 for option, value in sorted(options.__dict__.items()):
380 if option[0] == '_': 388 if option[0] == '_':
381 continue 389 continue
382 if isinstance(value, basestring): 390 if isinstance(value, basestring):
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 'cwd': os.getcwd(), 488 'cwd': os.getcwd(),
481 'build_files_arg': build_files_arg, 489 'build_files_arg': build_files_arg,
482 'gyp_binary': sys.argv[0], 490 'gyp_binary': sys.argv[0],
483 'home_dot_gyp': home_dot_gyp} 491 'home_dot_gyp': home_dot_gyp}
484 492
485 # Start with the default variables from the command line. 493 # Start with the default variables from the command line.
486 [generator, flat_list, targets, data] = Load(build_files, format, 494 [generator, flat_list, targets, data] = Load(build_files, format,
487 cmdline_default_variables, 495 cmdline_default_variables,
488 includes, options.depth, 496 includes, options.depth,
489 params, options.check, 497 params, options.check,
490 options.circular_check) 498 options.circular_check,
499 options.parallel)
491 500
492 # TODO(mark): Pass |data| for now because the generator needs a list of 501 # TODO(mark): Pass |data| for now because the generator needs a list of
493 # build files that came in. In the future, maybe it should just accept 502 # build files that came in. In the future, maybe it should just accept
494 # a list, and not the whole data dict. 503 # a list, and not the whole data dict.
495 # NOTE: flat_list is the flattened dependency graph specifying the order 504 # NOTE: flat_list is the flattened dependency graph specifying the order
496 # that targets may be built. Build systems that operate serially or that 505 # that targets may be built. Build systems that operate serially or that
497 # need to have dependencies defined before dependents reference them should 506 # need to have dependencies defined before dependents reference them should
498 # generate targets in the order specified in flat_list. 507 # generate targets in the order specified in flat_list.
499 generator.GenerateOutput(flat_list, targets, data, params) 508 generator.GenerateOutput(flat_list, targets, data, params)
500 509
(...skipping 10 matching lines...) Expand all
511 520
512 def main(args): 521 def main(args):
513 try: 522 try:
514 return gyp_main(args) 523 return gyp_main(args)
515 except GypError, e: 524 except GypError, e:
516 sys.stderr.write("gyp: %s\n" % e) 525 sys.stderr.write("gyp: %s\n" % e)
517 return 1 526 return 1
518 527
519 if __name__ == '__main__': 528 if __name__ == '__main__':
520 sys.exit(main(sys.argv[1:])) 529 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/input.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698