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 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 Loading... | |
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 Loading... | |
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) |
1313 else: | 1308 else: |
1314 cc, cxx = 'gcc', 'g++' | 1309 cc = 'gcc' |
1310 cxx = 'g++' | |
1311 ld = '$cxx' | |
1312 | |
1315 cc_host = None | 1313 cc_host = None |
1316 cxx_host = None | 1314 cxx_host = None |
1317 cc_host_global_setting = None | 1315 cc_host_global_setting = None |
1318 cxx_host_global_setting = None | 1316 cxx_host_global_setting = None |
1319 | 1317 |
1320 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) | 1318 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) |
1321 make_global_settings = data[build_file].get('make_global_settings', []) | 1319 make_global_settings = data[build_file].get('make_global_settings', []) |
1322 build_to_root = InvertRelativePath(build_dir) | 1320 build_to_root = InvertRelativePath(build_dir) |
1323 for key, value in make_global_settings: | 1321 for key, value in make_global_settings: |
1324 if key == 'CC': cc = os.path.join(build_to_root, value) | 1322 if key == 'CC': |
1325 if key == 'CXX': cxx = os.path.join(build_to_root, value) | 1323 cc = os.path.join(build_to_root, value) |
1326 if key == 'CC.host': cc_host = os.path.join(build_to_root, value) | 1324 if key == 'CXX': |
1327 if key == 'CXX.host': cxx_host = os.path.join(build_to_root, value) | 1325 cxx = os.path.join(build_to_root, value) |
1328 if key == 'CC.host': cc_host_global_setting = value | 1326 if key == 'CC.host': |
1329 if key == 'CXX.host': cxx_host_global_setting = value | 1327 cc_host = os.path.join(build_to_root, value) |
1328 cc_host_global_setting = value | |
1329 if key == 'CXX.host': | |
1330 cxx_host = os.path.join(build_to_root, value) | |
1331 cxx_host_global_setting = value | |
1330 | 1332 |
1331 flock = 'flock' | 1333 flock = 'flock' |
1332 if flavor == 'mac': | 1334 if flavor == 'mac': |
1333 flock = './gyp-mac-tool flock' | 1335 flock = './gyp-mac-tool flock' |
1334 cc = GetEnvironFallback(['CC_target', 'CC'], cc) | 1336 cc = GetEnvironFallback(['CC_target', 'CC'], cc) |
1335 master_ninja.variable('cc', cc) | 1337 master_ninja.variable('cc', cc) |
1336 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) | 1338 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) |
1337 master_ninja.variable('cxx', cxx) | 1339 master_ninja.variable('cxx', cxx) |
1340 ld = GetEnvironFallback(['LD_target', 'LD'], ld) | |
1338 | 1341 |
1339 if not cc_host: cc_host = cc | 1342 if not cc_host: cc_host = cc |
1340 if not cxx_host: cxx_host = cxx | 1343 if not cxx_host: cxx_host = cxx |
1341 | 1344 |
1342 if flavor == 'win': | 1345 if flavor == 'win': |
1343 master_ninja.variable('ld', 'link.exe') | 1346 master_ninja.variable('ld', ld) |
1344 master_ninja.variable('idl', 'midl.exe') | 1347 master_ninja.variable('idl', 'midl.exe') |
1345 master_ninja.variable('ar', 'lib.exe') | 1348 master_ninja.variable('ar', 'lib.exe') |
1346 master_ninja.variable('rc', 'rc.exe') | 1349 master_ninja.variable('rc', 'rc.exe') |
1347 master_ninja.variable('asm', 'ml.exe') | 1350 master_ninja.variable('asm', 'ml.exe') |
1348 master_ninja.variable('mt', 'mt.exe') | 1351 master_ninja.variable('mt', 'mt.exe') |
1349 master_ninja.variable('use_dep_database', '1') | 1352 master_ninja.variable('use_dep_database', '1') |
1350 else: | 1353 else: |
1351 master_ninja.variable('ld', flock + ' linker.lock $cxx') | 1354 master_ninja.variable('ld', flock + ' linker.lock ' + ld) |
1352 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar')) | 1355 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar')) |
1353 | 1356 |
1354 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar')) | 1357 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar')) |
1355 cc_host = GetEnvironFallback(['CC_host'], cc_host) | 1358 cc_host = GetEnvironFallback(['CC_host'], cc_host) |
1356 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host) | 1359 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host) |
1357 # The environment variable could be used in 'make_global_settings', like | 1360 # The environment variable could be used in 'make_global_settings', like |
1358 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here. | 1361 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here. |
1359 if cc_host.find('$(CC)') != -1 and cc_host_global_setting: | 1362 if '$(CC)' in cc_host and cc_host_global_setting: |
1360 cc_host = cc_host_global_setting.replace('$(CC)', cc) | 1363 cc_host = cc_host_global_setting.replace('$(CC)', cc) |
1361 if cxx_host.find('$(CXX)') != -1 and cxx_host_global_setting: | 1364 if '$(CXX)' in cxx_host and cxx_host_global_setting: |
1362 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) | 1365 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) |
1363 master_ninja.variable('cc_host', cc_host) | 1366 master_ninja.variable('cc_host', cc_host) |
1364 master_ninja.variable('cxx_host', cxx_host) | 1367 master_ninja.variable('cxx_host', cxx_host) |
1365 if flavor == 'win': | 1368 if flavor == 'win': |
1366 master_ninja.variable('ld_host', os.environ.get('LD_host', '$ld')) | 1369 master_ninja.variable('ld_host', os.environ.get('LD_host', '$ld')) |
1367 else: | 1370 else: |
1368 master_ninja.variable('ld_host', flock + ' linker.lock $cxx_host') | 1371 ld_host = os.environ.get('LD_host', '$cxx_host') |
1372 master_ninja.variable('ld_host', flock + ' linker.lock ' + ld_host) | |
1369 | 1373 |
1370 if flavor == 'mac': | 1374 if flavor == 'mac': |
1371 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) | 1375 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) |
1372 master_ninja.newline() | 1376 master_ninja.newline() |
1373 | 1377 |
1374 if flavor != 'win': | 1378 if flavor != 'win': |
1375 master_ninja.rule( | 1379 master_ninja.rule( |
1376 'cc', | 1380 'cc', |
1377 description='CC $out', | 1381 description='CC $out', |
1378 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' | 1382 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1509 master_ninja.rule('solink', description=dlldesc, command=dllcmd, | 1513 master_ninja.rule('solink', description=dlldesc, command=dllcmd, |
1510 rspfile='$dll.rsp', | 1514 rspfile='$dll.rsp', |
1511 rspfile_content='$libs $in_newline $ldflags', | 1515 rspfile_content='$libs $in_newline $ldflags', |
1512 restat=True) | 1516 restat=True) |
1513 master_ninja.rule('solink_module', description=dlldesc, command=dllcmd, | 1517 master_ninja.rule('solink_module', description=dlldesc, command=dllcmd, |
1514 rspfile='$dll.rsp', | 1518 rspfile='$dll.rsp', |
1515 rspfile_content='$libs $in_newline $ldflags', | 1519 rspfile_content='$libs $in_newline $ldflags', |
1516 restat=True) | 1520 restat=True) |
1517 # Note that ldflags goes at the end so that it has the option of | 1521 # Note that ldflags goes at the end so that it has the option of |
1518 # overriding default settings earlier in the command line. | 1522 # overriding default settings earlier in the command line. |
1523 command = ('%s gyp-win-tool link-wrapper $arch ' | |
1524 '$ld /nologo /OUT:$out /PDB:$out.pdb @$out.rsp' % | |
1525 sys.executable) | |
1526 if ('LD_target' not in os.environ | |
1527 and 'LD' not in os.environ | |
1528 and 'LD_host' not in os.environ): | |
1529 command += (' && %s gyp-win-tool manifest-wrapper $arch ' | |
1530 '$mt -nologo -manifest $manifests -out:$out.manifest' % | |
Nico
2012/08/13 23:14:07
nit: Windows doesn't do cross-compiling, this isn'
Sam Clegg
2012/08/14 21:10:32
Done
| |
1531 sys.executable) | |
1519 master_ninja.rule( | 1532 master_ninja.rule( |
1520 'link', | 1533 'link', |
1521 description='LINK $out', | 1534 description='LINK $out', |
1522 command=('%s gyp-win-tool link-wrapper $arch ' | 1535 command=command, |
1523 '$ld /nologo /OUT:$out /PDB:$out.pdb @$out.rsp && ' | |
1524 '%s gyp-win-tool manifest-wrapper $arch ' | |
1525 '$mt -nologo -manifest $manifests -out:$out.manifest' % | |
1526 (sys.executable, sys.executable)), | |
1527 rspfile='$out.rsp', | 1536 rspfile='$out.rsp', |
1528 rspfile_content='$in_newline $libs $ldflags') | 1537 rspfile_content='$in_newline $libs $ldflags') |
1529 else: | 1538 else: |
1530 master_ninja.rule( | 1539 master_ninja.rule( |
1531 'objc', | 1540 'objc', |
1532 description='OBJC $out', | 1541 description='OBJC $out', |
1533 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc ' | 1542 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc ' |
1534 '$cflags_pch_objc -c $in -o $out'), | 1543 '$cflags_pch_objc -c $in -o $out'), |
1535 depfile='$out.d') | 1544 depfile='$out.d') |
1536 master_ninja.rule( | 1545 master_ninja.rule( |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1690 | 1699 |
1691 user_config = params.get('generator_flags', {}).get('config', None) | 1700 user_config = params.get('generator_flags', {}).get('config', None) |
1692 if user_config: | 1701 if user_config: |
1693 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1702 GenerateOutputForConfig(target_list, target_dicts, data, params, |
1694 user_config) | 1703 user_config) |
1695 else: | 1704 else: |
1696 config_names = target_dicts[target_list[0]]['configurations'].keys() | 1705 config_names = target_dicts[target_list[0]]['configurations'].keys() |
1697 for config_name in config_names: | 1706 for config_name in config_names: |
1698 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1707 GenerateOutputForConfig(target_list, target_dicts, data, params, |
1699 config_name) | 1708 config_name) |
OLD | NEW |