| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 Returns None if there are no outputs (e.g. a settings-only 'none' type | 367 Returns None if there are no outputs (e.g. a settings-only 'none' type |
| 368 target).""" | 368 target).""" |
| 369 | 369 |
| 370 self.config_name = config_name | 370 self.config_name = config_name |
| 371 self.name = spec['target_name'] | 371 self.name = spec['target_name'] |
| 372 self.toolset = spec['toolset'] | 372 self.toolset = spec['toolset'] |
| 373 config = spec['configurations'][config_name] | 373 config = spec['configurations'][config_name] |
| 374 self.target = Target(spec['type']) | 374 self.target = Target(spec['type']) |
| 375 self.is_standalone_static_library = bool( | 375 self.is_standalone_static_library = bool( |
| 376 spec.get('standalone_static_library', 0)) | 376 spec.get('standalone_static_library', 0)) |
| 377 self.uses_cpp = False |
| 377 | 378 |
| 378 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec) | 379 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec) |
| 379 self.xcode_settings = self.msvs_settings = None | 380 self.xcode_settings = self.msvs_settings = None |
| 380 if self.flavor == 'mac': | 381 if self.flavor == 'mac': |
| 381 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec) | 382 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec) |
| 382 if self.flavor == 'win': | 383 if self.flavor == 'win': |
| 383 self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec, | 384 self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec, |
| 384 generator_flags) | 385 generator_flags) |
| 385 arch = self.msvs_settings.GetArch(config_name) | 386 arch = self.msvs_settings.GetArch(config_name) |
| 386 self.ninja.variable('arch', self.win_env[arch]) | 387 self.ninja.variable('arch', self.win_env[arch]) |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 bundle_depends.append(out) | 772 bundle_depends.append(out) |
| 772 | 773 |
| 773 def WriteSources(self, ninja_file, config_name, config, sources, predepends, | 774 def WriteSources(self, ninja_file, config_name, config, sources, predepends, |
| 774 precompiled_header, spec): | 775 precompiled_header, spec): |
| 775 """Write build rules to compile all of |sources|.""" | 776 """Write build rules to compile all of |sources|.""" |
| 776 if self.toolset == 'host': | 777 if self.toolset == 'host': |
| 777 self.ninja.variable('ar', '$ar_host') | 778 self.ninja.variable('ar', '$ar_host') |
| 778 self.ninja.variable('cc', '$cc_host') | 779 self.ninja.variable('cc', '$cc_host') |
| 779 self.ninja.variable('cxx', '$cxx_host') | 780 self.ninja.variable('cxx', '$cxx_host') |
| 780 self.ninja.variable('ld', '$ld_host') | 781 self.ninja.variable('ld', '$ld_host') |
| 782 self.ninja.variable('ldxx', '$ldxx_host') |
| 781 | 783 |
| 782 if self.flavor != 'mac' or len(self.archs) == 1: | 784 if self.flavor != 'mac' or len(self.archs) == 1: |
| 783 return self.WriteSourcesForArch( | 785 return self.WriteSourcesForArch( |
| 784 self.ninja, config_name, config, sources, predepends, | 786 self.ninja, config_name, config, sources, predepends, |
| 785 precompiled_header, spec) | 787 precompiled_header, spec) |
| 786 else: | 788 else: |
| 787 return dict((arch, self.WriteSourcesForArch( | 789 return dict((arch, self.WriteSourcesForArch( |
| 788 self.arch_subninjas[arch], config_name, config, sources, predepends, | 790 self.arch_subninjas[arch], config_name, config, sources, predepends, |
| 789 precompiled_header, spec, arch=arch)) | 791 precompiled_header, spec, arch=arch)) |
| 790 for arch in self.archs) | 792 for arch in self.archs) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 self.WriteVariableList(ninja_file, 'cflags_objcc', | 870 self.WriteVariableList(ninja_file, 'cflags_objcc', |
| 869 map(self.ExpandSpecial, cflags_objcc)) | 871 map(self.ExpandSpecial, cflags_objcc)) |
| 870 ninja_file.newline() | 872 ninja_file.newline() |
| 871 outputs = [] | 873 outputs = [] |
| 872 for source in sources: | 874 for source in sources: |
| 873 filename, ext = os.path.splitext(source) | 875 filename, ext = os.path.splitext(source) |
| 874 ext = ext[1:] | 876 ext = ext[1:] |
| 875 obj_ext = self.obj_ext | 877 obj_ext = self.obj_ext |
| 876 if ext in ('cc', 'cpp', 'cxx'): | 878 if ext in ('cc', 'cpp', 'cxx'): |
| 877 command = 'cxx' | 879 command = 'cxx' |
| 880 self.uses_cpp = True |
| 878 elif ext == 'c' or (ext == 'S' and self.flavor != 'win'): | 881 elif ext == 'c' or (ext == 'S' and self.flavor != 'win'): |
| 879 command = 'cc' | 882 command = 'cc' |
| 880 elif ext == 's' and self.flavor != 'win': # Doesn't generate .o.d files. | 883 elif ext == 's' and self.flavor != 'win': # Doesn't generate .o.d files. |
| 881 command = 'cc_s' | 884 command = 'cc_s' |
| 882 elif (self.flavor == 'win' and ext == 'asm' and | 885 elif (self.flavor == 'win' and ext == 'asm' and |
| 883 self.msvs_settings.GetArch(config_name) == 'x86' and | 886 self.msvs_settings.GetArch(config_name) == 'x86' and |
| 884 not self.msvs_settings.HasExplicitAsmRules(spec)): | 887 not self.msvs_settings.HasExplicitAsmRules(spec)): |
| 885 # Asm files only get auto assembled for x86 (not x64). | 888 # Asm files only get auto assembled for x86 (not x64). |
| 886 command = 'asm' | 889 command = 'asm' |
| 887 # Add the _asm suffix as msvs is capable of handling .cc and | 890 # Add the _asm suffix as msvs is capable of handling .cc and |
| 888 # .asm files of the same name without collision. | 891 # .asm files of the same name without collision. |
| 889 obj_ext = '_asm.obj' | 892 obj_ext = '_asm.obj' |
| 890 elif self.flavor == 'mac' and ext == 'm': | 893 elif self.flavor == 'mac' and ext == 'm': |
| 891 command = 'objc' | 894 command = 'objc' |
| 892 elif self.flavor == 'mac' and ext == 'mm': | 895 elif self.flavor == 'mac' and ext == 'mm': |
| 893 command = 'objcxx' | 896 command = 'objcxx' |
| 897 self.uses_cpp = True |
| 894 elif self.flavor == 'win' and ext == 'rc': | 898 elif self.flavor == 'win' and ext == 'rc': |
| 895 command = 'rc' | 899 command = 'rc' |
| 896 obj_ext = '.res' | 900 obj_ext = '.res' |
| 897 else: | 901 else: |
| 898 # Ignore unhandled extensions. | 902 # Ignore unhandled extensions. |
| 899 continue | 903 continue |
| 900 input = self.GypPathToNinja(source) | 904 input = self.GypPathToNinja(source) |
| 901 output = self.GypPathToUniqueOutput(filename + obj_ext) | 905 output = self.GypPathToUniqueOutput(filename + obj_ext) |
| 902 if arch is not None: | 906 if arch is not None: |
| 903 output = AddArch(output, arch) | 907 output = AddArch(output, arch) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 else: | 992 else: |
| 989 extra_link_deps.add(target.binary) | 993 extra_link_deps.add(target.binary) |
| 990 | 994 |
| 991 final_output = target.FinalOutput() | 995 final_output = target.FinalOutput() |
| 992 if not linkable or final_output != target.binary: | 996 if not linkable or final_output != target.binary: |
| 993 implicit_deps.add(final_output) | 997 implicit_deps.add(final_output) |
| 994 | 998 |
| 995 link_deps.extend(list(extra_link_deps)) | 999 link_deps.extend(list(extra_link_deps)) |
| 996 | 1000 |
| 997 extra_bindings = [] | 1001 extra_bindings = [] |
| 1002 if self.uses_cpp and self.flavor != 'win': |
| 1003 extra_bindings.append(('ld', '$ldxx')) |
| 1004 |
| 998 output = self.ComputeOutput(spec, arch) | 1005 output = self.ComputeOutput(spec, arch) |
| 999 if arch is None and not self.is_mac_bundle: | 1006 if arch is None and not self.is_mac_bundle: |
| 1000 self.AppendPostbuildVariable(extra_bindings, spec, output, output) | 1007 self.AppendPostbuildVariable(extra_bindings, spec, output, output) |
| 1001 | 1008 |
| 1002 is_executable = spec['type'] == 'executable' | 1009 is_executable = spec['type'] == 'executable' |
| 1003 if self.flavor == 'mac': | 1010 if self.flavor == 'mac': |
| 1004 ldflags = self.xcode_settings.GetLdflags(config_name, | 1011 ldflags = self.xcode_settings.GetLdflags(config_name, |
| 1005 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), | 1012 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), |
| 1006 self.GypPathToNinja, arch) | 1013 self.GypPathToNinja, arch) |
| 1007 elif self.flavor == 'win': | 1014 elif self.flavor == 'win': |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 # Overridden by local arch choice in the use_deps case. | 1643 # Overridden by local arch choice in the use_deps case. |
| 1637 # Chromium's ffmpeg c99conv.py currently looks for a 'cc =' line in | 1644 # Chromium's ffmpeg c99conv.py currently looks for a 'cc =' line in |
| 1638 # build.ninja so needs something valid here. http://crbug.com/233985 | 1645 # build.ninja so needs something valid here. http://crbug.com/233985 |
| 1639 cc = 'cl.exe' | 1646 cc = 'cl.exe' |
| 1640 cxx = 'cl.exe' | 1647 cxx = 'cl.exe' |
| 1641 ld = 'link.exe' | 1648 ld = 'link.exe' |
| 1642 ld_host = '$ld' | 1649 ld_host = '$ld' |
| 1643 else: | 1650 else: |
| 1644 cc = 'gcc' | 1651 cc = 'gcc' |
| 1645 cxx = 'g++' | 1652 cxx = 'g++' |
| 1646 ld = '$cxx' | 1653 ld = '$cc' |
| 1647 ld_c = '$cc' | 1654 ldxx = '$cxx' |
| 1648 ld_host = '$cxx_host' | 1655 ld_host = '$cc_host' |
| 1656 ldxx_host = '$cxx_host' |
| 1649 | 1657 |
| 1650 cc_host = None | 1658 cc_host = None |
| 1651 cxx_host = None | 1659 cxx_host = None |
| 1652 cc_host_global_setting = None | 1660 cc_host_global_setting = None |
| 1653 cxx_host_global_setting = None | 1661 cxx_host_global_setting = None |
| 1654 | 1662 |
| 1655 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) | 1663 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) |
| 1656 make_global_settings = data[build_file].get('make_global_settings', []) | 1664 make_global_settings = data[build_file].get('make_global_settings', []) |
| 1657 build_to_root = gyp.common.InvertRelativePath(build_dir, | 1665 build_to_root = gyp.common.InvertRelativePath(build_dir, |
| 1658 options.toplevel_dir) | 1666 options.toplevel_dir) |
| 1659 wrappers = {} | 1667 wrappers = {} |
| 1660 for key, value in make_global_settings: | 1668 for key, value in make_global_settings: |
| 1661 if key == 'CC': | 1669 if key == 'CC': |
| 1662 cc = os.path.join(build_to_root, value) | 1670 cc = os.path.join(build_to_root, value) |
| 1663 if key == 'CXX': | 1671 if key == 'CXX': |
| 1664 cxx = os.path.join(build_to_root, value) | 1672 cxx = os.path.join(build_to_root, value) |
| 1665 if key == 'LD': | |
| 1666 ld = os.path.join(build_to_root, value) | |
| 1667 if key == 'CC.host': | 1673 if key == 'CC.host': |
| 1668 cc_host = os.path.join(build_to_root, value) | 1674 cc_host = os.path.join(build_to_root, value) |
| 1669 cc_host_global_setting = value | 1675 cc_host_global_setting = value |
| 1670 if key == 'CXX.host': | 1676 if key == 'CXX.host': |
| 1671 cxx_host = os.path.join(build_to_root, value) | 1677 cxx_host = os.path.join(build_to_root, value) |
| 1672 cxx_host_global_setting = value | 1678 cxx_host_global_setting = value |
| 1673 if key == 'LD.host': | |
| 1674 ld_host = os.path.join(build_to_root, value) | |
| 1675 if key.endswith('_wrapper'): | 1679 if key.endswith('_wrapper'): |
| 1676 wrappers[key[:-len('_wrapper')]] = os.path.join(build_to_root, value) | 1680 wrappers[key[:-len('_wrapper')]] = os.path.join(build_to_root, value) |
| 1677 | 1681 |
| 1678 # Support wrappers from environment variables too. | 1682 # Support wrappers from environment variables too. |
| 1679 for key, value in os.environ.iteritems(): | 1683 for key, value in os.environ.iteritems(): |
| 1680 if key.lower().endswith('_wrapper'): | 1684 if key.lower().endswith('_wrapper'): |
| 1681 key_prefix = key[:-len('_wrapper')] | 1685 key_prefix = key[:-len('_wrapper')] |
| 1682 key_prefix = re.sub(r'\.HOST$', '.host', key_prefix) | 1686 key_prefix = re.sub(r'\.HOST$', '.host', key_prefix) |
| 1683 wrappers[key_prefix] = os.path.join(build_to_root, value) | 1687 wrappers[key_prefix] = os.path.join(build_to_root, value) |
| 1684 | 1688 |
| 1685 if flavor == 'win': | 1689 if flavor == 'win': |
| 1686 cl_paths = gyp.msvs_emulation.GenerateEnvironmentFiles( | 1690 cl_paths = gyp.msvs_emulation.GenerateEnvironmentFiles( |
| 1687 toplevel_build, generator_flags, OpenOutput) | 1691 toplevel_build, generator_flags, OpenOutput) |
| 1688 for arch, path in cl_paths.iteritems(): | 1692 for arch, path in cl_paths.iteritems(): |
| 1689 master_ninja.variable( | 1693 master_ninja.variable( |
| 1690 'cl_' + arch, CommandWithWrapper('CC', wrappers, | 1694 'cl_' + arch, CommandWithWrapper('CC', wrappers, |
| 1691 QuoteShellArgument(path, flavor))) | 1695 QuoteShellArgument(path, flavor))) |
| 1692 | 1696 |
| 1693 cc = GetEnvironFallback(['CC_target', 'CC'], cc) | 1697 cc = GetEnvironFallback(['CC_target', 'CC'], cc) |
| 1694 master_ninja.variable('cc', CommandWithWrapper('CC', wrappers, cc)) | 1698 master_ninja.variable('cc', CommandWithWrapper('CC', wrappers, cc)) |
| 1695 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) | 1699 cxx = GetEnvironFallback(['CXX_target', 'CXX'], cxx) |
| 1696 master_ninja.variable('cxx', CommandWithWrapper('CXX', wrappers, cxx)) | 1700 master_ninja.variable('cxx', CommandWithWrapper('CXX', wrappers, cxx)) |
| 1697 ld = GetEnvironFallback(['LD_target', 'LD'], ld) | |
| 1698 | 1701 |
| 1699 if flavor == 'win': | 1702 if flavor == 'win': |
| 1700 master_ninja.variable('ld', ld) | 1703 master_ninja.variable('ld', ld) |
| 1701 master_ninja.variable('idl', 'midl.exe') | 1704 master_ninja.variable('idl', 'midl.exe') |
| 1702 master_ninja.variable('ar', 'lib.exe') | 1705 master_ninja.variable('ar', 'lib.exe') |
| 1703 master_ninja.variable('rc', 'rc.exe') | 1706 master_ninja.variable('rc', 'rc.exe') |
| 1704 master_ninja.variable('asm', 'ml.exe') | 1707 master_ninja.variable('asm', 'ml.exe') |
| 1705 master_ninja.variable('mt', 'mt.exe') | 1708 master_ninja.variable('mt', 'mt.exe') |
| 1706 else: | 1709 else: |
| 1707 master_ninja.variable('ld', CommandWithWrapper('LINK', wrappers, ld)) | 1710 master_ninja.variable('ld', CommandWithWrapper('LINK', wrappers, ld)) |
| 1711 master_ninja.variable('ldxx', CommandWithWrapper('LINK', wrappers, ldxx)) |
| 1708 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar')) | 1712 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], 'ar')) |
| 1709 | 1713 |
| 1710 if generator_supports_multiple_toolsets: | 1714 if generator_supports_multiple_toolsets: |
| 1711 if not cc_host: | 1715 if not cc_host: |
| 1712 cc_host = cc | 1716 cc_host = cc |
| 1713 if not cxx_host: | 1717 if not cxx_host: |
| 1714 cxx_host = cxx | 1718 cxx_host = cxx |
| 1715 | 1719 |
| 1716 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar')) | 1720 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], 'ar')) |
| 1717 cc_host = GetEnvironFallback(['CC_host'], cc_host) | 1721 cc_host = GetEnvironFallback(['CC_host'], cc_host) |
| 1718 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host) | 1722 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host) |
| 1719 ld_host = GetEnvironFallback(['LD_host'], ld_host) | |
| 1720 | 1723 |
| 1721 # The environment variable could be used in 'make_global_settings', like | 1724 # The environment variable could be used in 'make_global_settings', like |
| 1722 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here. | 1725 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here. |
| 1723 if '$(CC)' in cc_host and cc_host_global_setting: | 1726 if '$(CC)' in cc_host and cc_host_global_setting: |
| 1724 cc_host = cc_host_global_setting.replace('$(CC)', cc) | 1727 cc_host = cc_host_global_setting.replace('$(CC)', cc) |
| 1725 if '$(CXX)' in cxx_host and cxx_host_global_setting: | 1728 if '$(CXX)' in cxx_host and cxx_host_global_setting: |
| 1726 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) | 1729 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) |
| 1727 master_ninja.variable('cc_host', | 1730 master_ninja.variable('cc_host', |
| 1728 CommandWithWrapper('CC.host', wrappers, cc_host)) | 1731 CommandWithWrapper('CC.host', wrappers, cc_host)) |
| 1729 master_ninja.variable('cxx_host', | 1732 master_ninja.variable('cxx_host', |
| 1730 CommandWithWrapper('CXX.host', wrappers, cxx_host)) | 1733 CommandWithWrapper('CXX.host', wrappers, cxx_host)) |
| 1731 if flavor == 'win': | 1734 if flavor == 'win': |
| 1732 master_ninja.variable('ld_host', ld_host) | 1735 master_ninja.variable('ld_host', ld_host) |
| 1733 else: | 1736 else: |
| 1734 master_ninja.variable('ld_host', CommandWithWrapper( | 1737 master_ninja.variable('ld_host', CommandWithWrapper( |
| 1735 'LINK', wrappers, ld_host)) | 1738 'LINK', wrappers, ld_host)) |
| 1739 master_ninja.variable('ldxx_host', CommandWithWrapper( |
| 1740 'LINK', wrappers, ldxx_host)) |
| 1736 | 1741 |
| 1737 master_ninja.newline() | 1742 master_ninja.newline() |
| 1738 | 1743 |
| 1739 master_ninja.pool('link_pool', depth=GetDefaultConcurrentLinks()) | 1744 master_ninja.pool('link_pool', depth=GetDefaultConcurrentLinks()) |
| 1740 master_ninja.newline() | 1745 master_ninja.newline() |
| 1741 | 1746 |
| 1742 deps = 'msvc' if flavor == 'win' else 'gcc' | 1747 deps = 'msvc' if flavor == 'win' else 'gcc' |
| 1743 | 1748 |
| 1744 if flavor != 'win': | 1749 if flavor != 'win': |
| 1745 master_ninja.rule( | 1750 master_ninja.rule( |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2095 arglists.append( | 2100 arglists.append( |
| 2096 (target_list, target_dicts, data, params, config_name)) | 2101 (target_list, target_dicts, data, params, config_name)) |
| 2097 pool.map(CallGenerateOutputForConfig, arglists) | 2102 pool.map(CallGenerateOutputForConfig, arglists) |
| 2098 except KeyboardInterrupt, e: | 2103 except KeyboardInterrupt, e: |
| 2099 pool.terminate() | 2104 pool.terminate() |
| 2100 raise e | 2105 raise e |
| 2101 else: | 2106 else: |
| 2102 for config_name in config_names: | 2107 for config_name in config_names: |
| 2103 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2108 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 2104 config_name) | 2109 config_name) |
| OLD | NEW |