| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 d = d.replace('#', '\\%03o' % ord('#')) | 101 d = d.replace('#', '\\%03o' % ord('#')) |
| 102 return QuoteShellArgument(ninja_syntax.escape('-D' + d), flavor) | 102 return QuoteShellArgument(ninja_syntax.escape('-D' + d), flavor) |
| 103 | 103 |
| 104 | 104 |
| 105 def AddArch(output, arch): | 105 def AddArch(output, arch): |
| 106 """Adds an arch string to an output path.""" | 106 """Adds an arch string to an output path.""" |
| 107 output, extension = os.path.splitext(output) | 107 output, extension = os.path.splitext(output) |
| 108 return '%s.%s%s' % (output, arch, extension) | 108 return '%s.%s%s' % (output, arch, extension) |
| 109 | 109 |
| 110 | 110 |
| 111 class Target: | 111 class Target(object): |
| 112 """Target represents the paths used within a single gyp target. | 112 """Target represents the paths used within a single gyp target. |
| 113 | 113 |
| 114 Conceptually, building a single target A is a series of steps: | 114 Conceptually, building a single target A is a series of steps: |
| 115 | 115 |
| 116 1) actions/rules/copies generates source/resources/etc. | 116 1) actions/rules/copies generates source/resources/etc. |
| 117 2) compiles generates .o files | 117 2) compiles generates .o files |
| 118 3) link generates a binary (library/executable) | 118 3) link generates a binary (library/executable) |
| 119 4) bundle merges the above in a mac bundle | 119 4) bundle merges the above in a mac bundle |
| 120 | 120 |
| 121 (Any of these steps can be optional.) | 121 (Any of these steps can be optional.) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 # We translate between these two notions of paths with two helper | 205 # We translate between these two notions of paths with two helper |
| 206 # functions: | 206 # functions: |
| 207 # | 207 # |
| 208 # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file) | 208 # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file) |
| 209 # into the equivalent ninja path. | 209 # into the equivalent ninja path. |
| 210 # | 210 # |
| 211 # - GypPathToUniqueOutput translates a gyp path into a ninja path to write | 211 # - GypPathToUniqueOutput translates a gyp path into a ninja path to write |
| 212 # an output file; the result can be namespaced such that it is unique | 212 # an output file; the result can be namespaced such that it is unique |
| 213 # to the input file name as well as the output target name. | 213 # to the input file name as well as the output target name. |
| 214 | 214 |
| 215 class NinjaWriter: | 215 class NinjaWriter(object): |
| 216 def __init__(self, hash_for_rules, target_outputs, base_dir, build_dir, | 216 def __init__(self, hash_for_rules, target_outputs, base_dir, build_dir, |
| 217 output_file, toplevel_build, output_file_name, flavor, | 217 output_file, toplevel_build, output_file_name, flavor, |
| 218 toplevel_dir=None): | 218 toplevel_dir=None): |
| 219 """ | 219 """ |
| 220 base_dir: path from source root to directory containing this gyp file, | 220 base_dir: path from source root to directory containing this gyp file, |
| 221 by gyp semantics, all input paths are relative to this | 221 by gyp semantics, all input paths are relative to this |
| 222 build_dir: path from source root to build output | 222 build_dir: path from source root to build output |
| 223 toplevel_dir: path to the toplevel directory | 223 toplevel_dir: path to the toplevel directory |
| 224 """ | 224 """ |
| 225 | 225 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 # TODO: if the command references the outputs directly, we should | 645 # TODO: if the command references the outputs directly, we should |
| 646 # simplify it to just use $out. | 646 # simplify it to just use $out. |
| 647 | 647 |
| 648 # Rules can potentially make use of some special variables which | 648 # Rules can potentially make use of some special variables which |
| 649 # must vary per source file. | 649 # must vary per source file. |
| 650 # Compute the list of variables we'll need to provide. | 650 # Compute the list of variables we'll need to provide. |
| 651 special_locals = ('source', 'root', 'dirname', 'ext', 'name') | 651 special_locals = ('source', 'root', 'dirname', 'ext', 'name') |
| 652 needed_variables = set(['source']) | 652 needed_variables = set(['source']) |
| 653 for argument in args: | 653 for argument in args: |
| 654 for var in special_locals: | 654 for var in special_locals: |
| 655 if ('${%s}' % var) in argument: | 655 if '${%s}' % var in argument: |
| 656 needed_variables.add(var) | 656 needed_variables.add(var) |
| 657 | 657 |
| 658 def cygwin_munge(path): | 658 def cygwin_munge(path): |
| 659 # pylint: disable=cell-var-from-loop |
| 659 if is_cygwin: | 660 if is_cygwin: |
| 660 return path.replace('\\', '/') | 661 return path.replace('\\', '/') |
| 661 return path | 662 return path |
| 662 | 663 |
| 663 inputs = [self.GypPathToNinja(i, env) for i in rule.get('inputs', [])] | 664 inputs = [self.GypPathToNinja(i, env) for i in rule.get('inputs', [])] |
| 664 | 665 |
| 665 # If there are n source files matching the rule, and m additional rule | 666 # If there are n source files matching the rule, and m additional rule |
| 666 # inputs, then adding 'inputs' to each build edge written below will | 667 # inputs, then adding 'inputs' to each build edge written below will |
| 667 # write m * n inputs. Collapsing reduces this to m + n. | 668 # write m * n inputs. Collapsing reduces this to m + n. |
| 668 sources = rule.get('rule_sources', []) | 669 sources = rule.get('rule_sources', []) |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 if def_file: | 1155 if def_file: |
| 1155 implicit_deps.add(def_file) | 1156 implicit_deps.add(def_file) |
| 1156 else: | 1157 else: |
| 1157 # Respect environment variables related to build, but target-specific | 1158 # Respect environment variables related to build, but target-specific |
| 1158 # flags can still override them. | 1159 # flags can still override them. |
| 1159 ldflags = env_ldflags + config.get('ldflags', []) | 1160 ldflags = env_ldflags + config.get('ldflags', []) |
| 1160 if is_executable and len(solibs): | 1161 if is_executable and len(solibs): |
| 1161 rpath = 'lib/' | 1162 rpath = 'lib/' |
| 1162 if self.toolset != 'target': | 1163 if self.toolset != 'target': |
| 1163 rpath += self.toolset | 1164 rpath += self.toolset |
| 1164 ldflags.append('-Wl,-rpath=\$$ORIGIN/%s' % rpath) | 1165 ldflags.append(r'-Wl,-rpath=\$$ORIGIN/%s' % rpath) |
| 1165 ldflags.append('-Wl,-rpath-link=%s' % rpath) | 1166 ldflags.append('-Wl,-rpath-link=%s' % rpath) |
| 1166 self.WriteVariableList(ninja_file, 'ldflags', | 1167 self.WriteVariableList(ninja_file, 'ldflags', |
| 1167 gyp.common.uniquer(map(self.ExpandSpecial, ldflags))) | 1168 gyp.common.uniquer(map(self.ExpandSpecial, ldflags))) |
| 1168 | 1169 |
| 1169 library_dirs = config.get('library_dirs', []) | 1170 library_dirs = config.get('library_dirs', []) |
| 1170 if self.flavor == 'win': | 1171 if self.flavor == 'win': |
| 1171 library_dirs = [self.msvs_settings.ConvertVSMacros(l, config_name) | 1172 library_dirs = [self.msvs_settings.ConvertVSMacros(l, config_name) |
| 1172 for l in library_dirs] | 1173 for l in library_dirs] |
| 1173 library_dirs = ['/LIBPATH:' + QuoteShellArgument(self.GypPathToNinja(l), | 1174 library_dirs = ['/LIBPATH:' + QuoteShellArgument(self.GypPathToNinja(l), |
| 1174 self.flavor) | 1175 self.flavor) |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2373 arglists.append( | 2374 arglists.append( |
| 2374 (target_list, target_dicts, data, params, config_name)) | 2375 (target_list, target_dicts, data, params, config_name)) |
| 2375 pool.map(CallGenerateOutputForConfig, arglists) | 2376 pool.map(CallGenerateOutputForConfig, arglists) |
| 2376 except KeyboardInterrupt, e: | 2377 except KeyboardInterrupt, e: |
| 2377 pool.terminate() | 2378 pool.terminate() |
| 2378 raise e | 2379 raise e |
| 2379 else: | 2380 else: |
| 2380 for config_name in config_names: | 2381 for config_name in config_names: |
| 2381 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2382 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 2382 config_name) | 2383 config_name) |
| OLD | NEW |