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

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: Add lock and explicit class for global state Created 8 years, 3 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') | pylib/gyp/input.py » ('J')
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 # --no-circular-check disables the check for circular relationships between 322 # --no-circular-check disables the check for circular relationships between
318 # .gyp files. These relationships should not exist, but they've only been 323 # .gyp files. These relationships should not exist, but they've only been
319 # observed to be harmful with the Xcode generator. Chromium's .gyp files 324 # observed to be harmful with the Xcode generator. Chromium's .gyp files
320 # currently have some circular relationships on non-Mac platforms, so this 325 # currently have some circular relationships on non-Mac platforms, so this
321 # option allows the strict behavior to be used on Macs and the lenient 326 # option allows the strict behavior to be used on Macs and the lenient
322 # behavior to be used elsewhere. 327 # behavior to be used elsewhere.
323 # TODO(mark): Remove this option when http://crbug.com/35878 is fixed. 328 # TODO(mark): Remove this option when http://crbug.com/35878 is fixed.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 elif sys.platform in ('win32', 'cygwin'): 366 elif sys.platform in ('win32', 'cygwin'):
362 options.formats = ['msvs'] 367 options.formats = ['msvs']
363 else: 368 else:
364 options.formats = ['make'] 369 options.formats = ['make']
365 370
366 if not options.generator_output and options.use_environment: 371 if not options.generator_output and options.use_environment:
367 g_o = os.environ.get('GYP_GENERATOR_OUTPUT') 372 g_o = os.environ.get('GYP_GENERATOR_OUTPUT')
368 if g_o: 373 if g_o:
369 options.generator_output = g_o 374 options.generator_output = g_o
370 375
376 if not options.parallel and options.use_environment:
377 options.parallel = bool(os.environ.get('GYP_PARALLEL'))
378
371 for mode in options.debug: 379 for mode in options.debug:
372 gyp.debug[mode] = 1 380 gyp.debug[mode] = 1
373 381
374 # Do an extra check to avoid work when we're not debugging. 382 # Do an extra check to avoid work when we're not debugging.
375 if DEBUG_GENERAL in gyp.debug.keys(): 383 if DEBUG_GENERAL in gyp.debug.keys():
376 DebugOutput(DEBUG_GENERAL, 'running with these options:') 384 DebugOutput(DEBUG_GENERAL, 'running with these options:')
377 for option, value in sorted(options.__dict__.items()): 385 for option, value in sorted(options.__dict__.items()):
378 if option[0] == '_': 386 if option[0] == '_':
379 continue 387 continue
380 if isinstance(value, basestring): 388 if isinstance(value, basestring):
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 'cwd': os.getcwd(), 486 'cwd': os.getcwd(),
479 'build_files_arg': build_files_arg, 487 'build_files_arg': build_files_arg,
480 'gyp_binary': sys.argv[0], 488 'gyp_binary': sys.argv[0],
481 'home_dot_gyp': home_dot_gyp} 489 'home_dot_gyp': home_dot_gyp}
482 490
483 # Start with the default variables from the command line. 491 # Start with the default variables from the command line.
484 [generator, flat_list, targets, data] = Load(build_files, format, 492 [generator, flat_list, targets, data] = Load(build_files, format,
485 cmdline_default_variables, 493 cmdline_default_variables,
486 includes, options.depth, 494 includes, options.depth,
487 params, options.check, 495 params, options.check,
488 options.circular_check) 496 options.circular_check,
497 options.parallel)
489 498
490 # TODO(mark): Pass |data| for now because the generator needs a list of 499 # TODO(mark): Pass |data| for now because the generator needs a list of
491 # build files that came in. In the future, maybe it should just accept 500 # build files that came in. In the future, maybe it should just accept
492 # a list, and not the whole data dict. 501 # a list, and not the whole data dict.
493 # NOTE: flat_list is the flattened dependency graph specifying the order 502 # NOTE: flat_list is the flattened dependency graph specifying the order
494 # that targets may be built. Build systems that operate serially or that 503 # that targets may be built. Build systems that operate serially or that
495 # need to have dependencies defined before dependents reference them should 504 # need to have dependencies defined before dependents reference them should
496 # generate targets in the order specified in flat_list. 505 # generate targets in the order specified in flat_list.
497 generator.GenerateOutput(flat_list, targets, data, params) 506 generator.GenerateOutput(flat_list, targets, data, params)
498 507
499 # Done 508 # Done
500 return 0 509 return 0
501 510
502 511
503 def main(args): 512 def main(args):
504 try: 513 try:
505 return gyp_main(args) 514 return gyp_main(args)
506 except GypError, e: 515 except GypError, e:
507 sys.stderr.write("gyp: %s\n" % e) 516 sys.stderr.write("gyp: %s\n" % e)
508 return 1 517 return 1
509 518
510 if __name__ == '__main__': 519 if __name__ == '__main__':
511 sys.exit(main(sys.argv[1:])) 520 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/input.py » ('j') | pylib/gyp/input.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698