Chromium Code Reviews| 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 copy | 5 import copy |
| 6 import hashlib | 6 import hashlib |
| 7 import multiprocessing | 7 import multiprocessing |
| 8 import os.path | 8 import os.path |
| 9 import re | 9 import re |
| 10 import signal | 10 import signal |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file) | 203 # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file) |
| 204 # into the equivalent ninja path. | 204 # into the equivalent ninja path. |
| 205 # | 205 # |
| 206 # - GypPathToUniqueOutput translates a gyp path into a ninja path to write | 206 # - GypPathToUniqueOutput translates a gyp path into a ninja path to write |
| 207 # an output file; the result can be namespaced such that it is unique | 207 # an output file; the result can be namespaced such that it is unique |
| 208 # to the input file name as well as the output target name. | 208 # to the input file name as well as the output target name. |
| 209 | 209 |
| 210 class NinjaWriter: | 210 class NinjaWriter: |
| 211 def __init__(self, qualified_target, target_outputs, base_dir, build_dir, | 211 def __init__(self, qualified_target, target_outputs, base_dir, build_dir, |
| 212 output_file, toplevel_build, output_file_name, flavor, | 212 output_file, toplevel_build, output_file_name, flavor, |
| 213 toplevel_dir=None): | 213 deps_file_name=None, toplevel_dir=None): |
|
Nico
2013/09/10 21:58:02
rename to deps_file
| |
| 214 """ | 214 """ |
| 215 base_dir: path from source root to directory containing this gyp file, | 215 base_dir: path from source root to directory containing this gyp file, |
| 216 by gyp semantics, all input paths are relative to this | 216 by gyp semantics, all input paths are relative to this |
| 217 build_dir: path from source root to build output | 217 build_dir: path from source root to build output |
| 218 toplevel_dir: path to the toplevel directory | 218 toplevel_dir: path to the toplevel directory |
| 219 """ | 219 """ |
| 220 | 220 |
| 221 self.qualified_target = qualified_target | 221 self.qualified_target = qualified_target |
| 222 self.target_outputs = target_outputs | 222 self.target_outputs = target_outputs |
| 223 self.base_dir = base_dir | 223 self.base_dir = base_dir |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 238 for arch in ('x86', 'x64'): | 238 for arch in ('x86', 'x64'): |
| 239 self.win_env[arch] = 'environment.' + arch | 239 self.win_env[arch] = 'environment.' + arch |
| 240 | 240 |
| 241 # Relative path from build output dir to base dir. | 241 # Relative path from build output dir to base dir. |
| 242 build_to_top = gyp.common.InvertRelativePath(build_dir, toplevel_dir) | 242 build_to_top = gyp.common.InvertRelativePath(build_dir, toplevel_dir) |
| 243 self.build_to_base = os.path.join(build_to_top, base_dir) | 243 self.build_to_base = os.path.join(build_to_top, base_dir) |
| 244 # Relative path from base dir to build dir. | 244 # Relative path from base dir to build dir. |
| 245 base_to_top = gyp.common.InvertRelativePath(base_dir, toplevel_dir) | 245 base_to_top = gyp.common.InvertRelativePath(base_dir, toplevel_dir) |
| 246 self.base_to_build = os.path.join(base_to_top, build_dir) | 246 self.base_to_build = os.path.join(base_to_top, build_dir) |
| 247 | 247 |
| 248 # The self.link_deps_file will either be a file object if the file is | |
| 249 # requested, or it will be false if not. This file should contain a | |
| 250 # mapping from target to the list of library dependencies it has. | |
| 251 if deps_file_name: | |
| 252 self.link_deps_file = open(deps_file_name, 'ab') | |
| 253 else: | |
| 254 self.link_deps_file = None | |
|
Nico
2013/09/10 21:58:02
remove most of this, and just keep `self.link_deps
| |
| 255 | |
| 248 def ExpandSpecial(self, path, product_dir=None): | 256 def ExpandSpecial(self, path, product_dir=None): |
| 249 """Expand specials like $!PRODUCT_DIR in |path|. | 257 """Expand specials like $!PRODUCT_DIR in |path|. |
| 250 | 258 |
| 251 If |product_dir| is None, assumes the cwd is already the product | 259 If |product_dir| is None, assumes the cwd is already the product |
| 252 dir. Otherwise, |product_dir| is the relative path to the product | 260 dir. Otherwise, |product_dir| is the relative path to the product |
| 253 dir. | 261 dir. |
| 254 """ | 262 """ |
| 255 | 263 |
| 256 PRODUCT_DIR = '$!PRODUCT_DIR' | 264 PRODUCT_DIR = '$!PRODUCT_DIR' |
| 257 if PRODUCT_DIR in path: | 265 if PRODUCT_DIR in path: |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 968 # - Linkable dependencies (like a .a or a .so): add them to the link line. | 976 # - Linkable dependencies (like a .a or a .so): add them to the link line. |
| 969 # - Non-linkable dependencies (like a rule that generates a file | 977 # - Non-linkable dependencies (like a rule that generates a file |
| 970 # and writes a stamp file): add them to implicit_deps | 978 # and writes a stamp file): add them to implicit_deps |
| 971 extra_link_deps = set() | 979 extra_link_deps = set() |
| 972 for dep in spec['dependencies']: | 980 for dep in spec['dependencies']: |
| 973 target = self.target_outputs.get(dep) | 981 target = self.target_outputs.get(dep) |
| 974 if not target: | 982 if not target: |
| 975 continue | 983 continue |
| 976 linkable = target.Linkable() | 984 linkable = target.Linkable() |
| 977 if linkable: | 985 if linkable: |
| 986 if self.link_deps_file: | |
| 987 # Save the mapping of link deps. | |
| 988 self.link_deps_file.write(self.qualified_target) | |
| 989 self.link_deps_file.write(' ') | |
| 990 self.link_deps_file.write(target.binary) | |
| 991 self.link_deps_file.write('\n') | |
| 992 | |
| 978 if (self.flavor == 'win' and | 993 if (self.flavor == 'win' and |
| 979 target.component_objs and | 994 target.component_objs and |
| 980 self.msvs_settings.IsUseLibraryDependencyInputs(config_name)): | 995 self.msvs_settings.IsUseLibraryDependencyInputs(config_name)): |
| 981 extra_link_deps |= set(target.component_objs) | 996 extra_link_deps |= set(target.component_objs) |
| 982 elif self.flavor == 'win' and target.import_lib: | 997 elif self.flavor == 'win' and target.import_lib: |
| 983 extra_link_deps.add(target.import_lib) | 998 extra_link_deps.add(target.import_lib) |
| 984 elif target.UsesToc(self.flavor): | 999 elif target.UsesToc(self.flavor): |
| 985 solibs.add(target.binary) | 1000 solibs.add(target.binary) |
| 986 implicit_deps.add(target.binary + '.TOC') | 1001 implicit_deps.add(target.binary + '.TOC') |
| 987 else: | 1002 else: |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2012 gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec) | 2027 gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec) |
| 2013 | 2028 |
| 2014 build_file = gyp.common.RelativePath(build_file, options.toplevel_dir) | 2029 build_file = gyp.common.RelativePath(build_file, options.toplevel_dir) |
| 2015 | 2030 |
| 2016 base_path = os.path.dirname(build_file) | 2031 base_path = os.path.dirname(build_file) |
| 2017 obj = 'obj' | 2032 obj = 'obj' |
| 2018 if toolset != 'target': | 2033 if toolset != 'target': |
| 2019 obj += '.' + toolset | 2034 obj += '.' + toolset |
| 2020 output_file = os.path.join(obj, base_path, name + '.ninja') | 2035 output_file = os.path.join(obj, base_path, name + '.ninja') |
| 2021 | 2036 |
| 2037 # Extract the optional link deps file name. | |
| 2038 LINK_DEPS_FILE = 'link_deps_file' | |
| 2039 if LINK_DEPS_FILE in generator_flags: | |
| 2040 link_deps_file = generator_flags.get(LINK_DEPS_FILE) | |
|
Nico
2013/09/10 21:58:02
Do link_deps_file = open(gen…ILE), 'wb') here
| |
| 2041 else: | |
| 2042 link_deps_file = None | |
| 2043 | |
| 2022 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, | 2044 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, |
| 2023 OpenOutput(os.path.join(toplevel_build, output_file)), | 2045 OpenOutput(os.path.join(toplevel_build, output_file)), |
| 2024 toplevel_build, output_file, | 2046 toplevel_build, output_file, |
| 2025 flavor, toplevel_dir=options.toplevel_dir) | 2047 flavor, link_deps_file, |
| 2048 toplevel_dir=options.toplevel_dir) | |
| 2026 master_ninja.subninja(output_file) | 2049 master_ninja.subninja(output_file) |
| 2027 | 2050 |
| 2028 target = writer.WriteSpec(spec, config_name, generator_flags) | 2051 target = writer.WriteSpec(spec, config_name, generator_flags) |
| 2029 if target: | 2052 if target: |
| 2030 if name != target.FinalOutput() and spec['toolset'] == 'target': | 2053 if name != target.FinalOutput() and spec['toolset'] == 'target': |
| 2031 target_short_names.setdefault(name, []).append(target) | 2054 target_short_names.setdefault(name, []).append(target) |
| 2032 target_outputs[qualified_target] = target | 2055 target_outputs[qualified_target] = target |
| 2033 if qualified_target in all_targets: | 2056 if qualified_target in all_targets: |
| 2034 all_outputs.add(target.FinalOutput()) | 2057 all_outputs.add(target.FinalOutput()) |
| 2035 | 2058 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2087 arglists.append( | 2110 arglists.append( |
| 2088 (target_list, target_dicts, data, params, config_name)) | 2111 (target_list, target_dicts, data, params, config_name)) |
| 2089 pool.map(CallGenerateOutputForConfig, arglists) | 2112 pool.map(CallGenerateOutputForConfig, arglists) |
| 2090 except KeyboardInterrupt, e: | 2113 except KeyboardInterrupt, e: |
| 2091 pool.terminate() | 2114 pool.terminate() |
| 2092 raise e | 2115 raise e |
| 2093 else: | 2116 else: |
| 2094 for config_name in config_names: | 2117 for config_name in config_names: |
| 2095 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2118 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 2096 config_name) | 2119 config_name) |
| OLD | NEW |