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

Side by Side Diff: pylib/gyp/generator/ninja.py

Issue 9649016: ninja: make cross-compilation use $CC/$CXX for the target compiler (Closed) Base URL: https://gyp.googlecode.com/svn/trunk
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« 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.system_test 9 import gyp.system_test
10 import gyp.xcode_emulation 10 import gyp.xcode_emulation
(...skipping 29 matching lines...) Expand all
40 'RULE_INPUT_ROOT': '${root}', 40 'RULE_INPUT_ROOT': '${root}',
41 'RULE_INPUT_DIRNAME': '${dirname}', 41 'RULE_INPUT_DIRNAME': '${dirname}',
42 'RULE_INPUT_PATH': '${source}', 42 'RULE_INPUT_PATH': '${source}',
43 'RULE_INPUT_EXT': '${ext}', 43 'RULE_INPUT_EXT': '${ext}',
44 'RULE_INPUT_NAME': '${name}', 44 'RULE_INPUT_NAME': '${name}',
45 } 45 }
46 46
47 # TODO: figure out how to not build extra host objects in the non-cross-compile 47 # TODO: figure out how to not build extra host objects in the non-cross-compile
48 # case when this is enabled, and enable unconditionally. 48 # case when this is enabled, and enable unconditionally.
49 generator_supports_multiple_toolsets = ( 49 generator_supports_multiple_toolsets = (
50 os.environ.get('AR_target') or os.environ.get('CC_target') or 50 os.environ.get('GYP_CROSSCOMPILE') or
51 os.environ.get('AR_host') or
52 os.environ.get('CC_host') or
53 os.environ.get('CXX_host') or
54 os.environ.get('AR_target') or
55 os.environ.get('CC_target') or
51 os.environ.get('CXX_target')) 56 os.environ.get('CXX_target'))
52 57
53 58
54 def StripPrefix(arg, prefix): 59 def StripPrefix(arg, prefix):
55 if arg.startswith(prefix): 60 if arg.startswith(prefix):
56 return arg[len(prefix):] 61 return arg[len(prefix):]
57 return arg 62 return arg
58 63
59 def QuoteShellArgument(arg, flavor): 64 def QuoteShellArgument(arg, flavor):
60 """Quote a string such that it will be interpreted as a single argument 65 """Quote a string such that it will be interpreted as a single argument
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 env = self.ComputeExportEnvString(env) 575 env = self.ComputeExportEnvString(env)
571 576
572 self.ninja.build(out, 'mac_tool', info_plist, 577 self.ninja.build(out, 'mac_tool', info_plist,
573 variables=[('mactool_cmd', 'copy-info-plist'), 578 variables=[('mactool_cmd', 'copy-info-plist'),
574 ('env', env)]) 579 ('env', env)])
575 bundle_depends.append(out) 580 bundle_depends.append(out)
576 581
577 def WriteSources(self, config_name, config, sources, predepends, 582 def WriteSources(self, config_name, config, sources, predepends,
578 precompiled_header): 583 precompiled_header):
579 """Write build rules to compile all of |sources|.""" 584 """Write build rules to compile all of |sources|."""
580 if self.toolset == 'target': 585 if self.toolset == 'host':
581 self.ninja.variable('ar', '$ar_target') 586 self.ninja.variable('ar', '$ar_host')
582 self.ninja.variable('cc', '$cc_target') 587 self.ninja.variable('cc', '$cc_host')
583 self.ninja.variable('cxx', '$cxx_target') 588 self.ninja.variable('cxx', '$cxx_host')
584 self.ninja.variable('ld', '$ld_target') 589 self.ninja.variable('ld', '$ld_host')
585 590
586 if self.flavor == 'mac': 591 if self.flavor == 'mac':
587 cflags = self.xcode_settings.GetCflags(config_name) 592 cflags = self.xcode_settings.GetCflags(config_name)
588 cflags_c = self.xcode_settings.GetCflagsC(config_name) 593 cflags_c = self.xcode_settings.GetCflagsC(config_name)
589 cflags_cc = self.xcode_settings.GetCflagsCC(config_name) 594 cflags_cc = self.xcode_settings.GetCflagsCC(config_name)
590 cflags_objc = ['$cflags_c'] + \ 595 cflags_objc = ['$cflags_c'] + \
591 self.xcode_settings.GetCflagsObjC(config_name) 596 self.xcode_settings.GetCflagsObjC(config_name)
592 cflags_objcc = ['$cflags_cc'] + \ 597 cflags_objcc = ['$cflags_cc'] + \
593 self.xcode_settings.GetCflagsObjCC(config_name) 598 self.xcode_settings.GetCflagsObjCC(config_name)
594 else: 599 else:
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 1029
1025 def OpenOutput(path): 1030 def OpenOutput(path):
1026 """Open |path| for writing, creating directories if necessary.""" 1031 """Open |path| for writing, creating directories if necessary."""
1027 try: 1032 try:
1028 os.makedirs(os.path.dirname(path)) 1033 os.makedirs(os.path.dirname(path))
1029 except OSError: 1034 except OSError:
1030 pass 1035 pass
1031 return open(path, 'w') 1036 return open(path, 'w')
1032 1037
1033 1038
1039 def GetEnvironFallback(var_list, default):
1040 for var in var_list:
1041 if var in os.environ:
1042 return os.environ[var]
1043 return default
1044
1045
1034 def GenerateOutputForConfig(target_list, target_dicts, data, params, 1046 def GenerateOutputForConfig(target_list, target_dicts, data, params,
1035 config_name): 1047 config_name):
1036 options = params['options'] 1048 options = params['options']
1037 flavor = gyp.common.GetFlavor(params) 1049 flavor = gyp.common.GetFlavor(params)
1038 generator_flags = params.get('generator_flags', {}) 1050 generator_flags = params.get('generator_flags', {})
1039 1051
1040 # build_dir: relative path from source root to our output files. 1052 # build_dir: relative path from source root to our output files.
1041 # e.g. "out/Debug" 1053 # e.g. "out/Debug"
1042 build_dir = os.path.join(generator_flags.get('output_dir', 'out'), 1054 build_dir = os.path.join(generator_flags.get('output_dir', 'out'),
1043 config_name) 1055 config_name)
1044 1056
1045 master_ninja = ninja_syntax.Writer( 1057 master_ninja = ninja_syntax.Writer(
1046 OpenOutput(os.path.join(options.toplevel_dir, build_dir, 'build.ninja')), 1058 OpenOutput(os.path.join(options.toplevel_dir, build_dir, 'build.ninja')),
1047 width=120) 1059 width=120)
1048 1060
1049 # Put build-time support tools in out/{config_name}. 1061 # Put build-time support tools in out/{config_name}.
1050 gyp.common.CopyTool(flavor, os.path.join(options.toplevel_dir, build_dir)) 1062 gyp.common.CopyTool(flavor, os.path.join(options.toplevel_dir, build_dir))
1051 1063
1052 # Grab make settings for CC/CXX. 1064 # Grab make settings for CC/CXX.
1053 if flavor == 'win': 1065 if flavor == 'win':
1054 cc = cxx = 'cl' 1066 cc = cxx = 'cl'
1055 else: 1067 else:
1056 cc, cxx = 'gcc', 'g++' 1068 cc, cxx = 'gcc', 'g++'
1069 cc_host, cxx_host = cc, cxx
Nico 2012/08/03 04:41:34 The mac bots set just 'CC' and nothing else. In th
1057 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) 1070 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
1058 make_global_settings = data[build_file].get('make_global_settings', []) 1071 make_global_settings = data[build_file].get('make_global_settings', [])
1059 build_to_root = InvertRelativePath(build_dir) 1072 build_to_root = InvertRelativePath(build_dir)
1060 for key, value in make_global_settings: 1073 for key, value in make_global_settings:
1061 if key == 'CC': cc = os.path.join(build_to_root, value) 1074 if key == 'CC': cc = os.path.join(build_to_root, value)
1062 if key == 'CXX': cxx = os.path.join(build_to_root, value) 1075 if key == 'CXX': cxx = os.path.join(build_to_root, value)
1076 if key == 'CC.host': cc_host = os.path.join(build_to_root, value)
1077 if key == 'CXX.host': cxx_host = os.path.join(build_to_root, value)
1063 1078
1064 flock = 'flock' 1079 flock = 'flock'
1065 if flavor == 'mac': 1080 if flavor == 'mac':
1066 flock = './gyp-mac-tool flock' 1081 flock = './gyp-mac-tool flock'
1067 master_ninja.variable('ar', os.environ.get('AR', 'ar')) 1082 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar'))
1068 master_ninja.variable('cc', os.environ.get('CC', cc)) 1083 master_ninja.variable('cc', GetEnvironFallback(['CC_target', 'CC'], cc))
1069 master_ninja.variable('cxx', os.environ.get('CXX', cxx)) 1084 master_ninja.variable('cxx', GetEnvironFallback(['CXX_target', 'CXX'], cxx))
1070 if flavor == 'win': 1085 if flavor == 'win':
1071 master_ninja.variable('ld', 'link') 1086 master_ninja.variable('ld', 'link')
1072 else: 1087 else:
1073 master_ninja.variable('ld', flock + ' linker.lock $cxx') 1088 master_ninja.variable('ld', flock + ' linker.lock $cxx')
1074 1089
1075 master_ninja.variable('ar_target', os.environ.get('AR_target', '$ar')) 1090 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar'))
1076 master_ninja.variable('cc_target', os.environ.get('CC_target', '$cc')) 1091 master_ninja.variable('cc_host', GetEnvironFallback(['CC_host'], cc_host))
1077 master_ninja.variable('cxx_target', os.environ.get('CXX_target', '$cxx')) 1092 master_ninja.variable('cxx_host', GetEnvironFallback(['CXX_host'], cxx_host))
1078 if flavor == 'win': 1093 if flavor == 'win':
1079 master_ninja.variable('ld_target', 'link') 1094 master_ninja.variable('ld_host', 'link')
1080 else: 1095 else:
1081 master_ninja.variable('ld_target', flock + ' linker.lock $cxx_target') 1096 master_ninja.variable('ld_host', flock + ' linker.lock $cxx_host')
1082 1097
1083 if flavor == 'mac': 1098 if flavor == 'mac':
1084 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) 1099 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool'))
1085 master_ninja.newline() 1100 master_ninja.newline()
1086 1101
1087 if flavor != 'win': 1102 if flavor != 'win':
1088 master_ninja.rule( 1103 master_ninja.rule(
1089 'cc', 1104 'cc',
1090 description='CC $out', 1105 description='CC $out',
1091 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' 1106 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c '
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 1295
1281 user_config = params.get('generator_flags', {}).get('config', None) 1296 user_config = params.get('generator_flags', {}).get('config', None)
1282 if user_config: 1297 if user_config:
1283 GenerateOutputForConfig(target_list, target_dicts, data, params, 1298 GenerateOutputForConfig(target_list, target_dicts, data, params,
1284 user_config) 1299 user_config)
1285 else: 1300 else:
1286 config_names = target_dicts[target_list[0]]['configurations'].keys() 1301 config_names = target_dicts[target_list[0]]['configurations'].keys()
1287 for config_name in config_names: 1302 for config_name in config_names:
1288 GenerateOutputForConfig(target_list, target_dicts, data, params, 1303 GenerateOutputForConfig(target_list, target_dicts, data, params,
1289 config_name) 1304 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