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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import copy 5 import copy
6 import gyp 6 import gyp
7 import gyp.common 7 import gyp.common
8 import gyp.msvs_emulation 8 import gyp.msvs_emulation
9 import gyp.MSVSVersion 9 import gyp.MSVSVersion
10 import gyp.system_test 10 import gyp.system_test
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 # Placates pylint. 50 # Placates pylint.
51 generator_additional_non_configuration_keys = [] 51 generator_additional_non_configuration_keys = []
52 generator_additional_path_sections = [] 52 generator_additional_path_sections = []
53 generator_extra_sources_for_rules = [] 53 generator_extra_sources_for_rules = []
54 54
55 # TODO: figure out how to not build extra host objects in the non-cross-compile 55 # TODO: figure out how to not build extra host objects in the non-cross-compile
56 # case when this is enabled, and enable unconditionally. 56 # case when this is enabled, and enable unconditionally.
57 generator_supports_multiple_toolsets = ( 57 generator_supports_multiple_toolsets = (
58 os.environ.get('AR_target') or os.environ.get('CC_target') or 58 os.environ.get('GYP_CROSSCOMPILE') or
59 os.environ.get('AR_host') or
60 os.environ.get('CC_host') or
61 os.environ.get('CXX_host') or
62 os.environ.get('AR_target') or
63 os.environ.get('CC_target') or
59 os.environ.get('CXX_target')) 64 os.environ.get('CXX_target'))
60 65
61 66
62 def StripPrefix(arg, prefix): 67 def StripPrefix(arg, prefix):
63 if arg.startswith(prefix): 68 if arg.startswith(prefix):
64 return arg[len(prefix):] 69 return arg[len(prefix):]
65 return arg 70 return arg
66 71
67 72
68 def QuoteShellArgument(arg, flavor): 73 def QuoteShellArgument(arg, flavor):
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 env = self.ComputeExportEnvString(env) 699 env = self.ComputeExportEnvString(env)
695 700
696 self.ninja.build(out, 'mac_tool', info_plist, 701 self.ninja.build(out, 'mac_tool', info_plist,
697 variables=[('mactool_cmd', 'copy-info-plist'), 702 variables=[('mactool_cmd', 'copy-info-plist'),
698 ('env', env)]) 703 ('env', env)])
699 bundle_depends.append(out) 704 bundle_depends.append(out)
700 705
701 def WriteSources(self, config_name, config, sources, predepends, 706 def WriteSources(self, config_name, config, sources, predepends,
702 precompiled_header): 707 precompiled_header):
703 """Write build rules to compile all of |sources|.""" 708 """Write build rules to compile all of |sources|."""
704 if self.toolset == 'target': 709 if self.toolset == 'host':
705 self.ninja.variable('ar', '$ar_target') 710 self.ninja.variable('ar', '$ar_host')
706 self.ninja.variable('cc', '$cc_target') 711 self.ninja.variable('cc', '$cc_host')
707 self.ninja.variable('cxx', '$cxx_target') 712 self.ninja.variable('cxx', '$cxx_host')
708 self.ninja.variable('ld', '$ld_target') 713 self.ninja.variable('ld', '$ld_host')
709 714
710 extra_defines = [] 715 extra_defines = []
711 if self.flavor == 'mac': 716 if self.flavor == 'mac':
712 cflags = self.xcode_settings.GetCflags(config_name) 717 cflags = self.xcode_settings.GetCflags(config_name)
713 cflags_c = self.xcode_settings.GetCflagsC(config_name) 718 cflags_c = self.xcode_settings.GetCflagsC(config_name)
714 cflags_cc = self.xcode_settings.GetCflagsCC(config_name) 719 cflags_cc = self.xcode_settings.GetCflagsCC(config_name)
715 cflags_objc = ['$cflags_c'] + \ 720 cflags_objc = ['$cflags_c'] + \
716 self.xcode_settings.GetCflagsObjC(config_name) 721 self.xcode_settings.GetCflagsObjC(config_name)
717 cflags_objcc = ['$cflags_cc'] + \ 722 cflags_objcc = ['$cflags_cc'] + \
718 self.xcode_settings.GetCflagsObjCC(config_name) 723 self.xcode_settings.GetCflagsObjCC(config_name)
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 1261
1257 def OpenOutput(path, mode='w'): 1262 def OpenOutput(path, mode='w'):
1258 """Open |path| for writing, creating directories if necessary.""" 1263 """Open |path| for writing, creating directories if necessary."""
1259 try: 1264 try:
1260 os.makedirs(os.path.dirname(path)) 1265 os.makedirs(os.path.dirname(path))
1261 except OSError: 1266 except OSError:
1262 pass 1267 pass
1263 return open(path, mode) 1268 return open(path, mode)
1264 1269
1265 1270
1271 def GetEnvironFallback(var_list, default):
1272 for var in var_list:
1273 if var in os.environ:
1274 return os.environ[var]
1275 return default
1276
1277
1266 def GenerateOutputForConfig(target_list, target_dicts, data, params, 1278 def GenerateOutputForConfig(target_list, target_dicts, data, params,
1267 config_name): 1279 config_name):
1268 options = params['options'] 1280 options = params['options']
1269 flavor = gyp.common.GetFlavor(params) 1281 flavor = gyp.common.GetFlavor(params)
1270 generator_flags = params.get('generator_flags', {}) 1282 generator_flags = params.get('generator_flags', {})
1271 1283
1272 # build_dir: relative path from source root to our output files. 1284 # build_dir: relative path from source root to our output files.
1273 # e.g. "out/Debug" 1285 # e.g. "out/Debug"
1274 build_dir = os.path.join(generator_flags.get('output_dir', 'out'), 1286 build_dir = os.path.join(generator_flags.get('output_dir', 'out'),
1275 config_name) 1287 config_name)
1276 1288
1277 toplevel_build = os.path.join(options.toplevel_dir, build_dir) 1289 toplevel_build = os.path.join(options.toplevel_dir, build_dir)
1278 1290
1279 master_ninja = ninja_syntax.Writer( 1291 master_ninja = ninja_syntax.Writer(
1280 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), 1292 OpenOutput(os.path.join(toplevel_build, 'build.ninja')),
1281 width=120) 1293 width=120)
1282 1294
1283 # Put build-time support tools in out/{config_name}. 1295 # Put build-time support tools in out/{config_name}.
1284 gyp.common.CopyTool(flavor, toplevel_build) 1296 gyp.common.CopyTool(flavor, toplevel_build)
1285 1297
1286 # Grab make settings for CC/CXX. 1298 # Grab make settings for CC/CXX.
1287 if flavor == 'win': 1299 if flavor == 'win':
1288 cc = cxx = 'cl.exe' 1300 cc = cxx = 'cl.exe'
1289 gyp.msvs_emulation.GenerateEnvironmentFiles( 1301 gyp.msvs_emulation.GenerateEnvironmentFiles(
1290 toplevel_build, generator_flags, OpenOutput) 1302 toplevel_build, generator_flags, OpenOutput)
1291 else: 1303 else:
1292 cc, cxx = 'gcc', 'g++' 1304 cc, cxx = 'gcc', 'g++'
1305 cc_host, cxx_host = cc, cxx
1293 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) 1306 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
1294 make_global_settings = data[build_file].get('make_global_settings', []) 1307 make_global_settings = data[build_file].get('make_global_settings', [])
1295 build_to_root = InvertRelativePath(build_dir) 1308 build_to_root = InvertRelativePath(build_dir)
1296 for key, value in make_global_settings: 1309 for key, value in make_global_settings:
1297 if key == 'CC': cc = os.path.join(build_to_root, value) 1310 if key == 'CC': cc = os.path.join(build_to_root, value)
1298 if key == 'CXX': cxx = os.path.join(build_to_root, value) 1311 if key == 'CXX': cxx = os.path.join(build_to_root, value)
1312 if key == 'CC.host': cc_host = os.path.join(build_to_root, value)
1313 if key == 'CXX.host': cxx_host = os.path.join(build_to_root, value)
1299 1314
1300 flock = 'flock' 1315 flock = 'flock'
1301 if flavor == 'mac': 1316 if flavor == 'mac':
1302 flock = './gyp-mac-tool flock' 1317 flock = './gyp-mac-tool flock'
1303 master_ninja.variable('cc', os.environ.get('CC', cc)) 1318 master_ninja.variable('cc', GetEnvironFallback(['CC_target', 'CC'], cc))
1304 master_ninja.variable('cxx', os.environ.get('CXX', cxx)) 1319 master_ninja.variable('cxx', GetEnvironFallback(['CXX_target', 'CXX'], cxx))
1305 if flavor == 'win': 1320 if flavor == 'win':
1306 master_ninja.variable('ld', 'link.exe') 1321 master_ninja.variable('ld', 'link.exe')
1307 master_ninja.variable('idl', 'midl.exe') 1322 master_ninja.variable('idl', 'midl.exe')
1308 master_ninja.variable('ar', 'lib.exe') 1323 master_ninja.variable('ar', 'lib.exe')
1309 master_ninja.variable('rc', 'rc.exe') 1324 master_ninja.variable('rc', 'rc.exe')
1310 master_ninja.variable('asm', 'ml.exe') 1325 master_ninja.variable('asm', 'ml.exe')
1311 master_ninja.variable('mt', 'mt.exe') 1326 master_ninja.variable('mt', 'mt.exe')
1312 else: 1327 else:
1313 master_ninja.variable('ld', flock + ' linker.lock $cxx') 1328 master_ninja.variable('ld', flock + ' linker.lock $cxx')
1314 master_ninja.variable('ar', os.environ.get('AR', 'ar')) 1329 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar'))
1315 1330
1316 master_ninja.variable('ar_target', os.environ.get('AR_target', '$ar')) 1331 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar'))
1317 master_ninja.variable('cc_target', os.environ.get('CC_target', '$cc')) 1332 master_ninja.variable('cc_host', GetEnvironFallback(['CC_host'], cc_host))
1318 master_ninja.variable('cxx_target', os.environ.get('CXX_target', '$cxx')) 1333 master_ninja.variable('cxx_host', GetEnvironFallback(['CXX_host'], cxx_host))
1319 if flavor == 'win': 1334 if flavor == 'win':
1320 master_ninja.variable('ld_target', os.environ.get('LD_target', '$ld')) 1335 master_ninja.variable('ld_host', os.environ.get('LD_target', '$ld'))
piman 2012/08/02 18:55:31 LD_host instead of LD_target
michaelbai 2012/08/02 21:33:48 Done.
1321 else: 1336 else:
1322 master_ninja.variable('ld_target', flock + ' linker.lock $cxx_target') 1337 master_ninja.variable('ld_host', flock + ' linker.lock $cxx_host')
1323 1338
1324 if flavor == 'mac': 1339 if flavor == 'mac':
1325 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) 1340 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool'))
1326 master_ninja.newline() 1341 master_ninja.newline()
1327 1342
1328 if flavor != 'win': 1343 if flavor != 'win':
1329 master_ninja.rule( 1344 master_ninja.rule(
1330 'cc', 1345 'cc',
1331 description='CC $out', 1346 description='CC $out',
1332 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' 1347 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c '
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 1659
1645 user_config = params.get('generator_flags', {}).get('config', None) 1660 user_config = params.get('generator_flags', {}).get('config', None)
1646 if user_config: 1661 if user_config:
1647 GenerateOutputForConfig(target_list, target_dicts, data, params, 1662 GenerateOutputForConfig(target_list, target_dicts, data, params,
1648 user_config) 1663 user_config)
1649 else: 1664 else:
1650 config_names = target_dicts[target_list[0]]['configurations'].keys() 1665 config_names = target_dicts[target_list[0]]['configurations'].keys()
1651 for config_name in config_names: 1666 for config_name in config_names:
1652 GenerateOutputForConfig(target_list, target_dicts, data, params, 1667 GenerateOutputForConfig(target_list, target_dicts, data, params,
1653 config_name) 1668 config_name)
OLDNEW
« 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