Reviewers: scottmg, Nico,
Message:
This should shave a few more seconds off the total time.
Description:
Parallelize ninja generation when GYP_PARALLEL=1.
This is a really easy approach, parallelizing by configs (Debug/Release).
It's probably not worth parallelizing this step much more because there's
some overhead and the total time of this step isn't that large.
Please review this at
http://codereview.chromium.org/11026061/
SVN Base:
http://git.chromium.org/external/gyp.git@master
Affected files:
M pylib/gyp/__init__.py
M pylib/gyp/generator/ninja.py
Index: pylib/gyp/__init__.py
diff --git a/pylib/gyp/__init__.py b/pylib/gyp/__init__.py
index
31f02d1a3cc728e42828a4d0a134242cafad7582..ac300a903c052744211179a94e51f573fe031ea0
100755
--- a/pylib/gyp/__init__.py
+++ b/pylib/gyp/__init__.py
@@ -47,7 +47,7 @@ def FindBuildFiles():
def Load(build_files, format, default_variables={},
includes=[], depth='.', params=None, check=False,
- circular_check=True, parallel=False):
+ circular_check=True):
"""
Loads one or more specified build files.
default_variables and includes will be copied before use.
@@ -126,7 +126,7 @@ def Load(build_files, format, default_variables={},
# Process the input specific to this generator.
result = gyp.input.Load(build_files, default_variables, includes[:],
depth, generator_input_info, check,
circular_check,
- parallel)
+ params['parallel'])
return [generator] + result
def NameValueListToDict(name_value_list):
@@ -488,15 +488,15 @@ def gyp_main(args):
'cwd': os.getcwd(),
'build_files_arg': build_files_arg,
'gyp_binary': sys.argv[0],
- 'home_dot_gyp': home_dot_gyp}
+ 'home_dot_gyp': home_dot_gyp,
+ 'parallel': options.parallel}
# Start with the default variables from the command line.
[generator, flat_list, targets, data] = Load(build_files, format,
cmdline_default_variables,
includes, options.depth,
params, options.check,
- options.circular_check,
- options.parallel)
+ options.circular_check)
# TODO(mark): Pass |data| for now because the generator needs a list of
# build files that came in. In the future, maybe it should just accept
Index: pylib/gyp/generator/ninja.py
diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py
index
c11ba9e9c44029d16a3f8f9f2821aa8759166448..8838f2f383b166c33dbab7caf8b8413a20f32219
100644
--- a/pylib/gyp/generator/ninja.py
+++ b/pylib/gyp/generator/ninja.py
@@ -4,6 +4,7 @@
import copy
import hashlib
+import multiprocessing
import os.path
import re
import subprocess
@@ -1736,6 +1737,10 @@ def PerformBuild(data, configurations, params):
subprocess.check_call(arguments)
+def CallGenerateOutputForConfig(arglist):
+ (target_list, target_dicts, data, params, config_name) = arglist
+ GenerateOutputForConfig(target_list, target_dicts, data, params,
config_name)
+
def GenerateOutput(target_list, target_dicts, data, params):
user_config = params.get('generator_flags', {}).get('config', None)
if user_config:
@@ -1743,6 +1748,13 @@ def GenerateOutput(target_list, target_dicts, data,
params):
user_config)
else:
config_names = target_dicts[target_list[0]]['configurations'].keys()
- for config_name in config_names:
- GenerateOutputForConfig(target_list, target_dicts, data, params,
- config_name)
+ if params['parallel']:
+ pool = multiprocessing.Pool(len(config_names))
+ arglists = []
+ for config_name in config_names:
+ arglists.append((target_list, target_dicts, data, params,
config_name))
+ pool.map(CallGenerateOutputForConfig, arglists)
+ else:
+ for config_name in config_names:
+ GenerateOutputForConfig(target_list, target_dicts, data, params,
+ config_name)