Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 _, 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 |
| 597 if linkable: | |
| 598 extra_link_deps.add(binary) | |
| 599 else: | |
| 600 # TODO: Chrome-specific HACK. Chrome runs this lastchange rule on | |
| 601 # every build, but we don't want to rebuild when it runs. | |
| 602 if 'lastchange' in binary: | |
| 600 continue | 603 continue |
| 601 if linkable: | 604 # TODO(evan): it's confusing that the variable here is called |
| 602 extra_link_deps.add(binary) | 605 # "binary", despite being a stamp file. Fix this. |
| 603 else: | 606 implicit_deps.add(binary) |
| 604 # TODO: Chrome-specific HACK. Chrome runs this lastchange rule on | |
| 605 # every build, but we don't want to rebuild when it runs. | |
| 606 if 'lastchange' in binary: | |
| 607 continue | |
| 608 # TODO(evan): it's confusing that the variable here is called | |
| 609 # "binary", despite being a stamp file. Fix this. | |
| 610 implicit_deps.add(binary) | |
| 611 link_deps.extend(list(extra_link_deps)) | 607 link_deps.extend(list(extra_link_deps)) |
| 612 | 608 |
| 613 if self.is_mac_bundle: | 609 if self.is_mac_bundle: |
| 614 output = self.ComputeMacBundleOutput(spec) | 610 output = self.ComputeMacBundleBinaryOutput(spec) |
| 615 output_binary = self.ComputeMacBundleBinaryOutput(spec) | |
| 616 if not link_deps: | |
| 617 output_binary = self.ComputeOutput(spec, type='none') | |
|
Evan Martin
2012/01/11 23:12:38
These two lines are the ones I'm not sure about --
| |
| 618 mac_bundle_depends.append(output_binary) | |
| 619 else: | 611 else: |
| 620 output = output_binary = self.ComputeOutput(spec) | 612 output = self.ComputeOutput(spec) |
| 621 | 613 |
| 622 command_map = { | 614 if self.flavor == 'mac': |
| 623 'executable': 'link', | 615 ldflags = self.xcode_settings.GetLdflags(config_name, |
| 624 'static_library': 'alink', | 616 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), |
| 625 'loadable_module': 'solink_module', | 617 self.GypPathToNinja) |
| 626 'shared_library': 'solink', | 618 else: |
| 627 'none': 'stamp', | 619 ldflags = config.get('ldflags', []) |
| 628 } | 620 self.WriteVariableList('ldflags', |
| 629 command = command_map[spec['type']] | 621 gyp.common.uniquer(map(self.ExpandSpecial, |
| 622 ldflags))) | |
| 630 | 623 |
| 631 if link_deps: | 624 libraries = gyp.common.uniquer(map(self.ExpandSpecial, |
| 632 final_deps = link_deps | 625 spec.get('libraries', []))) |
| 633 else: | 626 if self.flavor == 'mac': |
| 634 command = 'stamp' | 627 libraries = self.xcode_settings.AdjustFrameworkLibraries(libraries) |
| 635 order_only += final_deps | 628 self.WriteVariableList('libs', libraries) |
| 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 | 629 |
| 655 extra_bindings = [] | 630 extra_bindings = [] |
| 656 if command in ('solink', 'solink_module'): | 631 if command in ('solink', 'solink_module'): |
| 657 extra_bindings.append(('soname', os.path.split(output_binary)[1])) | 632 extra_bindings.append(('soname', os.path.split(output)[1])) |
| 658 | 633 |
| 659 self.ninja.build(output_binary, command, final_deps, | 634 self.ninja.build(output, command, link_deps, |
| 660 implicit=list(implicit_deps), | 635 implicit=list(implicit_deps), |
| 661 order_only=order_only, | |
| 662 variables=extra_bindings) | 636 variables=extra_bindings) |
| 637 return output | |
| 638 | |
| 639 def WriteTarget(self, spec, config_name, config, link_deps, final_deps, | |
| 640 mac_bundle_depends): | |
| 641 if spec['type'] == 'none': | |
| 642 # This target doesn't have any explicit final output, but is instead | |
| 643 # used for its effects before the final output (e.g. copies steps). | |
| 644 output = self.WriteCollapsedDependencies('foobar', final_deps)[0] | |
| 645 return output, output | |
| 646 elif spec['type'] == 'static_library': | |
| 647 output_binary = self.ComputeOutput(spec) | |
| 648 self.ninja.build(output_binary, 'alink', link_deps, | |
| 649 order_only=final_deps) | |
| 650 else: | |
| 651 output_binary = self.WriteLink(spec, config_name, config, link_deps) | |
| 652 | |
| 653 if self.is_mac_bundle: | |
| 654 output = self.ComputeMacBundleOutput(spec) | |
| 655 mac_bundle_depends.append(output_binary) | |
| 656 else: | |
| 657 output = output_binary | |
| 663 | 658 |
| 664 if self.is_mac_bundle: | 659 if self.is_mac_bundle: |
| 665 if spec['type'] in ('shared_library', 'loadable_module'): | 660 if spec['type'] in ('shared_library', 'loadable_module'): |
| 666 variables = [('version', self.xcode_settings.GetFrameworkVersion())] | 661 variables = [('version', self.xcode_settings.GetFrameworkVersion())] |
| 667 self.ninja.build(output, 'package_framework', mac_bundle_depends, | 662 self.ninja.build(output, 'package_framework', mac_bundle_depends, |
| 668 variables=variables) | 663 variables=variables) |
| 669 else: | 664 else: |
| 670 self.ninja.build(output, 'stamp', mac_bundle_depends) | 665 self.ninja.build(output, 'stamp', mac_bundle_depends) |
| 671 | 666 |
| 672 return output, output_binary | 667 return output, output_binary |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 if output: | 1011 if output: |
| 1017 linkable = spec['type'] in ('static_library', 'shared_library') | 1012 linkable = spec['type'] in ('static_library', 'shared_library') |
| 1018 target_outputs[qualified_target] = ( | 1013 target_outputs[qualified_target] = ( |
| 1019 output, output_binary, compile_depends, linkable) | 1014 output, output_binary, compile_depends, linkable) |
| 1020 | 1015 |
| 1021 if qualified_target in all_targets: | 1016 if qualified_target in all_targets: |
| 1022 all_outputs.add(output) | 1017 all_outputs.add(output) |
| 1023 | 1018 |
| 1024 if all_outputs: | 1019 if all_outputs: |
| 1025 master_ninja.build('all', 'phony', list(all_outputs)) | 1020 master_ninja.build('all', 'phony', list(all_outputs)) |
| OLD | NEW |