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 |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 'c': 'cflags_pch_c', | 1051 'c': 'cflags_pch_c', |
1052 'cc': 'cflags_pch_cc', | 1052 'cc': 'cflags_pch_cc', |
1053 'm': 'cflags_pch_objc', | 1053 'm': 'cflags_pch_objc', |
1054 'mm': 'cflags_pch_objcc', | 1054 'mm': 'cflags_pch_objcc', |
1055 }[lang] | 1055 }[lang] |
1056 | 1056 |
1057 map = { 'c': 'cc', 'cc': 'cxx', 'm': 'objc', 'mm': 'objcxx', } | 1057 map = { 'c': 'cc', 'cc': 'cxx', 'm': 'objc', 'mm': 'objcxx', } |
1058 cmd = map.get(lang) | 1058 cmd = map.get(lang) |
1059 ninja_file.build(gch, cmd, input, variables=[(var_name, lang_flag)]) | 1059 ninja_file.build(gch, cmd, input, variables=[(var_name, lang_flag)]) |
1060 | 1060 |
1061 def WriteLink(self, spec, config_name, config, link_deps): | 1061 def WriteLink(self, spec, config_name, config, link_deps, compile_deps): |
1062 """Write out a link step. Fills out target.binary. """ | 1062 """Write out a link step. Fills out target.binary. """ |
1063 if self.flavor != 'mac' or len(self.archs) == 1: | 1063 if self.flavor != 'mac' or len(self.archs) == 1: |
1064 return self.WriteLinkForArch( | 1064 return self.WriteLinkForArch( |
1065 self.ninja, spec, config_name, config, link_deps) | 1065 self.ninja, spec, config_name, config, link_deps, compile_deps) |
1066 else: | 1066 else: |
1067 output = self.ComputeOutput(spec) | 1067 output = self.ComputeOutput(spec) |
1068 inputs = [self.WriteLinkForArch(self.arch_subninjas[arch], spec, | 1068 inputs = [self.WriteLinkForArch(self.arch_subninjas[arch], spec, |
1069 config_name, config, link_deps[arch], | 1069 config_name, config, link_deps[arch], |
1070 arch=arch) | 1070 compile_deps, arch=arch) |
1071 for arch in self.archs] | 1071 for arch in self.archs] |
1072 extra_bindings = [] | 1072 extra_bindings = [] |
1073 build_output = output | 1073 build_output = output |
1074 if not self.is_mac_bundle: | 1074 if not self.is_mac_bundle: |
1075 self.AppendPostbuildVariable(extra_bindings, spec, output, output) | 1075 self.AppendPostbuildVariable(extra_bindings, spec, output, output) |
1076 | 1076 |
1077 # TODO(yyanagisawa): more work needed to fix: | 1077 # TODO(yyanagisawa): more work needed to fix: |
1078 # https://code.google.com/p/gyp/issues/detail?id=411 | 1078 # https://code.google.com/p/gyp/issues/detail?id=411 |
1079 if (spec['type'] in ('shared_library', 'loadable_module') and | 1079 if (spec['type'] in ('shared_library', 'loadable_module') and |
1080 not self.is_mac_bundle): | 1080 not self.is_mac_bundle): |
1081 extra_bindings.append(('lib', output)) | 1081 extra_bindings.append(('lib', output)) |
1082 self.ninja.build([output, output + '.TOC'], 'solipo', inputs, | 1082 self.ninja.build([output, output + '.TOC'], 'solipo', inputs, |
1083 variables=extra_bindings) | 1083 variables=extra_bindings) |
1084 else: | 1084 else: |
1085 self.ninja.build(build_output, 'lipo', inputs, variables=extra_bindings) | 1085 self.ninja.build(build_output, 'lipo', inputs, variables=extra_bindings) |
1086 return output | 1086 return output |
1087 | 1087 |
1088 def WriteLinkForArch(self, ninja_file, spec, config_name, config, | 1088 def WriteLinkForArch(self, ninja_file, spec, config_name, config, |
1089 link_deps, arch=None): | 1089 link_deps, compile_deps, arch=None): |
1090 """Write out a link step. Fills out target.binary. """ | 1090 """Write out a link step. Fills out target.binary. """ |
1091 command = { | 1091 command = { |
1092 'executable': 'link', | 1092 'executable': 'link', |
1093 'loadable_module': 'solink_module', | 1093 'loadable_module': 'solink_module', |
1094 'shared_library': 'solink', | 1094 'shared_library': 'solink', |
1095 }[spec['type']] | 1095 }[spec['type']] |
1096 command_suffix = '' | 1096 command_suffix = '' |
1097 | 1097 |
1098 implicit_deps = set() | 1098 implicit_deps = set() |
1099 solibs = set() | 1099 solibs = set() |
1100 order_deps = set() | 1100 order_deps = set() |
1101 | 1101 |
| 1102 if compile_deps: |
| 1103 # Normally, the compiles of the target already depend on compile_deps, |
| 1104 # but a shared_library target might have no sources and only link together |
| 1105 # a few static_library deps, so the link step also needs to depend |
| 1106 # on compile_deps to make sure actions in the shared_library target |
| 1107 # get run before the link. |
| 1108 order_deps.add(compile_deps) |
| 1109 |
1102 if 'dependencies' in spec: | 1110 if 'dependencies' in spec: |
1103 # Two kinds of dependencies: | 1111 # Two kinds of dependencies: |
1104 # - Linkable dependencies (like a .a or a .so): add them to the link line. | 1112 # - Linkable dependencies (like a .a or a .so): add them to the link line. |
1105 # - Non-linkable dependencies (like a rule that generates a file | 1113 # - Non-linkable dependencies (like a rule that generates a file |
1106 # and writes a stamp file): add them to implicit_deps | 1114 # and writes a stamp file): add them to implicit_deps |
1107 extra_link_deps = set() | 1115 extra_link_deps = set() |
1108 for dep in spec['dependencies']: | 1116 for dep in spec['dependencies']: |
1109 target = self.target_outputs.get(dep) | 1117 target = self.target_outputs.get(dep) |
1110 if not target: | 1118 if not target: |
1111 continue | 1119 continue |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 inputs.append(output) | 1309 inputs.append(output) |
1302 # TODO: It's not clear if libtool_flags should be passed to the alink | 1310 # TODO: It's not clear if libtool_flags should be passed to the alink |
1303 # call that combines single-arch .a files into a fat .a file. | 1311 # call that combines single-arch .a files into a fat .a file. |
1304 self.AppendPostbuildVariable(variables, spec, | 1312 self.AppendPostbuildVariable(variables, spec, |
1305 self.target.binary, self.target.binary) | 1313 self.target.binary, self.target.binary) |
1306 self.ninja.build(self.target.binary, 'alink', inputs, | 1314 self.ninja.build(self.target.binary, 'alink', inputs, |
1307 # FIXME: test proving order_only=compile_deps isn't | 1315 # FIXME: test proving order_only=compile_deps isn't |
1308 # needed. | 1316 # needed. |
1309 variables=variables) | 1317 variables=variables) |
1310 else: | 1318 else: |
1311 self.target.binary = self.WriteLink(spec, config_name, config, link_deps) | 1319 self.target.binary = self.WriteLink(spec, config_name, config, link_deps, |
| 1320 compile_deps) |
1312 return self.target.binary | 1321 return self.target.binary |
1313 | 1322 |
1314 def WriteMacBundle(self, spec, mac_bundle_depends, is_empty): | 1323 def WriteMacBundle(self, spec, mac_bundle_depends, is_empty): |
1315 assert self.is_mac_bundle | 1324 assert self.is_mac_bundle |
1316 package_framework = spec['type'] in ('shared_library', 'loadable_module') | 1325 package_framework = spec['type'] in ('shared_library', 'loadable_module') |
1317 output = self.ComputeMacBundleOutput() | 1326 output = self.ComputeMacBundleOutput() |
1318 if is_empty: | 1327 if is_empty: |
1319 output += '.stamp' | 1328 output += '.stamp' |
1320 variables = [] | 1329 variables = [] |
1321 self.AppendPostbuildVariable(variables, spec, output, self.target.binary, | 1330 self.AppendPostbuildVariable(variables, spec, output, self.target.binary, |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2401 arglists.append( | 2410 arglists.append( |
2402 (target_list, target_dicts, data, params, config_name)) | 2411 (target_list, target_dicts, data, params, config_name)) |
2403 pool.map(CallGenerateOutputForConfig, arglists) | 2412 pool.map(CallGenerateOutputForConfig, arglists) |
2404 except KeyboardInterrupt, e: | 2413 except KeyboardInterrupt, e: |
2405 pool.terminate() | 2414 pool.terminate() |
2406 raise e | 2415 raise e |
2407 else: | 2416 else: |
2408 for config_name in config_names: | 2417 for config_name in config_names: |
2409 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2418 GenerateOutputForConfig(target_list, target_dicts, data, params, |
2410 config_name) | 2419 config_name) |
OLD | NEW |