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

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

Issue 11031005: Add "standalone_static_library" flag (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
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 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 # that compose a .lib (rather than the .lib itself). That list is stored 153 # that compose a .lib (rather than the .lib itself). That list is stored
154 # here. 154 # here.
155 self.component_objs = None 155 self.component_objs = None
156 # Windows only. The import .lib is the output of a build step, but 156 # Windows only. The import .lib is the output of a build step, but
157 # because dependents only link against the lib (not both the lib and the 157 # because dependents only link against the lib (not both the lib and the
158 # dll) we keep track of the import library here. 158 # dll) we keep track of the import library here.
159 self.import_lib = None 159 self.import_lib = None
160 160
161 def Linkable(self): 161 def Linkable(self):
162 """Return true if this is a target that can be linked against.""" 162 """Return true if this is a target that can be linked against."""
163 return self.type in ('static_library', 'shared_library') 163 return self.type in ('static_library', 'shared_library',
164 'standalone_static_library')
164 165
165 def UsesToc(self, flavor): 166 def UsesToc(self, flavor):
166 """Return true if the target should produce a restat rule based on a TOC 167 """Return true if the target should produce a restat rule based on a TOC
167 file.""" 168 file."""
168 # For bundles, the .TOC should be produced for the binary, not for 169 # For bundles, the .TOC should be produced for the binary, not for
169 # FinalOutput(). But the naive approach would put the TOC file into the 170 # FinalOutput(). But the naive approach would put the TOC file into the
170 # bundle, so don't do this for bundles for now. 171 # bundle, so don't do this for bundles for now.
171 if flavor == 'win' or self.bundle: 172 if flavor == 'win' or self.bundle:
172 return False 173 return False
173 return self.type in ('shared_library', 'loadable_module') 174 return self.type in ('shared_library', 'loadable_module')
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 pch = gyp.xcode_emulation.MacPrefixHeader( 428 pch = gyp.xcode_emulation.MacPrefixHeader(
428 self.xcode_settings, self.GypPathToNinja, 429 self.xcode_settings, self.GypPathToNinja,
429 lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang)) 430 lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang))
430 link_deps = self.WriteSources( 431 link_deps = self.WriteSources(
431 config_name, config, sources, compile_depends_stamp, pch, 432 config_name, config, sources, compile_depends_stamp, pch,
432 case_sensitive_filesystem) 433 case_sensitive_filesystem)
433 # Some actions/rules output 'sources' that are already object files. 434 # Some actions/rules output 'sources' that are already object files.
434 link_deps += [self.GypPathToNinja(f) 435 link_deps += [self.GypPathToNinja(f)
435 for f in sources if f.endswith(self.obj_ext)] 436 for f in sources if f.endswith(self.obj_ext)]
436 437
437 if self.flavor == 'win' and self.target.type == 'static_library': 438 if self.flavor == 'win' and self.target.type in ('static_library',
439 'standalone_static_library'):
438 self.target.component_objs = link_deps 440 self.target.component_objs = link_deps
439 441
440 # Write out a link step, if needed. 442 # Write out a link step, if needed.
441 output = None 443 output = None
442 if link_deps or self.target.actions_stamp or actions_depends: 444 if link_deps or self.target.actions_stamp or actions_depends:
443 output = self.WriteTarget(spec, config_name, config, link_deps, 445 output = self.WriteTarget(spec, config_name, config, link_deps,
444 self.target.actions_stamp or actions_depends) 446 self.target.actions_stamp or actions_depends)
445 if self.is_mac_bundle: 447 if self.is_mac_bundle:
446 mac_bundle_depends.append(output) 448 mac_bundle_depends.append(output)
447 449
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 variables = [] 949 variables = []
948 postbuild = self.GetPostbuildCommand( 950 postbuild = self.GetPostbuildCommand(
949 spec, self.target.binary, self.target.binary) 951 spec, self.target.binary, self.target.binary)
950 if postbuild: 952 if postbuild:
951 variables.append(('postbuilds', postbuild)) 953 variables.append(('postbuilds', postbuild))
952 if self.xcode_settings: 954 if self.xcode_settings:
953 variables.append(('libtool_flags', 955 variables.append(('libtool_flags',
954 self.xcode_settings.GetLibtoolflags(config_name))) 956 self.xcode_settings.GetLibtoolflags(config_name)))
955 self.ninja.build(self.target.binary, 'alink', link_deps, 957 self.ninja.build(self.target.binary, 'alink', link_deps,
956 order_only=compile_deps, variables=variables) 958 order_only=compile_deps, variables=variables)
959 elif spec['type'] == 'standalone_static_library':
960 self.target.binary = self.ComputeOutput(spec)
961 variables = []
962 postbuild = self.GetPostbuildCommand(
963 spec, self.target.binary, self.target.binary)
964 if postbuild:
965 variables.append(('postbuilds', postbuild))
966 if self.xcode_settings:
967 variables.append(('libtool_flags',
968 self.xcode_settings.GetLibtoolflags(config_name)))
969 if self.flavor != 'mac' and self.flavor != 'win':
970 self.ninja.rule(
971 'alink',
972 description='AR $out',
973 command='rm -f $out && $ar rcs $out $in')
974 self.ninja.build(self.target.binary, 'alink', link_deps,
975 order_only=compile_deps, variables=variables)
957 else: 976 else:
958 self.WriteLink(spec, config_name, config, link_deps) 977 self.WriteLink(spec, config_name, config, link_deps)
959 return self.target.binary 978 return self.target.binary
960 979
961 def WriteMacBundle(self, spec, mac_bundle_depends): 980 def WriteMacBundle(self, spec, mac_bundle_depends):
962 assert self.is_mac_bundle 981 assert self.is_mac_bundle
963 package_framework = spec['type'] in ('shared_library', 'loadable_module') 982 package_framework = spec['type'] in ('shared_library', 'loadable_module')
964 output = self.ComputeMacBundleOutput() 983 output = self.ComputeMacBundleOutput()
965 postbuild = self.GetPostbuildCommand(spec, output, self.target.binary, 984 postbuild = self.GetPostbuildCommand(spec, output, self.target.binary,
966 is_command_start=not package_framework) 985 is_command_start=not package_framework)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1082
1064 default_variables = copy.copy(generator_default_variables) 1083 default_variables = copy.copy(generator_default_variables)
1065 CalculateVariables(default_variables, {'flavor': self.flavor}) 1084 CalculateVariables(default_variables, {'flavor': self.flavor})
1066 1085
1067 # Compute filename prefix: the product prefix, or a default for 1086 # Compute filename prefix: the product prefix, or a default for
1068 # the product type. 1087 # the product type.
1069 DEFAULT_PREFIX = { 1088 DEFAULT_PREFIX = {
1070 'loadable_module': default_variables['SHARED_LIB_PREFIX'], 1089 'loadable_module': default_variables['SHARED_LIB_PREFIX'],
1071 'shared_library': default_variables['SHARED_LIB_PREFIX'], 1090 'shared_library': default_variables['SHARED_LIB_PREFIX'],
1072 'static_library': default_variables['STATIC_LIB_PREFIX'], 1091 'static_library': default_variables['STATIC_LIB_PREFIX'],
1092 'standalone_static_library': default_variables['STATIC_LIB_PREFIX'],
1073 'executable': default_variables['EXECUTABLE_PREFIX'], 1093 'executable': default_variables['EXECUTABLE_PREFIX'],
1074 } 1094 }
1075 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, '')) 1095 prefix = spec.get('product_prefix', DEFAULT_PREFIX.get(type, ''))
1076 1096
1077 # Compute filename extension: the product extension, or a default 1097 # Compute filename extension: the product extension, or a default
1078 # for the product type. 1098 # for the product type.
1079 DEFAULT_EXTENSION = { 1099 DEFAULT_EXTENSION = {
1080 'loadable_module': default_variables['SHARED_LIB_SUFFIX'], 1100 'loadable_module': default_variables['SHARED_LIB_SUFFIX'],
1081 'shared_library': default_variables['SHARED_LIB_SUFFIX'], 1101 'shared_library': default_variables['SHARED_LIB_SUFFIX'],
1082 'static_library': default_variables['STATIC_LIB_SUFFIX'], 1102 'static_library': default_variables['STATIC_LIB_SUFFIX'],
1103 'standalone_static_library': default_variables['STATIC_LIB_SUFFIX'],
1083 'executable': default_variables['EXECUTABLE_SUFFIX'], 1104 'executable': default_variables['EXECUTABLE_SUFFIX'],
1084 } 1105 }
1085 extension = spec.get('product_extension') 1106 extension = spec.get('product_extension')
1086 if extension: 1107 if extension:
1087 extension = '.' + extension 1108 extension = '.' + extension
1088 else: 1109 else:
1089 extension = DEFAULT_EXTENSION.get(type, '') 1110 extension = DEFAULT_EXTENSION.get(type, '')
1090 1111
1091 if 'product_name' in spec: 1112 if 'product_name' in spec:
1092 # If we were given an explicit name, use that. 1113 # If we were given an explicit name, use that.
1093 target = spec['product_name'] 1114 target = spec['product_name']
1094 else: 1115 else:
1095 # Otherwise, derive a name from the target name. 1116 # Otherwise, derive a name from the target name.
1096 target = spec['target_name'] 1117 target = spec['target_name']
1097 if prefix == 'lib': 1118 if prefix == 'lib':
1098 # Snip out an extra 'lib' from libs if appropriate. 1119 # Snip out an extra 'lib' from libs if appropriate.
1099 target = StripPrefix(target, 'lib') 1120 target = StripPrefix(target, 'lib')
1100 1121
1101 if type in ('static_library', 'loadable_module', 'shared_library', 1122 if type in ('executable', 'loadable_module', 'shared_library',
1102 'executable'): 1123 'static_library', 'standalone_static_library'):
1103 return '%s%s%s' % (prefix, target, extension) 1124 return '%s%s%s' % (prefix, target, extension)
1104 elif type == 'none': 1125 elif type == 'none':
1105 return '%s.stamp' % target 1126 return '%s.stamp' % target
1106 else: 1127 else:
1107 raise Exception('Unhandled output type %s' % type) 1128 raise Exception('Unhandled output type %s' % type)
1108 1129
1109 def ComputeOutput(self, spec, type=None): 1130 def ComputeOutput(self, spec, type=None):
1110 """Compute the path for the final output of the spec.""" 1131 """Compute the path for the final output of the spec."""
1111 assert not self.is_mac_bundle or type 1132 assert not self.is_mac_bundle or type
1112 1133
1113 if not type: 1134 if not type:
1114 type = spec['type'] 1135 type = spec['type']
1115 1136
1116 if self.flavor == 'win': 1137 if self.flavor == 'win':
1117 override = self.msvs_settings.GetOutputName(self.config_name, 1138 override = self.msvs_settings.GetOutputName(self.config_name,
1118 self.ExpandSpecial) 1139 self.ExpandSpecial)
1119 if override: 1140 if override:
1120 return override 1141 return override
1121 1142
1122 if self.flavor == 'mac' and type in ( 1143 if self.flavor == 'mac' and type in (
1123 'static_library', 'executable', 'shared_library', 'loadable_module'): 1144 'executable', 'loadable_module', 'shared_library', 'static_library',
1145 'standalone_static_library'):
1124 filename = self.xcode_settings.GetExecutablePath() 1146 filename = self.xcode_settings.GetExecutablePath()
1125 else: 1147 else:
1126 filename = self.ComputeOutputFileName(spec, type) 1148 filename = self.ComputeOutputFileName(spec, type)
1127 1149
1128 if 'product_dir' in spec: 1150 if 'product_dir' in spec:
1129 path = os.path.join(spec['product_dir'], filename) 1151 path = os.path.join(spec['product_dir'], filename)
1130 return self.ExpandSpecial(path) 1152 return self.ExpandSpecial(path)
1131 1153
1132 # Some products go into the output root, libraries go into shared library 1154 # Some products go into the output root, libraries go into shared library
1133 # dir, and everything else goes into the normal place. 1155 # dir, and everything else goes into the normal place.
1134 type_in_output_root = ['executable', 'loadable_module'] 1156 type_in_output_root = ['executable', 'loadable_module',
1157 'standalone_static_library']
1135 if self.flavor == 'mac' and self.toolset == 'target': 1158 if self.flavor == 'mac' and self.toolset == 'target':
1136 type_in_output_root += ['shared_library', 'static_library'] 1159 type_in_output_root += ['shared_library', 'static_library']
1137 elif self.flavor == 'win' and self.toolset == 'target': 1160 elif self.flavor == 'win' and self.toolset == 'target':
1138 type_in_output_root += ['shared_library'] 1161 type_in_output_root += ['shared_library']
1139 1162
1140 if type in type_in_output_root: 1163 if type in type_in_output_root:
1141 return filename 1164 return filename
1142 elif type == 'shared_library': 1165 elif type == 'shared_library':
1143 libdir = 'lib' 1166 libdir = 'lib'
1144 if self.toolset != 'target': 1167 if self.toolset != 'target':
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 1757
1735 user_config = params.get('generator_flags', {}).get('config', None) 1758 user_config = params.get('generator_flags', {}).get('config', None)
1736 if user_config: 1759 if user_config:
1737 GenerateOutputForConfig(target_list, target_dicts, data, params, 1760 GenerateOutputForConfig(target_list, target_dicts, data, params,
1738 user_config) 1761 user_config)
1739 else: 1762 else:
1740 config_names = target_dicts[target_list[0]]['configurations'].keys() 1763 config_names = target_dicts[target_list[0]]['configurations'].keys()
1741 for config_name in config_names: 1764 for config_name in config_names:
1742 GenerateOutputForConfig(target_list, target_dicts, data, params, 1765 GenerateOutputForConfig(target_list, target_dicts, data, params,
1743 config_name) 1766 config_name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698