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

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

Issue 111373002: win ninja: Refactor manifest generate and embed to be 1-pass (Closed) Base URL: http://gyp.googlecode.com/svn/trunk
Patch Set: add some extra print in failure case, and rebase Created 7 years 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 | pylib/gyp/msvs_emulation.py » ('j') | pylib/gyp/msvs_emulation.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 copy 5 import copy
6 import hashlib 6 import hashlib
7 import json 7 import json
8 import multiprocessing 8 import multiprocessing
9 import os.path 9 import os.path
10 import re 10 import re
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 # linker flags are set via xcode_settings and msvs_settings, respectively. 1032 # linker flags are set via xcode_settings and msvs_settings, respectively.
1033 env_ldflags = os.environ.get('LDFLAGS', '').split() 1033 env_ldflags = os.environ.get('LDFLAGS', '').split()
1034 if self.flavor == 'mac': 1034 if self.flavor == 'mac':
1035 ldflags = self.xcode_settings.GetLdflags(config_name, 1035 ldflags = self.xcode_settings.GetLdflags(config_name,
1036 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), 1036 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']),
1037 self.GypPathToNinja, arch) 1037 self.GypPathToNinja, arch)
1038 ldflags = env_ldflags + ldflags 1038 ldflags = env_ldflags + ldflags
1039 elif self.flavor == 'win': 1039 elif self.flavor == 'win':
1040 manifest_name = self.GypPathToUniqueOutput( 1040 manifest_name = self.GypPathToUniqueOutput(
1041 self.ComputeOutputFileName(spec)) 1041 self.ComputeOutputFileName(spec))
1042 ldflags, manifest_files = self.msvs_settings.GetLdflags(config_name, 1042 ldflags, intermediate_manifest, manifest_files = \
1043 self.GypPathToNinja, self.ExpandSpecial, manifest_name, is_executable) 1043 self.msvs_settings.GetLdflags(config_name, self.GypPathToNinja,
1044 self.ExpandSpecial, manifest_name,
1045 is_executable,
1046 self.toplevel_build, OpenOutput)
1044 ldflags = env_ldflags + ldflags 1047 ldflags = env_ldflags + ldflags
1045 self.WriteVariableList(ninja_file, 'manifests', manifest_files) 1048 self.WriteVariableList(ninja_file, 'manifests', manifest_files)
1049 implicit_deps = implicit_deps.union(manifest_files)
1050 if intermediate_manifest:
1051 self.WriteVariableList(
1052 ninja_file, 'intermediatemanifest', [intermediate_manifest])
1046 command_suffix = _GetWinLinkRuleNameSuffix( 1053 command_suffix = _GetWinLinkRuleNameSuffix(
1047 self.msvs_settings.IsEmbedManifest(config_name), 1054 self.msvs_settings.IsEmbedManifest(config_name))
1048 self.msvs_settings.IsLinkIncremental(config_name))
1049 def_file = self.msvs_settings.GetDefFile(self.GypPathToNinja) 1055 def_file = self.msvs_settings.GetDefFile(self.GypPathToNinja)
1050 if def_file: 1056 if def_file:
1051 implicit_deps.add(def_file) 1057 implicit_deps.add(def_file)
1052 else: 1058 else:
1053 # Respect environment variables related to build, but target-specific 1059 # Respect environment variables related to build, but target-specific
1054 # flags can still override them. 1060 # flags can still override them.
1055 ldflags = env_ldflags + config.get('ldflags', []) 1061 ldflags = env_ldflags + config.get('ldflags', [])
1056 if is_executable and len(solibs): 1062 if is_executable and len(solibs):
1057 rpath = 'lib/' 1063 rpath = 'lib/'
1058 if self.toolset != 'target': 1064 if self.toolset != 'target':
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 # A static library debug build of Chromium's unit_tests takes ~2.7GB, so 1566 # A static library debug build of Chromium's unit_tests takes ~2.7GB, so
1561 # 4GB per ld process allows for some more bloat. 1567 # 4GB per ld process allows for some more bloat.
1562 return max(1, avail_bytes / (4 * (2 ** 30))) # total / 4GB 1568 return max(1, avail_bytes / (4 * (2 ** 30))) # total / 4GB
1563 except: 1569 except:
1564 return 1 1570 return 1
1565 else: 1571 else:
1566 # TODO(scottmg): Implement this for other platforms. 1572 # TODO(scottmg): Implement this for other platforms.
1567 return 1 1573 return 1
1568 1574
1569 1575
1570 def _GetWinLinkRuleNameSuffix(embed_manifest, link_incremental): 1576 def _GetWinLinkRuleNameSuffix(embed_manifest):
1571 """Returns the suffix used to select an appropriate linking rule depending on 1577 """Returns the suffix used to select an appropriate linking rule depending on
1572 whether the manifest embedding and/or incremental linking is enabled.""" 1578 whether the manifest embedding is enabled."""
1573 suffix = '' 1579 return '_embed' if embed_manifest else ''
1574 if embed_manifest:
1575 suffix += '_embed'
1576 if link_incremental:
1577 suffix += '_inc'
1578 return suffix
1579 1580
1580 1581
1581 def _AddWinLinkRules(master_ninja, embed_manifest, link_incremental): 1582 def _AddWinLinkRules(master_ninja, embed_manifest):
1582 """Adds link rules for Windows platform to |master_ninja|.""" 1583 """Adds link rules for Windows platform to |master_ninja|."""
1583 def FullLinkCommand(ldcmd, out, binary_type): 1584 def FullLinkCommand(ldcmd, out, binary_type):
1584 """Returns a one-liner written for cmd.exe to handle multiphase linker
1585 operations including manifest file generation. The command will be
1586 structured as follows:
1587 cmd /c (linkcmd1 a b) && (linkcmd2 x y) && ... &&
1588 if not "$manifests"=="" ((manifestcmd1 a b) && (manifestcmd2 x y) && ... )
1589 Note that $manifests becomes empty when no manifest file is generated."""
1590 link_commands = ['%(ldcmd)s',
1591 'if exist %(out)s.manifest del %(out)s.manifest']
1592 mt_cmd = ('%(python)s gyp-win-tool manifest-wrapper'
1593 ' $arch $mt -nologo -manifest $manifests')
1594 if embed_manifest and not link_incremental:
1595 # Embed manifest into a binary. If incremental linking is enabled,
1596 # embedding is postponed to the re-linking stage (see below).
1597 mt_cmd += ' -outputresource:%(out)s;%(resname)s'
1598 else:
1599 # Save manifest as an external file.
1600 mt_cmd += ' -out:%(out)s.manifest'
1601 manifest_commands = [mt_cmd]
1602 if link_incremental:
1603 # There is no point in generating separate rule for the case when
1604 # incremental linking is enabled, but manifest embedding is disabled.
1605 # In that case the basic rule should be used (e.g. 'link').
1606 # See also implementation of _GetWinLinkRuleNameSuffix().
1607 assert embed_manifest
1608 # Make .rc file out of manifest, compile it to .res file and re-link.
1609 manifest_commands += [
1610 ('%(python)s gyp-win-tool manifest-to-rc $arch %(out)s.manifest'
1611 ' %(out)s.manifest.rc %(resname)s'),
1612 '%(python)s gyp-win-tool rc-wrapper $arch $rc %(out)s.manifest.rc',
1613 '%(ldcmd)s %(out)s.manifest.res']
1614 cmd = 'cmd /c %s && if not "$manifests"=="" (%s)' % (
1615 ' && '.join(['(%s)' % c for c in link_commands]),
1616 ' && '.join(['(%s)' % c for c in manifest_commands]))
1617 resource_name = { 1585 resource_name = {
1618 'exe': '1', 1586 'exe': '1',
1619 'dll': '2', 1587 'dll': '2',
1620 }[binary_type] 1588 }[binary_type]
1621 return cmd % {'python': sys.executable, 1589 return '%(python)s gyp-win-tool link-with-manifests $arch %(embed)s ' \
1622 'out': out, 1590 '%(out)s "%(ldcmd)s" %(resname)s $mt $rc "$intermediatemanifest" ' \
1623 'ldcmd': ldcmd, 1591 '$manifests' % {
1624 'resname': resource_name} 1592 'python': sys.executable,
1625 1593 'out': out,
1626 rule_name_suffix = _GetWinLinkRuleNameSuffix(embed_manifest, link_incremental) 1594 'ldcmd': ldcmd,
1595 'resname': resource_name,
1596 'embed': embed_manifest }
1597 rule_name_suffix = _GetWinLinkRuleNameSuffix(embed_manifest)
1627 dlldesc = 'LINK%s(DLL) $dll' % rule_name_suffix.upper() 1598 dlldesc = 'LINK%s(DLL) $dll' % rule_name_suffix.upper()
1628 dllcmd = ('%s gyp-win-tool link-wrapper $arch ' 1599 dllcmd = ('%s gyp-win-tool link-wrapper $arch '
1629 '$ld /nologo $implibflag /DLL /OUT:$dll ' 1600 '$ld /nologo $implibflag /DLL /OUT:$dll '
1630 '/PDB:$dll.pdb @$dll.rsp' % sys.executable) 1601 '/PDB:$dll.pdb @$dll.rsp' % sys.executable)
1631 dllcmd = FullLinkCommand(dllcmd, '$dll', 'dll') 1602 dllcmd = FullLinkCommand(dllcmd, '$dll', 'dll')
1632 master_ninja.rule('solink' + rule_name_suffix, 1603 master_ninja.rule('solink' + rule_name_suffix,
1633 description=dlldesc, command=dllcmd, 1604 description=dlldesc, command=dllcmd,
1634 rspfile='$dll.rsp', 1605 rspfile='$dll.rsp',
1635 rspfile_content='$libs $in_newline $ldflags', 1606 rspfile_content='$libs $in_newline $ldflags',
1636 restat=True, 1607 restat=True,
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 pool='link_pool') 1879 pool='link_pool')
1909 elif flavor == 'win': 1880 elif flavor == 'win':
1910 master_ninja.rule( 1881 master_ninja.rule(
1911 'alink', 1882 'alink',
1912 description='LIB $out', 1883 description='LIB $out',
1913 command=('%s gyp-win-tool link-wrapper $arch ' 1884 command=('%s gyp-win-tool link-wrapper $arch '
1914 '$ar /nologo /ignore:4221 /OUT:$out @$out.rsp' % 1885 '$ar /nologo /ignore:4221 /OUT:$out @$out.rsp' %
1915 sys.executable), 1886 sys.executable),
1916 rspfile='$out.rsp', 1887 rspfile='$out.rsp',
1917 rspfile_content='$in_newline $libflags') 1888 rspfile_content='$in_newline $libflags')
1918 _AddWinLinkRules(master_ninja, embed_manifest=True, link_incremental=True) 1889 _AddWinLinkRules(master_ninja, embed_manifest=True)
1919 _AddWinLinkRules(master_ninja, embed_manifest=True, link_incremental=False) 1890 _AddWinLinkRules(master_ninja, embed_manifest=False)
1920 _AddWinLinkRules(master_ninja, embed_manifest=False, link_incremental=False)
1921 # Do not generate rules for embed_manifest=False and link_incremental=True
1922 # because in that case rules for (False, False) should be used (see
1923 # implementation of _GetWinLinkRuleNameSuffix()).
1924 else: 1891 else:
1925 master_ninja.rule( 1892 master_ninja.rule(
1926 'objc', 1893 'objc',
1927 description='OBJC $out', 1894 description='OBJC $out',
1928 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc ' 1895 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc '
1929 '$cflags_pch_objc -c $in -o $out'), 1896 '$cflags_pch_objc -c $in -o $out'),
1930 depfile='$out.d', 1897 depfile='$out.d',
1931 deps=deps) 1898 deps=deps)
1932 master_ninja.rule( 1899 master_ninja.rule(
1933 'objcxx', 1900 'objcxx',
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 arglists.append( 2127 arglists.append(
2161 (target_list, target_dicts, data, params, config_name)) 2128 (target_list, target_dicts, data, params, config_name))
2162 pool.map(CallGenerateOutputForConfig, arglists) 2129 pool.map(CallGenerateOutputForConfig, arglists)
2163 except KeyboardInterrupt, e: 2130 except KeyboardInterrupt, e:
2164 pool.terminate() 2131 pool.terminate()
2165 raise e 2132 raise e
2166 else: 2133 else:
2167 for config_name in config_names: 2134 for config_name in config_names:
2168 GenerateOutputForConfig(target_list, target_dicts, data, params, 2135 GenerateOutputForConfig(target_list, target_dicts, data, params,
2169 config_name) 2136 config_name)
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/msvs_emulation.py » ('j') | pylib/gyp/msvs_emulation.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698