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 | 6 import hashlib |
7 import os.path | 7 import os.path |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 # | 210 # |
211 # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file) | 211 # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file) |
212 # into the equivalent ninja path. | 212 # into the equivalent ninja path. |
213 # | 213 # |
214 # - GypPathToUniqueOutput translates a gyp path into a ninja path to write | 214 # - GypPathToUniqueOutput translates a gyp path into a ninja path to write |
215 # an output file; the result can be namespaced such that it is unique | 215 # an output file; the result can be namespaced such that it is unique |
216 # to the input file name as well as the output target name. | 216 # to the input file name as well as the output target name. |
217 | 217 |
218 class NinjaWriter: | 218 class NinjaWriter: |
219 def __init__(self, qualified_target, target_outputs, base_dir, build_dir, | 219 def __init__(self, qualified_target, target_outputs, base_dir, build_dir, |
220 output_file, flavor, abs_build_dir=None): | 220 output_file, flavor, options, abs_build_dir=None): |
221 """ | 221 """ |
222 base_dir: path from source root to directory containing this gyp file, | 222 base_dir: path from source root to directory containing this gyp file, |
223 by gyp semantics, all input paths are relative to this | 223 by gyp semantics, all input paths are relative to this |
224 build_dir: path from source root to build output | 224 build_dir: path from source root to build output |
225 abs_build_dir: absolute path to the build directory | 225 abs_build_dir: absolute path to the build directory |
226 """ | 226 """ |
227 | 227 |
228 self.qualified_target = qualified_target | 228 self.qualified_target = qualified_target |
229 self.target_outputs = target_outputs | 229 self.target_outputs = target_outputs |
230 self.base_dir = base_dir | 230 self.base_dir = base_dir |
231 self.build_dir = build_dir | 231 self.build_dir = build_dir |
232 self.ninja = ninja_syntax.Writer(output_file) | 232 self.ninja = ninja_syntax.Writer(output_file) |
233 self.flavor = flavor | 233 self.flavor = flavor |
| 234 self.options = options |
234 self.abs_build_dir = abs_build_dir | 235 self.abs_build_dir = abs_build_dir |
235 self.obj_ext = '.obj' if flavor == 'win' else '.o' | 236 self.obj_ext = '.obj' if flavor == 'win' else '.o' |
236 if flavor == 'win': | 237 if flavor == 'win': |
237 # See docstring of msvs_emulation.GenerateEnvironmentFiles(). | 238 # See docstring of msvs_emulation.GenerateEnvironmentFiles(). |
238 self.win_env = {} | 239 self.win_env = {} |
239 for arch in ('x86', 'x64'): | 240 for arch in ('x86', 'x64'): |
240 self.win_env[arch] = 'environment.' + arch | 241 self.win_env[arch] = 'environment.' + arch |
241 | 242 |
242 # Relative path from build output dir to base dir. | 243 # Relative path from build output dir to base dir. |
243 self.build_to_base = os.path.join(InvertRelativePath(build_dir), base_dir) | 244 self.build_to_base = os.path.join(InvertRelativePath(build_dir), base_dir) |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 assert self.is_mac_bundle | 1045 assert self.is_mac_bundle |
1045 path = self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']) | 1046 path = self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']) |
1046 return os.path.join(path, self.xcode_settings.GetExecutablePath()) | 1047 return os.path.join(path, self.xcode_settings.GetExecutablePath()) |
1047 | 1048 |
1048 def ComputeOutputFileName(self, spec, type=None): | 1049 def ComputeOutputFileName(self, spec, type=None): |
1049 """Compute the filename of the final output for the current target.""" | 1050 """Compute the filename of the final output for the current target.""" |
1050 if not type: | 1051 if not type: |
1051 type = spec['type'] | 1052 type = spec['type'] |
1052 | 1053 |
1053 default_variables = copy.copy(generator_default_variables) | 1054 default_variables = copy.copy(generator_default_variables) |
1054 CalculateVariables(default_variables, {'flavor': self.flavor}) | 1055 CalculateVariables(default_variables, {'flavor': self.flavor, |
1055 | 1056 'options': self.options }) |
1056 # Compute filename prefix: the product prefix, or a default for | 1057 # Compute filename prefix: the product prefix, or a default for |
1057 # the product type. | 1058 # the product type. |
1058 DEFAULT_PREFIX = { | 1059 DEFAULT_PREFIX = { |
1059 'loadable_module': default_variables['SHARED_LIB_PREFIX'], | 1060 'loadable_module': default_variables['SHARED_LIB_PREFIX'], |
1060 'shared_library': default_variables['SHARED_LIB_PREFIX'], | 1061 'shared_library': default_variables['SHARED_LIB_PREFIX'], |
1061 'static_library': default_variables['STATIC_LIB_PREFIX'], | 1062 'static_library': default_variables['STATIC_LIB_PREFIX'], |
1062 'executable': default_variables['EXECUTABLE_PREFIX'], | 1063 'executable': default_variables['EXECUTABLE_PREFIX'], |
1063 } | 1064 } |
1064 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, '')) | 1065 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, '')) |
1065 | 1066 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 self.ninja.newline() | 1197 self.ninja.newline() |
1197 | 1198 |
1198 return rule_name | 1199 return rule_name |
1199 | 1200 |
1200 | 1201 |
1201 def CalculateVariables(default_variables, params): | 1202 def CalculateVariables(default_variables, params): |
1202 """Calculate additional variables for use in the build (called by gyp).""" | 1203 """Calculate additional variables for use in the build (called by gyp).""" |
1203 global generator_additional_non_configuration_keys | 1204 global generator_additional_non_configuration_keys |
1204 global generator_additional_path_sections | 1205 global generator_additional_path_sections |
1205 flavor = gyp.common.GetFlavor(params) | 1206 flavor = gyp.common.GetFlavor(params) |
| 1207 default_variables.setdefault('HOST_OS', gyp.common.GetHostFlavor(params)) |
1206 if flavor == 'mac': | 1208 if flavor == 'mac': |
1207 default_variables.setdefault('OS', 'mac') | 1209 default_variables.setdefault('OS', 'mac') |
1208 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib') | 1210 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib') |
1209 default_variables.setdefault('SHARED_LIB_DIR', | 1211 default_variables.setdefault('SHARED_LIB_DIR', |
1210 generator_default_variables['PRODUCT_DIR']) | 1212 generator_default_variables['PRODUCT_DIR']) |
1211 default_variables.setdefault('LIB_DIR', | 1213 default_variables.setdefault('LIB_DIR', |
1212 generator_default_variables['PRODUCT_DIR']) | 1214 generator_default_variables['PRODUCT_DIR']) |
1213 | 1215 |
1214 # Copy additional generator configuration data from Xcode, which is shared | 1216 # Copy additional generator configuration data from Xcode, which is shared |
1215 # by the Mac Ninja generator. | 1217 # by the Mac Ninja generator. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 os.makedirs(os.path.dirname(path)) | 1271 os.makedirs(os.path.dirname(path)) |
1270 except OSError: | 1272 except OSError: |
1271 pass | 1273 pass |
1272 return open(path, mode) | 1274 return open(path, mode) |
1273 | 1275 |
1274 | 1276 |
1275 def GenerateOutputForConfig(target_list, target_dicts, data, params, | 1277 def GenerateOutputForConfig(target_list, target_dicts, data, params, |
1276 config_name): | 1278 config_name): |
1277 options = params['options'] | 1279 options = params['options'] |
1278 flavor = gyp.common.GetFlavor(params) | 1280 flavor = gyp.common.GetFlavor(params) |
| 1281 host_flavor = gyp.common.GetHostFlavor(params) |
1279 generator_flags = params.get('generator_flags', {}) | 1282 generator_flags = params.get('generator_flags', {}) |
1280 | 1283 |
1281 # build_dir: relative path from source root to our output files. | 1284 # build_dir: relative path from source root to our output files. |
1282 # e.g. "out/Debug" | 1285 # e.g. "out/Debug" |
1283 build_dir = os.path.join(generator_flags.get('output_dir', 'out'), | 1286 build_dir = os.path.join(generator_flags.get('output_dir', 'out'), |
1284 config_name) | 1287 config_name) |
1285 | 1288 |
1286 toplevel_build = os.path.join(options.toplevel_dir, build_dir) | 1289 toplevel_build = os.path.join(options.toplevel_dir, build_dir) |
1287 | 1290 |
1288 master_ninja = ninja_syntax.Writer( | 1291 master_ninja = ninja_syntax.Writer( |
1289 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), | 1292 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), |
1290 width=120) | 1293 width=120) |
1291 | 1294 |
1292 # Put build-time support tools in out/{config_name}. | 1295 # Put build-time support tools in out/{config_name}. |
1293 gyp.common.CopyTool(flavor, toplevel_build) | 1296 gyp.common.CopyTool(host_flavor, toplevel_build) |
1294 | 1297 |
1295 # Grab make settings for CC/CXX. | 1298 # Grab make settings for CC/CXX. |
1296 # The rules are | 1299 # The rules are |
1297 # - The priority from low to high is gcc/g++, the 'make_global_settings' in | 1300 # - The priority from low to high is gcc/g++, the 'make_global_settings' in |
1298 # gyp, the environment variable. | 1301 # gyp, the environment variable. |
1299 # - If there is no 'make_global_settings' for CC.host/CXX.host or | 1302 # - If there is no 'make_global_settings' for CC.host/CXX.host or |
1300 # 'CC_host'/'CXX_host' enviroment variable, cc_host/cxx_host should be set | 1303 # 'CC_host'/'CXX_host' enviroment variable, cc_host/cxx_host should be set |
1301 # to cc/cxx. | 1304 # to cc/cxx. |
1302 if flavor == 'win': | 1305 if flavor == 'win': |
1303 cc = 'cl.exe' | 1306 cc = 'cl.exe' |
(...skipping 26 matching lines...) Expand all Loading... |
1330 if key == 'CC.host': | 1333 if key == 'CC.host': |
1331 cc_host = os.path.join(build_to_root, value) | 1334 cc_host = os.path.join(build_to_root, value) |
1332 cc_host_global_setting = value | 1335 cc_host_global_setting = value |
1333 if key == 'CXX.host': | 1336 if key == 'CXX.host': |
1334 cxx_host = os.path.join(build_to_root, value) | 1337 cxx_host = os.path.join(build_to_root, value) |
1335 cxx_host_global_setting = value | 1338 cxx_host_global_setting = value |
1336 if key == 'LD.host': | 1339 if key == 'LD.host': |
1337 ld_host = os.path.join(build_to_root, value) | 1340 ld_host = os.path.join(build_to_root, value) |
1338 | 1341 |
1339 flock = 'flock' | 1342 flock = 'flock' |
1340 if flavor == 'mac': | 1343 if host_flavor == 'mac': |
1341 flock = './gyp-mac-tool flock' | 1344 flock = './gyp-mac-tool flock' |
1342 cc = GetEnvironFallback(['CC_target', 'CC'], cc) | 1345 cc = GetEnvironFallback(['CC_target', 'CC'], cc) |
1343 master_ninja.variable('cc', cc) | 1346 master_ninja.variable('cc', cc) |
1344 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) | 1347 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) |
1345 master_ninja.variable('cxx', cxx) | 1348 master_ninja.variable('cxx', cxx) |
1346 ld = GetEnvironFallback(['LD_target', 'LD'], ld) | 1349 ld = GetEnvironFallback(['LD_target', 'LD'], ld) |
1347 | 1350 |
1348 if not cc_host: | 1351 if not cc_host: |
1349 cc_host = cc | 1352 cc_host = cc |
1350 if not cxx_host: | 1353 if not cxx_host: |
(...skipping 22 matching lines...) Expand all Loading... |
1373 cc_host = cc_host_global_setting.replace('$(CC)', cc) | 1376 cc_host = cc_host_global_setting.replace('$(CC)', cc) |
1374 if '$(CXX)' in cxx_host and cxx_host_global_setting: | 1377 if '$(CXX)' in cxx_host and cxx_host_global_setting: |
1375 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) | 1378 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) |
1376 master_ninja.variable('cc_host', cc_host) | 1379 master_ninja.variable('cc_host', cc_host) |
1377 master_ninja.variable('cxx_host', cxx_host) | 1380 master_ninja.variable('cxx_host', cxx_host) |
1378 if flavor == 'win': | 1381 if flavor == 'win': |
1379 master_ninja.variable('ld_host', ld_host) | 1382 master_ninja.variable('ld_host', ld_host) |
1380 else: | 1383 else: |
1381 master_ninja.variable('ld_host', flock + ' linker.lock ' + ld_host) | 1384 master_ninja.variable('ld_host', flock + ' linker.lock ' + ld_host) |
1382 | 1385 |
1383 if flavor == 'mac': | 1386 if host_flavor == 'mac': |
1384 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) | 1387 master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) |
1385 master_ninja.newline() | 1388 master_ninja.newline() |
1386 | 1389 |
1387 if flavor != 'win': | 1390 if flavor != 'win': |
1388 master_ninja.rule( | 1391 master_ninja.rule( |
1389 'cc', | 1392 'cc', |
1390 description='CC $out', | 1393 description='CC $out', |
1391 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' | 1394 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' |
1392 '$cflags_pch_c -c $in -o $out'), | 1395 '$cflags_pch_c -c $in -o $out'), |
1393 depfile='$out.d') | 1396 depfile='$out.d') |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 'link', | 1601 'link', |
1599 description='LINK $out, POSTBUILDS', | 1602 description='LINK $out, POSTBUILDS', |
1600 command=('$ld $ldflags -o $out ' | 1603 command=('$ld $ldflags -o $out ' |
1601 '$in $solibs $libs$postbuilds')) | 1604 '$in $solibs $libs$postbuilds')) |
1602 master_ninja.rule( | 1605 master_ninja.rule( |
1603 'infoplist', | 1606 'infoplist', |
1604 description='INFOPLIST $out', | 1607 description='INFOPLIST $out', |
1605 command=('$cc -E -P -Wno-trigraphs -x c $defines $in -o $out && ' | 1608 command=('$cc -E -P -Wno-trigraphs -x c $defines $in -o $out && ' |
1606 'plutil -convert xml1 $out $out')) | 1609 'plutil -convert xml1 $out $out')) |
1607 master_ninja.rule( | 1610 master_ninja.rule( |
1608 'mac_tool', | |
1609 description='MACTOOL $mactool_cmd $in', | |
1610 command='$env $mac_tool $mactool_cmd $in $out') | |
1611 master_ninja.rule( | |
1612 'package_framework', | 1611 'package_framework', |
1613 description='PACKAGE FRAMEWORK $out, POSTBUILDS', | 1612 description='PACKAGE FRAMEWORK $out, POSTBUILDS', |
1614 command='$mac_tool package-framework $out $version$postbuilds ' | 1613 command='$mac_tool package-framework $out $version$postbuilds ' |
1615 '&& touch $out') | 1614 '&& touch $out') |
| 1615 |
| 1616 if host_flavor == 'mac': |
| 1617 master_ninja.rule( |
| 1618 'mac_tool', |
| 1619 description='MACTOOL $mactool_cmd $in', |
| 1620 command='$env $mac_tool $mactool_cmd $in $out') |
| 1621 |
1616 if flavor == 'win': | 1622 if flavor == 'win': |
1617 master_ninja.rule( | 1623 master_ninja.rule( |
1618 'stamp', | 1624 'stamp', |
1619 description='STAMP $out', | 1625 description='STAMP $out', |
1620 command='%s gyp-win-tool stamp $out' % sys.executable) | 1626 command='%s gyp-win-tool stamp $out' % sys.executable) |
1621 master_ninja.rule( | 1627 master_ninja.rule( |
1622 'copy', | 1628 'copy', |
1623 description='COPY $in $out', | 1629 description='COPY $in $out', |
1624 command='%s gyp-win-tool recursive-mirror $in $out' % sys.executable) | 1630 command='%s gyp-win-tool recursive-mirror $in $out' % sys.executable) |
1625 else: | 1631 else: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 | 1669 |
1664 base_path = os.path.dirname(build_file) | 1670 base_path = os.path.dirname(build_file) |
1665 obj = 'obj' | 1671 obj = 'obj' |
1666 if toolset != 'target': | 1672 if toolset != 'target': |
1667 obj += '.' + toolset | 1673 obj += '.' + toolset |
1668 output_file = os.path.join(obj, base_path, name + '.ninja') | 1674 output_file = os.path.join(obj, base_path, name + '.ninja') |
1669 | 1675 |
1670 abs_build_dir = os.path.abspath(toplevel_build) | 1676 abs_build_dir = os.path.abspath(toplevel_build) |
1671 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, | 1677 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, |
1672 OpenOutput(os.path.join(toplevel_build, output_file)), | 1678 OpenOutput(os.path.join(toplevel_build, output_file)), |
1673 flavor, abs_build_dir=abs_build_dir) | 1679 flavor, options, abs_build_dir=abs_build_dir) |
1674 master_ninja.subninja(output_file) | 1680 master_ninja.subninja(output_file) |
1675 | 1681 |
1676 target = writer.WriteSpec(spec, config_name, generator_flags) | 1682 target = writer.WriteSpec(spec, config_name, generator_flags) |
1677 if target: | 1683 if target: |
1678 if name != target.FinalOutput() and spec['toolset'] == 'target': | 1684 if name != target.FinalOutput() and spec['toolset'] == 'target': |
1679 target_short_names.setdefault(name, []).append(target) | 1685 target_short_names.setdefault(name, []).append(target) |
1680 target_outputs[qualified_target] = target | 1686 target_outputs[qualified_target] = target |
1681 if qualified_target in all_targets: | 1687 if qualified_target in all_targets: |
1682 all_outputs.add(target.FinalOutput()) | 1688 all_outputs.add(target.FinalOutput()) |
1683 | 1689 |
(...skipping 19 matching lines...) Expand all Loading... |
1703 | 1709 |
1704 user_config = params.get('generator_flags', {}).get('config', None) | 1710 user_config = params.get('generator_flags', {}).get('config', None) |
1705 if user_config: | 1711 if user_config: |
1706 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1712 GenerateOutputForConfig(target_list, target_dicts, data, params, |
1707 user_config) | 1713 user_config) |
1708 else: | 1714 else: |
1709 config_names = target_dicts[target_list[0]]['configurations'].keys() | 1715 config_names = target_dicts[target_list[0]]['configurations'].keys() |
1710 for config_name in config_names: | 1716 for config_name in config_names: |
1711 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1717 GenerateOutputForConfig(target_list, target_dicts, data, params, |
1712 config_name) | 1718 config_name) |
OLD | NEW |