Browse Source

gyp: update to r1214

v0.9.1-release
Ben Noordhuis 13 years ago
parent
commit
4af673e161
  1. 43
      tools/gyp/buildbot/buildbot_run.py
  2. 4
      tools/gyp/gyptest.py
  3. 29
      tools/gyp/pylib/gyp/common.py
  4. 8
      tools/gyp/pylib/gyp/generator/dump_dependency_json.py
  5. 1145
      tools/gyp/pylib/gyp/generator/make.py
  6. 89
      tools/gyp/pylib/gyp/generator/msvs.py
  7. 803
      tools/gyp/pylib/gyp/generator/ninja.py
  8. 42
      tools/gyp/pylib/gyp/generator/ninja_test.py
  9. 20
      tools/gyp/pylib/gyp/input.py
  10. 150
      tools/gyp/pylib/gyp/mac_tool.py
  11. 64
      tools/gyp/pylib/gyp/ninja_syntax.py
  12. 15
      tools/gyp/pylib/gyp/system_test.py
  13. 972
      tools/gyp/pylib/gyp/xcode_emulation.py
  14. 6
      tools/gyp/test/home_dot_gyp/gyptest-home-includes-regyp.py
  15. 4
      tools/gyp/test/home_dot_gyp/gyptest-home-includes.py
  16. 27
      tools/gyp/test/lib/TestGyp.py
  17. 34
      tools/gyp/test/mac/action-envvars/action/action.gyp
  18. 8
      tools/gyp/test/mac/action-envvars/action/action.sh
  19. 4
      tools/gyp/test/mac/archs/my_file.cc
  20. 9
      tools/gyp/test/mac/archs/my_main_file.cc
  21. 27
      tools/gyp/test/mac/archs/test-archs-x86_64.gyp
  22. 21
      tools/gyp/test/mac/archs/test-no-archs.gyp
  23. 1
      tools/gyp/test/mac/copy-dylib/empty.c
  24. 31
      tools/gyp/test/mac/copy-dylib/test.gyp
  25. 1
      tools/gyp/test/mac/depend-on-bundle/English.lproj/InfoPlist.strings
  26. 28
      tools/gyp/test/mac/depend-on-bundle/Info.plist
  27. 1
      tools/gyp/test/mac/depend-on-bundle/bundle.c
  28. 4
      tools/gyp/test/mac/depend-on-bundle/executable.c
  29. 28
      tools/gyp/test/mac/depend-on-bundle/test.gyp
  30. 11
      tools/gyp/test/mac/global-settings/src/dir1/dir1.gyp
  31. 22
      tools/gyp/test/mac/global-settings/src/dir2/dir2.gyp
  32. 1
      tools/gyp/test/mac/global-settings/src/dir2/file.txt
  33. 30
      tools/gyp/test/mac/gyptest-action-envvars.py
  34. 4
      tools/gyp/test/mac/gyptest-app.py
  35. 37
      tools/gyp/test/mac/gyptest-archs.py
  36. 4
      tools/gyp/test/mac/gyptest-copies.py
  37. 25
      tools/gyp/test/mac/gyptest-copy-dylib.py
  38. 2
      tools/gyp/test/mac/gyptest-debuginfo.py
  39. 40
      tools/gyp/test/mac/gyptest-depend-on-bundle.py
  40. 4
      tools/gyp/test/mac/gyptest-framework.py
  41. 26
      tools/gyp/test/mac/gyptest-global-settings.py
  42. 4
      tools/gyp/test/mac/gyptest-infoplist-process.py
  43. 22
      tools/gyp/test/mac/gyptest-libraries.py
  44. 4
      tools/gyp/test/mac/gyptest-loadable-module.py
  45. 33
      tools/gyp/test/mac/gyptest-non-strs-flattened-to-env.py
  46. 62
      tools/gyp/test/mac/gyptest-postbuild-copy-bundle.py
  47. 29
      tools/gyp/test/mac/gyptest-postbuild-defaults.py
  48. 4
      tools/gyp/test/mac/gyptest-postbuild-fail.py
  49. 26
      tools/gyp/test/mac/gyptest-postbuild-multiple-configurations.py
  50. 28
      tools/gyp/test/mac/gyptest-postbuild-static-library.gyp
  51. 2
      tools/gyp/test/mac/gyptest-postbuild.py
  52. 4
      tools/gyp/test/mac/gyptest-prefixheader.py
  53. 29
      tools/gyp/test/mac/gyptest-rebuild.py
  54. 46
      tools/gyp/test/mac/gyptest-sourceless-module.gyp
  55. 2
      tools/gyp/test/mac/gyptest-strip.py
  56. 4
      tools/gyp/test/mac/gyptest-type-envvars.py
  57. 59
      tools/gyp/test/mac/gyptest-xcode-env-order.py
  58. 1
      tools/gyp/test/mac/libraries/subdir/README.txt
  59. 10
      tools/gyp/test/mac/libraries/subdir/hello.cc
  60. 7
      tools/gyp/test/mac/libraries/subdir/mylib.c
  61. 66
      tools/gyp/test/mac/libraries/subdir/test.gyp
  62. 15
      tools/gyp/test/mac/non-strs-flattened-to-env/Info.plist
  63. 7
      tools/gyp/test/mac/non-strs-flattened-to-env/main.c
  64. 24
      tools/gyp/test/mac/non-strs-flattened-to-env/test.gyp
  65. 30
      tools/gyp/test/mac/postbuild-copy-bundle/Framework-Info.plist
  66. 32
      tools/gyp/test/mac/postbuild-copy-bundle/TestApp-Info.plist
  67. 0
      tools/gyp/test/mac/postbuild-copy-bundle/empty.c
  68. 4
      tools/gyp/test/mac/postbuild-copy-bundle/main.c
  69. 9
      tools/gyp/test/mac/postbuild-copy-bundle/postbuild-copy-framework.sh
  70. 1
      tools/gyp/test/mac/postbuild-copy-bundle/resource_file.sb
  71. 43
      tools/gyp/test/mac/postbuild-copy-bundle/test.gyp
  72. 13
      tools/gyp/test/mac/postbuild-defaults/Info.plist
  73. 7
      tools/gyp/test/mac/postbuild-defaults/main.c
  74. 15
      tools/gyp/test/mac/postbuild-defaults/postbuild-defaults.sh
  75. 26
      tools/gyp/test/mac/postbuild-defaults/test.gyp
  76. 2
      tools/gyp/test/mac/postbuild-fail/postbuild-fail.sh
  77. 4
      tools/gyp/test/mac/postbuild-multiple-configurations/main.c
  78. 7
      tools/gyp/test/mac/postbuild-multiple-configurations/postbuild-touch-file.sh
  79. 26
      tools/gyp/test/mac/postbuild-multiple-configurations/test.gyp
  80. 4
      tools/gyp/test/mac/postbuild-static-library/empty.c
  81. 7
      tools/gyp/test/mac/postbuild-static-library/postbuild-touch-file.sh
  82. 34
      tools/gyp/test/mac/postbuild-static-library/test.gyp
  83. 1
      tools/gyp/test/mac/prefixheader/file.cc
  84. 1
      tools/gyp/test/mac/prefixheader/file.m
  85. 1
      tools/gyp/test/mac/prefixheader/file.mm
  86. 61
      tools/gyp/test/mac/prefixheader/test.gyp
  87. 32
      tools/gyp/test/mac/rebuild/TestApp-Info.plist
  88. 6
      tools/gyp/test/mac/rebuild/delay-touch.sh
  89. 0
      tools/gyp/test/mac/rebuild/empty.c
  90. 1
      tools/gyp/test/mac/rebuild/main.c
  91. 56
      tools/gyp/test/mac/rebuild/test.gyp
  92. 1
      tools/gyp/test/mac/sourceless-module/empty.c
  93. 39
      tools/gyp/test/mac/sourceless-module/test.gyp
  94. 11
      tools/gyp/test/mac/type_envvars/test.gyp
  95. 8
      tools/gyp/test/mac/type_envvars/test_bundle_executable.sh
  96. 9
      tools/gyp/test/mac/type_envvars/test_bundle_loadable_module.sh
  97. 9
      tools/gyp/test/mac/type_envvars/test_bundle_shared_library.sh
  98. 8
      tools/gyp/test/mac/type_envvars/test_nonbundle_executable.sh
  99. 8
      tools/gyp/test/mac/type_envvars/test_nonbundle_loadable_module.sh
  100. 16
      tools/gyp/test/mac/type_envvars/test_nonbundle_none.sh

43
tools/gyp/buildbot/buildbot_run.py

@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -23,32 +23,6 @@ BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__))
TRUNK_DIR = os.path.dirname(BUILDBOT_DIR)
ROOT_DIR = os.path.dirname(TRUNK_DIR)
OUT_DIR = os.path.join(TRUNK_DIR, 'out')
NINJA_PATH = os.path.join(TRUNK_DIR, 'ninja' + EXE_SUFFIX)
NINJA_WORK_DIR = os.path.join(ROOT_DIR, 'ninja_work')
def InstallNinja():
"""Install + build ninja.
Returns:
0 for success, 1 for failure.
"""
print '@@@BUILD_STEP install ninja@@@'
# Delete old version if any.
try:
shutil.rmtree(NINJA_WORK_DIR, ignore_errors=True)
except:
pass
# Sync new copy from git.
subprocess.check_call(
'git clone https://github.com/martine/ninja.git ' + NINJA_WORK_DIR,
shell=True)
# Bootstrap.
subprocess.check_call('./bootstrap.sh', cwd=NINJA_WORK_DIR, shell=True)
# Copy out ninja.
shutil.copyfile(os.path.join(NINJA_WORK_DIR, 'ninja' + EXE_SUFFIX),
NINJA_PATH)
os.chmod(NINJA_PATH, 0777)
def GypTestFormat(title, format=None, msvs_version=None):
@ -64,17 +38,6 @@ def GypTestFormat(title, format=None, msvs_version=None):
if not format:
format = title
# Install ninja if needed.
# NOTE: as ninja gets installed each time, regressions to ninja can come
# either from changes to ninja itself, or changes to gyp.
if format == 'ninja':
try:
InstallNinja()
except Exception, e:
print '@@@STEP_FAILURE@@@'
print str(e)
return 1
print '@@@BUILD_STEP ' + title + '@@@'
sys.stdout.flush()
env = os.environ.copy()
@ -104,10 +67,6 @@ def GypBuild():
print '@@@BUILD_STEP cleanup@@@'
print 'Removing %s...' % OUT_DIR
shutil.rmtree(OUT_DIR, ignore_errors=True)
print 'Removing %s...' % NINJA_WORK_DIR
shutil.rmtree(NINJA_WORK_DIR, ignore_errors=True)
print 'Removing %s...' % NINJA_PATH
shutil.rmtree(NINJA_PATH, ignore_errors=True)
print 'Done.'
retcode = 0

4
tools/gyp/gyptest.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -209,7 +209,7 @@ def main(argv=None):
'freebsd7': ['make'],
'freebsd8': ['make'],
'cygwin': ['msvs'],
'win32': ['msvs'],
'win32': ['msvs', 'ninja'],
'linux2': ['make', 'ninja'],
'linux3': ['make', 'ninja'],
'darwin': ['make', 'ninja', 'xcode'],

29
tools/gyp/pylib/gyp/common.py

@ -1,7 +1,9 @@
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import with_statement
import errno
import filecmp
import os.path
@ -347,6 +349,8 @@ def WriteOnDiff(filename):
def GetFlavor(params):
"""Returns |params.flavor| if it's set, the system's default flavor else."""
flavors = {
'cygwin': 'win',
'win32': 'win',
'darwin': 'mac',
'sunos5': 'solaris',
'freebsd7': 'freebsd',
@ -356,6 +360,29 @@ def GetFlavor(params):
return params.get('flavor', flavor)
def CopyTool(flavor, out_path):
"""Finds (mac|sun)_tool.gyp in the gyp directory and copies it
to |out_path|."""
prefix = { 'solaris': 'sun', 'mac': 'mac' }.get(flavor, None)
if not prefix:
return
# Slurp input file.
source_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '%s_tool.py' % prefix)
with open(source_path) as source_file:
source = source_file.readlines()
# Add header and write it out.
tool_path = os.path.join(out_path, 'gyp-%s-tool' % prefix)
with open(tool_path, 'w') as tool_file:
tool_file.write(
''.join([source[0], '# Generated by gyp. Do not edit.\n'] + source[1:]))
# Make file executable.
os.chmod(tool_path, 0755)
# From Alex Martelli,
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
# ASPN: Python Cookbook: Remove duplicates from a sequence

8
tools/gyp/pylib/gyp/generator/dump_dependency_json.py

@ -20,15 +20,15 @@ for unused in ['RULE_INPUT_PATH', 'RULE_INPUT_ROOT', 'RULE_INPUT_NAME',
'RULE_INPUT_DIRNAME', 'RULE_INPUT_EXT',
'EXECUTABLE_PREFIX', 'EXECUTABLE_SUFFIX',
'STATIC_LIB_PREFIX', 'STATIC_LIB_SUFFIX',
'SHARED_LIB_PREFIX', 'SHARED_LIB_SUFFIX',
'LINKER_SUPPORTS_ICF']:
'SHARED_LIB_PREFIX', 'SHARED_LIB_SUFFIX']:
generator_default_variables[unused] = ''
def CalculateVariables(default_variables, params):
generator_flags = params.get('generator_flags', {})
default_variables['OS'] = generator_flags.get(
'os', gyp.common.GetFlavor(params))
for key, val in generator_flags.items():
default_variables.setdefault(key, val)
default_variables.setdefault('OS', gyp.common.GetFlavor(params))
def CalculateGeneratorInputInfo(params):

1145
tools/gyp/pylib/gyp/generator/make.py

File diff suppressed because it is too large

89
tools/gyp/pylib/gyp/generator/msvs.py

@ -1,4 +1,4 @@
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -162,7 +162,8 @@ def _FixPaths(paths):
return [_FixPath(i) for i in paths]
def _ConvertSourcesToFilterHierarchy(sources, prefix=None, excluded=None):
def _ConvertSourcesToFilterHierarchy(sources, prefix=None, excluded=None,
list_excluded=True):
"""Converts a list split source file paths into a vcproj folder hierarchy.
Arguments:
@ -197,14 +198,15 @@ def _ConvertSourcesToFilterHierarchy(sources, prefix=None, excluded=None):
folders[s[0]] = []
folders[s[0]].append(s[1:])
# Add a folder for excluded files.
if excluded_result:
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)
excluded=excluded,
list_excluded=list_excluded)
contents = MSVSProject.Filter(f, contents=contents)
result.append(contents)
@ -831,13 +833,14 @@ def _GetGuidOfProject(proj_path, spec):
return guid
def _GenerateProject(project, options, version):
def _GenerateProject(project, options, version, generator_flags):
"""Generates a vcproj file.
Arguments:
project: the MSVSProject object.
options: global generator options.
version: the MSVSVersion object.
generator_flags: dict of generator-specific flags.
"""
default_config = _GetDefaultConfiguration(project.spec)
@ -846,18 +849,19 @@ def _GenerateProject(project, options, version):
return
if version.UsesVcxproj():
_GenerateMSBuildProject(project, options, version)
_GenerateMSBuildProject(project, options, version, generator_flags)
else:
_GenerateMSVSProject(project, options, version)
_GenerateMSVSProject(project, options, version, generator_flags)
def _GenerateMSVSProject(project, options, version):
def _GenerateMSVSProject(project, options, version, generator_flags):
"""Generates a .vcproj file. It may create .rules and .user files too.
Arguments:
project: The project object we will generate the file for.
options: Global options passed to the generator.
version: The VisualStudioVersion object.
generator_flags: dict of generator-specific flags.
"""
spec = project.spec
vcproj_dir = os.path.dirname(project.path)
@ -886,9 +890,10 @@ def _GenerateMSVSProject(project, options, version):
_GenerateRulesForMSVS(p, project_dir, options, spec,
sources, excluded_sources,
actions_to_add)
list_excluded = generator_flags.get('msvs_list_excluded_files', True)
sources, excluded_sources, excluded_idl = (
_AdjustSourcesAndConvertToFilterHierarchy(
spec, options, project_dir, sources, excluded_sources))
spec, options, project_dir, sources, excluded_sources, list_excluded))
# Add in files.
_VerifySourcesExist(sources, project_dir)
@ -904,7 +909,8 @@ def _GenerateMSVSProject(project, options, version):
# Don't excluded sources with actions attached, or they won't run.
excluded_sources = _FilterActionsFromExcluded(
excluded_sources, actions_to_add)
_ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl)
_ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl,
list_excluded)
_AddAccumulatedActionsToMSVS(p, spec, actions_to_add)
# Write it out.
@ -963,7 +969,6 @@ def _GetMSVSConfigurationType(spec, build_file):
'loadable_module': '2', # .dll
'static_library': '4', # .lib
'none': '10', # Utility type
'dummy_executable': '1', # .exe
}[spec['type']]
except KeyError:
if spec.get('type'):
@ -1120,7 +1125,6 @@ def _GetOutputFilePathAndTool(spec):
# VisualStudio 2010, we will have to change the value of $(OutDir)
# to contain the \lib suffix, rather than doing it as below.
'static_library': ('VCLibrarianTool', 'Lib', '$(OutDir)\\lib\\', '.lib'),
'dummy_executable': ('VCLinkerTool', 'Link', '$(IntDir)\\', '.junk'),
}
output_file_props = output_file_map.get(spec['type'])
if output_file_props and int(spec.get('msvs_auto_output_file', 1)):
@ -1287,7 +1291,7 @@ def _PrepareListOfSources(spec, gyp_file):
def _AdjustSourcesAndConvertToFilterHierarchy(
spec, options, gyp_dir, sources, excluded_sources):
spec, options, gyp_dir, sources, excluded_sources, list_excluded):
"""Adjusts the list of sources and excluded sources.
Also converts the sets to lists.
@ -1321,13 +1325,8 @@ def _AdjustSourcesAndConvertToFilterHierarchy(
# Convert to folders and the right slashes.
sources = [i.split('\\') for i in sources]
sources = _ConvertSourcesToFilterHierarchy(sources, excluded=fully_excluded)
# Add in dummy file for type none.
if spec['type'] == 'dummy_executable':
# Pull in a dummy main so it can link successfully.
dummy_relpath = gyp.common.RelativePath(
options.depth + '\\tools\\gyp\\gyp_dummy.c', gyp_dir)
sources.append(dummy_relpath)
sources = _ConvertSourcesToFilterHierarchy(sources, excluded=fully_excluded,
list_excluded=list_excluded)
return sources, excluded_sources, excluded_idl
@ -1358,9 +1357,16 @@ def _GetPrecompileRelatedFiles(spec):
return precompiled_related
def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl):
def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl,
list_excluded):
exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
for file_name, excluded_configs in exclusions.iteritems():
if (not list_excluded and
len(excluded_configs) == len(spec['configurations'])):
# If we're not listing excluded files, then they won't appear in the
# project, so don't try to configure them to be excluded.
pass
else:
for config_name, config in excluded_configs:
p.AddFileConfig(file_name, _ConfigFullName(config_name, config),
{'ExcludedFromBuild': 'true'})
@ -1751,6 +1757,8 @@ def GenerateOutput(target_list, target_dicts, data, params):
# GeneratorCalculatedVariables.
msvs_version = params['msvs_version']
generator_flags = params.get('generator_flags', {})
# Optionally shard targets marked with 'msvs_shard': SHARD_COUNT.
(target_list, target_dicts) = _ShardTargets(target_list, target_dicts)
@ -1769,7 +1777,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
# Generate each project.
for project in project_objects.values():
fixpath_prefix = project.fixpath_prefix
_GenerateProject(project, options, msvs_version)
_GenerateProject(project, options, msvs_version, generator_flags)
fixpath_prefix = None
for build_file in data:
@ -1873,7 +1881,10 @@ def _MapFileToMsBuildSourceType(source, extension_to_rule_name):
A pair of (group this file should be part of, the label of element)
"""
_, ext = os.path.splitext(source)
if ext in ['.cc', '.cpp', '.c', '.cxx']:
if ext in extension_to_rule_name:
group = 'rule'
element = extension_to_rule_name[ext]
elif ext in ['.cc', '.cpp', '.c', '.cxx']:
group = 'compile'
element = 'ClCompile'
elif ext in ['.h', '.hxx']:
@ -1885,9 +1896,6 @@ def _MapFileToMsBuildSourceType(source, extension_to_rule_name):
elif ext == '.idl':
group = 'midl'
element = 'Midl'
elif ext in extension_to_rule_name:
group = 'rule'
element = extension_to_rule_name[ext]
else:
group = 'none'
element = 'None'
@ -2663,14 +2671,14 @@ def _VerifySourcesExist(sources, root_dir):
def _GetMSBuildSources(spec, sources, exclusions, extension_to_rule_name,
actions_spec, sources_handled_by_action):
actions_spec, sources_handled_by_action, list_excluded):
groups = ['none', 'midl', 'include', 'compile', 'resource', 'rule']
grouped_sources = {}
for g in groups:
grouped_sources[g] = []
_AddSources2(spec, sources, exclusions, grouped_sources,
extension_to_rule_name, sources_handled_by_action)
extension_to_rule_name, sources_handled_by_action, list_excluded)
sources = []
for g in groups:
if grouped_sources[g]:
@ -2681,12 +2689,14 @@ def _GetMSBuildSources(spec, sources, exclusions, extension_to_rule_name,
def _AddSources2(spec, sources, exclusions, grouped_sources,
extension_to_rule_name, sources_handled_by_action):
extension_to_rule_name, sources_handled_by_action,
list_excluded):
extensions_excluded_from_precompile = []
for source in sources:
if isinstance(source, MSVSProject.Filter):
_AddSources2(spec, source.contents, exclusions, grouped_sources,
extension_to_rule_name, sources_handled_by_action)
extension_to_rule_name, sources_handled_by_action,
list_excluded)
else:
if not source in sources_handled_by_action:
detail = []
@ -2741,17 +2751,22 @@ def _GetMSBuildProjectReferences(project):
guid = dependency.guid
project_dir = os.path.split(project.path)[0]
relative_path = gyp.common.RelativePath(dependency.path, project_dir)
group.append(
['ProjectReference',
project_ref = ['ProjectReference',
{'Include': relative_path},
['Project', guid],
['ReferenceOutputAssembly', 'false']
])
]
for config in dependency.spec.get('configurations', {}).itervalues():
# If it's disabled in any config, turn it off in the reference.
if config.get('msvs_2010_disable_uldi_when_referenced', 0):
project_ref.append(['UseLibraryDependencyInputs', 'false'])
break
group.append(project_ref)
references.append(group)
return references
def _GenerateMSBuildProject(project, options, version):
def _GenerateMSBuildProject(project, options, version, generator_flags):
spec = project.spec
configurations = spec['configurations']
project_dir, project_file_name = os.path.split(project.path)
@ -2769,6 +2784,7 @@ def _GenerateMSBuildProject(project, options, version):
props_files_of_rules = set()
targets_files_of_rules = set()
extension_to_rule_name = {}
list_excluded = generator_flags.get('msvs_list_excluded_files', True)
_GenerateRulesForMSBuild(project_dir, options, spec,
sources, excluded_sources,
props_files_of_rules, targets_files_of_rules,
@ -2776,7 +2792,8 @@ def _GenerateMSBuildProject(project, options, version):
sources, excluded_sources, excluded_idl = (
_AdjustSourcesAndConvertToFilterHierarchy(spec, options,
project_dir, sources,
excluded_sources))
excluded_sources,
list_excluded))
_AddActions(actions_to_add, spec, project.build_file)
_AddCopies(actions_to_add, spec)
@ -2826,7 +2843,7 @@ def _GenerateMSBuildProject(project, options, version):
content += _GetMSBuildToolSettingsSections(spec, configurations)
content += _GetMSBuildSources(
spec, sources, exclusions, extension_to_rule_name, actions_spec,
sources_handled_by_action)
sources_handled_by_action, list_excluded)
content += _GetMSBuildProjectReferences(project)
content += import_cpp_targets_section
content += _GetMSBuildExtensionTargets(targets_files_of_rules)

803
tools/gyp/pylib/gyp/generator/ninja.py

File diff suppressed because it is too large

42
tools/gyp/pylib/gyp/generator/ninja_test.py

@ -0,0 +1,42 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Unit tests for the ninja.py file. """
import gyp.generator.ninja as ninja
import unittest
import StringIO
import TestCommon
class TestPrefixesAndSuffixes(unittest.TestCase):
def test_BinaryNamesWindows(self):
writer = ninja.NinjaWriter('wee', '.', '.', 'ninja.build', 'win')
spec = { 'target_name': 'wee' }
self.assertTrue(writer.ComputeOutputFileName(spec, 'executable').
endswith('.exe'))
self.assertTrue(writer.ComputeOutputFileName(spec, 'shared_library').
endswith('.dll'))
self.assertTrue(writer.ComputeOutputFileName(spec, 'static_library').
endswith('.lib'))
def test_BinaryNamesLinux(self):
writer = ninja.NinjaWriter('wee', '.', '.', 'ninja.build', 'linux')
spec = {
'target_name': 'wee'
}
self.assertTrue('.' not in writer.ComputeOutputFileName(spec, 'executable'))
self.assertTrue(writer.ComputeOutputFileName(spec, 'shared_library').
startswith('lib'))
self.assertTrue(writer.ComputeOutputFileName(spec, 'static_library').
startswith('lib'))
self.assertTrue(writer.ComputeOutputFileName(spec, 'shared_library').
endswith('.so'))
self.assertTrue(writer.ComputeOutputFileName(spec, 'static_library').
endswith('.a'))
if __name__ == '__main__':
unittest.main()

20
tools/gyp/pylib/gyp/input.py

@ -2065,6 +2065,25 @@ def ProcessListFiltersInList(name, the_list):
ProcessListFiltersInList(name, item)
def ValidateTargetType(target, target_dict):
"""Ensures the 'type' field on the target is one of the known types.
Arguments:
target: string, name of target.
target_dict: dict, target spec.
Raises an exception on error.
"""
VALID_TARGET_TYPES = ('executable', 'loadable_module',
'static_library', 'shared_library',
'none')
target_type = target_dict.get('type', None)
if target_type not in VALID_TARGET_TYPES:
raise Exception("Target %s has an invalid target type '%s'. "
"Must be one of %s." %
(target, target_type, '/'.join(VALID_TARGET_TYPES)))
def ValidateRulesInTarget(target, target_dict, extra_sources_for_rules):
"""Ensures that the rules sections in target_dict are valid and consistent,
and determines which sources they apply to.
@ -2349,6 +2368,7 @@ def Load(build_files, variables, includes, depth, generator_input_info, check,
for target in flat_list:
target_dict = targets[target]
build_file = gyp.common.BuildFile(target)
ValidateTargetType(target, target_dict)
ValidateRulesInTarget(target, target_dict, extra_sources_for_rules)
ValidateRunAsInTarget(target, target_dict, build_file)
ValidateActionsInTarget(target, target_dict, build_file)

150
tools/gyp/pylib/gyp/mac_tool.py

@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -8,9 +8,10 @@
These functions are executed via gyp-mac-tool when using the Makefile generator.
"""
import os
import fcntl
import os
import plistlib
import re
import shutil
import string
import subprocess
@ -19,7 +20,9 @@ import sys
def main(args):
executor = MacTool()
executor.Dispatch(args)
exit_code = executor.Dispatch(args)
if exit_code is not None:
sys.exit(exit_code)
class MacTool(object):
@ -32,18 +35,70 @@ class MacTool(object):
raise Exception("Not enough arguments")
method = "Exec%s" % self._CommandifyName(args[0])
getattr(self, method)(*args[1:])
return getattr(self, method)(*args[1:])
def _CommandifyName(self, name_string):
"""Transforms a tool name like copy-info-plist to CopyInfoPlist"""
return name_string.title().replace('-', '')
def ExecFlock(self, lockfile, *cmd_list):
"""Emulates the most basic behavior of Linux's flock(1)."""
# Rely on exception handling to report errors.
fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
fcntl.flock(fd, fcntl.LOCK_EX)
return subprocess.call(cmd_list)
def ExecCopyBundleResource(self, source, dest):
"""Copies a resource file to the bundle/Resources directory, performing any
necessary compilation on each resource."""
extension = os.path.splitext(source)[1].lower()
if os.path.isdir(source):
# Copy tree.
if os.path.exists(dest):
shutil.rmtree(dest)
shutil.copytree(source, dest)
elif extension == '.xib':
self._CopyXIBFile(source, dest)
elif extension == '.strings':
self._CopyStringsFile(source, dest)
# TODO: Given that files with arbitrary extensions can be copied to the
# bundle, we will want to get rid of this whitelist eventually.
elif extension in [
'.icns', '.manifest', '.pak', '.pdf', '.png', '.sb', '.sh',
'.ttf', '.sdef']:
shutil.copyfile(source, dest)
else:
raise NotImplementedError(
"Don't know how to copy bundle resources of type %s while copying "
"%s to %s)" % (extension, source, dest))
def _CopyXIBFile(self, source, dest):
"""Compiles a XIB file with ibtool into a binary plist in the bundle."""
args = ['/Developer/usr/bin/ibtool', '--errors', '--warnings',
'--notices', '--output-format', 'human-readable-text', '--compile',
dest, source]
subprocess.call(args)
def _CopyStringsFile(self, source, dest):
"""Copies a .strings file using iconv to reconvert the input into UTF-16."""
input_code = self._DetectInputEncoding(source) or "UTF-8"
fp = open(dest, 'w')
args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code',
'UTF-16', source]
subprocess.call(args, stdout=fp)
fp.close()
def _DetectInputEncoding(self, file_name):
"""Reads the first few bytes from file_name and tries to guess the text
encoding. Returns None as a guess if it can't detect it."""
fp = open(file_name, 'rb')
try:
header = fp.read(3)
except e:
fp.close()
return None
fp.close()
if header.startswith("\xFE\xFF"):
return "UTF-16BE"
elif header.startswith("\xFF\xFE"):
return "UTF-16LE"
elif header.startswith("\xEF\xBB\xBF"):
return "UTF-8"
else:
return None
def ExecCopyInfoPlist(self, source, dest):
"""Copies the |source| Info.plist to the destination directory |dest|."""
@ -92,6 +147,22 @@ class MacTool(object):
fp.write('%s%s' % (package_type, signature_code))
fp.close()
def ExecFlock(self, lockfile, *cmd_list):
"""Emulates the most basic behavior of Linux's flock(1)."""
# Rely on exception handling to report errors.
fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
fcntl.flock(fd, fcntl.LOCK_EX)
return subprocess.call(cmd_list)
def ExecFilterLibtool(self, *cmd_list):
"""Calls libtool and filters out 'libtool: file: foo.o has no symbols'."""
libtool_re = re.compile(r'^libtool: file: .* has no symbols$')
libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE)
for line in libtoolout.stderr:
if not libtool_re.match(line):
sys.stderr.write(line)
return libtoolout.returncode
def ExecPackageFramework(self, framework, version):
"""Takes a path to Something.framework and the Current version of that and
sets up all the symlinks."""
@ -128,65 +199,6 @@ class MacTool(object):
os.remove(link)
os.symlink(dest, link)
def ExecCopyBundleResource(self, source, dest):
"""Copies a resource file to the bundle/Resources directory, performing any
necessary compilation on each resource."""
extension = os.path.splitext(source)[1].lower()
if os.path.isdir(source):
# Copy tree.
if os.path.exists(dest):
shutil.rmtree(dest)
shutil.copytree(source, dest)
elif extension == '.xib':
self._CopyXIBFile(source, dest)
elif extension == '.strings':
self._CopyStringsFile(source, dest)
# TODO: Given that files with arbitrary extensions can be copied to the
# bundle, we will want to get rid of this whitelist eventually.
elif extension in [
'.icns', '.manifest', '.pak', '.pdf', '.png', '.sb', '.sh',
'.ttf', '.sdef']:
shutil.copyfile(source, dest)
else:
raise NotImplementedError(
"Don't know how to copy bundle resources of type %s while copying "
"%s to %s)" % (extension, source, dest))
def _CopyXIBFile(self, source, dest):
"""Compiles a XIB file with ibtool into a binary plist in the bundle."""
args = ['/Developer/usr/bin/ibtool', '--errors', '--warnings',
'--notices', '--output-format', 'human-readable-text', '--compile',
dest, source]
subprocess.call(args)
def _CopyStringsFile(self, source, dest):
"""Copies a .strings file using iconv to reconvert the input into UTF-16."""
input_code = self._DetectInputEncoding(source) or "UTF-8"
fp = open(dest, 'w')
args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code',
'UTF-16', source]
subprocess.call(args, stdout=fp)
fp.close()
def _DetectInputEncoding(self, file_name):
"""Reads the first few bytes from file_name and tries to guess the text
encoding. Returns None as a guess if it can't detect it."""
fp = open(file_name, 'rb')
try:
header = fp.read(3)
except e:
fp.close()
return None
fp.close()
if header.startswith("\xFE\xFF"):
return "UTF-16BE"
elif header.startswith("\xFF\xFE"):
return "UTF-16LE"
elif header.startswith("\xEF\xBB\xBF"):
return "UTF-8"
else:
return None
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))

64
tools/gyp/pylib/gyp/ninja_syntax.py

@ -31,19 +31,23 @@ class Writer(object):
if value is None:
return
if isinstance(value, list):
value = ' '.join(value)
value = ' '.join(filter(None, value)) # Filter out empty strings.
self._line('%s = %s' % (key, value), indent)
def rule(self, name, command, description=None, depfile=None,
generator=False):
generator=False, restat=False, deplist=None):
self._line('rule %s' % name)
self.variable('command', command, indent=1)
if description:
self.variable('description', description, indent=1)
if depfile:
self.variable('depfile', depfile, indent=1)
if deplist:
self.variable('deplist', deplist, indent=1)
if generator:
self.variable('generator', '1', indent=1)
if restat:
self.variable('restat', '1', indent=1)
def build(self, outputs, rule, inputs=None, implicit=None, order_only=None,
variables=None):
@ -80,49 +84,49 @@ class Writer(object):
def default(self, paths):
self._line('default %s' % ' '.join(self._as_list(paths)))
def _count_dollars_before_index(self, s, i):
"""Returns the number of '$' characters right in front of s[i]."""
dollar_count = 0
dollar_index = i - 1
while dollar_index > 0 and s[dollar_index] == '$':
dollar_count += 1
dollar_index -= 1
return dollar_count
def _line(self, text, indent=0):
"""Write 'text' word-wrapped at self.width characters."""
leading_space = ' ' * indent
while len(text) > self.width:
# The text is too wide; wrap if possible.
self.output.write(leading_space)
# Find the rightmost space that would obey our width constraint and
# that's not an escaped space.
available_space = self.width - len(leading_space) - len(' $')
# Write as much as we can into this line.
done = False
written_stuff = False
while available_space > 0:
space = re.search('((\$\$)+([^$]|^)|[^$]|^) ', text)
if space:
space_idx = space.start() + 1
else:
# No spaces left.
done = True
space = available_space
while True:
space = text.rfind(' ', 0, space)
if space < 0 or \
self._count_dollars_before_index(text, space) % 2 == 0:
break
if space_idx > available_space:
# We're out of space.
if written_stuff:
# See if we can fit it on the next line.
if space < 0:
# No such space; just use the first unescaped space we can find.
space = available_space - 1
while True:
space = text.find(' ', space + 1)
if space < 0 or \
self._count_dollars_before_index(text, space) % 2 == 0:
break
if space < 0:
# Give up on breaking.
break
# If we haven't written anything yet on this line, don't
# try to wrap.
self.output.write(text[0:space_idx] + ' ')
written_stuff = True
text = text[space_idx+1:]
available_space -= space_idx+1
self.output.write('$\n')
self.output.write(leading_space + text[0:space] + ' $\n')
text = text[space+1:]
# Subsequent lines are continuations, so indent them.
leading_space = ' ' * (indent+2)
if done:
# No more spaces, so bail.
break
self.output.write(leading_space + text + '\n')
def _as_list(self, input):

15
tools/gyp/pylib/gyp/system_test.py

@ -51,20 +51,6 @@ def TestArSupportsT(ar_command='ar', cc_command='cc'):
env={'ar': ar_command, 'cc': cc_command})
def TestLinkerSupportsThreads(cc_command='cc'):
"""Test whether the linker supports the --threads flag."""
return TestCommands(['%(cc)s -Wl,--threads test.c'],
files={'test.c': 'int main(){}'},
env={'cc': cc_command})
def TestLinkerSupportsICF(cc_command='cc'):
"""Test whether the linker supports identical code folding."""
return TestCommands(['%(cc)s -Wl,--icf=safe test.c'],
files={'test.c': 'int main(){}'},
env={'cc': cc_command})
def main():
# Run the various test functions and print the results.
def RunTest(description, function, **kwargs):
@ -75,7 +61,6 @@ def main():
print 'fail'
RunTest("ar 'T' flag", TestArSupportsT)
RunTest("ar 'T' flag with ccache", TestArSupportsT, cc_command='ccache cc')
RunTest("ld --threads", TestLinkerSupportsThreads)
return 0

972
tools/gyp/pylib/gyp/xcode_emulation.py

@ -0,0 +1,972 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
This module contains classes that help to emulate xcodebuild behavior on top of
other build systems, such as make and ninja.
"""
import gyp.common
import os.path
import re
import shlex
class XcodeSettings(object):
"""A class that understands the gyp 'xcode_settings' object."""
def __init__(self, spec):
self.spec = spec
# Per-target 'xcode_settings' are pushed down into configs earlier by gyp.
# This means self.xcode_settings[config] always contains all settings
# for that config -- the per-target settings as well. Settings that are
# the same for all configs are implicitly per-target settings.
self.xcode_settings = {}
configs = spec['configurations']
for configname, config in configs.iteritems():
self.xcode_settings[configname] = config.get('xcode_settings', {})
# This is only non-None temporarily during the execution of some methods.
self.configname = None
# Used by _AdjustLibrary to match .a and .dylib entries in libraries.
self.library_re = re.compile(r'^lib([^/]+)\.(a|dylib)$')
def _Settings(self):
assert self.configname
return self.xcode_settings[self.configname]
def _Test(self, test_key, cond_key, default):
return self._Settings().get(test_key, default) == cond_key
def _Appendf(self, lst, test_key, format_str, default=None):
if test_key in self._Settings():
lst.append(format_str % str(self._Settings()[test_key]))
elif default:
lst.append(format_str % str(default))
def _WarnUnimplemented(self, test_key):
if test_key in self._Settings():
print 'Warning: Ignoring not yet implemented key "%s".' % test_key
def _IsBundle(self):
return int(self.spec.get('mac_bundle', 0)) != 0
def GetFrameworkVersion(self):
"""Returns the framework version of the current target. Only valid for
bundles."""
assert self._IsBundle()
return self.GetPerTargetSetting('FRAMEWORK_VERSION', default='A')
def GetWrapperExtension(self):
"""Returns the bundle extension (.app, .framework, .plugin, etc). Only
valid for bundles."""
assert self._IsBundle()
if self.spec['type'] in ('loadable_module', 'shared_library'):
default_wrapper_extension = {
'loadable_module': 'bundle',
'shared_library': 'framework',
}[self.spec['type']]
wrapper_extension = self.GetPerTargetSetting(
'WRAPPER_EXTENSION', default=default_wrapper_extension)
return '.' + self.spec.get('product_extension', wrapper_extension)
elif self.spec['type'] == 'executable':
return '.app'
else:
assert False, "Don't know extension for '%s', target '%s'" % (
self.spec['type'], self.spec['target_name'])
def GetProductName(self):
"""Returns PRODUCT_NAME."""
return self.spec.get('product_name', self.spec['target_name'])
def GetFullProductName(self):
"""Returns FULL_PRODUCT_NAME."""
if self._IsBundle():
return self.GetWrapperName()
else:
return self._GetStandaloneBinaryPath()
def GetWrapperName(self):
"""Returns the directory name of the bundle represented by this target.
Only valid for bundles."""
assert self._IsBundle()
return self.GetProductName() + self.GetWrapperExtension()
def GetBundleContentsFolderPath(self):
"""Returns the qualified path to the bundle's contents folder. E.g.
Chromium.app/Contents or Foo.bundle/Versions/A. Only valid for bundles."""
assert self._IsBundle()
if self.spec['type'] == 'shared_library':
return os.path.join(
self.GetWrapperName(), 'Versions', self.GetFrameworkVersion())
else:
# loadable_modules have a 'Contents' folder like executables.
return os.path.join(self.GetWrapperName(), 'Contents')
def GetBundleResourceFolder(self):
"""Returns the qualified path to the bundle's resource folder. E.g.
Chromium.app/Contents/Resources. Only valid for bundles."""
assert self._IsBundle()
return os.path.join(self.GetBundleContentsFolderPath(), 'Resources')
def GetBundlePlistPath(self):
"""Returns the qualified path to the bundle's plist file. E.g.
Chromium.app/Contents/Info.plist. Only valid for bundles."""
assert self._IsBundle()
if self.spec['type'] in ('executable', 'loadable_module'):
return os.path.join(self.GetBundleContentsFolderPath(), 'Info.plist')
else:
return os.path.join(self.GetBundleContentsFolderPath(),
'Resources', 'Info.plist')
def GetProductType(self):
"""Returns the PRODUCT_TYPE of this target."""
if self._IsBundle():
return {
'executable': 'com.apple.product-type.application',
'loadable_module': 'com.apple.product-type.bundle',
'shared_library': 'com.apple.product-type.framework',
}[self.spec['type']]
else:
return {
'executable': 'com.apple.product-type.tool',
'loadable_module': 'com.apple.product-type.library.dynamic',
'shared_library': 'com.apple.product-type.library.dynamic',
'static_library': 'com.apple.product-type.library.static',
}[self.spec['type']]
def GetMachOType(self):
"""Returns the MACH_O_TYPE of this target."""
# Weird, but matches Xcode.
if not self._IsBundle() and self.spec['type'] == 'executable':
return ''
return {
'executable': 'mh_execute',
'static_library': 'staticlib',
'shared_library': 'mh_dylib',
'loadable_module': 'mh_bundle',
}[self.spec['type']]
def _GetBundleBinaryPath(self):
"""Returns the name of the bundle binary of by this target.
E.g. Chromium.app/Contents/MacOS/Chromium. Only valid for bundles."""
assert self._IsBundle()
if self.spec['type'] in ('shared_library'):
path = self.GetBundleContentsFolderPath()
elif self.spec['type'] in ('executable', 'loadable_module'):
path = os.path.join(self.GetBundleContentsFolderPath(), 'MacOS')
return os.path.join(path, self.GetExecutableName())
def _GetStandaloneExecutableSuffix(self):
if 'product_extension' in self.spec:
return '.' + self.spec['product_extension']
return {
'executable': '',
'static_library': '.a',
'shared_library': '.dylib',
'loadable_module': '.so',
}[self.spec['type']]
def _GetStandaloneExecutablePrefix(self):
return self.spec.get('product_prefix', {
'executable': '',
'static_library': 'lib',
'shared_library': 'lib',
# Non-bundled loadable_modules are called foo.so for some reason
# (that is, .so and no prefix) with the xcode build -- match that.
'loadable_module': '',
}[self.spec['type']])
def _GetStandaloneBinaryPath(self):
"""Returns the name of the non-bundle binary represented by this target.
E.g. hello_world. Only valid for non-bundles."""
assert not self._IsBundle()
assert self.spec['type'] in (
'executable', 'shared_library', 'static_library', 'loadable_module'), (
'Unexpected type %s' % self.spec['type'])
target = self.spec['target_name']
if self.spec['type'] == 'static_library':
if target[:3] == 'lib':
target = target[3:]
elif self.spec['type'] in ('loadable_module', 'shared_library'):
if target[:3] == 'lib':
target = target[3:]
target_prefix = self._GetStandaloneExecutablePrefix()
target = self.spec.get('product_name', target)
target_ext = self._GetStandaloneExecutableSuffix()
return target_prefix + target + target_ext
def GetExecutableName(self):
"""Returns the executable name of the bundle represented by this target.
E.g. Chromium."""
if self._IsBundle():
return self.spec.get('product_name', self.spec['target_name'])
else:
return self._GetStandaloneBinaryPath()
def GetExecutablePath(self):
"""Returns the directory name of the bundle represented by this target. E.g.
Chromium.app/Contents/MacOS/Chromium."""
if self._IsBundle():
return self._GetBundleBinaryPath()
else:
return self._GetStandaloneBinaryPath()
def _SdkPath(self):
sdk_root = self.GetPerTargetSetting('SDKROOT', default='macosx10.5')
if sdk_root.startswith('macosx'):
sdk_root = 'MacOSX' + sdk_root[len('macosx'):]
return '/Developer/SDKs/%s.sdk' % sdk_root
def GetCflags(self, configname):
"""Returns flags that need to be added to .c, .cc, .m, and .mm
compilations."""
# This functions (and the similar ones below) do not offer complete
# emulation of all xcode_settings keys. They're implemented on demand.
self.configname = configname
cflags = []
sdk_root = self._SdkPath()
if 'SDKROOT' in self._Settings():
cflags.append('-isysroot %s' % sdk_root)
if self._Test('GCC_CHAR_IS_UNSIGNED_CHAR', 'YES', default='NO'):
cflags.append('-funsigned-char')
if self._Test('GCC_CW_ASM_SYNTAX', 'YES', default='YES'):
cflags.append('-fasm-blocks')
if 'GCC_DYNAMIC_NO_PIC' in self._Settings():
if self._Settings()['GCC_DYNAMIC_NO_PIC'] == 'YES':
cflags.append('-mdynamic-no-pic')
else:
pass
# TODO: In this case, it depends on the target. xcode passes
# mdynamic-no-pic by default for executable and possibly static lib
# according to mento
if self._Test('GCC_ENABLE_PASCAL_STRINGS', 'YES', default='YES'):
cflags.append('-mpascal-strings')
self._Appendf(cflags, 'GCC_OPTIMIZATION_LEVEL', '-O%s', default='s')
if self._Test('GCC_GENERATE_DEBUGGING_SYMBOLS', 'YES', default='YES'):
dbg_format = self._Settings().get('DEBUG_INFORMATION_FORMAT', 'dwarf')
if dbg_format == 'dwarf':
cflags.append('-gdwarf-2')
elif dbg_format == 'stabs':
raise NotImplementedError('stabs debug format is not supported yet.')
elif dbg_format == 'dwarf-with-dsym':
cflags.append('-gdwarf-2')
else:
raise NotImplementedError('Unknown debug format %s' % dbg_format)
if self._Test('GCC_SYMBOLS_PRIVATE_EXTERN', 'YES', default='NO'):
cflags.append('-fvisibility=hidden')
if self._Test('GCC_TREAT_WARNINGS_AS_ERRORS', 'YES', default='NO'):
cflags.append('-Werror')
if self._Test('GCC_WARN_ABOUT_MISSING_NEWLINE', 'YES', default='NO'):
cflags.append('-Wnewline-eof')
self._Appendf(cflags, 'MACOSX_DEPLOYMENT_TARGET', '-mmacosx-version-min=%s')
# TODO:
if self._Test('COPY_PHASE_STRIP', 'YES', default='NO'):
self._WarnUnimplemented('COPY_PHASE_STRIP')
self._WarnUnimplemented('GCC_DEBUGGING_SYMBOLS')
self._WarnUnimplemented('GCC_ENABLE_OBJC_EXCEPTIONS')
self._WarnUnimplemented('GCC_ENABLE_OBJC_GC')
# TODO: This is exported correctly, but assigning to it is not supported.
self._WarnUnimplemented('MACH_O_TYPE')
self._WarnUnimplemented('PRODUCT_TYPE')
archs = self._Settings().get('ARCHS', ['i386'])
if len(archs) != 1:
# TODO: Supporting fat binaries will be annoying.
self._WarnUnimplemented('ARCHS')
archs = ['i386']
cflags.append('-arch ' + archs[0])
if archs[0] in ('i386', 'x86_64'):
if self._Test('GCC_ENABLE_SSE3_EXTENSIONS', 'YES', default='NO'):
cflags.append('-msse3')
if self._Test('GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS', 'YES',
default='NO'):
cflags.append('-mssse3') # Note 3rd 's'.
if self._Test('GCC_ENABLE_SSE41_EXTENSIONS', 'YES', default='NO'):
cflags.append('-msse4.1')
if self._Test('GCC_ENABLE_SSE42_EXTENSIONS', 'YES', default='NO'):
cflags.append('-msse4.2')
cflags += self._Settings().get('OTHER_CFLAGS', [])
cflags += self._Settings().get('WARNING_CFLAGS', [])
config = self.spec['configurations'][self.configname]
framework_dirs = config.get('mac_framework_dirs', [])
for directory in framework_dirs:
cflags.append('-F ' + directory.replace('$(SDKROOT)', sdk_root))
self.configname = None
return cflags
def GetCflagsC(self, configname):
"""Returns flags that need to be added to .c, and .m compilations."""
self.configname = configname
cflags_c = []
self._Appendf(cflags_c, 'GCC_C_LANGUAGE_STANDARD', '-std=%s')
self.configname = None
return cflags_c
def GetCflagsCC(self, configname):
"""Returns flags that need to be added to .cc, and .mm compilations."""
self.configname = configname
cflags_cc = []
if self._Test('GCC_ENABLE_CPP_RTTI', 'NO', default='YES'):
cflags_cc.append('-fno-rtti')
if self._Test('GCC_ENABLE_CPP_EXCEPTIONS', 'NO', default='YES'):
cflags_cc.append('-fno-exceptions')
if self._Test('GCC_INLINES_ARE_PRIVATE_EXTERN', 'YES', default='NO'):
cflags_cc.append('-fvisibility-inlines-hidden')
if self._Test('GCC_THREADSAFE_STATICS', 'NO', default='YES'):
cflags_cc.append('-fno-threadsafe-statics')
self.configname = None
return cflags_cc
def GetCflagsObjC(self, configname):
"""Returns flags that need to be added to .m compilations."""
self.configname = configname
self.configname = None
return []
def GetCflagsObjCC(self, configname):
"""Returns flags that need to be added to .mm compilations."""
self.configname = configname
cflags_objcc = []
if self._Test('GCC_OBJC_CALL_CXX_CDTORS', 'YES', default='NO'):
cflags_objcc.append('-fobjc-call-cxx-cdtors')
self.configname = None
return cflags_objcc
def GetLdflags(self, configname, product_dir, gyp_to_build_path):
"""Returns flags that need to be passed to the linker.
Args:
configname: The name of the configuration to get ld flags for.
product_dir: The directory where products such static and dynamic
libraries are placed. This is added to the library search path.
gyp_to_build_path: A function that converts paths relative to the
current gyp file to paths relative to the build direcotry.
"""
self.configname = configname
ldflags = []
# The xcode build is relative to a gyp file's directory, and OTHER_LDFLAGS
# contains two entries that depend on this. Explicitly absolutify for these
# two cases.
def MapGypPathWithPrefix(flag, prefix):
if flag.startswith(prefix):
flag = prefix + gyp_to_build_path(flag[len(prefix):])
return flag
for ldflag in self._Settings().get('OTHER_LDFLAGS', []):
# Required for ffmpeg (no idea why they don't use LIBRARY_SEARCH_PATHS,
# TODO(thakis): Update ffmpeg.gyp):
ldflag = MapGypPathWithPrefix(ldflag, '-L')
# Required for the nacl plugin:
ldflag = MapGypPathWithPrefix(ldflag, '-Wl,-exported_symbols_list ')
ldflags.append(ldflag)
if self._Test('DEAD_CODE_STRIPPING', 'YES', default='NO'):
ldflags.append('-Wl,-dead_strip')
if self._Test('PREBINDING', 'YES', default='NO'):
ldflags.append('-Wl,-prebind')
self._Appendf(
ldflags, 'DYLIB_COMPATIBILITY_VERSION', '-compatibility_version %s')
self._Appendf(
ldflags, 'DYLIB_CURRENT_VERSION', '-current_version %s')
self._Appendf(
ldflags, 'MACOSX_DEPLOYMENT_TARGET', '-mmacosx-version-min=%s')
if 'SDKROOT' in self._Settings():
ldflags.append('-isysroot ' + self._SdkPath())
for library_path in self._Settings().get('LIBRARY_SEARCH_PATHS', []):
ldflags.append('-L' + gyp_to_build_path(library_path))
if 'ORDER_FILE' in self._Settings():
ldflags.append('-Wl,-order_file ' +
'-Wl,' + gyp_to_build_path(
self._Settings()['ORDER_FILE']))
archs = self._Settings().get('ARCHS', ['i386'])
if len(archs) != 1:
# TODO: Supporting fat binaries will be annoying.
self._WarnUnimplemented('ARCHS')
archs = ['i386']
ldflags.append('-arch ' + archs[0])
# Xcode adds the product directory by default.
ldflags.append('-L' + product_dir)
install_name = self.GetPerTargetSetting('LD_DYLIB_INSTALL_NAME')
install_base = self.GetPerTargetSetting('DYLIB_INSTALL_NAME_BASE')
default_install_name = \
'$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)'
if not install_name and install_base:
install_name = default_install_name
if install_name:
# Hardcode support for the variables used in chromium for now, to unblock
# people using the make build.
if '$' in install_name:
assert install_name in ('$(DYLIB_INSTALL_NAME_BASE:standardizepath)/'
'$(WRAPPER_NAME)/$(PRODUCT_NAME)', default_install_name), (
'Variables in LD_DYLIB_INSTALL_NAME are not generally supported yet'
' in target \'%s\' (got \'%s\')' %
(self.spec['target_name'], install_name))
# I'm not quite sure what :standardizepath does. Just call normpath(),
# but don't let @executable_path/../foo collapse to foo.
if '/' in install_base:
prefix, rest = '', install_base
if install_base.startswith('@'):
prefix, rest = install_base.split('/', 1)
rest = os.path.normpath(rest) # :standardizepath
install_base = os.path.join(prefix, rest)
install_name = install_name.replace(
'$(DYLIB_INSTALL_NAME_BASE:standardizepath)', install_base)
if self._IsBundle():
# These are only valid for bundles, hence the |if|.
install_name = install_name.replace(
'$(WRAPPER_NAME)', self.GetWrapperName())
install_name = install_name.replace(
'$(PRODUCT_NAME)', self.GetProductName())
else:
assert '$(WRAPPER_NAME)' not in install_name
assert '$(PRODUCT_NAME)' not in install_name
install_name = install_name.replace(
'$(EXECUTABLE_PATH)', self.GetExecutablePath())
install_name = install_name.replace(' ', r'\ ')
ldflags.append('-install_name ' + install_name)
self.configname = None
return ldflags
def GetPerTargetSettings(self):
"""Gets a list of all the per-target settings. This will only fetch keys
whose values are the same across all configurations."""
first_pass = True
result = {}
for configname in sorted(self.xcode_settings.keys()):
if first_pass:
result = dict(self.xcode_settings[configname])
first_pass = False
else:
for key, value in self.xcode_settings[configname].iteritems():
if key not in result:
continue
elif result[key] != value:
del result[key]
return result
def GetPerTargetSetting(self, setting, default=None):
"""Tries to get xcode_settings.setting from spec. Assumes that the setting
has the same value in all configurations and throws otherwise."""
first_pass = True
result = None
for configname in sorted(self.xcode_settings.keys()):
if first_pass:
result = self.xcode_settings[configname].get(setting, None)
first_pass = False
else:
assert result == self.xcode_settings[configname].get(setting, None), (
"Expected per-target setting for '%s', got per-config setting "
"(target %s)" % (setting, spec['target_name']))
if result is None:
return default
return result
def _GetStripPostbuilds(self, configname, output_binary, quiet):
"""Returns a list of shell commands that contain the shell commands
neccessary to strip this target's binary. These should be run as postbuilds
before the actual postbuilds run."""
self.configname = configname
result = []
if (self._Test('DEPLOYMENT_POSTPROCESSING', 'YES', default='NO') and
self._Test('STRIP_INSTALLED_PRODUCT', 'YES', default='NO')):
default_strip_style = 'debugging'
if self._IsBundle():
default_strip_style = 'non-global'
elif self.spec['type'] == 'executable':
default_strip_style = 'all'
strip_style = self._Settings().get('STRIP_STYLE', default_strip_style)
strip_flags = {
'all': '',
'non-global': '-x',
'debugging': '-S',
}[strip_style]
explicit_strip_flags = self._Settings().get('STRIPFLAGS', '')
if explicit_strip_flags:
strip_flags += ' ' + _NormalizeEnvVarReferences(explicit_strip_flags)
if not quiet:
result.append('echo STRIP\\(%s\\)' % self.spec['target_name'])
result.append('strip %s %s' % (strip_flags, output_binary))
self.configname = None
return result
def _GetDebugInfoPostbuilds(self, configname, output, output_binary, quiet):
"""Returns a list of shell commands that contain the shell commands
neccessary to massage this target's debug information. These should be run
as postbuilds before the actual postbuilds run."""
self.configname = configname
# For static libraries, no dSYMs are created.
result = []
if (self._Test('GCC_GENERATE_DEBUGGING_SYMBOLS', 'YES', default='YES') and
self._Test(
'DEBUG_INFORMATION_FORMAT', 'dwarf-with-dsym', default='dwarf') and
self.spec['type'] != 'static_library'):
if not quiet:
result.append('echo DSYMUTIL\\(%s\\)' % self.spec['target_name'])
result.append('dsymutil %s -o %s' % (output_binary, output + '.dSYM'))
self.configname = None
return result
def GetTargetPostbuilds(self, configname, output, output_binary, quiet=False):
"""Returns a list of shell commands that contain the shell commands
to run as postbuilds for this target, before the actual postbuilds."""
# dSYMs need to build before stripping happens.
return (
self._GetDebugInfoPostbuilds(configname, output, output_binary, quiet) +
self._GetStripPostbuilds(configname, output_binary, quiet))
def _AdjustLibrary(self, library):
if library.endswith('.framework'):
l = '-framework ' + os.path.splitext(os.path.basename(library))[0]
else:
m = self.library_re.match(library)
if m:
l = '-l' + m.group(1)
else:
l = library
return l.replace('$(SDKROOT)', self._SdkPath())
def AdjustLibraries(self, libraries):
"""Transforms entries like 'Cocoa.framework' in libraries into entries like
'-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc.
"""
libraries = [ self._AdjustLibrary(library) for library in libraries]
return libraries
class MacPrefixHeader(object):
"""A class that helps with emulating Xcode's GCC_PREFIX_HEADER feature.
This feature consists of several pieces:
* If GCC_PREFIX_HEADER is present, all compilations in that project get an
additional |-include path_to_prefix_header| cflag.
* If GCC_PRECOMPILE_PREFIX_HEADER is present too, then the prefix header is
instead compiled, and all other compilations in the project get an
additional |-include path_to_compiled_header| instead.
+ Compiled prefix headers have the extension gch. There is one gch file for
every language used in the project (c, cc, m, mm), since gch files for
different languages aren't compatible.
+ gch files themselves are built with the target's normal cflags, but they
obviously don't get the |-include| flag. Instead, they need a -x flag that
describes their language.
+ All o files in the target need to depend on the gch file, to make sure
it's built before any o file is built.
This class helps with some of these tasks, but it needs help from the build
system for writing dependencies to the gch files, for writing build commands
for the gch files, and for figuring out the location of the gch files.
"""
def __init__(self, xcode_settings,
gyp_path_to_build_path, gyp_path_to_build_output):
"""If xcode_settings is None, all methods on this class are no-ops.
Args:
gyp_path_to_build_path: A function that takes a gyp-relative path,
and returns a path relative to the build directory.
gyp_path_to_build_output: A function that takes a gyp-relative path and
a language code ('c', 'cc', 'm', or 'mm'), and that returns a path
to where the output of precompiling that path for that language
should be placed (without the trailing '.gch').
"""
# This doesn't support per-configuration prefix headers. Good enough
# for now.
self.header = None
self.compile_headers = False
if xcode_settings:
self.header = xcode_settings.GetPerTargetSetting('GCC_PREFIX_HEADER')
self.compile_headers = xcode_settings.GetPerTargetSetting(
'GCC_PRECOMPILE_PREFIX_HEADER', default='NO') != 'NO'
self.compiled_headers = {}
if self.header:
if self.compile_headers:
for lang in ['c', 'cc', 'm', 'mm']:
self.compiled_headers[lang] = gyp_path_to_build_output(
self.header, lang)
self.header = gyp_path_to_build_path(self.header)
def GetInclude(self, lang):
"""Gets the cflags to include the prefix header for language |lang|."""
if self.compile_headers and lang in self.compiled_headers:
return '-include %s' % self.compiled_headers[lang]
elif self.header:
return '-include %s' % self.header
else:
return ''
def _Gch(self, lang):
"""Returns the actual file name of the prefix header for language |lang|."""
assert self.compile_headers
return self.compiled_headers[lang] + '.gch'
def GetObjDependencies(self, sources, objs):
"""Given a list of source files and the corresponding object files, returns
a list of (source, object, gch) tuples, where |gch| is the build-directory
relative path to the gch file each object file depends on. |compilable[i]|
has to be the source file belonging to |objs[i]|."""
if not self.header or not self.compile_headers:
return []
result = []
for source, obj in zip(sources, objs):
ext = os.path.splitext(source)[1]
lang = {
'.c': 'c',
'.cpp': 'cc', '.cc': 'cc', '.cxx': 'cc',
'.m': 'm',
'.mm': 'mm',
}.get(ext, None)
if lang:
result.append((source, obj, self._Gch(lang)))
return result
def GetGchBuildCommands(self):
"""Returns [(path_to_gch, language_flag, language, header)].
|path_to_gch| and |header| are relative to the build directory.
"""
if not self.header or not self.compile_headers:
return []
return [
(self._Gch('c'), '-x c-header', 'c', self.header),
(self._Gch('cc'), '-x c++-header', 'cc', self.header),
(self._Gch('m'), '-x objective-c-header', 'm', self.header),
(self._Gch('mm'), '-x objective-c++-header', 'mm', self.header),
]
def MergeGlobalXcodeSettingsToSpec(global_dict, spec):
"""Merges the global xcode_settings dictionary into each configuration of the
target represented by spec. For keys that are both in the global and the local
xcode_settings dict, the local key gets precendence.
"""
# The xcode generator special-cases global xcode_settings and does something
# that amounts to merging in the global xcode_settings into each local
# xcode_settings dict.
global_xcode_settings = global_dict.get('xcode_settings', {})
for config in spec['configurations'].values():
if 'xcode_settings' in config:
new_settings = global_xcode_settings.copy()
new_settings.update(config['xcode_settings'])
config['xcode_settings'] = new_settings
def IsMacBundle(flavor, spec):
"""Returns if |spec| should be treated as a bundle.
Bundles are directories with a certain subdirectory structure, instead of
just a single file. Bundle rules do not produce a binary but also package
resources into that directory."""
is_mac_bundle = (int(spec.get('mac_bundle', 0)) != 0 and flavor == 'mac')
if is_mac_bundle:
assert spec['type'] != 'none', (
'mac_bundle targets cannot have type none (target "%s")' %
spec['target_name'])
return is_mac_bundle
def GetMacBundleResources(product_dir, xcode_settings, resources):
"""Yields (output, resource) pairs for every resource in |resources|.
Only call this for mac bundle targets.
Args:
product_dir: Path to the directory containing the output bundle,
relative to the build directory.
xcode_settings: The XcodeSettings of the current target.
resources: A list of bundle resources, relative to the build directory.
"""
dest = os.path.join(product_dir,
xcode_settings.GetBundleResourceFolder())
for res in resources:
output = dest
# The make generator doesn't support it, so forbid it everywhere
# to keep the generators more interchangable.
assert ' ' not in res, (
"Spaces in resource filenames not supported (%s)" % res)
# Split into (path,file).
res_parts = os.path.split(res)
# Now split the path into (prefix,maybe.lproj).
lproj_parts = os.path.split(res_parts[0])
# If the resource lives in a .lproj bundle, add that to the destination.
if lproj_parts[1].endswith('.lproj'):
output = os.path.join(output, lproj_parts[1])
output = os.path.join(output, res_parts[1])
# Compiled XIB files are referred to by .nib.
if output.endswith('.xib'):
output = output[0:-3] + 'nib'
yield output, res
def GetMacInfoPlist(product_dir, xcode_settings, gyp_path_to_build_path):
"""Returns (info_plist, dest_plist, defines, extra_env), where:
* |info_plist| is the sourc plist path, relative to the
build directory,
* |dest_plist| is the destination plist path, relative to the
build directory,
* |defines| is a list of preprocessor defines (empty if the plist
shouldn't be preprocessed,
* |extra_env| is a dict of env variables that should be exported when
invoking |mac_tool copy-info-plist|.
Only call this for mac bundle targets.
Args:
product_dir: Path to the directory containing the output bundle,
relative to the build directory.
xcode_settings: The XcodeSettings of the current target.
gyp_to_build_path: A function that converts paths relative to the
current gyp file to paths relative to the build direcotry.
"""
info_plist = xcode_settings.GetPerTargetSetting('INFOPLIST_FILE')
if not info_plist:
return None, None, [], {}
# The make generator doesn't support it, so forbid it everywhere
# to keep the generators more interchangable.
assert ' ' not in info_plist, (
"Spaces in Info.plist filenames not supported (%s)" % info_plist)
info_plist = gyp_path_to_build_path(info_plist)
# If explicitly set to preprocess the plist, invoke the C preprocessor and
# specify any defines as -D flags.
if xcode_settings.GetPerTargetSetting(
'INFOPLIST_PREPROCESS', default='NO') == 'YES':
# Create an intermediate file based on the path.
defines = shlex.split(xcode_settings.GetPerTargetSetting(
'INFOPLIST_PREPROCESSOR_DEFINITIONS', default=''))
else:
defines = []
dest_plist = os.path.join(product_dir, xcode_settings.GetBundlePlistPath())
extra_env = xcode_settings.GetPerTargetSettings()
return info_plist, dest_plist, defines, extra_env
def GetXcodeEnv(xcode_settings, built_products_dir, srcroot, configuration,
additional_settings=None):
"""Return the environment variables that Xcode would set. See
http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW153
for a full list.
Args:
xcode_settings: An XcodeSettings object. If this is None, this function
returns an empty dict.
built_products_dir: Absolute path to the built products dir.
srcroot: Absolute path to the source root.
configuration: The build configuration name.
additional_settings: An optional dict with more values to add to the
result.
"""
if not xcode_settings: return {}
# This function is considered a friend of XcodeSettings, so let it reach into
# its implementation details.
spec = xcode_settings.spec
# These are filled in on a as-needed basis.
env = {
'BUILT_PRODUCTS_DIR' : built_products_dir,
'CONFIGURATION' : configuration,
'PRODUCT_NAME' : xcode_settings.GetProductName(),
# See /Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX\ Product\ Types.xcspec for FULL_PRODUCT_NAME
'SRCROOT' : srcroot,
'SOURCE_ROOT': '${SRCROOT}',
# This is not true for static libraries, but currently the env is only
# written for bundles:
'TARGET_BUILD_DIR' : built_products_dir,
'TEMP_DIR' : '${TMPDIR}',
}
if spec['type'] in (
'executable', 'static_library', 'shared_library', 'loadable_module'):
env['EXECUTABLE_NAME'] = xcode_settings.GetExecutableName()
env['EXECUTABLE_PATH'] = xcode_settings.GetExecutablePath()
env['FULL_PRODUCT_NAME'] = xcode_settings.GetFullProductName()
mach_o_type = xcode_settings.GetMachOType()
if mach_o_type:
env['MACH_O_TYPE'] = mach_o_type
env['PRODUCT_TYPE'] = xcode_settings.GetProductType()
if xcode_settings._IsBundle():
env['CONTENTS_FOLDER_PATH'] = \
xcode_settings.GetBundleContentsFolderPath()
env['UNLOCALIZED_RESOURCES_FOLDER_PATH'] = \
xcode_settings.GetBundleResourceFolder()
env['INFOPLIST_PATH'] = xcode_settings.GetBundlePlistPath()
env['WRAPPER_NAME'] = xcode_settings.GetWrapperName()
if not additional_settings:
additional_settings = {}
else:
# Flatten lists to strings.
for k in additional_settings:
if not isinstance(additional_settings[k], str):
additional_settings[k] = ' '.join(additional_settings[k])
additional_settings.update(env)
for k in additional_settings:
additional_settings[k] = _NormalizeEnvVarReferences(additional_settings[k])
return additional_settings
def _NormalizeEnvVarReferences(str):
"""Takes a string containing variable references in the form ${FOO}, $(FOO),
or $FOO, and returns a string with all variable references in the form ${FOO}.
"""
# $FOO -> ${FOO}
str = re.sub(r'\$([a-zA-Z_][a-zA-Z0-9_]*)', r'${\1}', str)
# $(FOO) -> ${FOO}
matches = re.findall(r'(\$\(([a-zA-Z0-9\-_]+)\))', str)
for match in matches:
to_replace, variable = match
assert '$(' not in match, '$($(FOO)) variables not supported: ' + match
str = str.replace(to_replace, '${' + variable + '}')
return str
def ExpandEnvVars(string, expansions):
"""Expands ${VARIABLES}, $(VARIABLES), and $VARIABLES in string per the
expansions dict. If the variable expands to something that references
another variable, this variable is expanded as well if it's in env --
until no variables present in env are left."""
for k in reversed(TopologicallySortedEnvVarKeys(expansions)):
string = string.replace('${' + k + '}', expansions[k])
string = string.replace('$(' + k + ')', expansions[k])
string = string.replace('$' + k, expansions[k])
return string
def TopologicallySortedEnvVarKeys(env):
"""Takes a dict |env| whose values are strings that can refer to other keys,
for example env['foo'] = '$(bar) and $(baz)'. Returns a list L of all keys of
env such that key2 is after key1 in L if env[key2] refers to env[key1].
Throws an Exception in case of dependency cycles.
"""
# Since environment variables can refer to other variables, the evaluation
# order is important. Below is the logic to compute the dependency graph
# and sort it.
regex = re.compile(r'\$\{([a-zA-Z0-9\-_]+)\}')
# First sort the list of keys.
key_list = sorted(env.keys())
# Phase 1: Create a set of edges of (DEPENDEE, DEPENDER) where in the graph,
# DEPENDEE -> DEPENDER. Also create sets of dependers and dependees.
edges = set()
dependees = set()
dependers = set()
for k in key_list:
matches = regex.findall(env[k])
if not len(matches):
continue
depends_on_other_var = False
for dependee in matches:
assert '${' not in dependee, 'Nested variables not supported: ' + dependee
if dependee in env:
edges.add((dependee, k))
dependees.add(dependee)
depends_on_other_var = True
if depends_on_other_var:
dependers.add(k)
# Phase 2: Create a list of graph nodes with no incoming edges.
sorted_nodes = []
edgeless_nodes = dependees - dependers
# Phase 3: Perform Kahn topological sort.
while len(edgeless_nodes):
# Find a node with no incoming edges, add it to the sorted list, and
# remove it from the list of nodes that aren't part of the graph.
node = edgeless_nodes.pop()
sorted_nodes.append(node)
key_list.remove(node)
# Find all the edges between |node| and other nodes.
edges_to_node = [e for e in edges if e[0] == node]
for edge in edges_to_node:
edges.remove(edge)
# If the node connected to |node| by |edge| has no other incoming edges,
# add it to |edgeless_nodes|.
if not len([e for e in edges if e[1] == edge[1]]):
edgeless_nodes.add(edge[1])
# Any remaining edges indicate a cycle.
if len(edges):
raise Exception('Xcode environment variables are cyclically dependent: ' +
str(edges))
# Append the "nodes" not in the graph to those that were just sorted.
sorted_nodes.extend(key_list)
return sorted_nodes
def GetSpecPostbuildCommands(spec, gyp_path_to_build_path, quiet=False):
"""Returns the list of postbuilds explicitly defined on |spec|, in a form
executable by a shell."""
postbuilds = []
for postbuild in spec.get('postbuilds', []):
if not quiet:
postbuilds.append('echo POSTBUILD\\(%s\\) %s' % (
spec['target_name'], postbuild['postbuild_name']))
shell_list = postbuild['action'][:]
# The first element is the command. If it's a relative path, it's
# a script in the source tree relative to the gyp file and needs to be
# absolutified. Else, it's in the PATH (e.g. install_name_tool, ln).
if os.path.sep in shell_list[0]:
shell_list[0] = gyp_path_to_build_path(shell_list[0])
# "script.sh" -> "./script.sh"
if not os.path.sep in shell_list[0]:
shell_list[0] = os.path.join('.', shell_list[0])
postbuilds.append(gyp.common.EncodePOSIXShellList(shell_list))
return postbuilds

6
tools/gyp/test/home_dot_gyp/gyptest-home-includes-regyp.py

@ -5,7 +5,7 @@
# found in the LICENSE file.
"""
Verifies inclusion of $HOME/.gyp/includes.gypi works properly with relocation
Verifies inclusion of $HOME/.gyp/include.gypi works properly with relocation
and with regeneration.
"""
@ -21,7 +21,7 @@ os.environ['HOME'] = os.path.abspath('home')
test.run_gyp('all.gyp', chdir='src')
# After relocating, we should still be able to build (build file shouldn't
# contain relative reference to ~/.gyp/includes.gypi)
# contain relative reference to ~/.gyp/include.gypi)
test.relocate('src', 'relocate/src')
test.build('all.gyp', test.ALL, chdir='relocate/src')
@ -30,7 +30,7 @@ test.run_built_executable('printfoo',
chdir='relocate/src',
stdout='FOO is fromhome\n')
# Building should notice any changes to ~/.gyp/includes.gypi and regyp.
# Building should notice any changes to ~/.gyp/include.gypi and regyp.
test.sleep()
test.write('home/.gyp/include.gypi', test.read('home2/.gyp/include.gypi'))

4
tools/gyp/test/home_dot_gyp/gyptest-home-includes.py

@ -5,7 +5,7 @@
# found in the LICENSE file.
"""
Verifies inclusion of $HOME/.gyp/includes.gypi works.
Verifies inclusion of $HOME/.gyp/include.gypi works.
"""
import os
@ -18,7 +18,7 @@ os.environ['HOME'] = os.path.abspath('home')
test.run_gyp('all.gyp', chdir='src')
# After relocating, we should still be able to build (build file shouldn't
# contain relative reference to ~/.gyp/includes.gypi)
# contain relative reference to ~/.gyp/include.gypi)
test.relocate('src', 'relocate/src')
test.build('all.gyp', test.ALL, chdir='relocate/src')

27
tools/gyp/test/lib/TestGyp.py

@ -1,4 +1,4 @@
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -222,7 +222,11 @@ class TestGypBase(TestCommon.TestCommon):
Runs gyp against the specified gyp_file with the specified args.
"""
# TODO: --depth=. works around Chromium-specific tree climbing.
args = ('--depth=.', '--format='+self.format, gyp_file) + args
depth = '.'
if 'depth' in kw:
depth = kw['depth']
del kw['depth']
args = ('--depth='+depth, '--format='+self.format, gyp_file) + args
return self.run(program=self.gyp, arguments=args, **kw)
def run(self, *args, **kw):
@ -415,24 +419,10 @@ class TestGypNinja(TestGypBase):
ALL = 'all'
DEFAULT = 'all'
# The default library prefix is computed from TestCommon.lib_prefix,
# but ninja uses no prefix for static libraries.
lib_ = ''
def run_gyp(self, gyp_file, *args, **kw):
# We must pass the desired configuration as a parameter.
if self.configuration:
args = list(args) + ['-Gconfig=' + self.configuration]
# Stash the gyp configuration we used to run gyp, so we can
# know whether we need to rerun it later.
self.last_gyp_configuration = self.configuration
TestGypBase.run_gyp(self, gyp_file, *args, **kw)
def build(self, gyp_file, target=None, **kw):
if self.last_gyp_configuration != self.configuration:
# Rerun gyp if necessary.
self.run_gyp(gyp_file)
arguments = kw.get('arguments', [])[:]
# Add a -C output/path to the command line.
@ -450,9 +440,9 @@ class TestGypNinja(TestGypBase):
# Enclosing the name in a list avoids prepending the original dir.
program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)]
if sys.platform == 'darwin':
libdir = os.path.join('out', 'Default', 'lib')
libdir = os.path.join('out', 'Default')
if self.configuration:
libdir = os.path.join('out', self.configuration, 'lib')
libdir = os.path.join('out', self.configuration)
os.environ['DYLD_LIBRARY_PATH'] = libdir
return self.run(program=program, *args, **kw)
@ -467,6 +457,7 @@ class TestGypNinja(TestGypBase):
if sys.platform != 'darwin':
result.append('obj')
elif type == self.SHARED_LIB:
if sys.platform != 'darwin':
result.append('lib')
subdir = kw.get('subdir')
if subdir:

34
tools/gyp/test/mac/action-envvars/action/action.gyp

@ -0,0 +1,34 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'action',
'type': 'none',
'actions': [
{
'inputs': [ ],
'outputs': [
'<(PRODUCT_DIR)/result',
'<(SHARED_INTERMEDIATE_DIR)/tempfile',
],
'action_name': 'Test action',
'action': ['./action.sh', '<(SHARED_INTERMEDIATE_DIR)/tempfile' ],
},
{
'inputs': [
'<(SHARED_INTERMEDIATE_DIR)/tempfile',
],
'outputs': [
'<(PRODUCT_DIR)/other_result',
],
'action_name': 'Other test action',
'action': ['cp', '<(SHARED_INTERMEDIATE_DIR)/tempfile',
'<(PRODUCT_DIR)/other_result' ],
},
],
},
],
}

8
tools/gyp/test/mac/action-envvars/action/action.sh

@ -0,0 +1,8 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
echo 'Test output' > "${BUILT_PRODUCTS_DIR}/result"
echo 'Other output' > "$1"

4
tools/gyp/test/mac/archs/my_file.cc

@ -0,0 +1,4 @@
/* Copyright (c) 2012 Google Inc. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
int x = 1;

9
tools/gyp/test/mac/archs/my_main_file.cc

@ -0,0 +1,9 @@
/* Copyright (c) 2012 Google Inc. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
#include <stdio.h>
extern int x;
int main() {
printf("hello, world %d\n", x);
}

27
tools/gyp/test/mac/archs/test-archs-x86_64.gyp

@ -0,0 +1,27 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'lib',
'product_name': 'Test64',
'type': 'static_library',
'sources': [ 'my_file.cc' ],
'xcode_settings': {
'ARCHS': [ 'x86_64' ],
},
},
{
'target_name': 'exe',
'product_name': 'Test64',
'type': 'executable',
'dependencies': [ 'lib' ],
'sources': [ 'my_main_file.cc' ],
'xcode_settings': {
'ARCHS': [ 'x86_64' ],
},
},
]
}

21
tools/gyp/test/mac/archs/test-no-archs.gyp

@ -0,0 +1,21 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'lib',
'product_name': 'Test',
'type': 'static_library',
'sources': [ 'my_file.cc' ],
},
{
'target_name': 'exe',
'product_name': 'Test',
'type': 'executable',
'dependencies': [ 'lib' ],
'sources': [ 'my_main_file.cc' ],
},
]
}

1
tools/gyp/test/mac/copy-dylib/empty.c

@ -0,0 +1 @@
int main() {}

31
tools/gyp/test/mac/copy-dylib/test.gyp

@ -0,0 +1,31 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'my_dylib',
'type': 'shared_library',
'sources': [ 'empty.c', ],
},
{
'target_name': 'test_app',
'product_name': 'Test App',
'type': 'executable',
'mac_bundle': 1,
'dependencies': [ 'my_dylib', ],
'sources': [
'empty.c',
],
'copies': [
{
'destination': '<(PRODUCT_DIR)/Test App.app/Contents/Resources',
'files': [
'<(PRODUCT_DIR)/libmy_dylib.dylib',
],
},
],
},
],
}

1
tools/gyp/test/mac/depend-on-bundle/English.lproj/InfoPlist.strings

@ -0,0 +1 @@
/* Localized versions of Info.plist keys */

28
tools/gyp/test/mac/depend-on-bundle/Info.plist

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

1
tools/gyp/test/mac/depend-on-bundle/bundle.c

@ -0,0 +1 @@
int f() { return 42; }

4
tools/gyp/test/mac/depend-on-bundle/executable.c

@ -0,0 +1,4 @@
int f();
int main() {
return f();
}

28
tools/gyp/test/mac/depend-on-bundle/test.gyp

@ -0,0 +1,28 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'my_bundle',
'type': 'shared_library',
'mac_bundle': 1,
'sources': [ 'bundle.c' ],
'mac_bundle_resources': [
'English.lproj/InfoPlist.strings',
],
'xcode_settings': {
'INFOPLIST_FILE': 'Info.plist',
}
},
{
'target_name': 'dependent_on_bundle',
'type': 'executable',
'sources': [ 'executable.c' ],
'dependencies': [
'my_bundle',
],
},
],
}

11
tools/gyp/test/mac/global-settings/src/dir1/dir1.gyp

@ -0,0 +1,11 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'dir1_target',
'type': 'none',
},
],
}

22
tools/gyp/test/mac/global-settings/src/dir2/dir2.gyp

@ -0,0 +1,22 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'dir2_target',
'type': 'none',
'dependencies': [
'../dir1/dir1.gyp:dir1_target',
],
'actions': [
{
'inputs': [ ],
'outputs': [ '<(PRODUCT_DIR)/file.txt' ],
'action_name': 'Test action',
'action': ['cp', 'file.txt', '${BUILT_PRODUCTS_DIR}/file.txt' ],
},
],
},
],
}

1
tools/gyp/test/mac/global-settings/src/dir2/file.txt

@ -0,0 +1 @@
File.

30
tools/gyp/test/mac/gyptest-action-envvars.py

@ -0,0 +1,30 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that env vars work with actions, with relative directory paths.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
CHDIR = 'action-envvars'
test.run_gyp('action/action.gyp', chdir=CHDIR)
test.build('action/action.gyp', 'action', chdir=CHDIR, SYMROOT='../build')
result_file = test.built_file_path('result', chdir=CHDIR)
test.must_exist(result_file)
test.must_contain(result_file, 'Test output')
other_result_file = test.built_file_path('other_result', chdir=CHDIR)
test.must_exist(other_result_file)
test.must_contain(other_result_file, 'Other output')
test.pass_test()

4
tools/gyp/test/mac/gyptest-app.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -13,7 +13,7 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='app-bundle')

37
tools/gyp/test/mac/gyptest-archs.py

@ -0,0 +1,37 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Tests things related to ARCHS.
"""
import TestGyp
import subprocess
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
def CheckFileType(file, expected):
proc = subprocess.Popen(['file', '-b', file], stdout=subprocess.PIPE)
o = proc.communicate()[0].strip()
assert not proc.returncode
if o != expected:
print 'File: Expected %s, got %s' % (expected, o)
test.fail_test()
test.run_gyp('test-no-archs.gyp', chdir='archs')
test.build('test-no-archs.gyp', test.ALL, chdir='archs')
result_file = test.built_file_path('Test', chdir='archs')
test.must_exist(result_file)
CheckFileType(result_file, 'Mach-O executable i386')
test.run_gyp('test-archs-x86_64.gyp', chdir='archs')
test.build('test-archs-x86_64.gyp', test.ALL, chdir='archs')
result_file = test.built_file_path('Test64', chdir='archs')
test.must_exist(result_file)
CheckFileType(result_file, 'Mach-O 64-bit executable x86_64')

4
tools/gyp/test/mac/gyptest-copies.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -15,7 +15,7 @@ import sys
import time
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('framework.gyp', chdir='framework')

25
tools/gyp/test/mac/gyptest-copy-dylib.py

@ -0,0 +1,25 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that dylibs can be copied into app bundles.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='copy-dylib')
test.build('test.gyp', 'test_app', chdir='copy-dylib')
test.built_file_must_exist(
'Test App.app/Contents/Resources/libmy_dylib.dylib', chdir='copy-dylib')
test.pass_test()

2
tools/gyp/test/mac/gyptest-debuginfo.py

@ -13,7 +13,7 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='debuginfo')

40
tools/gyp/test/mac/gyptest-depend-on-bundle.py

@ -0,0 +1,40 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that a dependency on a bundle causes the whole bundle to be built.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='depend-on-bundle')
test.build('test.gyp', 'dependent_on_bundle', chdir='depend-on-bundle')
# Binary itself.
test.built_file_must_exist('dependent_on_bundle', chdir='depend-on-bundle')
# Bundle dependency.
test.built_file_must_exist(
'my_bundle.framework/Versions/A/my_bundle',
chdir='depend-on-bundle')
test.built_file_must_exist( # package_framework
'my_bundle.framework/my_bundle',
chdir='depend-on-bundle')
test.built_file_must_exist( # plist
'my_bundle.framework/Versions/A/Resources/Info.plist',
chdir='depend-on-bundle')
test.built_file_must_exist(
'my_bundle.framework/Versions/A/Resources/English.lproj/' # Resources
'InfoPlist.strings',
chdir='depend-on-bundle')
test.pass_test()

4
tools/gyp/test/mac/gyptest-framework.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -13,7 +13,7 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('framework.gyp', chdir='framework')

26
tools/gyp/test/mac/gyptest-global-settings.py

@ -0,0 +1,26 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that the global xcode_settings processing doesn't throw.
Regression test for http://crbug.com/109163
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('src/dir2/dir2.gyp', chdir='global-settings', depth='src')
# run_gyp shouldn't throw.
# Check that BUILT_PRODUCTS_DIR was set correctly, too.
test.build('dir2/dir2.gyp', 'dir2_target', chdir='global-settings/src',
SYMROOT='../build')
test.built_file_must_exist('file.txt', chdir='global-settings/src')
test.pass_test()

4
tools/gyp/test/mac/gyptest-infoplist-process.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -13,7 +13,7 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
CHDIR = 'infoplist-process'
INFO_PLIST_PATH = 'Test.app/Contents/Info.plist'

22
tools/gyp/test/mac/gyptest-libraries.py

@ -0,0 +1,22 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies libraries (in link_settings) are properly found.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('subdir/test.gyp', chdir='libraries')
test.build('subdir/test.gyp', test.ALL, chdir='libraries')
test.pass_test()

4
tools/gyp/test/mac/gyptest-loadable-module.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -14,7 +14,7 @@ import os
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='loadable-module')
test.build('test.gyp', test.ALL, chdir='loadable-module')

33
tools/gyp/test/mac/gyptest-non-strs-flattened-to-env.py

@ -0,0 +1,33 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that list xcode_settings are flattened before being exported to the
environment.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
CHDIR = 'non-strs-flattened-to-env'
INFO_PLIST_PATH = 'Test.app/Contents/Info.plist'
test.run_gyp('test.gyp', chdir=CHDIR)
test.build('test.gyp', test.ALL, chdir=CHDIR)
info_plist = test.built_file_path(INFO_PLIST_PATH, chdir=CHDIR)
test.must_exist(info_plist)
test.must_contain(info_plist, '''\
\t<key>My Variable</key>
\t<string>some expansion</string>''')
test.must_contain(info_plist, '''\
\t<key>CFlags</key>
\t<string>-fstack-protector-all -fno-strict-aliasing -DS="A Space"</string>''')
test.pass_test()

62
tools/gyp/test/mac/gyptest-postbuild-copy-bundle.py

@ -0,0 +1,62 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that a postbuild copying a dependend framework into an app bundle is
rerun if the resources in the framework change.
"""
import TestGyp
import os.path
import sys
if sys.platform == 'darwin':
# TODO(thakis): Make this pass with the make generator, http://crbug.com/95529
test = TestGyp.TestGyp(formats=['ninja', 'xcode'])
CHDIR = 'postbuild-copy-bundle'
test.run_gyp('test.gyp', chdir=CHDIR)
app_bundle_dir = test.built_file_path('Test app.app', chdir=CHDIR)
bundled_framework_dir = os.path.join(
app_bundle_dir, 'Contents', 'My Framework.framework', 'Resources')
final_plist_path = os.path.join(bundled_framework_dir, 'Info.plist')
final_resource_path = os.path.join(bundled_framework_dir, 'resource_file.sb')
# Check that the dependency was built and copied into the app bundle:
test.build('test.gyp', 'test_app', chdir=CHDIR)
test.must_exist(final_resource_path)
test.must_match(final_resource_path,
'This is included in the framework bundle.\n')
test.must_exist(final_plist_path)
test.must_contain(final_plist_path, '''\
\t<key>RandomKey</key>
\t<string>RandomValue</string>''')
# Touch the dependency's bundle resource, and check that the modification
# makes it all the way into the app bundle:
test.sleep()
test.write('postbuild-copy-bundle/resource_file.sb', 'New text\n')
test.build('test.gyp', 'test_app', chdir=CHDIR)
test.must_exist(final_resource_path)
test.must_match(final_resource_path, 'New text\n')
# Check the same for the plist file.
test.sleep()
contents = test.read('postbuild-copy-bundle/Framework-Info.plist')
contents = contents.replace('RandomValue', 'NewRandomValue')
test.write('postbuild-copy-bundle/Framework-Info.plist', contents)
test.build('test.gyp', 'test_app', chdir=CHDIR)
test.must_exist(final_plist_path)
test.must_contain(final_plist_path, '''\
\t<key>RandomKey</key>
\t<string>NewRandomValue</string>''')
test.pass_test()

29
tools/gyp/test/mac/gyptest-postbuild-defaults.py

@ -0,0 +1,29 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that a postbuild invoking |defaults| works.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
CHDIR = 'postbuild-defaults'
test.run_gyp('test.gyp', chdir=CHDIR)
test.build('test.gyp', test.ALL, chdir=CHDIR)
result_file = test.built_file_path('result', chdir=CHDIR)
test.must_exist(result_file)
test.must_contain(result_file, '''\
Test
${PRODUCT_NAME}
''')
test.pass_test()

4
tools/gyp/test/mac/gyptest-postbuild-fail.py

@ -14,13 +14,15 @@ import sys
if sys.platform == 'darwin':
# set |match| to ignore build stderr output.
test = TestGyp.TestGyp(formats=['make', 'xcode'], match = lambda a, b: True)
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'],
match = lambda a, b: True)
test.run_gyp('test.gyp', chdir='postbuild-fail')
build_error_code = {
'xcode': 1,
'make': 2,
'ninja': 1,
}[test.format]

26
tools/gyp/test/mac/gyptest-postbuild-multiple-configurations.py

@ -0,0 +1,26 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that a postbuild work in projects with multiple configurations.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
CHDIR = 'postbuild-multiple-configurations'
test.run_gyp('test.gyp', chdir=CHDIR)
for configuration in ['Debug', 'Release']:
test.set_configuration(configuration)
test.build('test.gyp', test.ALL, chdir=CHDIR)
test.built_file_must_exist('postbuild-file', chdir=CHDIR)
test.pass_test()

28
tools/gyp/test/mac/gyptest-postbuild-static-library.gyp

@ -0,0 +1,28 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that a postbuilds on static libraries work, and that sourceless
libraries don't cause failures at gyp time.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
CHDIR = 'postbuild-static-library'
test.run_gyp('test.gyp', chdir=CHDIR)
test.build('test.gyp', 'my_lib', chdir=CHDIR)
# Building my_sourceless_lib doesn't work with make. gyp should probably
# forbid sourceless static libraries, since they're pretty pointless.
# But they shouldn't cause gyp time exceptions.
test.built_file_must_exist('postbuild-file', chdir=CHDIR)
test.pass_test()

2
tools/gyp/test/mac/gyptest-postbuild.py

@ -13,7 +13,7 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='postbuilds')

4
tools/gyp/test/mac/gyptest-prefixheader.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -13,7 +13,7 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='prefixheader')
test.build('test.gyp', test.ALL, chdir='prefixheader')
test.pass_test()

29
tools/gyp/test/mac/gyptest-rebuild.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -14,16 +14,29 @@ import os
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='app-bundle')
CHDIR = 'rebuild'
test.run_gyp('test.gyp', chdir=CHDIR)
test.build('test.gyp', test.ALL, chdir='app-bundle')
test.build('test.gyp', 'test_app', chdir=CHDIR)
# Touch a source file, rebuild, and check that the app target is up-to-date.
os.utime('app-bundle/TestApp/main.m', None)
test.build('test.gyp', test.ALL, chdir='app-bundle')
test.up_to_date('test.gyp', test.ALL, chdir='app-bundle')
test.touch('rebuild/main.c')
test.build('test.gyp', 'test_app', chdir=CHDIR)
test.up_to_date('test.gyp', 'test_app', chdir=CHDIR)
# Xcode runs postbuilds on every build, so targets with postbuilds are
# never marked as up_to_date.
if test.format != 'xcode':
# Same for a framework bundle.
test.build('test.gyp', 'test_framework_postbuilds', chdir=CHDIR)
test.up_to_date('test.gyp', 'test_framework_postbuilds', chdir=CHDIR)
# Test that an app bundle with a postbuild that touches the app binary needs
# to be built only once.
test.build('test.gyp', 'test_app_postbuilds', chdir=CHDIR)
test.up_to_date('test.gyp', 'test_app_postbuilds', chdir=CHDIR)
test.pass_test()

46
tools/gyp/test/mac/gyptest-sourceless-module.gyp

@ -0,0 +1,46 @@
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies that bundles that have no 'sources' (pure resource containers) work.
"""
import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='sourceless-module')
# Just needs to build without errors.
test.build('test.gyp', 'empty_bundle', chdir='sourceless-module')
test.built_file_must_not_exist(
'empty_bundle.bundle', chdir='sourceless-module')
# Needs to build, and contain a resource.
test.build('test.gyp', 'resource_bundle', chdir='sourceless-module')
test.built_file_must_exist(
'resource_bundle.bundle/Contents/Resources/foo.manifest',
chdir='sourceless-module')
test.built_file_must_not_exist(
'resource_bundle.bundle/Contents/MacOS/resource_bundle',
chdir='sourceless-module')
# Needs to build and cause the bundle to be built.
test.build(
'test.gyp', 'dependent_on_resource_bundle', chdir='sourceless-module')
test.built_file_must_exist(
'resource_bundle.bundle/Contents/Resources/foo.manifest',
chdir='sourceless-module')
test.built_file_must_not_exist(
'resource_bundle.bundle/Contents/MacOS/resource_bundle',
chdir='sourceless-module')
test.pass_test()

2
tools/gyp/test/mac/gyptest-strip.py

@ -17,7 +17,7 @@ import sys
import time
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='strip')

4
tools/gyp/test/mac/gyptest-type-envvars.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -13,7 +13,7 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
test.run_gyp('test.gyp', chdir='type_envvars')

59
tools/gyp/test/mac/gyptest-xcode-env-order.py

@ -1,6 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -13,18 +13,65 @@ import TestGyp
import sys
if sys.platform == 'darwin':
test = TestGyp.TestGyp(formats=['make', 'xcode'])
test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
CHDIR = 'xcode-env-order'
INFO_PLIST_PATH = 'Test.app/Contents/Info.plist'
test.run_gyp('test.gyp', chdir=CHDIR)
test.build('test.gyp', test.ALL, chdir=CHDIR)
# Env vars in 'copies' filenames.
test.built_file_must_exist('Test-copy-brace/main.c', chdir=CHDIR)
test.built_file_must_exist('Test-copy-paren/main.c', chdir=CHDIR)
test.built_file_must_exist('Test-copy-bare/main.c', chdir=CHDIR)
# Env vars in 'actions' filenames and inline actions
test.built_file_must_exist('action-copy-brace.txt', chdir=CHDIR)
test.built_file_must_exist('action-copy-paren.txt', chdir=CHDIR)
test.built_file_must_exist('action-copy-bare.txt', chdir=CHDIR)
# Env vars in Info.plist.
info_plist = test.built_file_path(INFO_PLIST_PATH, chdir=CHDIR)
test.must_exist(info_plist)
test.must_contain(info_plist, '>/Source/Project/Test')
test.must_contain(info_plist, '>DEP:/Source/Project/Test')
test.must_contain(info_plist,
'>com.apple.product-type.application:DEP:/Source/Project/Test')
test.must_contain(info_plist, '''\
\t<key>BraceProcessedKey1</key>
\t<string>D:/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>BraceProcessedKey2</key>
\t<string>/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>BraceProcessedKey3</key>
\t<string>com.apple.product-type.application:D:/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>ParenProcessedKey1</key>
\t<string>D:/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>ParenProcessedKey2</key>
\t<string>/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>ParenProcessedKey3</key>
\t<string>com.apple.product-type.application:D:/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>BareProcessedKey1</key>
\t<string>D:/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>BareProcessedKey2</key>
\t<string>/Source/Project/Test</string>''')
# NOTE: For bare variables, $PRODUCT_TYPE is not replaced! It _is_ replaced
# if it's not right at the start of the string (e.g. ':$PRODUCT_TYPE'), so
# this looks like an Xcode bug. This bug isn't emulated (yet?), so check this
# only for Xcode.
if test.format == 'xcode':
test.must_contain(info_plist, '''\
\t<key>BareProcessedKey3</key>
\t<string>$PRODUCT_TYPE:D:/Source/Project/Test</string>''')
test.must_contain(info_plist, '''\
\t<key>MixedProcessedKey</key>
\t<string>/Source/Project:Test:mh_execute</string>''')
test.pass_test()

1
tools/gyp/test/mac/libraries/subdir/README.txt

@ -0,0 +1 @@
Make things live in a subdirectory, to make sure that DEPTH works correctly.

10
tools/gyp/test/mac/libraries/subdir/hello.cc

@ -0,0 +1,10 @@
// Copyright (c) 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}

7
tools/gyp/test/mac/libraries/subdir/mylib.c

@ -0,0 +1,7 @@
// Copyright (c) 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
int my_foo(int x) {
return x + 1;
}

66
tools/gyp/test/mac/libraries/subdir/test.gyp

@ -0,0 +1,66 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'libraries-test',
'type': 'executable',
'sources': [
'hello.cc',
],
'link_settings': {
'libraries': [
'libcrypto.dylib',
'libfl.a',
],
},
},
{
# This creates a static library and puts it in a nonstandard location for
# libraries-search-path-test.
'target_name': 'mylib',
'type': 'static_library',
'sources': [
'mylib.c',
],
'postbuilds': [
{
'postbuild_name': 'Make a secret location',
'action': [
'mkdir',
'-p',
'${SRCROOT}/../secret_location',
],
},
{
'postbuild_name': 'Copy to secret location, with secret name',
'action': [
'cp',
'${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}',
'${SRCROOT}/../secret_location/libmysecretlib.a',
],
},
],
},
{
'target_name': 'libraries-search-path-test',
'type': 'executable',
'dependencies': [ 'mylib' ],
'sources': [
'hello.cc',
],
'xcode_settings': {
'LIBRARY_SEARCH_PATHS': [
'<(DEPTH)/secret_location',
],
},
'link_settings': {
'libraries': [
'libmysecretlib.a',
],
},
},
],
}

15
tools/gyp/test/mac/non-strs-flattened-to-env/Info.plist

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Not a valid plist file since it's missing so much. That's fine. -->
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>My Variable</key>
<string>${MY_VAR}</string>
<key>CFlags</key>
<string>${OTHER_CFLAGS}</string>
</dict>
</plist>

7
tools/gyp/test/mac/non-strs-flattened-to-env/main.c

@ -0,0 +1,7 @@
// Copyright (c) 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
int main() {
return 0;
}

24
tools/gyp/test/mac/non-strs-flattened-to-env/test.gyp

@ -0,0 +1,24 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'test_app',
'product_name': 'Test',
'type': 'executable',
'mac_bundle': 1,
'sources': [ 'main.c', ],
'xcode_settings': {
'INFOPLIST_FILE': 'Info.plist',
'MY_VAR': 'some expansion',
'OTHER_CFLAGS': [
# Just some (more than one) random flags.
'-fstack-protector-all',
'-fno-strict-aliasing',
'-DS="A Space"', # Would normally be in 'defines'
],
},
},
],
}

30
tools/gyp/test/mac/postbuild-copy-bundle/Framework-Info.plist

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSPrincipalClass</key>
<string></string>
<key>RandomKey</key>
<string>RandomValue</string>
</dict>
</plist>

32
tools/gyp/test/mac/postbuild-copy-bundle/TestApp-Info.plist

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.google.${PRODUCT_NAME}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

0
tools/gyp/test/mac/postbuild-copy-bundle/empty.c

4
tools/gyp/test/mac/postbuild-copy-bundle/main.c

@ -0,0 +1,4 @@
// Copyright (c) 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
int main() {}

9
tools/gyp/test/mac/postbuild-copy-bundle/postbuild-copy-framework.sh

@ -0,0 +1,9 @@
#!/bin/bash
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
rsync -acC --delete "$1" "$2"

1
tools/gyp/test/mac/postbuild-copy-bundle/resource_file.sb

@ -0,0 +1 @@
This is included in the framework bundle.

43
tools/gyp/test/mac/postbuild-copy-bundle/test.gyp

@ -0,0 +1,43 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'test_bundle',
'product_name': 'My Framework',
'type': 'shared_library',
'mac_bundle': 1,
'sources': [ 'empty.c', ],
'xcode_settings': {
'INFOPLIST_FILE': 'Framework-Info.plist',
},
'mac_bundle_resources': [
'resource_file.sb',
],
},
{
'target_name': 'test_app',
'product_name': 'Test App',
'type': 'executable',
'mac_bundle': 1,
'dependencies': [
'test_bundle',
],
'sources': [ 'main.c', ],
'xcode_settings': {
'INFOPLIST_FILE': 'TestApp-Info.plist',
},
'postbuilds': [
{
'postbuild_name': 'Copy dependent framework into app',
'action': [
'./postbuild-copy-framework.sh',
'${BUILT_PRODUCTS_DIR}/My Framework.framework',
'${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/',
],
},
],
},
],
}

13
tools/gyp/test/mac/postbuild-defaults/Info.plist

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Not a valid plist file since it's missing so much. That's fine. -->
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
</dict>
</plist>

7
tools/gyp/test/mac/postbuild-defaults/main.c

@ -0,0 +1,7 @@
// Copyright (c) 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
int main() {
return 0;
}

15
tools/gyp/test/mac/postbuild-defaults/postbuild-defaults.sh

@ -0,0 +1,15 @@
#!/bin/bash
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
# This is the built Info.plist in the output directory.
PLIST="${BUILT_PRODUCTS_DIR}"/Test.app/Contents/Info # No trailing .plist
echo $(defaults read "${PLIST}" "CFBundleName") > "${BUILT_PRODUCTS_DIR}/result"
# This is the source Info.plist next to this script file.
PLIST="${SRCROOT}"/Info # No trailing .plist
echo $(defaults read "${PLIST}" "CFBundleName") \
>> "${BUILT_PRODUCTS_DIR}/result"

26
tools/gyp/test/mac/postbuild-defaults/test.gyp

@ -0,0 +1,26 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'test_app',
'product_name': 'Test',
'type': 'executable',
'mac_bundle': 1,
'sources': [ 'main.c', ],
'xcode_settings': {
'INFOPLIST_FILE': 'Info.plist',
},
'postbuilds': [
{
'postbuild_name': 'Postbuild that calls defaults',
'action': [
'./postbuild-defaults.sh',
'${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}',
],
},
],
},
],
}

2
tools/gyp/test/mac/postbuild-fail/postbuild-fail.sh

@ -1,4 +1,4 @@
#!/usr/bash
#!/usr/bin/bash
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

4
tools/gyp/test/mac/postbuild-multiple-configurations/main.c

@ -0,0 +1,4 @@
// Copyright (c) 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
int main() {}

7
tools/gyp/test/mac/postbuild-multiple-configurations/postbuild-touch-file.sh

@ -0,0 +1,7 @@
#!/bin/bash
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
touch "${BUILT_PRODUCTS_DIR}/postbuild-file"

26
tools/gyp/test/mac/postbuild-multiple-configurations/test.gyp

@ -0,0 +1,26 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'target_defaults': {
'configurations': {
'Debug': {},
'Release': {},
},
},
'targets': [
{
'target_name': 'random_target',
'type': 'executable',
'sources': [ 'main.c', ],
'postbuilds': [
{
'postbuild_name': 'Touch a file.',
'action': [
'./postbuild-touch-file.sh',
],
},
],
},
],
}

4
tools/gyp/test/mac/postbuild-static-library/empty.c

@ -0,0 +1,4 @@
// Copyright (c) 2012 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
void f() {}

7
tools/gyp/test/mac/postbuild-static-library/postbuild-touch-file.sh

@ -0,0 +1,7 @@
#!/bin/bash
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
touch "${BUILT_PRODUCTS_DIR}/$1"

34
tools/gyp/test/mac/postbuild-static-library/test.gyp

@ -0,0 +1,34 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'my_lib',
'type': 'static_library',
'sources': [ 'empty.c', ],
'postbuilds': [
{
'postbuild_name': 'Postbuild that touches a file',
'action': [
'./postbuild-touch-file.sh', 'postbuild-file'
],
},
],
},
{
'target_name': 'my_sourceless_lib',
'type': 'static_library',
'dependencies': [ 'my_lib' ],
'postbuilds': [
{
'postbuild_name': 'Postbuild that touches a file',
'action': [
'./postbuild-touch-file.sh', 'postbuild-file-sourceless'
],
},
],
},
],
}

1
tools/gyp/test/mac/prefixheader/file.cc

@ -0,0 +1 @@
MyInt f() { return 0; }

1
tools/gyp/test/mac/prefixheader/file.m

@ -0,0 +1 @@
MyInt f() { return 0; }

1
tools/gyp/test/mac/prefixheader/file.mm

@ -0,0 +1 @@
MyInt f() { return 0; }

61
tools/gyp/test/mac/prefixheader/test.gyp

@ -4,7 +4,7 @@
{
'targets': [
{
'target_name': 'prefix_header',
'target_name': 'prefix_header_c',
'type': 'static_library',
'sources': [ 'file.c', ],
'xcode_settings': {
@ -12,7 +12,7 @@
},
},
{
'target_name': 'precompiled_prefix_header',
'target_name': 'precompiled_prefix_header_c',
'type': 'shared_library',
'mac_bundle': 1,
'sources': [ 'file.c', ],
@ -21,5 +21,62 @@
'GCC_PRECOMPILE_PREFIX_HEADER': 'YES',
},
},
{
'target_name': 'prefix_header_cc',
'type': 'static_library',
'sources': [ 'file.cc', ],
'xcode_settings': {
'GCC_PREFIX_HEADER': 'header.h',
},
},
{
'target_name': 'precompiled_prefix_header_cc',
'type': 'shared_library',
'mac_bundle': 1,
'sources': [ 'file.cc', ],
'xcode_settings': {
'GCC_PREFIX_HEADER': 'header.h',
'GCC_PRECOMPILE_PREFIX_HEADER': 'YES',
},
},
{
'target_name': 'prefix_header_m',
'type': 'static_library',
'sources': [ 'file.m', ],
'xcode_settings': {
'GCC_PREFIX_HEADER': 'header.h',
},
},
{
'target_name': 'precompiled_prefix_header_m',
'type': 'shared_library',
'mac_bundle': 1,
'sources': [ 'file.m', ],
'xcode_settings': {
'GCC_PREFIX_HEADER': 'header.h',
'GCC_PRECOMPILE_PREFIX_HEADER': 'YES',
},
},
{
'target_name': 'prefix_header_mm',
'type': 'static_library',
'sources': [ 'file.mm', ],
'xcode_settings': {
'GCC_PREFIX_HEADER': 'header.h',
},
},
{
'target_name': 'precompiled_prefix_header_mm',
'type': 'shared_library',
'mac_bundle': 1,
'sources': [ 'file.mm', ],
'xcode_settings': {
'GCC_PREFIX_HEADER': 'header.h',
'GCC_PRECOMPILE_PREFIX_HEADER': 'YES',
},
},
],
}

32
tools/gyp/test/mac/rebuild/TestApp-Info.plist

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.google.${PRODUCT_NAME}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

6
tools/gyp/test/mac/rebuild/delay-touch.sh

@ -0,0 +1,6 @@
#!/bin/bash
set -e
sleep 1 # mtime resolution is 1 sec on unix.
touch "$1"

0
tools/gyp/test/mac/rebuild/empty.c

1
tools/gyp/test/mac/rebuild/main.c

@ -0,0 +1 @@
int main() {}

56
tools/gyp/test/mac/rebuild/test.gyp

@ -0,0 +1,56 @@
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'test_app',
'product_name': 'Test App',
'type': 'executable',
'mac_bundle': 1,
'sources': [
'main.c',
],
'xcode_settings': {
'INFOPLIST_FILE': 'TestApp-Info.plist',
},
},
{
'target_name': 'test_app_postbuilds',
'product_name': 'Test App 2',
'type': 'executable',
'mac_bundle': 1,
'sources': [
'main.c',
],
'xcode_settings': {
'INFOPLIST_FILE': 'TestApp-Info.plist',
},
'postbuilds': [
{
'postbuild_name': 'Postbuild that touches the app binary',
'action': [
'./delay-touch.sh', '${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}',
],
},
],
},
{
'target_name': 'test_framework_postbuilds',
'product_name': 'Test Framework',
'type': 'shared_library',
'mac_bundle': 1,
'sources': [
'empty.c',
],
'postbuilds': [
{
'postbuild_name': 'Postbuild that touches the framework binary',
'action': [
'./delay-touch.sh', '${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}',
],
},
],
},
],
}

1
tools/gyp/test/mac/sourceless-module/empty.c

@ -0,0 +1 @@
int main() {}

39
tools/gyp/test/mac/sourceless-module/test.gyp

@ -0,0 +1,39 @@
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'empty_bundle',
'type': 'loadable_module',
'mac_bundle': 1,
},
{
'target_name': 'resource_bundle',
'type': 'loadable_module',
'mac_bundle': 1,
'actions': [
{
'action_name': 'Add Resource',
'inputs': [],
'outputs': [
'<(INTERMEDIATE_DIR)/app_manifest/foo.manifest',
],
'action': [
'touch', '<(INTERMEDIATE_DIR)/app_manifest/foo.manifest',
],
'process_outputs_as_mac_bundle_resources': 1,
},
],
},
{
'target_name': 'dependent_on_resource_bundle',
'type': 'executable',
'sources': [ 'empty.c' ],
'dependencies': [
'resource_bundle',
],
},
],
}

11
tools/gyp/test/mac/type_envvars/test.gyp

@ -40,6 +40,7 @@
},
],
},
# Types 'static_library' and 'none' can't exist as bundles.
{
'target_name': 'nonbundle_executable',
@ -85,5 +86,15 @@
},
],
},
{
'target_name': 'nonbundle_none',
'type': 'none',
'postbuilds': [
{
'postbuild_name': 'envtest',
'action': [ './test_nonbundle_none.sh', ],
},
],
},
],
}

8
tools/gyp/test/mac/type_envvars/test_bundle_executable.sh

@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -7,3 +7,9 @@ set -e
test $MACH_O_TYPE = mh_execute
test $PRODUCT_TYPE = com.apple.product-type.application
test "${PRODUCT_NAME}" = "My App"
test "${FULL_PRODUCT_NAME}" = "My App.app"
test "${EXECUTABLE_NAME}" = "My App"
test "${EXECUTABLE_PATH}" = "My App.app/Contents/MacOS/My App"
test "${WRAPPER_NAME}" = "My App.app"

9
tools/gyp/test/mac/type_envvars/test_bundle_loadable_module.sh

@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -7,3 +7,10 @@ set -e
test $MACH_O_TYPE = mh_bundle
test $PRODUCT_TYPE = com.apple.product-type.bundle
test $PRODUCT_NAME = bundle_loadable_module
test $FULL_PRODUCT_NAME = bundle_loadable_module.bundle
test $EXECUTABLE_NAME = bundle_loadable_module
test $EXECUTABLE_PATH = \
"bundle_loadable_module.bundle/Contents/MacOS/bundle_loadable_module"
test $WRAPPER_NAME = bundle_loadable_module.bundle

9
tools/gyp/test/mac/type_envvars/test_bundle_shared_library.sh

@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -7,3 +7,10 @@ set -e
test $MACH_O_TYPE = mh_dylib
test $PRODUCT_TYPE = com.apple.product-type.framework
test $PRODUCT_NAME = bundle_shared_library
test $FULL_PRODUCT_NAME = bundle_shared_library.framework
test $EXECUTABLE_NAME = bundle_shared_library
test $EXECUTABLE_PATH = \
"bundle_shared_library.framework/Versions/A/bundle_shared_library"
test $WRAPPER_NAME = bundle_shared_library.framework

8
tools/gyp/test/mac/type_envvars/test_nonbundle_executable.sh

@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -8,3 +8,9 @@ set -e
# Check for "not set", not just "empty":
[[ ! $MACH_O_TYPE && ${MACH_O_TYPE-_} ]]
test $PRODUCT_TYPE = com.apple.product-type.tool
test $PRODUCT_NAME = nonbundle_executable
test $FULL_PRODUCT_NAME = nonbundle_executable
test $EXECUTABLE_NAME = nonbundle_executable
test $EXECUTABLE_PATH = nonbundle_executable
[[ ! $WRAPPER_NAME && ${WRAPPER_NAME-_} ]]

8
tools/gyp/test/mac/type_envvars/test_nonbundle_loadable_module.sh

@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@ -7,3 +7,9 @@ set -e
test $MACH_O_TYPE = mh_bundle
test $PRODUCT_TYPE = com.apple.product-type.library.dynamic
test $PRODUCT_NAME = nonbundle_loadable_module
test $FULL_PRODUCT_NAME = nonbundle_loadable_module.so
test $EXECUTABLE_NAME = nonbundle_loadable_module.so
test $EXECUTABLE_PATH = nonbundle_loadable_module.so
[[ ! $WRAPPER_NAME && ${WRAPPER_NAME-_} ]]

16
tools/gyp/test/mac/type_envvars/test_nonbundle_none.sh

@ -0,0 +1,16 @@
#!/bin/bash
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
# Check for "not set", not just "empty":
[[ ! $MACH_O_TYPE && ${MACH_O_TYPE-_} ]]
[[ ! $PRODUCT_TYPE && ${PRODUCT_TYPE-_} ]]
test $PRODUCT_NAME = nonbundle_none
[[ ! $FULL_PRODUCT_NAME && ${FULL_PRODUCT_NAME-_} ]]
[[ ! $EXECUTABLE_NAME && ${EXECUTABLE_NAME-_} ]]
[[ ! $EXECUTABLE_PATH && ${EXECUTABLE_PATH-_} ]]
[[ ! $WRAPPER_NAME && ${WRAPPER_NAME-_} ]]

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save