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

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

Issue 164023009: Support for custom NM/readelf binaries in your toolchain. (Closed) Base URL: http://gyp.googlecode.com/svn/trunk
Patch Set: Created 6 years, 3 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
OLDNEW
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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 798
799 def WriteSources(self, ninja_file, config_name, config, sources, predepends, 799 def WriteSources(self, ninja_file, config_name, config, sources, predepends,
800 precompiled_header, spec): 800 precompiled_header, spec):
801 """Write build rules to compile all of |sources|.""" 801 """Write build rules to compile all of |sources|."""
802 if self.toolset == 'host': 802 if self.toolset == 'host':
803 self.ninja.variable('ar', '$ar_host') 803 self.ninja.variable('ar', '$ar_host')
804 self.ninja.variable('cc', '$cc_host') 804 self.ninja.variable('cc', '$cc_host')
805 self.ninja.variable('cxx', '$cxx_host') 805 self.ninja.variable('cxx', '$cxx_host')
806 self.ninja.variable('ld', '$ld_host') 806 self.ninja.variable('ld', '$ld_host')
807 self.ninja.variable('ldxx', '$ldxx_host') 807 self.ninja.variable('ldxx', '$ldxx_host')
808 self.ninja.variable('nm', '$nm_host')
809 self.ninja.variable('readelf', '$readelf_host')
808 810
809 if self.flavor != 'mac' or len(self.archs) == 1: 811 if self.flavor != 'mac' or len(self.archs) == 1:
810 return self.WriteSourcesForArch( 812 return self.WriteSourcesForArch(
811 self.ninja, config_name, config, sources, predepends, 813 self.ninja, config_name, config, sources, predepends,
812 precompiled_header, spec) 814 precompiled_header, spec)
813 else: 815 else:
814 return dict((arch, self.WriteSourcesForArch( 816 return dict((arch, self.WriteSourcesForArch(
815 self.arch_subninjas[arch], config_name, config, sources, predepends, 817 self.arch_subninjas[arch], config_name, config, sources, predepends,
816 precompiled_header, spec, arch=arch)) 818 precompiled_header, spec, arch=arch))
817 for arch in self.archs) 819 for arch in self.archs)
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 ldxx = '$cxx' 1737 ldxx = '$cxx'
1736 ld_host = '$cc_host' 1738 ld_host = '$cc_host'
1737 ldxx_host = '$cxx_host' 1739 ldxx_host = '$cxx_host'
1738 1740
1739 ar_host = 'ar' 1741 ar_host = 'ar'
1740 cc_host = None 1742 cc_host = None
1741 cxx_host = None 1743 cxx_host = None
1742 cc_host_global_setting = None 1744 cc_host_global_setting = None
1743 cxx_host_global_setting = None 1745 cxx_host_global_setting = None
1744 clang_cl = None 1746 clang_cl = None
1747 nm = 'nm'
1748 nm_host = 'nm'
1749 readelf = 'readelf'
1750 readelf_host = 'readelf'
1745 1751
1746 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) 1752 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
1747 make_global_settings = data[build_file].get('make_global_settings', []) 1753 make_global_settings = data[build_file].get('make_global_settings', [])
1748 build_to_root = gyp.common.InvertRelativePath(build_dir, 1754 build_to_root = gyp.common.InvertRelativePath(build_dir,
1749 options.toplevel_dir) 1755 options.toplevel_dir)
1750 wrappers = {} 1756 wrappers = {}
1751 for key, value in make_global_settings: 1757 for key, value in make_global_settings:
1752 if key == 'AR': 1758 if key == 'AR':
1753 ar = os.path.join(build_to_root, value) 1759 ar = os.path.join(build_to_root, value)
1754 if key == 'AR.host': 1760 if key == 'AR.host':
1755 ar_host = os.path.join(build_to_root, value) 1761 ar_host = os.path.join(build_to_root, value)
1756 if key == 'CC': 1762 if key == 'CC':
1757 cc = os.path.join(build_to_root, value) 1763 cc = os.path.join(build_to_root, value)
1758 if cc.endswith('clang-cl'): 1764 if cc.endswith('clang-cl'):
1759 clang_cl = cc 1765 clang_cl = cc
1760 if key == 'CXX': 1766 if key == 'CXX':
1761 cxx = os.path.join(build_to_root, value) 1767 cxx = os.path.join(build_to_root, value)
1762 if key == 'CC.host': 1768 if key == 'CC.host':
1763 cc_host = os.path.join(build_to_root, value) 1769 cc_host = os.path.join(build_to_root, value)
1764 cc_host_global_setting = value 1770 cc_host_global_setting = value
1765 if key == 'CXX.host': 1771 if key == 'CXX.host':
1766 cxx_host = os.path.join(build_to_root, value) 1772 cxx_host = os.path.join(build_to_root, value)
1767 cxx_host_global_setting = value 1773 cxx_host_global_setting = value
1768 if key == 'LD': 1774 if key == 'LD':
1769 ld = os.path.join(build_to_root, value) 1775 ld = os.path.join(build_to_root, value)
1770 if key == 'LD.host': 1776 if key == 'LD.host':
1771 ld_host = os.path.join(build_to_root, value) 1777 ld_host = os.path.join(build_to_root, value)
1778 if key == 'NM':
1779 nm = os.path.join(build_to_root, value)
1780 if key == 'NM.host':
1781 nm_host = os.path.join(build_to_root, value)
1782 if key == 'READELF':
1783 readelf = os.path.join(build_to_root, value)
1784 if key == 'READELF.host':
1785 readelf_host = os.path.join(build_to_root, value)
1772 if key.endswith('_wrapper'): 1786 if key.endswith('_wrapper'):
1773 wrappers[key[:-len('_wrapper')]] = os.path.join(build_to_root, value) 1787 wrappers[key[:-len('_wrapper')]] = os.path.join(build_to_root, value)
1774 1788
1775 # Support wrappers from environment variables too. 1789 # Support wrappers from environment variables too.
1776 for key, value in os.environ.iteritems(): 1790 for key, value in os.environ.iteritems():
1777 if key.lower().endswith('_wrapper'): 1791 if key.lower().endswith('_wrapper'):
1778 key_prefix = key[:-len('_wrapper')] 1792 key_prefix = key[:-len('_wrapper')]
1779 key_prefix = re.sub(r'\.HOST$', '.host', key_prefix) 1793 key_prefix = re.sub(r'\.HOST$', '.host', key_prefix)
1780 wrappers[key_prefix] = os.path.join(build_to_root, value) 1794 wrappers[key_prefix] = os.path.join(build_to_root, value)
1781 1795
(...skipping 27 matching lines...) Expand all
1809 master_ninja.variable('ld', ld) 1823 master_ninja.variable('ld', ld)
1810 master_ninja.variable('idl', 'midl.exe') 1824 master_ninja.variable('idl', 'midl.exe')
1811 master_ninja.variable('ar', ar) 1825 master_ninja.variable('ar', ar)
1812 master_ninja.variable('rc', 'rc.exe') 1826 master_ninja.variable('rc', 'rc.exe')
1813 master_ninja.variable('asm', 'ml.exe') 1827 master_ninja.variable('asm', 'ml.exe')
1814 master_ninja.variable('mt', 'mt.exe') 1828 master_ninja.variable('mt', 'mt.exe')
1815 else: 1829 else:
1816 master_ninja.variable('ld', CommandWithWrapper('LINK', wrappers, ld)) 1830 master_ninja.variable('ld', CommandWithWrapper('LINK', wrappers, ld))
1817 master_ninja.variable('ldxx', CommandWithWrapper('LINK', wrappers, ldxx)) 1831 master_ninja.variable('ldxx', CommandWithWrapper('LINK', wrappers, ldxx))
1818 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], ar)) 1832 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], ar))
1833 if flavor != 'mac':
Nico 2014/08/27 23:53:06 yukawa: You could add a `or generator_supports_mul
1834 # Mac does not use readelf/nm for .TOC generation, so avoiding polluting
1835 # the master ninja with extra unused variables.
1836 master_ninja.variable(
1837 'nm', GetEnvironFallback(['NM_target', 'NM'], nm))
1838 master_ninja.variable(
1839 'readelf', GetEnvironFallback(['READELF_target', 'READELF'], readelf))
1819 1840
1820 if generator_supports_multiple_toolsets: 1841 if generator_supports_multiple_toolsets:
1821 if not cc_host: 1842 if not cc_host:
1822 cc_host = cc 1843 cc_host = cc
1823 if not cxx_host: 1844 if not cxx_host:
1824 cxx_host = cxx 1845 cxx_host = cxx
1825 1846
1826 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], ar_host)) 1847 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], ar_host))
1848 master_ninja.variable('nm_host', GetEnvironFallback(['NM_host'], nm_host))
1849 master_ninja.variable('readelf_host',
1850 GetEnvironFallback(['READELF_host'], readelf_host))
1827 cc_host = GetEnvironFallback(['CC_host'], cc_host) 1851 cc_host = GetEnvironFallback(['CC_host'], cc_host)
1828 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host) 1852 cxx_host = GetEnvironFallback(['CXX_host'], cxx_host)
1829 1853
1830 # The environment variable could be used in 'make_global_settings', like 1854 # The environment variable could be used in 'make_global_settings', like
1831 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here. 1855 # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here.
1832 if '$(CC)' in cc_host and cc_host_global_setting: 1856 if '$(CC)' in cc_host and cc_host_global_setting:
1833 cc_host = cc_host_global_setting.replace('$(CC)', cc) 1857 cc_host = cc_host_global_setting.replace('$(CC)', cc)
1834 if '$(CXX)' in cxx_host and cxx_host_global_setting: 1858 if '$(CXX)' in cxx_host and cxx_host_global_setting:
1835 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx) 1859 cxx_host = cxx_host_global_setting.replace('$(CXX)', cxx)
1836 master_ninja.variable('cc_host', 1860 master_ninja.variable('cc_host',
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 # is used in the final substitution below. 1962 # is used in the final substitution below.
1939 mtime_preserving_solink_base = ( 1963 mtime_preserving_solink_base = (
1940 'if [ ! -e $lib -o ! -e $lib.TOC ]; then ' 1964 'if [ ! -e $lib -o ! -e $lib.TOC ]; then '
1941 '%(solink)s && %(extract_toc)s > $lib.TOC; else ' 1965 '%(solink)s && %(extract_toc)s > $lib.TOC; else '
1942 '%(solink)s && %(extract_toc)s > $lib.tmp && ' 1966 '%(solink)s && %(extract_toc)s > $lib.tmp && '
1943 'if ! cmp -s $lib.tmp $lib.TOC; then mv $lib.tmp $lib.TOC ; ' 1967 'if ! cmp -s $lib.tmp $lib.TOC; then mv $lib.tmp $lib.TOC ; '
1944 'fi; fi' 1968 'fi; fi'
1945 % { 'solink': 1969 % { 'solink':
1946 '$ld -shared $ldflags -o $lib -Wl,-soname=$soname %(suffix)s', 1970 '$ld -shared $ldflags -o $lib -Wl,-soname=$soname %(suffix)s',
1947 'extract_toc': 1971 'extract_toc':
1948 ('{ readelf -d $lib | grep SONAME ; ' 1972 ('{ $readelf -d $lib | grep SONAME ; '
1949 'nm -gD -f p $lib | cut -f1-2 -d\' \'; }')}) 1973 '$nm -gD -f p $lib | cut -f1-2 -d\' \'; }')})
1950 1974
1951 master_ninja.rule( 1975 master_ninja.rule(
1952 'solink', 1976 'solink',
1953 description='SOLINK $lib', 1977 description='SOLINK $lib',
1954 restat=True, 1978 restat=True,
1955 command=mtime_preserving_solink_base % {'suffix': '@$link_file_list'}, 1979 command=mtime_preserving_solink_base % {'suffix': '@$link_file_list'},
1956 rspfile='$link_file_list', 1980 rspfile='$link_file_list',
1957 rspfile_content= 1981 rspfile_content=
1958 '-Wl,--whole-archive $in $solibs -Wl,--no-whole-archive $libs', 1982 '-Wl,--whole-archive $in $solibs -Wl,--no-whole-archive $libs',
1959 pool='link_pool') 1983 pool='link_pool')
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 arglists.append( 2254 arglists.append(
2231 (target_list, target_dicts, data, params, config_name)) 2255 (target_list, target_dicts, data, params, config_name))
2232 pool.map(CallGenerateOutputForConfig, arglists) 2256 pool.map(CallGenerateOutputForConfig, arglists)
2233 except KeyboardInterrupt, e: 2257 except KeyboardInterrupt, e:
2234 pool.terminate() 2258 pool.terminate()
2235 raise e 2259 raise e
2236 else: 2260 else:
2237 for config_name in config_names: 2261 for config_name in config_names:
2238 GenerateOutputForConfig(target_list, target_dicts, data, params, 2262 GenerateOutputForConfig(target_list, target_dicts, data, params,
2239 config_name) 2263 config_name)
OLDNEW
« no previous file with comments | « no previous file | test/compiler-override/compiler.gyp » ('j') | test/compiler-override/gyptest-compiler-env-toolchain.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698