Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
deps: update gyp to 828ce09
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny authored and tjfontaine committed Dec 30, 2013
1 parent 34b9280 commit cb5da7b
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 134 deletions.
8 changes: 8 additions & 0 deletions tools/gyp/pylib/gyp/common.py
Expand Up @@ -391,6 +391,14 @@ def close(self):
return Writer()


def EnsureDirExists(path):
"""Make sure the directory for |path| exists."""
try:
os.makedirs(os.path.dirname(path))
except OSError:
pass


def GetFlavor(params):
"""Returns |params.flavor| if it's set, the system's default flavor else."""
flavors = {
Expand Down
4 changes: 2 additions & 2 deletions tools/gyp/pylib/gyp/generator/android.py
Expand Up @@ -145,7 +145,7 @@ def Write(self, qualified_target, relative_target, base_path, output_filename,
spec, configs: gyp info
part_of_all: flag indicating this target is part of 'all'
"""
make.ensure_directory_exists(output_filename)
gyp.common.EnsureDirExists(output_filename)

self.fp = open(output_filename, 'w')

Expand Down Expand Up @@ -983,7 +983,7 @@ def CalculateMakefilePath(build_file, base_name):
makefile_path = os.path.join(options.toplevel_dir, makefile_name)
assert not options.generator_output, (
'The Android backend does not support options.generator_output.')
make.ensure_directory_exists(makefile_path)
gyp.common.EnsureDirExists(makefile_path)
root_makefile = open(makefile_path, 'w')

root_makefile.write(header)
Expand Down
9 changes: 1 addition & 8 deletions tools/gyp/pylib/gyp/generator/cmake.py
Expand Up @@ -118,13 +118,6 @@ def NormjoinPath(base_path, rel_path):
return os.path.normpath(os.path.join(base_path, rel_path))


def EnsureDirectoryExists(path):
"""Python version of 'mkdir -p'."""
dirPath = os.path.dirname(path)
if dirPath and not os.path.exists(dirPath):
os.makedirs(dirPath)


def CMakeStringEscape(a):
"""Escapes the string 'a' for use inside a CMake string.
Expand Down Expand Up @@ -1041,7 +1034,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data,
toplevel_build = os.path.join(options.toplevel_dir, build_dir)

output_file = os.path.join(toplevel_build, 'CMakeLists.txt')
EnsureDirectoryExists(output_file)
gyp.common.EnsureDirExists(output_file)

output = open(output_file, 'w')
output.write('cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n')
Expand Down
6 changes: 3 additions & 3 deletions tools/gyp/pylib/gyp/generator/eclipse.py
Expand Up @@ -270,9 +270,9 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
shared_intermediate_dirs = [os.path.join(toplevel_build, 'obj', 'gen'),
os.path.join(toplevel_build, 'gen')]

if not os.path.exists(toplevel_build):
os.makedirs(toplevel_build)
out = open(os.path.join(toplevel_build, 'eclipse-cdt-settings.xml'), 'w')
out_name = os.path.join(toplevel_build, 'eclipse-cdt-settings.xml')
gyp.common.EnsureDirExists(out_name)
out = open(out_name, 'w')

out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
out.write('<cdtprojectproperties>\n')
Expand Down
17 changes: 6 additions & 11 deletions tools/gyp/pylib/gyp/generator/make.py
Expand Up @@ -117,12 +117,6 @@ def CalculateGeneratorInputInfo(params):
}


def ensure_directory_exists(path):
dir = os.path.dirname(path)
if dir and not os.path.exists(dir):
os.makedirs(dir)


# The .d checking code below uses these functions:
# wildcard, sort, foreach, shell, wordlist
# wildcard can handle spaces, the rest can't.
Expand Down Expand Up @@ -691,7 +685,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
spec, configs: gyp info
part_of_all: flag indicating this target is part of 'all'
"""
ensure_directory_exists(output_filename)
gyp.common.EnsureDirExists(output_filename)

self.fp = open(output_filename, 'w')

Expand Down Expand Up @@ -820,7 +814,7 @@ def WriteSubMake(self, output_filename, makefile_path, targets, build_dir):
targets: list of "all" targets for this sub-project
build_dir: build output directory, relative to the sub-project
"""
ensure_directory_exists(output_filename)
gyp.common.EnsureDirExists(output_filename)
self.fp = open(output_filename, 'w')
self.fp.write(header)
# For consistency with other builders, put sub-project build output in the
Expand Down Expand Up @@ -2056,8 +2050,9 @@ def CalculateMakefilePath(build_file, base_name):
make_global_settings += (
'ifneq (,$(filter $(origin %s), undefined default))\n' % key)
# Let gyp-time envvars win over global settings.
if key in os.environ:
value = os.environ[key]
env_key = key.replace('.', '_') # CC.host -> CC_host
if env_key in os.environ:
value = os.environ[env_key]
make_global_settings += ' %s = %s\n' % (key, value)
make_global_settings += 'endif\n'
else:
Expand All @@ -2067,7 +2062,7 @@ def CalculateMakefilePath(build_file, base_name):

header_params['make_global_settings'] = make_global_settings

ensure_directory_exists(makefile_path)
gyp.common.EnsureDirExists(makefile_path)
root_makefile = open(makefile_path, 'w')
root_makefile.write(SHARED_HEADER % header_params)
# Currently any versions have the same effect, but in future the behavior
Expand Down
35 changes: 17 additions & 18 deletions tools/gyp/pylib/gyp/generator/msvs.py
Expand Up @@ -22,6 +22,16 @@
import gyp.MSVSVersion as MSVSVersion
from gyp.common import GypError

# TODO: Remove once bots are on 2.7, http://crbug.com/241769
def _import_OrderedDict():
import collections
try:
return collections.OrderedDict
except AttributeError:
import gyp.ordered_dict
return gyp.ordered_dict.OrderedDict
OrderedDict = _import_OrderedDict()


# Regular expression for validating Visual Studio GUIDs. If the GUID
# contains lowercase hex letters, MSVS will be fine. However,
Expand Down Expand Up @@ -220,7 +230,6 @@ def _ConvertSourcesToFilterHierarchy(sources, prefix=None, excluded=None,
if not prefix: prefix = []
result = []
excluded_result = []
folders = collections.OrderedDict()
# Gather files into the final result, excluded, or folders.
for s in sources:
if len(s) == 1:
Expand All @@ -230,22 +239,16 @@ def _ConvertSourcesToFilterHierarchy(sources, prefix=None, excluded=None,
else:
result.append(filename)
else:
if not folders.get(s[0]):
folders[s[0]] = []
folders[s[0]].append(s[1:])
contents = _ConvertSourcesToFilterHierarchy([s[1:]], prefix + [s[0]],
excluded=excluded,
list_excluded=list_excluded)
contents = MSVSProject.Filter(s[0], contents=contents)
result.append(contents)
# Add a folder for excluded files.
if excluded_result and list_excluded:
excluded_folder = MSVSProject.Filter('_excluded_files',
contents=excluded_result)
result.append(excluded_folder)
# Populate all the folders.
for f in folders:
contents = _ConvertSourcesToFilterHierarchy(folders[f], prefix=prefix + [f],
excluded=excluded,
list_excluded=list_excluded)
contents = MSVSProject.Filter(f, contents=contents)
result.append(contents)

return result


Expand Down Expand Up @@ -941,9 +944,7 @@ def _GenerateMSVSProject(project, options, version, generator_flags):
generator_flags: dict of generator-specific flags.
"""
spec = project.spec
vcproj_dir = os.path.dirname(project.path)
if vcproj_dir and not os.path.exists(vcproj_dir):
os.makedirs(vcproj_dir)
gyp.common.EnsureDirExists(project.path)

platforms = _GetUniquePlatforms(spec)
p = MSVSProject.Writer(project.path, version, spec['target_name'],
Expand Down Expand Up @@ -3096,9 +3097,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
spec = project.spec
configurations = spec['configurations']
project_dir, project_file_name = os.path.split(project.path)
msbuildproj_dir = os.path.dirname(project.path)
if msbuildproj_dir and not os.path.exists(msbuildproj_dir):
os.makedirs(msbuildproj_dir)
gyp.common.EnsureDirExists(project.path)
# Prepare list of sources and excluded sources.
gyp_path = _NormalizedSource(project.build_file)
relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
Expand Down
87 changes: 25 additions & 62 deletions tools/gyp/pylib/gyp/generator/ninja.py
Expand Up @@ -1039,13 +1039,18 @@ def WriteLinkForArch(self, ninja_file, spec, config_name, config,
elif self.flavor == 'win':
manifest_name = self.GypPathToUniqueOutput(
self.ComputeOutputFileName(spec))
ldflags, manifest_files = self.msvs_settings.GetLdflags(config_name,
self.GypPathToNinja, self.ExpandSpecial, manifest_name, is_executable)
ldflags, intermediate_manifest, manifest_files = \
self.msvs_settings.GetLdflags(config_name, self.GypPathToNinja,
self.ExpandSpecial, manifest_name,
is_executable, self.toplevel_build)
ldflags = env_ldflags + ldflags
self.WriteVariableList(ninja_file, 'manifests', manifest_files)
implicit_deps = implicit_deps.union(manifest_files)
if intermediate_manifest:
self.WriteVariableList(
ninja_file, 'intermediatemanifest', [intermediate_manifest])
command_suffix = _GetWinLinkRuleNameSuffix(
self.msvs_settings.IsEmbedManifest(config_name),
self.msvs_settings.IsLinkIncremental(config_name))
self.msvs_settings.IsEmbedManifest(config_name))
def_file = self.msvs_settings.GetDefFile(self.GypPathToNinja)
if def_file:
implicit_deps.add(def_file)
Expand Down Expand Up @@ -1505,10 +1510,7 @@ def CalculateGeneratorInputInfo(params):

def OpenOutput(path, mode='w'):
"""Open |path| for writing, creating directories if necessary."""
try:
os.makedirs(os.path.dirname(path))
except OSError:
pass
gyp.common.EnsureDirExists(path)
return open(path, mode)


Expand Down Expand Up @@ -1567,63 +1569,28 @@ class MEMORYSTATUSEX(ctypes.Structure):
return 1


def _GetWinLinkRuleNameSuffix(embed_manifest, link_incremental):
def _GetWinLinkRuleNameSuffix(embed_manifest):
"""Returns the suffix used to select an appropriate linking rule depending on
whether the manifest embedding and/or incremental linking is enabled."""
suffix = ''
if embed_manifest:
suffix += '_embed'
if link_incremental:
suffix += '_inc'
return suffix
whether the manifest embedding is enabled."""
return '_embed' if embed_manifest else ''


def _AddWinLinkRules(master_ninja, embed_manifest, link_incremental):
def _AddWinLinkRules(master_ninja, embed_manifest):
"""Adds link rules for Windows platform to |master_ninja|."""
def FullLinkCommand(ldcmd, out, binary_type):
"""Returns a one-liner written for cmd.exe to handle multiphase linker
operations including manifest file generation. The command will be
structured as follows:
cmd /c (linkcmd1 a b) && (linkcmd2 x y) && ... &&
if not "$manifests"=="" ((manifestcmd1 a b) && (manifestcmd2 x y) && ... )
Note that $manifests becomes empty when no manifest file is generated."""
link_commands = ['%(ldcmd)s',
'if exist %(out)s.manifest del %(out)s.manifest']
mt_cmd = ('%(python)s gyp-win-tool manifest-wrapper'
' $arch $mt -nologo -manifest $manifests')
if embed_manifest and not link_incremental:
# Embed manifest into a binary. If incremental linking is enabled,
# embedding is postponed to the re-linking stage (see below).
mt_cmd += ' -outputresource:%(out)s;%(resname)s'
else:
# Save manifest as an external file.
mt_cmd += ' -out:%(out)s.manifest'
manifest_commands = [mt_cmd]
if link_incremental:
# There is no point in generating separate rule for the case when
# incremental linking is enabled, but manifest embedding is disabled.
# In that case the basic rule should be used (e.g. 'link').
# See also implementation of _GetWinLinkRuleNameSuffix().
assert embed_manifest
# Make .rc file out of manifest, compile it to .res file and re-link.
manifest_commands += [
('%(python)s gyp-win-tool manifest-to-rc $arch %(out)s.manifest'
' %(out)s.manifest.rc %(resname)s'),
'%(python)s gyp-win-tool rc-wrapper $arch $rc %(out)s.manifest.rc',
'%(ldcmd)s %(out)s.manifest.res']
cmd = 'cmd /c %s && if not "$manifests"=="" (%s)' % (
' && '.join(['(%s)' % c for c in link_commands]),
' && '.join(['(%s)' % c for c in manifest_commands]))
resource_name = {
'exe': '1',
'dll': '2',
}[binary_type]
return cmd % {'python': sys.executable,
'out': out,
'ldcmd': ldcmd,
'resname': resource_name}

rule_name_suffix = _GetWinLinkRuleNameSuffix(embed_manifest, link_incremental)
return '%(python)s gyp-win-tool link-with-manifests $arch %(embed)s ' \
'%(out)s "%(ldcmd)s" %(resname)s $mt $rc "$intermediatemanifest" ' \
'$manifests' % {
'python': sys.executable,
'out': out,
'ldcmd': ldcmd,
'resname': resource_name,
'embed': embed_manifest }
rule_name_suffix = _GetWinLinkRuleNameSuffix(embed_manifest)
dlldesc = 'LINK%s(DLL) $dll' % rule_name_suffix.upper()
dllcmd = ('%s gyp-win-tool link-wrapper $arch '
'$ld /nologo $implibflag /DLL /OUT:$dll '
Expand Down Expand Up @@ -1915,12 +1882,8 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params,
sys.executable),
rspfile='$out.rsp',
rspfile_content='$in_newline $libflags')
_AddWinLinkRules(master_ninja, embed_manifest=True, link_incremental=True)
_AddWinLinkRules(master_ninja, embed_manifest=True, link_incremental=False)
_AddWinLinkRules(master_ninja, embed_manifest=False, link_incremental=False)
# Do not generate rules for embed_manifest=False and link_incremental=True
# because in that case rules for (False, False) should be used (see
# implementation of _GetWinLinkRuleNameSuffix()).
_AddWinLinkRules(master_ninja, embed_manifest=True)
_AddWinLinkRules(master_ninja, embed_manifest=False)
else:
master_ninja.rule(
'objc',
Expand Down
3 changes: 1 addition & 2 deletions tools/gyp/pylib/gyp/input.py
Expand Up @@ -822,8 +822,7 @@ def ExpandVariables(input, phase, variables, build_file):
rel_build_file_dir = build_file_dir
qualified_out_dir = generator_filelist_paths['qualified_out_dir']
path = os.path.join(qualified_out_dir, rel_build_file_dir, replacement)
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
gyp.common.EnsureDirExists(path)

replacement = gyp.common.RelativePath(path, build_file_dir)
f = gyp.common.WriteOnDiff(path)
Expand Down

0 comments on commit cb5da7b

Please sign in to comment.