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 generator_flags, toplevel_dir=None): |
|
Nico
2013/09/09 23:27:27
It's nicer to not pass in the whole flags object,
brettw
2013/09/10 21:12:13
Done.
| |
| 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 LINK_DEPS_FILE = 'link_deps_file' | |
| 252 if LINK_DEPS_FILE in generator_flags: | |
| 253 self.link_deps_file = open(generator_flags.get(LINK_DEPS_FILE), 'ab') | |
|
Nico
2013/09/09 23:27:27
Do you want to empty the file before creating the
brettw
2013/09/10 21:12:13
I currently delete it from GN before doing the spa
Nico
2013/09/10 21:56:55
Huh? Couldn't you create the file in GenerateOutpu
| |
| 254 else: | |
| 255 self.link_deps_file = False | |
|
Evan Martin
2013/09/09 23:49:34
Why not "None" (also above in the comment), since
brettw
2013/09/10 21:12:13
Good idea, done.
| |
| 256 | |
| 248 def ExpandSpecial(self, path, product_dir=None): | 257 def ExpandSpecial(self, path, product_dir=None): |
| 249 """Expand specials like $!PRODUCT_DIR in |path|. | 258 """Expand specials like $!PRODUCT_DIR in |path|. |
| 250 | 259 |
| 251 If |product_dir| is None, assumes the cwd is already the product | 260 If |product_dir| is None, assumes the cwd is already the product |
| 252 dir. Otherwise, |product_dir| is the relative path to the product | 261 dir. Otherwise, |product_dir| is the relative path to the product |
| 253 dir. | 262 dir. |
| 254 """ | 263 """ |
| 255 | 264 |
| 256 PRODUCT_DIR = '$!PRODUCT_DIR' | 265 PRODUCT_DIR = '$!PRODUCT_DIR' |
| 257 if PRODUCT_DIR in path: | 266 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. | 977 # - 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 | 978 # - Non-linkable dependencies (like a rule that generates a file |
| 970 # and writes a stamp file): add them to implicit_deps | 979 # and writes a stamp file): add them to implicit_deps |
| 971 extra_link_deps = set() | 980 extra_link_deps = set() |
| 972 for dep in spec['dependencies']: | 981 for dep in spec['dependencies']: |
| 973 target = self.target_outputs.get(dep) | 982 target = self.target_outputs.get(dep) |
| 974 if not target: | 983 if not target: |
| 975 continue | 984 continue |
| 976 linkable = target.Linkable() | 985 linkable = target.Linkable() |
| 977 if linkable: | 986 if linkable: |
| 987 if self.link_deps_file: | |
| 988 # Save the mapping of link deps. | |
| 989 self.link_deps_file.write(self.qualified_target) | |
| 990 self.link_deps_file.write(' ') | |
| 991 self.link_deps_file.write(target.binary) | |
|
Nico
2013/09/09 23:27:27
This isn't correct on windows if you want to use i
brettw
2013/09/10 21:12:13
I'll worry about this later, I don't understand ho
| |
| 992 self.link_deps_file.write('\n') | |
| 993 | |
| 978 if (self.flavor == 'win' and | 994 if (self.flavor == 'win' and |
| 979 target.component_objs and | 995 target.component_objs and |
| 980 self.msvs_settings.IsUseLibraryDependencyInputs(config_name)): | 996 self.msvs_settings.IsUseLibraryDependencyInputs(config_name)): |
| 981 extra_link_deps |= set(target.component_objs) | 997 extra_link_deps |= set(target.component_objs) |
| 982 elif self.flavor == 'win' and target.import_lib: | 998 elif self.flavor == 'win' and target.import_lib: |
| 983 extra_link_deps.add(target.import_lib) | 999 extra_link_deps.add(target.import_lib) |
| 984 elif target.UsesToc(self.flavor): | 1000 elif target.UsesToc(self.flavor): |
| 985 solibs.add(target.binary) | 1001 solibs.add(target.binary) |
| 986 implicit_deps.add(target.binary + '.TOC') | 1002 implicit_deps.add(target.binary + '.TOC') |
| 987 else: | 1003 else: |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2015 | 2031 |
| 2016 base_path = os.path.dirname(build_file) | 2032 base_path = os.path.dirname(build_file) |
| 2017 obj = 'obj' | 2033 obj = 'obj' |
| 2018 if toolset != 'target': | 2034 if toolset != 'target': |
| 2019 obj += '.' + toolset | 2035 obj += '.' + toolset |
| 2020 output_file = os.path.join(obj, base_path, name + '.ninja') | 2036 output_file = os.path.join(obj, base_path, name + '.ninja') |
| 2021 | 2037 |
| 2022 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, | 2038 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, |
| 2023 OpenOutput(os.path.join(toplevel_build, output_file)), | 2039 OpenOutput(os.path.join(toplevel_build, output_file)), |
| 2024 toplevel_build, output_file, | 2040 toplevel_build, output_file, |
| 2025 flavor, toplevel_dir=options.toplevel_dir) | 2041 flavor, generator_flags, |
| 2042 toplevel_dir=options.toplevel_dir) | |
| 2026 master_ninja.subninja(output_file) | 2043 master_ninja.subninja(output_file) |
| 2027 | 2044 |
| 2028 target = writer.WriteSpec(spec, config_name, generator_flags) | 2045 target = writer.WriteSpec(spec, config_name, generator_flags) |
| 2029 if target: | 2046 if target: |
| 2030 if name != target.FinalOutput() and spec['toolset'] == 'target': | 2047 if name != target.FinalOutput() and spec['toolset'] == 'target': |
| 2031 target_short_names.setdefault(name, []).append(target) | 2048 target_short_names.setdefault(name, []).append(target) |
| 2032 target_outputs[qualified_target] = target | 2049 target_outputs[qualified_target] = target |
| 2033 if qualified_target in all_targets: | 2050 if qualified_target in all_targets: |
| 2034 all_outputs.add(target.FinalOutput()) | 2051 all_outputs.add(target.FinalOutput()) |
| 2035 | 2052 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2087 arglists.append( | 2104 arglists.append( |
| 2088 (target_list, target_dicts, data, params, config_name)) | 2105 (target_list, target_dicts, data, params, config_name)) |
| 2089 pool.map(CallGenerateOutputForConfig, arglists) | 2106 pool.map(CallGenerateOutputForConfig, arglists) |
| 2090 except KeyboardInterrupt, e: | 2107 except KeyboardInterrupt, e: |
| 2091 pool.terminate() | 2108 pool.terminate() |
| 2092 raise e | 2109 raise e |
| 2093 else: | 2110 else: |
| 2094 for config_name in config_names: | 2111 for config_name in config_names: |
| 2095 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2112 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 2096 config_name) | 2113 config_name) |
| OLD | NEW |