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

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

Issue 10833021: Honor $CC/$CC_host and friends in make generator. (Closed) Base URL: http://git.chromium.org/external/gyp.git@master
Patch Set: Remove msvs_emulation.py changes 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 | « pylib/gyp/generator/make.py ('k') | test/compiler-override/compiler.gyp » ('j') | 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 hashlib
7 import os.path
8 import re
9 import subprocess
10 import sys
6 import gyp 11 import gyp
7 import gyp.common 12 import gyp.common
8 import gyp.msvs_emulation 13 import gyp.msvs_emulation
9 import gyp.MSVSVersion 14 import gyp.MSVSVersion
10 import gyp.system_test 15 import gyp.system_test
11 import gyp.xcode_emulation 16 import gyp.xcode_emulation
12 import hashlib
13 import os.path
14 import re
15 import subprocess
16 import sys
17 17
18 from gyp.common import GetEnvironFallback
18 import gyp.ninja_syntax as ninja_syntax 19 import gyp.ninja_syntax as ninja_syntax
19 20
20 generator_default_variables = { 21 generator_default_variables = {
21 'EXECUTABLE_PREFIX': '', 22 'EXECUTABLE_PREFIX': '',
22 'EXECUTABLE_SUFFIX': '', 23 'EXECUTABLE_SUFFIX': '',
23 'STATIC_LIB_PREFIX': 'lib', 24 'STATIC_LIB_PREFIX': 'lib',
24 'STATIC_LIB_SUFFIX': '.a', 25 'STATIC_LIB_SUFFIX': '.a',
25 'SHARED_LIB_PREFIX': 'lib', 26 'SHARED_LIB_PREFIX': 'lib',
26 27
27 # Gyp expects the following variables to be expandable by the build 28 # Gyp expects the following variables to be expandable by the build
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 rspfile=rspfile, rspfile_content=rspfile_content) 1195 rspfile=rspfile, rspfile_content=rspfile_content)
1195 self.ninja.newline() 1196 self.ninja.newline()
1196 1197
1197 return rule_name 1198 return rule_name
1198 1199
1199 1200
1200 def CalculateVariables(default_variables, params): 1201 def CalculateVariables(default_variables, params):
1201 """Calculate additional variables for use in the build (called by gyp).""" 1202 """Calculate additional variables for use in the build (called by gyp)."""
1202 global generator_additional_non_configuration_keys 1203 global generator_additional_non_configuration_keys
1203 global generator_additional_path_sections 1204 global generator_additional_path_sections
1204 cc_target = os.environ.get('CC.target', os.environ.get('CC', 'cc'))
1205 flavor = gyp.common.GetFlavor(params) 1205 flavor = gyp.common.GetFlavor(params)
1206 if flavor == 'mac': 1206 if flavor == 'mac':
1207 default_variables.setdefault('OS', 'mac') 1207 default_variables.setdefault('OS', 'mac')
1208 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib') 1208 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib')
1209 default_variables.setdefault('SHARED_LIB_DIR', 1209 default_variables.setdefault('SHARED_LIB_DIR',
1210 generator_default_variables['PRODUCT_DIR']) 1210 generator_default_variables['PRODUCT_DIR'])
1211 default_variables.setdefault('LIB_DIR', 1211 default_variables.setdefault('LIB_DIR',
1212 generator_default_variables['PRODUCT_DIR']) 1212 generator_default_variables['PRODUCT_DIR'])
1213 1213
1214 # Copy additional generator configuration data from Xcode, which is shared 1214 # Copy additional generator configuration data from Xcode, which is shared
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 1265
1266 def OpenOutput(path, mode='w'): 1266 def OpenOutput(path, mode='w'):
1267 """Open |path| for writing, creating directories if necessary.""" 1267 """Open |path| for writing, creating directories if necessary."""
1268 try: 1268 try:
1269 os.makedirs(os.path.dirname(path)) 1269 os.makedirs(os.path.dirname(path))
1270 except OSError: 1270 except OSError:
1271 pass 1271 pass
1272 return open(path, mode) 1272 return open(path, mode)
1273 1273
1274 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
1282 def GenerateOutputForConfig(target_list, target_dicts, data, params, 1275 def GenerateOutputForConfig(target_list, target_dicts, data, params,
1283 config_name): 1276 config_name):
1284 options = params['options'] 1277 options = params['options']
1285 flavor = gyp.common.GetFlavor(params) 1278 flavor = gyp.common.GetFlavor(params)
1286 generator_flags = params.get('generator_flags', {}) 1279 generator_flags = params.get('generator_flags', {})
1287 1280
1288 # build_dir: relative path from source root to our output files. 1281 # build_dir: relative path from source root to our output files.
1289 # e.g. "out/Debug" 1282 # e.g. "out/Debug"
1290 build_dir = os.path.join(generator_flags.get('output_dir', 'out'), 1283 build_dir = os.path.join(generator_flags.get('output_dir', 'out'),
1291 config_name) 1284 config_name)
1292 1285
1293 toplevel_build = os.path.join(options.toplevel_dir, build_dir) 1286 toplevel_build = os.path.join(options.toplevel_dir, build_dir)
1294 1287
1295 master_ninja = ninja_syntax.Writer( 1288 master_ninja = ninja_syntax.Writer(
1296 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), 1289 OpenOutput(os.path.join(toplevel_build, 'build.ninja')),
1297 width=120) 1290 width=120)
1298 1291
1299 # Put build-time support tools in out/{config_name}. 1292 # Put build-time support tools in out/{config_name}.
1300 gyp.common.CopyTool(flavor, toplevel_build) 1293 gyp.common.CopyTool(flavor, toplevel_build)
1301 1294
1302 # Grab make settings for CC/CXX. 1295 # Grab make settings for CC/CXX.
1303 # The rules are 1296 # The rules are
1304 # - The priority from low to high is gcc/g++, the 'make_global_settings' in 1297 # - The priority from low to high is gcc/g++, the 'make_global_settings' in
1305 # gyp, the environment variable. 1298 # gyp, the environment variable.
1306 # - If there is no 'make_global_settings' for CC.host/CXX.host or 1299 # - 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 1300 # 'CC_host'/'CXX_host' enviroment variable, cc_host/cxx_host should be set
1308 # to cc/cxx. 1301 # to cc/cxx.
1309 if flavor == 'win': 1302 if flavor == 'win':
1310 cc = cxx = 'cl.exe' 1303 cc = 'cl.exe'
1304 cxx = 'cl.exe'
1305 ld = 'link.exe'
1311 gyp.msvs_emulation.GenerateEnvironmentFiles( 1306 gyp.msvs_emulation.GenerateEnvironmentFiles(
1312 toplevel_build, generator_flags, OpenOutput) 1307 toplevel_build, generator_flags, OpenOutput)
1308 ld_host = '$ld'
1313 else: 1309 else:
1314 cc, cxx = 'gcc', 'g++' 1310 cc = 'gcc'
1311 cxx = 'g++'
1312 ld = '$cxx'
1313 ld_host = '$cxx_host'
1314
1315 cc_host = None 1315 cc_host = None
1316 cxx_host = None 1316 cxx_host = None
1317 cc_host_global_setting = None 1317 cc_host_global_setting = None
1318 cxx_host_global_setting = None 1318 cxx_host_global_setting = None
1319 1319
1320 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) 1320 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
1321 make_global_settings = data[build_file].get('make_global_settings', []) 1321 make_global_settings = data[build_file].get('make_global_settings', [])
1322 build_to_root = InvertRelativePath(build_dir) 1322 build_to_root = InvertRelativePath(build_dir)
1323 for key, value in make_global_settings: 1323 for key, value in make_global_settings:
1324 if key == 'CC': cc = os.path.join(build_to_root, value) 1324 if key == 'CC':
1325 if key == 'CXX': cxx = os.path.join(build_to_root, value) 1325 cc = os.path.join(build_to_root, value)
1326 if key == 'CC.host': cc_host = os.path.join(build_to_root, value) 1326 if key == 'CXX':
1327 if key == 'CXX.host': cxx_host = os.path.join(build_to_root, value) 1327 cxx = os.path.join(build_to_root, value)
1328 if key == 'CC.host': cc_host_global_setting = value 1328 if key == 'LD':
1329 if key == 'CXX.host': cxx_host_global_setting = value 1329 ld = os.path.join(build_to_root, value)
1330 if key == 'CC.host':
1331 cc_host = os.path.join(build_to_root, value)
1332 cc_host_global_setting = value
1333 if key == 'CXX.host':
1334 cxx_host = os.path.join(build_to_root, value)
1335 cxx_host_global_setting = value
1336 if key == 'LD.host':
1337 ld_host = os.path.join(build_to_root, value)
1330 1338
1331 flock = 'flock' 1339 flock = 'flock'
1332 if flavor == 'mac': 1340 if flavor == 'mac':
1333 flock = './gyp-mac-tool flock' 1341 flock = './gyp-mac-tool flock'
1334 cc = GetEnvironFallback(['CC_target', 'CC'], cc) 1342 cc = GetEnvironFallback(['CC_target', 'CC'], cc)
1335 master_ninja.variable('cc', cc) 1343 master_ninja.variable('cc', cc)
1336 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) 1344 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx)
1337 master_ninja.variable('cxx', cxx) 1345 master_ninja.variable('cxx', cxx)
1346 ld = GetEnvironFallback(['LD_target', 'LD'], ld)
1338 1347
1339 if not cc_host: cc_host = cc 1348 if not cc_host:
1340 if not cxx_host: cxx_host = cxx 1349 cc_host = cc
1350 if not cxx_host:
1351 cxx_host = cxx
1341 1352
1342 if flavor == 'win': 1353 if flavor == 'win':
1343 master_ninja.variable('ld', 'link.exe') 1354 master_ninja.variable('ld', ld)
1344 master_ninja.variable('idl', 'midl.exe') 1355 master_ninja.variable('idl', 'midl.exe')
1345 master_ninja.variable('ar', 'lib.exe') 1356 master_ninja.variable('ar', 'lib.exe')
1346 master_ninja.variable('rc', 'rc.exe') 1357 master_ninja.variable('rc', 'rc.exe')
1347 master_ninja.variable('asm', 'ml.exe') 1358 master_ninja.variable('asm', 'ml.exe')
1348 master_ninja.variable('mt', 'mt.exe') 1359 master_ninja.variable('mt', 'mt.exe')
1349 master_ninja.variable('use_dep_database', '1') 1360 master_ninja.variable('use_dep_database', '1')
1350 else: 1361 else:
1351 master_ninja.variable('ld', flock + ' linker.lock $cxx') 1362 master_ninja.variable('ld', flock + ' linker.lock ' + ld)
1352 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar')) 1363 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar'))
1353 1364
1354 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar')) 1365 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar'))
1355 cc_host = GetEnvironFallback(['CC_host'], cc_host) 1366 cc_host = GetEnvironFallback(['CC_host'], cc_host)
1356 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host) 1367 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host)
1368 ld_host = GetEnvironFallback(['LD_host'], ld_host)
1369
1357 # The environment variable could be used in 'make_global_settings', like 1370 # The environment variable could be used in 'make_global_settings', like
1358 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here. 1371 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here.
1359 if cc_host.find('$(CC)') != -1 and cc_host_global_setting: 1372 if '$(CC)' in cc_host and cc_host_global_setting:
1360 cc_host = cc_host_global_setting.replace('$(CC)', cc) 1373 cc_host = cc_host_global_setting.replace('$(CC)', cc)
1361 if cxx_host.find('$(CXX)') != -1 and cxx_host_global_setting: 1374 if '$(CXX)' in cxx_host and cxx_host_global_setting:
1362 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) 1375 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx)
1363 master_ninja.variable('cc_host', cc_host) 1376 master_ninja.variable('cc_host', cc_host)
1364 master_ninja.variable('cxx_host', cxx_host) 1377 master_ninja.variable('cxx_host', cxx_host)
1365 if flavor == 'win': 1378 if flavor == 'win':
1366 master_ninja.variable('ld_host', os.environ.get('LD_host', '$ld')) 1379 master_ninja.variable('ld_host', ld_host)
1367 else: 1380 else:
1368 master_ninja.variable('ld_host', flock + ' linker.lock $cxx_host') 1381 master_ninja.variable('ld_host', flock + ' linker.lock ' + ld_host)
1369 1382
1370 if flavor == 'mac': 1383 if flavor == 'mac':
1371 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) 1384 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool'))
1372 master_ninja.newline() 1385 master_ninja.newline()
1373 1386
1374 if flavor != 'win': 1387 if flavor != 'win':
1375 master_ninja.rule( 1388 master_ninja.rule(
1376 'cc', 1389 'cc',
1377 description='CC $out', 1390 description='CC $out',
1378 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' 1391 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c '
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 1703
1691 user_config = params.get('generator_flags', {}).get('config', None) 1704 user_config = params.get('generator_flags', {}).get('config', None)
1692 if user_config: 1705 if user_config:
1693 GenerateOutputForConfig(target_list, target_dicts, data, params, 1706 GenerateOutputForConfig(target_list, target_dicts, data, params,
1694 user_config) 1707 user_config)
1695 else: 1708 else:
1696 config_names = target_dicts[target_list[0]]['configurations'].keys() 1709 config_names = target_dicts[target_list[0]]['configurations'].keys()
1697 for config_name in config_names: 1710 for config_name in config_names:
1698 GenerateOutputForConfig(target_list, target_dicts, data, params, 1711 GenerateOutputForConfig(target_list, target_dicts, data, params,
1699 config_name) 1712 config_name)
OLDNEW
« no previous file with comments | « pylib/gyp/generator/make.py ('k') | test/compiler-override/compiler.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698