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

Unified Diff: pylib/gyp/generator/ninja.py

Issue 10836080: ninja: make cross-compilation use $CC/$CXX for the target compiler (Closed) Base URL: http://git.chromium.org/external/gyp.git@master
Patch Set: Fix the path issue Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/generator/ninja.py
diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py
index 8aee8749ac3280fd1c02148c30c4947688bb193d..f7ba0b44c8a59766e094169206c15aef3d58566d 100644
--- a/pylib/gyp/generator/ninja.py
+++ b/pylib/gyp/generator/ninja.py
@@ -58,7 +58,12 @@ generator_extra_sources_for_rules = []
# TODO: figure out how to not build extra host objects in the non-cross-compile
# case when this is enabled, and enable unconditionally.
generator_supports_multiple_toolsets = (
- os.environ.get('AR_target') or os.environ.get('CC_target') or
+ os.environ.get('GYP_CROSSCOMPILE') or
+ os.environ.get('AR_host') or
+ os.environ.get('CC_host') or
+ os.environ.get('CXX_host') or
+ os.environ.get('AR_target') or
+ os.environ.get('CC_target') or
os.environ.get('CXX_target'))
@@ -705,11 +710,11 @@ class NinjaWriter:
def WriteSources(self, config_name, config, sources, predepends,
precompiled_header):
"""Write build rules to compile all of |sources|."""
- if self.toolset == 'target':
- self.ninja.variable('ar', '$ar_target')
- self.ninja.variable('cc', '$cc_target')
- self.ninja.variable('cxx', '$cxx_target')
- self.ninja.variable('ld', '$ld_target')
+ if self.toolset == 'host':
+ self.ninja.variable('ar', '$ar_host')
+ self.ninja.variable('cc', '$cc_host')
+ self.ninja.variable('cxx', '$cxx_host')
+ self.ninja.variable('ld', '$ld_host')
extra_defines = []
if self.flavor == 'mac':
@@ -1267,6 +1272,13 @@ def OpenOutput(path, mode='w'):
return open(path, mode)
+def GetEnvironFallback(var_list, default):
+ for var in var_list:
+ if var in os.environ:
+ return os.environ[var]
+ return default
+
+
def GenerateOutputForConfig(target_list, target_dicts, data, params,
config_name):
options = params['options']
@@ -1288,24 +1300,45 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
gyp.common.CopyTool(flavor, toplevel_build)
# Grab make settings for CC/CXX.
+ # The rules are
+ # - The priority from low to high is gcc/g++, the 'make_global_settings' in
+ # gyp, the environment variable.
+ # - If there is no 'make_global_settings' for CC.host/CXX.host or
+ # 'CC_host'/'CXX_host' enviroment variable, cc_host/cxx_host should be set
+ # to cc/cxx.
if flavor == 'win':
cc = cxx = 'cl.exe'
gyp.msvs_emulation.GenerateEnvironmentFiles(
toplevel_build, generator_flags, OpenOutput)
else:
cc, cxx = 'gcc', 'g++'
+ cc_host = None
+ cxx_host = None
+ cc_host_global_setting = None
+ cxx_host_global_setting = None
+
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
make_global_settings = data[build_file].get('make_global_settings', [])
build_to_root = InvertRelativePath(build_dir)
for key, value in make_global_settings:
if key == 'CC': cc = os.path.join(build_to_root, value)
if key == 'CXX': cxx = os.path.join(build_to_root, value)
+ if key == 'CC.host': cc_host = os.path.join(build_to_root, value)
+ if key == 'CXX.host': cxx_host = os.path.join(build_to_root, value)
+ if key == 'CC.host': cc_host_global_setting = value
+ if key == 'CXX.host': cxx_host_global_setting = value
flock = 'flock'
if flavor == 'mac':
flock = './gyp-mac-tool flock'
- master_ninja.variable('cc', os.environ.get('CC', cc))
- master_ninja.variable('cxx', os.environ.get('CXX', cxx))
+ cc = GetEnvironFallback(['CC_target', 'CC'], cc)
+ master_ninja.variable('cc', cc)
+ cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx)
+ master_ninja.variable('cxx', cxx)
+
+ if not cc_host: cc_host = cc
+ if not cxx_host: cxx_host = cxx
+
if flavor == 'win':
master_ninja.variable('ld', 'link.exe')
master_ninja.variable('idl', 'midl.exe')
@@ -1316,15 +1349,23 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
master_ninja.variable('use_dep_database', '1')
else:
master_ninja.variable('ld', flock + ' linker.lock $cxx')
- master_ninja.variable('ar', os.environ.get('AR', 'ar'))
-
- master_ninja.variable('ar_target', os.environ.get('AR_target', '$ar'))
- master_ninja.variable('cc_target', os.environ.get('CC_target', '$cc'))
- master_ninja.variable('cxx_target', os.environ.get('CXX_target', '$cxx'))
+ master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar'))
+
+ master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar'))
+ cc_host = GetEnvironFallback(['CC_host'], cc_host)
+ cxx_host = GetEnvironFallback(['CXX_host'], cxx_host)
+ # The environment variable could be used in 'make_global_settings', like
+ # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here.
+ if cc_host.find('$(CC)') != -1 and cc_host_global_setting:
+ cc_host = cc_host_global_setting.replace('$(CC)', cc)
+ if cxx_host.find('$(CXX)') != -1 and cxx_host_global_setting:
+ cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx)
Nico 2012/08/08 17:36:11 I understand that you need to add a "cc_host = " i
michaelbai 2012/08/08 17:40:42 The cc_host_global_setting stores the raw value wi
+ master_ninja.variable('cc_host', cc_host)
+ master_ninja.variable('cxx_host', cxx_host)
if flavor == 'win':
- master_ninja.variable('ld_target', os.environ.get('LD_target', '$ld'))
+ master_ninja.variable('ld_host', os.environ.get('LD_host', '$ld'))
else:
- master_ninja.variable('ld_target', flock + ' linker.lock $cxx_target')
+ master_ninja.variable('ld_host', flock + ' linker.lock $cxx_host')
if flavor == 'mac':
master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool'))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698