Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: pylib/gyp/generator/ninja.py

Issue 9107028: ninja: split out the logic for linking from target writing (Closed) Base URL: https://gyp.googlecode.com/svn/trunk
Patch Set: fix branch Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 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 gyp 5 import gyp
6 import gyp.common 6 import gyp.common
7 import gyp.system_test 7 import gyp.system_test
8 import gyp.xcode_emulation 8 import gyp.xcode_emulation
9 import os.path 9 import os.path
10 import re 10 import re
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang))) 274 lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang)))
275 # Some actions/rules output 'sources' that are already object files. 275 # Some actions/rules output 'sources' that are already object files.
276 link_deps += [self.GypPathToNinja(f) for f in sources if f.endswith('.o')] 276 link_deps += [self.GypPathToNinja(f) for f in sources if f.endswith('.o')]
277 277
278 # The final output of our target depends on the last output of the 278 # The final output of our target depends on the last output of the
279 # above steps. 279 # above steps.
280 output = output_binary = None 280 output = output_binary = None
281 if link_deps or sources_depends or actions_depends: 281 if link_deps or sources_depends or actions_depends:
282 output, output_binary = self.WriteTarget( 282 output, output_binary = self.WriteTarget(
283 spec, config_name, config, link_deps, 283 spec, config_name, config, link_deps,
284 sources_depends or actions_depends, mac_bundle_depends, 284 sources_depends or actions_depends, mac_bundle_depends)
285 order_only=actions_depends)
286 if self.name != output and self.toolset == 'target': 285 if self.name != output and self.toolset == 'target':
287 # Write a short name to build this target. This benefits both the 286 # Write a short name to build this target. This benefits both the
288 # "build chrome" case as well as the gyp tests, which expect to be 287 # "build chrome" case as well as the gyp tests, which expect to be
289 # able to run actions and build libraries by their short name. 288 # able to run actions and build libraries by their short name.
290 self.ninja.build(self.name, 'phony', output) 289 self.ninja.build(self.name, 'phony', output)
291 290
292 return output, output_binary, compile_depends 291 return output, output_binary, compile_depends
293 292
294 def WriteActionsRulesCopies(self, spec, extra_sources, prebuild, 293 def WriteActionsRulesCopies(self, spec, extra_sources, prebuild,
295 mac_bundle_depends): 294 mac_bundle_depends):
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 var_name = { 564 var_name = {
566 'c': 'cflags_pch_c', 565 'c': 'cflags_pch_c',
567 'cc': 'cflags_pch_cc', 566 'cc': 'cflags_pch_cc',
568 'm': 'cflags_pch_objc', 567 'm': 'cflags_pch_objc',
569 'mm': 'cflags_pch_objcc', 568 'mm': 'cflags_pch_objcc',
570 }[lang] 569 }[lang]
571 570
572 cmd = { 'c': 'cc', 'cc': 'cxx', 'm': 'objc', 'mm': 'objcxx', }.get(lang) 571 cmd = { 'c': 'cc', 'cc': 'cxx', 'm': 'objc', 'mm': 'objcxx', }.get(lang)
573 self.ninja.build(gch, cmd, input, variables=[(var_name, lang_flag)]) 572 self.ninja.build(gch, cmd, input, variables=[(var_name, lang_flag)])
574 573
575 def WriteTarget(self, spec, config_name, config, link_deps, final_deps,
576 mac_bundle_depends, order_only):
577 if spec['type'] == 'none':
578 # This target doesn't have any explicit final output, but is instead
579 # used for its effects before the final output (e.g. copies steps).
580 # Reuse the existing output if it's easy.
581 if len(final_deps) == 1:
582 return final_deps[0], final_deps[0]
583 # Otherwise, fall through to writing out a stamp file.
584 574
585 output_uses_linker = spec['type'] in ('executable', 'loadable_module', 575 def WriteLink(self, spec, config_name, config, link_deps):
586 'shared_library') 576 """Write out a link step. Returns the path to the output."""
577
578 command = {
579 'executable': 'link',
580 'loadable_module': 'solink_module',
581 'shared_library': 'solink',
582 }[spec['type']]
587 583
588 implicit_deps = set() 584 implicit_deps = set()
585
589 if 'dependencies' in spec: 586 if 'dependencies' in spec:
590 # Two kinds of dependencies: 587 # Two kinds of dependencies:
591 # - Linkable dependencies (like a .a or a .so): add them to the link line. 588 # - Linkable dependencies (like a .a or a .so): add them to the link line.
592 # - Non-linkable dependencies (like a rule that generates a file 589 # - Non-linkable dependencies (like a rule that generates a file
593 # and writes a stamp file): add them to implicit_deps 590 # and writes a stamp file): add them to implicit_deps
594 if output_uses_linker: 591 extra_link_deps = set()
595 extra_link_deps = set() 592 for dep in spec['dependencies']:
596 for dep in spec['dependencies']: 593 output, binary, _, linkable = self.target_outputs.get(
597 _, binary, _, linkable = self.target_outputs.get( 594 dep, (None, None, [], False))
598 dep, (None, None, [], False)) 595 if not binary:
599 if not binary: 596 continue
600 continue 597 if linkable:
601 if linkable: 598 extra_link_deps.add(binary)
602 extra_link_deps.add(binary) 599
603 else: 600 # TODO: Chrome-specific HACK. Chrome runs this lastchange rule on
604 # TODO: Chrome-specific HACK. Chrome runs this lastchange rule on 601 # every build, but we don't want to rebuild when it runs.
605 # every build, but we don't want to rebuild when it runs. 602 if 'lastchange' in binary:
Nico 2012/01/12 06:24:33 'lastchange' is probably a stamp file, so i think
606 if 'lastchange' in binary: 603 continue
607 continue 604 implicit_deps.add(output)
Evan Martin 2012/01/12 02:53:16 From here to "if linkable" above is different than
608 # TODO(evan): it's confusing that the variable here is called 605 link_deps.extend(list(extra_link_deps))
609 # "binary", despite being a stamp file. Fix this. 606
610 implicit_deps.add(binary) 607 if self.is_mac_bundle:
611 link_deps.extend(list(extra_link_deps)) 608 output = self.ComputeMacBundleBinaryOutput(spec)
609 else:
610 output = self.ComputeOutput(spec)
611
612 if self.flavor == 'mac':
613 ldflags = self.xcode_settings.GetLdflags(config_name,
614 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']),
615 self.GypPathToNinja)
616 else:
617 ldflags = config.get('ldflags', [])
618 self.WriteVariableList('ldflags',
619 gyp.common.uniquer(map(self.ExpandSpecial,
620 ldflags)))
621
622 libraries = gyp.common.uniquer(map(self.ExpandSpecial,
623 spec.get('libraries', [])))
624 if self.flavor == 'mac':
625 libraries = self.xcode_settings.AdjustFrameworkLibraries(libraries)
626 self.WriteVariableList('libs', libraries)
627
628 extra_bindings = []
629 if command in ('solink', 'solink_module'):
630 extra_bindings.append(('soname', os.path.split(output)[1]))
631
632 self.ninja.build(output, command, link_deps,
633 implicit=list(implicit_deps),
634 variables=extra_bindings)
635 return output
636
637 def WriteTarget(self, spec, config_name, config, link_deps, final_deps,
638 mac_bundle_depends):
639 if spec['type'] == 'none':
640 # This target doesn't have any explicit final output, but is instead
641 # used for its effects before the final output (e.g. copies steps).
642 output = self.WriteCollapsedDependencies('foobar', final_deps)[0]
Nico 2012/01/12 06:24:33 nit: Maybe there's a better name than 'foobar'.
643 return output, output
644 elif spec['type'] == 'static_library':
645 output_binary = self.ComputeOutput(spec)
646 self.ninja.build(output_binary, 'alink', link_deps,
647 order_only=final_deps)
648 else:
649 output_binary = self.WriteLink(spec, config_name, config, link_deps)
612 650
613 if self.is_mac_bundle: 651 if self.is_mac_bundle:
614 output = self.ComputeMacBundleOutput(spec) 652 output = self.ComputeMacBundleOutput(spec)
615 output_binary = self.ComputeMacBundleBinaryOutput(spec)
616 if not link_deps:
617 output_binary = self.ComputeOutput(spec, type='none')
618 mac_bundle_depends.append(output_binary) 653 mac_bundle_depends.append(output_binary)
619 else: 654 else:
620 output = output_binary = self.ComputeOutput(spec) 655 output = output_binary
621
622 command_map = {
623 'executable': 'link',
624 'static_library': 'alink',
625 'loadable_module': 'solink_module',
626 'shared_library': 'solink',
627 'none': 'stamp',
628 }
629 command = command_map[spec['type']]
630
631 if link_deps:
632 final_deps = link_deps
633 else:
634 command = 'stamp'
635 order_only += final_deps
636 final_deps = []
637
638 if output_uses_linker:
639 if self.flavor == 'mac':
640 ldflags = self.xcode_settings.GetLdflags(config_name,
641 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']),
642 self.GypPathToNinja)
643 else:
644 ldflags = config.get('ldflags', [])
645 self.WriteVariableList('ldflags',
646 gyp.common.uniquer(map(self.ExpandSpecial,
647 ldflags)))
648
649 libraries = gyp.common.uniquer(map(self.ExpandSpecial,
650 spec.get('libraries', [])))
651 if self.flavor == 'mac':
652 libraries = self.xcode_settings.AdjustFrameworkLibraries(libraries)
653 self.WriteVariableList('libs', libraries)
654
655 extra_bindings = []
656 if command in ('solink', 'solink_module'):
657 extra_bindings.append(('soname', os.path.split(output_binary)[1]))
658
659 self.ninja.build(output_binary, command, final_deps,
660 implicit=list(implicit_deps),
661 order_only=order_only,
662 variables=extra_bindings)
663 656
664 if self.is_mac_bundle: 657 if self.is_mac_bundle:
665 if spec['type'] in ('shared_library', 'loadable_module'): 658 if spec['type'] in ('shared_library', 'loadable_module'):
666 variables = [('version', self.xcode_settings.GetFrameworkVersion())] 659 variables = [('version', self.xcode_settings.GetFrameworkVersion())]
667 self.ninja.build(output, 'package_framework', mac_bundle_depends, 660 self.ninja.build(output, 'package_framework', mac_bundle_depends,
668 variables=variables) 661 variables=variables)
669 else: 662 else:
670 self.ninja.build(output, 'stamp', mac_bundle_depends) 663 self.ninja.build(output, 'stamp', mac_bundle_depends)
671 664
672 return output, output_binary 665 return output, output_binary
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 if output: 1009 if output:
1017 linkable = spec['type'] in ('static_library', 'shared_library') 1010 linkable = spec['type'] in ('static_library', 'shared_library')
1018 target_outputs[qualified_target] = ( 1011 target_outputs[qualified_target] = (
1019 output, output_binary, compile_depends, linkable) 1012 output, output_binary, compile_depends, linkable)
1020 1013
1021 if qualified_target in all_targets: 1014 if qualified_target in all_targets:
1022 all_outputs.add(output) 1015 all_outputs.add(output)
1023 1016
1024 if all_outputs: 1017 if all_outputs:
1025 master_ninja.build('all', 'phony', list(all_outputs)) 1018 master_ninja.build('all', 'phony', list(all_outputs))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698