Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 } | 51 } |
| 52 | 52 |
| 53 # Placates pylint. | 53 # Placates pylint. |
| 54 generator_additional_non_configuration_keys = [] | 54 generator_additional_non_configuration_keys = [] |
| 55 generator_additional_path_sections = [] | 55 generator_additional_path_sections = [] |
| 56 generator_extra_sources_for_rules = [] | 56 generator_extra_sources_for_rules = [] |
| 57 | 57 |
| 58 # TODO: figure out how to not build extra host objects in the non-cross-compile | 58 # TODO: figure out how to not build extra host objects in the non-cross-compile |
| 59 # case when this is enabled, and enable unconditionally. | 59 # case when this is enabled, and enable unconditionally. |
| 60 generator_supports_multiple_toolsets = ( | 60 generator_supports_multiple_toolsets = ( |
| 61 os.environ.get('AR_target') or os.environ.get('CC_target') or | 61 os.environ.get('GYP_CROSSCOMPILE') or |
| 62 os.environ.get('AR_host') or | |
| 63 os.environ.get('CC_host') or | |
| 64 os.environ.get('CXX_host') or | |
| 65 os.environ.get('AR_target') or | |
| 66 os.environ.get('CC_target') or | |
| 62 os.environ.get('CXX_target')) | 67 os.environ.get('CXX_target')) |
| 63 | 68 |
| 64 | 69 |
| 65 def StripPrefix(arg, prefix): | 70 def StripPrefix(arg, prefix): |
| 66 if arg.startswith(prefix): | 71 if arg.startswith(prefix): |
| 67 return arg[len(prefix):] | 72 return arg[len(prefix):] |
| 68 return arg | 73 return arg |
| 69 | 74 |
| 70 | 75 |
| 71 def QuoteShellArgument(arg, flavor): | 76 def QuoteShellArgument(arg, flavor): |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 env = self.ComputeExportEnvString(env) | 703 env = self.ComputeExportEnvString(env) |
| 699 | 704 |
| 700 self.ninja.build(out, 'mac_tool', info_plist, | 705 self.ninja.build(out, 'mac_tool', info_plist, |
| 701 variables=[('mactool_cmd', 'copy-info-plist'), | 706 variables=[('mactool_cmd', 'copy-info-plist'), |
| 702 ('env', env)]) | 707 ('env', env)]) |
| 703 bundle_depends.append(out) | 708 bundle_depends.append(out) |
| 704 | 709 |
| 705 def WriteSources(self, config_name, config, sources, predepends, | 710 def WriteSources(self, config_name, config, sources, predepends, |
| 706 precompiled_header): | 711 precompiled_header): |
| 707 """Write build rules to compile all of |sources|.""" | 712 """Write build rules to compile all of |sources|.""" |
| 708 if self.toolset == 'target': | 713 if self.toolset == 'host': |
| 709 self.ninja.variable('ar', '$ar_target') | 714 self.ninja.variable('ar', '$ar_host') |
| 710 self.ninja.variable('cc', '$cc_target') | 715 self.ninja.variable('cc', '$cc_host') |
| 711 self.ninja.variable('cxx', '$cxx_target') | 716 self.ninja.variable('cxx', '$cxx_host') |
| 712 self.ninja.variable('ld', '$ld_target') | 717 self.ninja.variable('ld', '$ld_host') |
| 713 | 718 |
| 714 extra_defines = [] | 719 extra_defines = [] |
| 715 if self.flavor == 'mac': | 720 if self.flavor == 'mac': |
| 716 cflags = self.xcode_settings.GetCflags(config_name) | 721 cflags = self.xcode_settings.GetCflags(config_name) |
| 717 cflags_c = self.xcode_settings.GetCflagsC(config_name) | 722 cflags_c = self.xcode_settings.GetCflagsC(config_name) |
| 718 cflags_cc = self.xcode_settings.GetCflagsCC(config_name) | 723 cflags_cc = self.xcode_settings.GetCflagsCC(config_name) |
| 719 cflags_objc = ['$cflags_c'] + \ | 724 cflags_objc = ['$cflags_c'] + \ |
| 720 self.xcode_settings.GetCflagsObjC(config_name) | 725 self.xcode_settings.GetCflagsObjC(config_name) |
| 721 cflags_objcc = ['$cflags_cc'] + \ | 726 cflags_objcc = ['$cflags_cc'] + \ |
| 722 self.xcode_settings.GetCflagsObjCC(config_name) | 727 self.xcode_settings.GetCflagsObjCC(config_name) |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 | 1265 |
| 1261 def OpenOutput(path, mode='w'): | 1266 def OpenOutput(path, mode='w'): |
| 1262 """Open |path| for writing, creating directories if necessary.""" | 1267 """Open |path| for writing, creating directories if necessary.""" |
| 1263 try: | 1268 try: |
| 1264 os.makedirs(os.path.dirname(path)) | 1269 os.makedirs(os.path.dirname(path)) |
| 1265 except OSError: | 1270 except OSError: |
| 1266 pass | 1271 pass |
| 1267 return open(path, mode) | 1272 return open(path, mode) |
| 1268 | 1273 |
| 1269 | 1274 |
| 1275 def GetEnvironFallback(var_list, default): | |
| 1276 for var in var_list: | |
| 1277 if var in os.environ: | |
| 1278 return os.environ[var] | |
| 1279 return default | |
| 1280 | |
| 1281 | |
| 1270 def GenerateOutputForConfig(target_list, target_dicts, data, params, | 1282 def GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 1271 config_name): | 1283 config_name): |
| 1272 options = params['options'] | 1284 options = params['options'] |
| 1273 flavor = gyp.common.GetFlavor(params) | 1285 flavor = gyp.common.GetFlavor(params) |
| 1274 generator_flags = params.get('generator_flags', {}) | 1286 generator_flags = params.get('generator_flags', {}) |
| 1275 | 1287 |
| 1276 # build_dir: relative path from source root to our output files. | 1288 # build_dir: relative path from source root to our output files. |
| 1277 # e.g. "out/Debug" | 1289 # e.g. "out/Debug" |
| 1278 build_dir = os.path.join(generator_flags.get('output_dir', 'out'), | 1290 build_dir = os.path.join(generator_flags.get('output_dir', 'out'), |
| 1279 config_name) | 1291 config_name) |
| 1280 | 1292 |
| 1281 toplevel_build = os.path.join(options.toplevel_dir, build_dir) | 1293 toplevel_build = os.path.join(options.toplevel_dir, build_dir) |
| 1282 | 1294 |
| 1283 master_ninja = ninja_syntax.Writer( | 1295 master_ninja = ninja_syntax.Writer( |
| 1284 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), | 1296 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), |
| 1285 width=120) | 1297 width=120) |
| 1286 | 1298 |
| 1287 # Put build-time support tools in out/{config_name}. | 1299 # Put build-time support tools in out/{config_name}. |
| 1288 gyp.common.CopyTool(flavor, toplevel_build) | 1300 gyp.common.CopyTool(flavor, toplevel_build) |
| 1289 | 1301 |
| 1290 # Grab make settings for CC/CXX. | 1302 # Grab make settings for CC/CXX. |
| 1303 # The rules are | |
| 1304 # - The priority from low to high is gcc/g++, the 'make_global_settings' in | |
| 1305 # gyp, the environment variable. | |
| 1306 # - If there is no 'make_global_settings' for CC.host/CXX.host or | |
| 1307 # 'CC_host'/'CXX_host' enviroment variable, cc_host/cxx_host should be set | |
| 1308 # to cc/cxx. | |
| 1291 if flavor == 'win': | 1309 if flavor == 'win': |
| 1292 cc = cxx = 'cl.exe' | 1310 cc = cxx = 'cl.exe' |
| 1293 gyp.msvs_emulation.GenerateEnvironmentFiles( | 1311 gyp.msvs_emulation.GenerateEnvironmentFiles( |
| 1294 toplevel_build, generator_flags, OpenOutput) | 1312 toplevel_build, generator_flags, OpenOutput) |
| 1295 else: | 1313 else: |
| 1296 cc, cxx = 'gcc', 'g++' | 1314 cc, cxx = 'gcc', 'g++' |
| 1315 cc_host = None | |
| 1316 cxx_host = None | |
| 1317 cc_host_global_setting = None | |
| 1318 cxx_host_global_setting = None | |
| 1319 | |
| 1297 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) | 1320 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) |
| 1298 make_global_settings = data[build_file].get('make_global_settings', []) | 1321 make_global_settings = data[build_file].get('make_global_settings', []) |
| 1299 build_to_root = InvertRelativePath(build_dir) | 1322 build_to_root = InvertRelativePath(build_dir) |
| 1300 for key, value in make_global_settings: | 1323 for key, value in make_global_settings: |
| 1301 if key == 'CC': cc = os.path.join(build_to_root, value) | 1324 if key == 'CC': cc = os.path.join(build_to_root, value) |
| 1302 if key == 'CXX': cxx = os.path.join(build_to_root, value) | 1325 if key == 'CXX': cxx = os.path.join(build_to_root, value) |
| 1326 if key == 'CC.host': cc_host = os.path.join(build_to_root, value) | |
| 1327 if key == 'CXX.host': cxx_host = os.path.join(build_to_root, value) | |
| 1328 if key == 'CC.host': cc_host_global_setting = value | |
| 1329 if key == 'CXX.host': cxx_host_global_setting = value | |
| 1303 | 1330 |
| 1304 flock = 'flock' | 1331 flock = 'flock' |
| 1305 if flavor == 'mac': | 1332 if flavor == 'mac': |
| 1306 flock = './gyp-mac-tool flock' | 1333 flock = './gyp-mac-tool flock' |
| 1307 master_ninja.variable('cc', os.environ.get('CC', cc)) | 1334 cc = GetEnvironFallback(['CC_target', 'CC'], cc) |
| 1308 master_ninja.variable('cxx', os.environ.get('CXX', cxx)) | 1335 master_ninja.variable('cc', cc) |
| 1336 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) | |
| 1337 master_ninja.variable('cxx', cxx) | |
| 1338 | |
| 1339 if not cc_host: cc_host = cc | |
| 1340 if not cxx_host: cxx_host = cxx | |
| 1341 | |
| 1309 if flavor == 'win': | 1342 if flavor == 'win': |
| 1310 master_ninja.variable('ld', 'link.exe') | 1343 master_ninja.variable('ld', 'link.exe') |
| 1311 master_ninja.variable('idl', 'midl.exe') | 1344 master_ninja.variable('idl', 'midl.exe') |
| 1312 master_ninja.variable('ar', 'lib.exe') | 1345 master_ninja.variable('ar', 'lib.exe') |
| 1313 master_ninja.variable('rc', 'rc.exe') | 1346 master_ninja.variable('rc', 'rc.exe') |
| 1314 master_ninja.variable('asm', 'ml.exe') | 1347 master_ninja.variable('asm', 'ml.exe') |
| 1315 master_ninja.variable('mt', 'mt.exe') | 1348 master_ninja.variable('mt', 'mt.exe') |
| 1316 master_ninja.variable('use_dep_database', '1') | 1349 master_ninja.variable('use_dep_database', '1') |
| 1317 else: | 1350 else: |
| 1318 master_ninja.variable('ld', flock + ' linker.lock $cxx') | 1351 master_ninja.variable('ld', flock + ' linker.lock $cxx') |
| 1319 master_ninja.variable('ar', os.environ.get('AR', 'ar')) | 1352 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar')) |
| 1320 | 1353 |
| 1321 master_ninja.variable('ar_target', os.environ.get('AR_target', '$ar')) | 1354 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar')) |
| 1322 master_ninja.variable('cc_target', os.environ.get('CC_target', '$cc')) | 1355 cc_host = GetEnvironFallback(['CC_host'], cc_host) |
| 1323 master_ninja.variable('cxx_target', os.environ.get('CXX_target', '$cxx')) | 1356 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host) |
| 1357 # The environment variable could be used in 'make_global_settings', like | |
| 1358 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here. | |
| 1359 if cc_host.find('$(CC)') != -1 and cc_host_global_setting: | |
| 1360 cc_host = cc_host_global_setting.replace('$(CC)', cc) | |
| 1361 if cxx_host.find('$(CXX)') != -1 and cxx_host_global_setting: | |
| 1362 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
| |
| 1363 master_ninja.variable('cc_host', cc_host) | |
| 1364 master_ninja.variable('cxx_host', cxx_host) | |
| 1324 if flavor == 'win': | 1365 if flavor == 'win': |
| 1325 master_ninja.variable('ld_target', os.environ.get('LD_target', '$ld')) | 1366 master_ninja.variable('ld_host', os.environ.get('LD_host', '$ld')) |
| 1326 else: | 1367 else: |
| 1327 master_ninja.variable('ld_target', flock + ' linker.lock $cxx_target') | 1368 master_ninja.variable('ld_host', flock + ' linker.lock $cxx_host') |
| 1328 | 1369 |
| 1329 if flavor == 'mac': | 1370 if flavor == 'mac': |
| 1330 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) | 1371 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) |
| 1331 master_ninja.newline() | 1372 master_ninja.newline() |
| 1332 | 1373 |
| 1333 if flavor != 'win': | 1374 if flavor != 'win': |
| 1334 master_ninja.rule( | 1375 master_ninja.rule( |
| 1335 'cc', | 1376 'cc', |
| 1336 description='CC $out', | 1377 description='CC $out', |
| 1337 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' | 1378 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 | 1690 |
| 1650 user_config = params.get('generator_flags', {}).get('config', None) | 1691 user_config = params.get('generator_flags', {}).get('config', None) |
| 1651 if user_config: | 1692 if user_config: |
| 1652 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1693 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 1653 user_config) | 1694 user_config) |
| 1654 else: | 1695 else: |
| 1655 config_names = target_dicts[target_list[0]]['configurations'].keys() | 1696 config_names = target_dicts[target_list[0]]['configurations'].keys() |
| 1656 for config_name in config_names: | 1697 for config_name in config_names: |
| 1657 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1698 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 1658 config_name) | 1699 config_name) |
| OLD | NEW |