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

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

Issue 376603002: This CL adds support for extension in GYP. (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Created 6 years, 5 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 | « no previous file | pylib/gyp/generator/xcode.py » ('j') | pylib/gyp/xcode_emulation.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 17 matching lines...) Expand all
1077 else: 1081 else:
1078 # Respect environment variables related to build, but target-specific 1082 # Respect environment variables related to build, but target-specific
1079 # flags can still override them. 1083 # flags can still override them.
1080 ldflags = env_ldflags + config.get('ldflags', []) 1084 ldflags = env_ldflags + config.get('ldflags', [])
1081 if is_executable and len(solibs): 1085 if is_executable and len(solibs):
1082 rpath = 'lib/' 1086 rpath = 'lib/'
1083 if self.toolset != 'target': 1087 if self.toolset != 'target':
1084 rpath += self.toolset 1088 rpath += self.toolset
1085 ldflags.append('-Wl,-rpath=\$$ORIGIN/%s' % rpath) 1089 ldflags.append('-Wl,-rpath=\$$ORIGIN/%s' % rpath)
1086 ldflags.append('-Wl,-rpath-link=%s' % rpath) 1090 ldflags.append('-Wl,-rpath-link=%s' % rpath)
1091
justincohen 2014/07/07 14:13:58 nit: blank line
olivierrobin 2014/07/07 14:36:35 Done.
1087 self.WriteVariableList(ninja_file, 'ldflags', 1092 self.WriteVariableList(ninja_file, 'ldflags',
1088 gyp.common.uniquer(map(self.ExpandSpecial, ldflags))) 1093 gyp.common.uniquer(map(self.ExpandSpecial, ldflags)))
1089 1094
1090 library_dirs = config.get('library_dirs', []) 1095 library_dirs = config.get('library_dirs', [])
1091 if self.flavor == 'win': 1096 if self.flavor == 'win':
1092 library_dirs = [self.msvs_settings.ConvertVSMacros(l, config_name) 1097 library_dirs = [self.msvs_settings.ConvertVSMacros(l, config_name)
1093 for l in library_dirs] 1098 for l in library_dirs]
1094 library_dirs = ['/LIBPATH:' + QuoteShellArgument(self.GypPathToNinja(l), 1099 library_dirs = ['/LIBPATH:' + QuoteShellArgument(self.GypPathToNinja(l),
1095 self.flavor) 1100 self.flavor)
1096 for l in library_dirs] 1101 for l in library_dirs]
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 default_variables = copy.copy(generator_default_variables) 1338 default_variables = copy.copy(generator_default_variables)
1334 CalculateVariables(default_variables, {'flavor': self.flavor}) 1339 CalculateVariables(default_variables, {'flavor': self.flavor})
1335 1340
1336 # Compute filename prefix: the product prefix, or a default for 1341 # Compute filename prefix: the product prefix, or a default for
1337 # the product type. 1342 # the product type.
1338 DEFAULT_PREFIX = { 1343 DEFAULT_PREFIX = {
1339 'loadable_module': default_variables['SHARED_LIB_PREFIX'], 1344 'loadable_module': default_variables['SHARED_LIB_PREFIX'],
1340 'shared_library': default_variables['SHARED_LIB_PREFIX'], 1345 'shared_library': default_variables['SHARED_LIB_PREFIX'],
1341 'static_library': default_variables['STATIC_LIB_PREFIX'], 1346 'static_library': default_variables['STATIC_LIB_PREFIX'],
1342 'executable': default_variables['EXECUTABLE_PREFIX'], 1347 'executable': default_variables['EXECUTABLE_PREFIX'],
1348 'extension': default_variables['EXTENSION_PREFIX'],
1343 } 1349 }
1344 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, '')) 1350 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, ''))
1345 1351
1346 # Compute filename extension: the product extension, or a default 1352 # Compute filename extension: the product extension, or a default
1347 # for the product type. 1353 # for the product type.
1348 DEFAULT_EXTENSION = { 1354 DEFAULT_EXTENSION = {
1349 'loadable_module': default_variables['SHARED_LIB_SUFFIX'], 1355 'loadable_module': default_variables['SHARED_LIB_SUFFIX'],
1350 'shared_library': default_variables['SHARED_LIB_SUFFIX'], 1356 'shared_library': default_variables['SHARED_LIB_SUFFIX'],
1351 'static_library': default_variables['STATIC_LIB_SUFFIX'], 1357 'static_library': default_variables['STATIC_LIB_SUFFIX'],
1352 'executable': default_variables['EXECUTABLE_SUFFIX'], 1358 'executable': default_variables['EXECUTABLE_SUFFIX'],
1359 'extension': default_variables['EXTENSION_SUFFIX'],
1353 } 1360 }
1354 extension = spec.get('product_extension') 1361 extension = spec.get('product_extension')
1355 if extension: 1362 if extension:
1356 extension = '.' + extension 1363 extension = '.' + extension
1357 else: 1364 else:
1358 extension = DEFAULT_EXTENSION.get(type, '') 1365 extension = DEFAULT_EXTENSION.get(type, '')
1359 1366
1360 if 'product_name' in spec: 1367 if 'product_name' in spec:
1361 # If we were given an explicit name, use that. 1368 # If we were given an explicit name, use that.
1362 target = spec['product_name'] 1369 target = spec['product_name']
1363 else: 1370 else:
1364 # Otherwise, derive a name from the target name. 1371 # Otherwise, derive a name from the target name.
1365 target = spec['target_name'] 1372 target = spec['target_name']
1366 if prefix == 'lib': 1373 if prefix == 'lib':
1367 # Snip out an extra 'lib' from libs if appropriate. 1374 # Snip out an extra 'lib' from libs if appropriate.
1368 target = StripPrefix(target, 'lib') 1375 target = StripPrefix(target, 'lib')
1369 1376
1370 if type in ('static_library', 'loadable_module', 'shared_library', 1377 if type in ('static_library', 'loadable_module', 'shared_library',
1371 'executable'): 1378 'executable', 'extension'):
1372 return '%s%s%s' % (prefix, target, extension) 1379 return '%s%s%s' % (prefix, target, extension)
1373 elif type == 'none': 1380 elif type == 'none':
1374 return '%s.stamp' % target 1381 return '%s.stamp' % target
1375 else: 1382 else:
1376 raise Exception('Unhandled output type %s' % type) 1383 raise Exception('Unhandled output type %s' % type)
1377 1384
1378 def ComputeOutput(self, spec, arch=None): 1385 def ComputeOutput(self, spec, arch=None):
1379 """Compute the path for the final output of the spec.""" 1386 """Compute the path for the final output of the spec."""
1380 type = spec['type'] 1387 type = spec['type']
1381 1388
1382 if self.flavor == 'win': 1389 if self.flavor == 'win':
1383 override = self.msvs_settings.GetOutputName(self.config_name, 1390 override = self.msvs_settings.GetOutputName(self.config_name,
1384 self.ExpandSpecial) 1391 self.ExpandSpecial)
1385 if override: 1392 if override:
1386 return override 1393 return override
1387 1394
1388 if arch is None and self.flavor == 'mac' and type in ( 1395 if arch is None and self.flavor == 'mac' and type in (
1389 'static_library', 'executable', 'shared_library', 'loadable_module'): 1396 'static_library',
1397 'executable',
1398 'extension',
1399 'shared_library',
1400 'loadable_module'):
1390 filename = self.xcode_settings.GetExecutablePath() 1401 filename = self.xcode_settings.GetExecutablePath()
1391 else: 1402 else:
1392 filename = self.ComputeOutputFileName(spec, type) 1403 filename = self.ComputeOutputFileName(spec, type)
1393 1404
1394 if arch is None and 'product_dir' in spec: 1405 if arch is None and 'product_dir' in spec:
1395 path = os.path.join(spec['product_dir'], filename) 1406 path = os.path.join(spec['product_dir'], filename)
1396 return self.ExpandSpecial(path) 1407 return self.ExpandSpecial(path)
1397 1408
1398 # Some products go into the output root, libraries go into shared library 1409 # Some products go into the output root, libraries go into shared library
1399 # dir, and everything else goes into the normal place. 1410 # dir, and everything else goes into the normal place.
1400 type_in_output_root = ['executable', 'loadable_module'] 1411 type_in_output_root = ['executable', 'extension', 'loadable_module']
1401 if self.flavor == 'mac' and self.toolset == 'target': 1412 if self.flavor == 'mac' and self.toolset == 'target':
1402 type_in_output_root += ['shared_library', 'static_library'] 1413 type_in_output_root += ['shared_library', 'static_library']
1403 elif self.flavor == 'win' and self.toolset == 'target': 1414 elif self.flavor == 'win' and self.toolset == 'target':
1404 type_in_output_root += ['shared_library'] 1415 type_in_output_root += ['shared_library']
1405 1416
1406 if arch is not None: 1417 if arch is not None:
1407 # Make sure partial executables don't end up in a bundle or the regular 1418 # Make sure partial executables don't end up in a bundle or the regular
1408 # output directory. 1419 # output directory.
1409 archdir = 'arch' 1420 archdir = 'arch'
1410 if self.toolset != 'target': 1421 if self.toolset != 'target':
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
2220 arglists.append( 2231 arglists.append(
2221 (target_list, target_dicts, data, params, config_name)) 2232 (target_list, target_dicts, data, params, config_name))
2222 pool.map(CallGenerateOutputForConfig, arglists) 2233 pool.map(CallGenerateOutputForConfig, arglists)
2223 except KeyboardInterrupt, e: 2234 except KeyboardInterrupt, e:
2224 pool.terminate() 2235 pool.terminate()
2225 raise e 2236 raise e
2226 else: 2237 else:
2227 for config_name in config_names: 2238 for config_name in config_names:
2228 GenerateOutputForConfig(target_list, target_dicts, data, params, 2239 GenerateOutputForConfig(target_list, target_dicts, data, params,
2229 config_name) 2240 config_name)
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/generator/xcode.py » ('j') | pylib/gyp/xcode_emulation.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698