OLD | NEW |
1 # Copyright (c) 2013 Google Inc. All rights reserved. | 1 # Copyright (c) 2013 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 collections | 5 import collections |
6 import copy | 6 import copy |
7 import hashlib | 7 import hashlib |
8 import json | 8 import json |
9 import multiprocessing | 9 import multiprocessing |
10 import os.path | 10 import os.path |
11 import re | 11 import re |
12 import signal | 12 import signal |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 import gyp | 15 import gyp |
16 import gyp.common | 16 import gyp.common |
17 import gyp.msvs_emulation | 17 import gyp.msvs_emulation |
18 import gyp.MSVSUtil as MSVSUtil | 18 import gyp.MSVSUtil as MSVSUtil |
19 import gyp.xcode_emulation | 19 import gyp.xcode_emulation |
20 from cStringIO import StringIO | 20 from cStringIO import StringIO |
21 | 21 |
22 from gyp.common import GetEnvironFallback | 22 from gyp.common import GetEnvironFallback |
23 import gyp.ninja_syntax as ninja_syntax | 23 import gyp.ninja_syntax as ninja_syntax |
24 | 24 |
25 generator_default_variables = { | 25 generator_default_variables = { |
26 'EXECUTABLE_PREFIX': '', | 26 'EXECUTABLE_PREFIX': '', |
27 'EXECUTABLE_SUFFIX': '', | 27 'EXECUTABLE_SUFFIX': '', |
| 28 'EXTENSION_PREFIX': '', |
| 29 'EXTENSION_SUFFIX': '', |
28 'STATIC_LIB_PREFIX': 'lib', | 30 'STATIC_LIB_PREFIX': 'lib', |
29 'STATIC_LIB_SUFFIX': '.a', | 31 'STATIC_LIB_SUFFIX': '.a', |
30 'SHARED_LIB_PREFIX': 'lib', | 32 'SHARED_LIB_PREFIX': 'lib', |
31 | 33 |
32 # Gyp expects the following variables to be expandable by the build | 34 # Gyp expects the following variables to be expandable by the build |
33 # system to the appropriate locations. Ninja prefers paths to be | 35 # system to the appropriate locations. Ninja prefers paths to be |
34 # known at gyp time. To resolve this, introduce special | 36 # known at gyp time. To resolve this, introduce special |
35 # variables starting with $! and $| (which begin with a $ so gyp knows it | 37 # variables starting with $! and $| (which begin with a $ so gyp knows it |
36 # should be treated specially, but is otherwise an invalid | 38 # should be treated specially, but is otherwise an invalid |
37 # ninja/shell variable) that are passed to gyp here but expanded | 39 # ninja/shell variable) that are passed to gyp here but expanded |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 if not self.is_mac_bundle: | 992 if not self.is_mac_bundle: |
991 self.AppendPostbuildVariable(extra_bindings, spec, output, output) | 993 self.AppendPostbuildVariable(extra_bindings, spec, output, output) |
992 self.ninja.build(output, 'lipo', inputs, variables=extra_bindings) | 994 self.ninja.build(output, 'lipo', inputs, variables=extra_bindings) |
993 return output | 995 return output |
994 | 996 |
995 def WriteLinkForArch(self, ninja_file, spec, config_name, config, | 997 def WriteLinkForArch(self, ninja_file, spec, config_name, config, |
996 link_deps, arch=None): | 998 link_deps, arch=None): |
997 """Write out a link step. Fills out target.binary. """ | 999 """Write out a link step. Fills out target.binary. """ |
998 command = { | 1000 command = { |
999 'executable': 'link', | 1001 'executable': 'link', |
| 1002 'extension': 'link', |
1000 'loadable_module': 'solink_module', | 1003 'loadable_module': 'solink_module', |
1001 'shared_library': 'solink', | 1004 'shared_library': 'solink', |
1002 }[spec['type']] | 1005 }[spec['type']] |
1003 command_suffix = '' | 1006 command_suffix = '' |
1004 | 1007 |
1005 implicit_deps = set() | 1008 implicit_deps = set() |
1006 solibs = set() | 1009 solibs = set() |
1007 | 1010 |
1008 if 'dependencies' in spec: | 1011 if 'dependencies' in spec: |
1009 # Two kinds of dependencies: | 1012 # Two kinds of dependencies: |
(...skipping 29 matching lines...) Expand all Loading... |
1039 implicit_deps.add(final_output) | 1042 implicit_deps.add(final_output) |
1040 | 1043 |
1041 extra_bindings = [] | 1044 extra_bindings = [] |
1042 if self.uses_cpp and self.flavor != 'win': | 1045 if self.uses_cpp and self.flavor != 'win': |
1043 extra_bindings.append(('ld', '$ldxx')) | 1046 extra_bindings.append(('ld', '$ldxx')) |
1044 | 1047 |
1045 output = self.ComputeOutput(spec, arch) | 1048 output = self.ComputeOutput(spec, arch) |
1046 if arch is None and not self.is_mac_bundle: | 1049 if arch is None and not self.is_mac_bundle: |
1047 self.AppendPostbuildVariable(extra_bindings, spec, output, output) | 1050 self.AppendPostbuildVariable(extra_bindings, spec, output, output) |
1048 | 1051 |
1049 is_executable = spec['type'] == 'executable' | 1052 is_executable = (spec['type'] == 'executable' or |
| 1053 spec['type'] == 'extension') |
1050 # The ldflags config key is not used on mac or win. On those platforms | 1054 # The ldflags config key is not used on mac or win. On those platforms |
1051 # linker flags are set via xcode_settings and msvs_settings, respectively. | 1055 # linker flags are set via xcode_settings and msvs_settings, respectively. |
1052 env_ldflags = os.environ.get('LDFLAGS', '').split() | 1056 env_ldflags = os.environ.get('LDFLAGS', '').split() |
1053 if self.flavor == 'mac': | 1057 if self.flavor == 'mac': |
1054 ldflags = self.xcode_settings.GetLdflags(config_name, | 1058 ldflags = self.xcode_settings.GetLdflags(config_name, |
1055 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), | 1059 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), |
1056 self.GypPathToNinja, arch) | 1060 self.GypPathToNinja, arch) |
1057 ldflags = env_ldflags + ldflags | 1061 ldflags = env_ldflags + ldflags |
1058 elif self.flavor == 'win': | 1062 elif self.flavor == 'win': |
1059 manifest_base_name = self.GypPathToUniqueOutput( | 1063 manifest_base_name = self.GypPathToUniqueOutput( |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 default_variables = copy.copy(generator_default_variables) | 1337 default_variables = copy.copy(generator_default_variables) |
1334 CalculateVariables(default_variables, {'flavor': self.flavor}) | 1338 CalculateVariables(default_variables, {'flavor': self.flavor}) |
1335 | 1339 |
1336 # Compute filename prefix: the product prefix, or a default for | 1340 # Compute filename prefix: the product prefix, or a default for |
1337 # the product type. | 1341 # the product type. |
1338 DEFAULT_PREFIX = { | 1342 DEFAULT_PREFIX = { |
1339 'loadable_module': default_variables['SHARED_LIB_PREFIX'], | 1343 'loadable_module': default_variables['SHARED_LIB_PREFIX'], |
1340 'shared_library': default_variables['SHARED_LIB_PREFIX'], | 1344 'shared_library': default_variables['SHARED_LIB_PREFIX'], |
1341 'static_library': default_variables['STATIC_LIB_PREFIX'], | 1345 'static_library': default_variables['STATIC_LIB_PREFIX'], |
1342 'executable': default_variables['EXECUTABLE_PREFIX'], | 1346 'executable': default_variables['EXECUTABLE_PREFIX'], |
| 1347 'extension': default_variables['EXTENSION_PREFIX'], |
1343 } | 1348 } |
1344 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, '')) | 1349 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, '')) |
1345 | 1350 |
1346 # Compute filename extension: the product extension, or a default | 1351 # Compute filename extension: the product extension, or a default |
1347 # for the product type. | 1352 # for the product type. |
1348 DEFAULT_EXTENSION = { | 1353 DEFAULT_EXTENSION = { |
1349 'loadable_module': default_variables['SHARED_LIB_SUFFIX'], | 1354 'loadable_module': default_variables['SHARED_LIB_SUFFIX'], |
1350 'shared_library': default_variables['SHARED_LIB_SUFFIX'], | 1355 'shared_library': default_variables['SHARED_LIB_SUFFIX'], |
1351 'static_library': default_variables['STATIC_LIB_SUFFIX'], | 1356 'static_library': default_variables['STATIC_LIB_SUFFIX'], |
1352 'executable': default_variables['EXECUTABLE_SUFFIX'], | 1357 'executable': default_variables['EXECUTABLE_SUFFIX'], |
| 1358 'extension': default_variables['EXTENSION_SUFFIX'], |
1353 } | 1359 } |
1354 extension = spec.get('product_extension') | 1360 extension = spec.get('product_extension') |
1355 if extension: | 1361 if extension: |
1356 extension = '.' + extension | 1362 extension = '.' + extension |
1357 else: | 1363 else: |
1358 extension = DEFAULT_EXTENSION.get(type, '') | 1364 extension = DEFAULT_EXTENSION.get(type, '') |
1359 | 1365 |
1360 if 'product_name' in spec: | 1366 if 'product_name' in spec: |
1361 # If we were given an explicit name, use that. | 1367 # If we were given an explicit name, use that. |
1362 target = spec['product_name'] | 1368 target = spec['product_name'] |
1363 else: | 1369 else: |
1364 # Otherwise, derive a name from the target name. | 1370 # Otherwise, derive a name from the target name. |
1365 target = spec['target_name'] | 1371 target = spec['target_name'] |
1366 if prefix == 'lib': | 1372 if prefix == 'lib': |
1367 # Snip out an extra 'lib' from libs if appropriate. | 1373 # Snip out an extra 'lib' from libs if appropriate. |
1368 target = StripPrefix(target, 'lib') | 1374 target = StripPrefix(target, 'lib') |
1369 | 1375 |
1370 if type in ('static_library', 'loadable_module', 'shared_library', | 1376 if type in ('static_library', 'loadable_module', 'shared_library', |
1371 'executable'): | 1377 'executable', 'extension'): |
1372 return '%s%s%s' % (prefix, target, extension) | 1378 return '%s%s%s' % (prefix, target, extension) |
1373 elif type == 'none': | 1379 elif type == 'none': |
1374 return '%s.stamp' % target | 1380 return '%s.stamp' % target |
1375 else: | 1381 else: |
1376 raise Exception('Unhandled output type %s' % type) | 1382 raise Exception('Unhandled output type %s' % type) |
1377 | 1383 |
1378 def ComputeOutput(self, spec, arch=None): | 1384 def ComputeOutput(self, spec, arch=None): |
1379 """Compute the path for the final output of the spec.""" | 1385 """Compute the path for the final output of the spec.""" |
1380 type = spec['type'] | 1386 type = spec['type'] |
1381 | 1387 |
1382 if self.flavor == 'win': | 1388 if self.flavor == 'win': |
1383 override = self.msvs_settings.GetOutputName(self.config_name, | 1389 override = self.msvs_settings.GetOutputName(self.config_name, |
1384 self.ExpandSpecial) | 1390 self.ExpandSpecial) |
1385 if override: | 1391 if override: |
1386 return override | 1392 return override |
1387 | 1393 |
1388 if arch is None and self.flavor == 'mac' and type in ( | 1394 if arch is None and self.flavor == 'mac' and type in ( |
1389 'static_library', 'executable', 'shared_library', 'loadable_module'): | 1395 'static_library', |
| 1396 'executable', |
| 1397 'extension', |
| 1398 'shared_library', |
| 1399 'loadable_module'): |
1390 filename = self.xcode_settings.GetExecutablePath() | 1400 filename = self.xcode_settings.GetExecutablePath() |
1391 else: | 1401 else: |
1392 filename = self.ComputeOutputFileName(spec, type) | 1402 filename = self.ComputeOutputFileName(spec, type) |
1393 | 1403 |
1394 if arch is None and 'product_dir' in spec: | 1404 if arch is None and 'product_dir' in spec: |
1395 path = os.path.join(spec['product_dir'], filename) | 1405 path = os.path.join(spec['product_dir'], filename) |
1396 return self.ExpandSpecial(path) | 1406 return self.ExpandSpecial(path) |
1397 | 1407 |
1398 # Some products go into the output root, libraries go into shared library | 1408 # Some products go into the output root, libraries go into shared library |
1399 # dir, and everything else goes into the normal place. | 1409 # dir, and everything else goes into the normal place. |
1400 type_in_output_root = ['executable', 'loadable_module'] | 1410 type_in_output_root = ['executable', 'extension', 'loadable_module'] |
1401 if self.flavor == 'mac' and self.toolset == 'target': | 1411 if self.flavor == 'mac' and self.toolset == 'target': |
1402 type_in_output_root += ['shared_library', 'static_library'] | 1412 type_in_output_root += ['shared_library', 'static_library'] |
1403 elif self.flavor == 'win' and self.toolset == 'target': | 1413 elif self.flavor == 'win' and self.toolset == 'target': |
1404 type_in_output_root += ['shared_library'] | 1414 type_in_output_root += ['shared_library'] |
1405 | 1415 |
1406 if arch is not None: | 1416 if arch is not None: |
1407 # Make sure partial executables don't end up in a bundle or the regular | 1417 # Make sure partial executables don't end up in a bundle or the regular |
1408 # output directory. | 1418 # output directory. |
1409 archdir = 'arch' | 1419 archdir = 'arch' |
1410 if self.toolset != 'target': | 1420 if self.toolset != 'target': |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2220 arglists.append( | 2230 arglists.append( |
2221 (target_list, target_dicts, data, params, config_name)) | 2231 (target_list, target_dicts, data, params, config_name)) |
2222 pool.map(CallGenerateOutputForConfig, arglists) | 2232 pool.map(CallGenerateOutputForConfig, arglists) |
2223 except KeyboardInterrupt, e: | 2233 except KeyboardInterrupt, e: |
2224 pool.terminate() | 2234 pool.terminate() |
2225 raise e | 2235 raise e |
2226 else: | 2236 else: |
2227 for config_name in config_names: | 2237 for config_name in config_names: |
2228 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2238 GenerateOutputForConfig(target_list, target_dicts, data, params, |
2229 config_name) | 2239 config_name) |
OLD | NEW |