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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 obj = 'obj' | 337 obj = 'obj' |
338 if self.toolset != 'target': | 338 if self.toolset != 'target': |
339 obj += '.' + self.toolset | 339 obj += '.' + self.toolset |
340 | 340 |
341 path_dir, path_basename = os.path.split(path) | 341 path_dir, path_basename = os.path.split(path) |
342 if qualified: | 342 if qualified: |
343 path_basename = self.name + '.' + path_basename | 343 path_basename = self.name + '.' + path_basename |
344 return os.path.normpath(os.path.join(obj, self.base_dir, path_dir, | 344 return os.path.normpath(os.path.join(obj, self.base_dir, path_dir, |
345 path_basename)) | 345 path_basename)) |
346 | 346 |
347 def WriteCollapsedDependencies(self, name, targets): | 347 def WriteCollapsedDependencies(self, name, targets, order_only=None): |
348 """Given a list of targets, return a path for a single file | 348 """Given a list of targets, return a path for a single file |
349 representing the result of building all the targets or None. | 349 representing the result of building all the targets or None. |
350 | 350 |
351 Uses a stamp file if necessary.""" | 351 Uses a stamp file if necessary.""" |
352 | 352 |
353 assert targets == filter(None, targets), targets | 353 assert targets == filter(None, targets), targets |
354 if len(targets) == 0: | 354 if len(targets) == 0: |
| 355 assert not order_only |
355 return None | 356 return None |
356 if len(targets) > 1: | 357 if len(targets) > 1 or order_only: |
357 stamp = self.GypPathToUniqueOutput(name + '.stamp') | 358 stamp = self.GypPathToUniqueOutput(name + '.stamp') |
358 targets = self.ninja.build(stamp, 'stamp', targets) | 359 targets = self.ninja.build(stamp, 'stamp', targets, order_only=order_only) |
359 self.ninja.newline() | 360 self.ninja.newline() |
360 return targets[0] | 361 return targets[0] |
361 | 362 |
362 def _SubninjaNameForArch(self, arch): | 363 def _SubninjaNameForArch(self, arch): |
363 output_file_base = os.path.splitext(self.output_file_name)[0] | 364 output_file_base = os.path.splitext(self.output_file_name)[0] |
364 return '%s.%s.ninja' % (output_file_base, arch) | 365 return '%s.%s.ninja' % (output_file_base, arch) |
365 | 366 |
366 def WriteSpec(self, spec, config_name, generator_flags): | 367 def WriteSpec(self, spec, config_name, generator_flags): |
367 """The main entry point for NinjaWriter: write the build rules for a spec. | 368 """The main entry point for NinjaWriter: write the build rules for a spec. |
368 | 369 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 if ('${%s}' % var) in argument: | 651 if ('${%s}' % var) in argument: |
651 needed_variables.add(var) | 652 needed_variables.add(var) |
652 | 653 |
653 def cygwin_munge(path): | 654 def cygwin_munge(path): |
654 if is_cygwin: | 655 if is_cygwin: |
655 return path.replace('\\', '/') | 656 return path.replace('\\', '/') |
656 return path | 657 return path |
657 | 658 |
658 inputs = [self.GypPathToNinja(i, env) for i in rule.get('inputs', [])] | 659 inputs = [self.GypPathToNinja(i, env) for i in rule.get('inputs', [])] |
659 | 660 |
| 661 # If there are n source files matching the rule, and m additional rule |
| 662 # inputs, then adding 'inputs' to each build edge written below will |
| 663 # write m * n inputs. Collapsing reduces this to m + n. |
| 664 sources = rule.get('rule_sources', []) |
| 665 num_inputs = len(inputs) |
| 666 if prebuild: |
| 667 num_inputs += 1 |
| 668 if num_inputs > 2 and len(sources) > 2: |
| 669 inputs = [ |
| 670 self.WriteCollapsedDependencies(name, inputs, order_only=prebuild)] |
| 671 prebuild = [] |
| 672 |
660 # For each source file, write an edge that generates all the outputs. | 673 # For each source file, write an edge that generates all the outputs. |
661 for source in rule.get('rule_sources', []): | 674 for source in sources: |
662 source = os.path.normpath(source) | 675 source = os.path.normpath(source) |
663 dirname, basename = os.path.split(source) | 676 dirname, basename = os.path.split(source) |
664 root, ext = os.path.splitext(basename) | 677 root, ext = os.path.splitext(basename) |
665 | 678 |
666 # Gather the list of inputs and outputs, expanding $vars if possible. | 679 # Gather the list of inputs and outputs, expanding $vars if possible. |
667 outputs = [self.ExpandRuleVariables(o, root, dirname, | 680 outputs = [self.ExpandRuleVariables(o, root, dirname, |
668 source, ext, basename) | 681 source, ext, basename) |
669 for o in rule['outputs']] | 682 for o in rule['outputs']] |
670 | 683 |
671 if int(rule.get('process_outputs_as_sources', False)): | 684 if int(rule.get('process_outputs_as_sources', False)): |
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2186 arglists.append( | 2199 arglists.append( |
2187 (target_list, target_dicts, data, params, config_name)) | 2200 (target_list, target_dicts, data, params, config_name)) |
2188 pool.map(CallGenerateOutputForConfig, arglists) | 2201 pool.map(CallGenerateOutputForConfig, arglists) |
2189 except KeyboardInterrupt, e: | 2202 except KeyboardInterrupt, e: |
2190 pool.terminate() | 2203 pool.terminate() |
2191 raise e | 2204 raise e |
2192 else: | 2205 else: |
2193 for config_name in config_names: | 2206 for config_name in config_names: |
2194 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2207 GenerateOutputForConfig(target_list, target_dicts, data, params, |
2195 config_name) | 2208 config_name) |
OLD | NEW |