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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if len(targets) > 1: | 352 if len(targets) > 1: |
353 stamp = self.GypPathToUniqueOutput(name + '.stamp') | 353 stamp = self.GypPathToUniqueOutput(name + '.stamp') |
354 targets = self.ninja.build(stamp, 'stamp', targets) | 354 targets = self.ninja.build(stamp, 'stamp', targets) |
355 self.ninja.newline() | 355 self.ninja.newline() |
356 return targets[0] | 356 return targets[0] |
357 | 357 |
358 def _SubninjaNameForArch(self, arch): | 358 def _SubninjaNameForArch(self, arch): |
359 output_file_base = os.path.splitext(self.output_file_name)[0] | 359 output_file_base = os.path.splitext(self.output_file_name)[0] |
360 return '%s.%s.ninja' % (output_file_base, arch) | 360 return '%s.%s.ninja' % (output_file_base, arch) |
361 | 361 |
362 def WriteSpec(self, spec, config_name, generator_flags, | 362 def WriteSpec(self, spec, config_name, generator_flags): |
363 case_sensitive_filesystem): | |
364 """The main entry point for NinjaWriter: write the build rules for a spec. | 363 """The main entry point for NinjaWriter: write the build rules for a spec. |
365 | 364 |
366 Returns a Target object, which represents the output paths for this spec. | 365 Returns a Target object, which represents the output paths for this spec. |
367 Returns None if there are no outputs (e.g. a settings-only 'none' type | 366 Returns None if there are no outputs (e.g. a settings-only 'none' type |
368 target).""" | 367 target).""" |
369 | 368 |
370 self.config_name = config_name | 369 self.config_name = config_name |
371 self.name = spec['target_name'] | 370 self.name = spec['target_name'] |
372 self.toolset = spec['toolset'] | 371 self.toolset = spec['toolset'] |
373 config = spec['configurations'][config_name] | 372 config = spec['configurations'][config_name] |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 sources, self.abs_build_dir, generator_flags, self.GypPathToNinja) | 450 sources, self.abs_build_dir, generator_flags, self.GypPathToNinja) |
452 pch = gyp.msvs_emulation.PrecompiledHeader( | 451 pch = gyp.msvs_emulation.PrecompiledHeader( |
453 self.msvs_settings, config_name, self.GypPathToNinja, | 452 self.msvs_settings, config_name, self.GypPathToNinja, |
454 self.GypPathToUniqueOutput, self.obj_ext) | 453 self.GypPathToUniqueOutput, self.obj_ext) |
455 else: | 454 else: |
456 pch = gyp.xcode_emulation.MacPrefixHeader( | 455 pch = gyp.xcode_emulation.MacPrefixHeader( |
457 self.xcode_settings, self.GypPathToNinja, | 456 self.xcode_settings, self.GypPathToNinja, |
458 lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang)) | 457 lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang)) |
459 link_deps = self.WriteSources( | 458 link_deps = self.WriteSources( |
460 self.ninja, config_name, config, sources, compile_depends_stamp, pch, | 459 self.ninja, config_name, config, sources, compile_depends_stamp, pch, |
461 case_sensitive_filesystem, spec) | 460 spec) |
462 # Some actions/rules output 'sources' that are already object files. | 461 # Some actions/rules output 'sources' that are already object files. |
463 obj_outputs = [f for f in sources if f.endswith(self.obj_ext)] | 462 obj_outputs = [f for f in sources if f.endswith(self.obj_ext)] |
464 if obj_outputs: | 463 if obj_outputs: |
465 if self.flavor != 'mac' or len(self.archs) == 1: | 464 if self.flavor != 'mac' or len(self.archs) == 1: |
466 link_deps += [self.GypPathToNinja(o) for o in obj_outputs] | 465 link_deps += [self.GypPathToNinja(o) for o in obj_outputs] |
467 else: | 466 else: |
468 print "Warning: Actions/rules writing object files don't work with " \ | 467 print "Warning: Actions/rules writing object files don't work with " \ |
469 "multiarch targets, dropping. (target %s)" % spec['target_name'] | 468 "multiarch targets, dropping. (target %s)" % spec['target_name'] |
470 | 469 |
471 | 470 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 | 749 |
751 env = self.GetSortedXcodeEnv(additional_settings=extra_env) | 750 env = self.GetSortedXcodeEnv(additional_settings=extra_env) |
752 env = self.ComputeExportEnvString(env) | 751 env = self.ComputeExportEnvString(env) |
753 | 752 |
754 self.ninja.build(out, 'mac_tool', info_plist, | 753 self.ninja.build(out, 'mac_tool', info_plist, |
755 variables=[('mactool_cmd', 'copy-info-plist'), | 754 variables=[('mactool_cmd', 'copy-info-plist'), |
756 ('env', env)]) | 755 ('env', env)]) |
757 bundle_depends.append(out) | 756 bundle_depends.append(out) |
758 | 757 |
759 def WriteSources(self, ninja_file, config_name, config, sources, predepends, | 758 def WriteSources(self, ninja_file, config_name, config, sources, predepends, |
760 precompiled_header, case_sensitive_filesystem, spec): | 759 precompiled_header, spec): |
761 """Write build rules to compile all of |sources|.""" | 760 """Write build rules to compile all of |sources|.""" |
762 if self.toolset == 'host': | 761 if self.toolset == 'host': |
763 self.ninja.variable('ar', '$ar_host') | 762 self.ninja.variable('ar', '$ar_host') |
764 self.ninja.variable('cc', '$cc_host') | 763 self.ninja.variable('cc', '$cc_host') |
765 self.ninja.variable('cxx', '$cxx_host') | 764 self.ninja.variable('cxx', '$cxx_host') |
766 self.ninja.variable('ld', '$ld_host') | 765 self.ninja.variable('ld', '$ld_host') |
767 | 766 |
768 if self.flavor != 'mac' or len(self.archs) == 1: | 767 if self.flavor != 'mac' or len(self.archs) == 1: |
769 return self.WriteSourcesForArch( | 768 return self.WriteSourcesForArch( |
770 self.ninja, config_name, config, sources, predepends, | 769 self.ninja, config_name, config, sources, predepends, |
771 precompiled_header, case_sensitive_filesystem, spec) | 770 precompiled_header, spec) |
772 else: | 771 else: |
773 return dict((arch, self.WriteSourcesForArch( | 772 return dict((arch, self.WriteSourcesForArch( |
774 self.arch_subninjas[arch], config_name, config, sources, predepends, | 773 self.arch_subninjas[arch], config_name, config, sources, predepends, |
775 precompiled_header, case_sensitive_filesystem, spec, arch=arch)) | 774 precompiled_header, spec, arch=arch)) |
776 for arch in self.archs) | 775 for arch in self.archs) |
777 | 776 |
778 def WriteSourcesForArch(self, ninja_file, config_name, config, sources, | 777 def WriteSourcesForArch(self, ninja_file, config_name, config, sources, |
779 predepends, precompiled_header, | 778 predepends, precompiled_header, spec, arch=None): |
780 case_sensitive_filesystem, spec, arch=None): | |
781 """Write build rules to compile all of |sources|.""" | 779 """Write build rules to compile all of |sources|.""" |
782 | 780 |
783 extra_defines = [] | 781 extra_defines = [] |
784 if self.flavor == 'mac': | 782 if self.flavor == 'mac': |
785 cflags = self.xcode_settings.GetCflags(config_name, arch=arch) | 783 cflags = self.xcode_settings.GetCflags(config_name, arch=arch) |
786 cflags_c = self.xcode_settings.GetCflagsC(config_name) | 784 cflags_c = self.xcode_settings.GetCflagsC(config_name) |
787 cflags_cc = self.xcode_settings.GetCflagsCC(config_name) | 785 cflags_cc = self.xcode_settings.GetCflagsCC(config_name) |
788 cflags_objc = ['$cflags_c'] + \ | 786 cflags_objc = ['$cflags_c'] + \ |
789 self.xcode_settings.GetCflagsObjC(config_name) | 787 self.xcode_settings.GetCflagsObjC(config_name) |
790 cflags_objcc = ['$cflags_cc'] + \ | 788 cflags_objcc = ['$cflags_cc'] + \ |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 elif self.flavor == 'win' and ext == 'rc': | 879 elif self.flavor == 'win' and ext == 'rc': |
882 command = 'rc' | 880 command = 'rc' |
883 obj_ext = '.res' | 881 obj_ext = '.res' |
884 else: | 882 else: |
885 # Ignore unhandled extensions. | 883 # Ignore unhandled extensions. |
886 continue | 884 continue |
887 input = self.GypPathToNinja(source) | 885 input = self.GypPathToNinja(source) |
888 output = self.GypPathToUniqueOutput(filename + obj_ext) | 886 output = self.GypPathToUniqueOutput(filename + obj_ext) |
889 if arch is not None: | 887 if arch is not None: |
890 output = AddArch(output, arch) | 888 output = AddArch(output, arch) |
891 # Ninja's depfile handling gets confused when the case of a filename | |
892 # changes on a case-insensitive file system. To work around that, always | |
893 # convert .o filenames to lowercase on such file systems. See | |
894 # https://github.com/martine/ninja/issues/402 for details. | |
895 if not case_sensitive_filesystem: | |
896 output = output.lower() | |
897 implicit = precompiled_header.GetObjDependencies([input], [output], arch) | 889 implicit = precompiled_header.GetObjDependencies([input], [output], arch) |
898 variables = [] | 890 variables = [] |
899 if self.flavor == 'win': | 891 if self.flavor == 'win': |
900 variables, output, implicit = precompiled_header.GetFlagsModifications( | 892 variables, output, implicit = precompiled_header.GetFlagsModifications( |
901 input, output, implicit, command, cflags_c, cflags_cc, | 893 input, output, implicit, command, cflags_c, cflags_cc, |
902 self.ExpandSpecial) | 894 self.ExpandSpecial) |
903 ninja_file.build(output, command, input, | 895 ninja_file.build(output, command, input, |
904 implicit=[gch for _, _, gch in implicit], | 896 implicit=[gch for _, _, gch in implicit], |
905 order_only=predepends, variables=variables) | 897 order_only=predepends, variables=variables) |
906 outputs.append(output) | 898 outputs.append(output) |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 # e.g. "out/Debug" | 1593 # e.g. "out/Debug" |
1602 build_dir = os.path.normpath(os.path.join(generator_dir, | 1594 build_dir = os.path.normpath(os.path.join(generator_dir, |
1603 output_dir, | 1595 output_dir, |
1604 config_name)) | 1596 config_name)) |
1605 | 1597 |
1606 toplevel_build = os.path.join(options.toplevel_dir, build_dir) | 1598 toplevel_build = os.path.join(options.toplevel_dir, build_dir) |
1607 | 1599 |
1608 master_ninja = ninja_syntax.Writer( | 1600 master_ninja = ninja_syntax.Writer( |
1609 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), | 1601 OpenOutput(os.path.join(toplevel_build, 'build.ninja')), |
1610 width=120) | 1602 width=120) |
1611 case_sensitive_filesystem = not os.path.exists( | |
1612 os.path.join(toplevel_build, 'BUILD.NINJA')) | |
1613 | 1603 |
1614 # Put build-time support tools in out/{config_name}. | 1604 # Put build-time support tools in out/{config_name}. |
1615 gyp.common.CopyTool(flavor, toplevel_build) | 1605 gyp.common.CopyTool(flavor, toplevel_build) |
1616 | 1606 |
1617 # Grab make settings for CC/CXX. | 1607 # Grab make settings for CC/CXX. |
1618 # The rules are | 1608 # The rules are |
1619 # - The priority from low to high is gcc/g++, the 'make_global_settings' in | 1609 # - The priority from low to high is gcc/g++, the 'make_global_settings' in |
1620 # gyp, the environment variable. | 1610 # gyp, the environment variable. |
1621 # - If there is no 'make_global_settings' for CC.host/CXX.host or | 1611 # - If there is no 'make_global_settings' for CC.host/CXX.host or |
1622 # 'CC_host'/'CXX_host' enviroment variable, cc_host/cxx_host should be set | 1612 # 'CC_host'/'CXX_host' enviroment variable, cc_host/cxx_host should be set |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2007 if toolset != 'target': | 1997 if toolset != 'target': |
2008 obj += '.' + toolset | 1998 obj += '.' + toolset |
2009 output_file = os.path.join(obj, base_path, name + '.ninja') | 1999 output_file = os.path.join(obj, base_path, name + '.ninja') |
2010 | 2000 |
2011 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, | 2001 writer = NinjaWriter(qualified_target, target_outputs, base_path, build_dir, |
2012 OpenOutput(os.path.join(toplevel_build, output_file)), | 2002 OpenOutput(os.path.join(toplevel_build, output_file)), |
2013 toplevel_build, output_file, | 2003 toplevel_build, output_file, |
2014 flavor, toplevel_dir=options.toplevel_dir) | 2004 flavor, toplevel_dir=options.toplevel_dir) |
2015 master_ninja.subninja(output_file) | 2005 master_ninja.subninja(output_file) |
2016 | 2006 |
2017 target = writer.WriteSpec( | 2007 target = writer.WriteSpec(spec, config_name, generator_flags) |
2018 spec, config_name, generator_flags, case_sensitive_filesystem) | |
2019 if target: | 2008 if target: |
2020 if name != target.FinalOutput() and spec['toolset'] == 'target': | 2009 if name != target.FinalOutput() and spec['toolset'] == 'target': |
2021 target_short_names.setdefault(name, []).append(target) | 2010 target_short_names.setdefault(name, []).append(target) |
2022 target_outputs[qualified_target] = target | 2011 target_outputs[qualified_target] = target |
2023 if qualified_target in all_targets: | 2012 if qualified_target in all_targets: |
2024 all_outputs.add(target.FinalOutput()) | 2013 all_outputs.add(target.FinalOutput()) |
2025 | 2014 |
2026 if target_short_names: | 2015 if target_short_names: |
2027 # Write a short name to build this target. This benefits both the | 2016 # Write a short name to build this target. This benefits both the |
2028 # "build chrome" case as well as the gyp tests, which expect to be | 2017 # "build chrome" case as well as the gyp tests, which expect to be |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 arglists.append( | 2066 arglists.append( |
2078 (target_list, target_dicts, data, params, config_name)) | 2067 (target_list, target_dicts, data, params, config_name)) |
2079 pool.map(CallGenerateOutputForConfig, arglists) | 2068 pool.map(CallGenerateOutputForConfig, arglists) |
2080 except KeyboardInterrupt, e: | 2069 except KeyboardInterrupt, e: |
2081 pool.terminate() | 2070 pool.terminate() |
2082 raise e | 2071 raise e |
2083 else: | 2072 else: |
2084 for config_name in config_names: | 2073 for config_name in config_names: |
2085 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2074 GenerateOutputForConfig(target_list, target_dicts, data, params, |
2086 config_name) | 2075 config_name) |
OLD | NEW |