diff options
author | Torne (Richard Coles) <torne@google.com> | 2013-12-18 16:25:46 +0000 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2013-12-18 16:25:46 +0000 |
commit | 61a3675259f54120dc9edfce3f2bc6dc5c95a90e (patch) | |
tree | b0907b47be77d6ad90a2aa690f870948980e26b8 | |
parent | 5822b3d993f4c8c7e59a113f164f950c27f6f56b (diff) | |
parent | 01e685f00610343d90c474aea28cc75d0546547d (diff) | |
download | gyp-61a3675259f54120dc9edfce3f2bc6dc5c95a90e.tar.gz |
Merge from Chromium at DEPS revision 240154
This commit was generated by merge_to_master.py.
Change-Id: I83f80c35b32722035e9b918caf1d5a12b09b4a64
45 files changed, 2685 insertions, 175 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 5567b88b..9c474eb2 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -97,14 +97,19 @@ def CheckChangeOnCommit(input_api, output_api): 'http://gyp-status.appspot.com/status', 'http://gyp-status.appspot.com/current')) + import os import sys old_sys_path = sys.path try: sys.path = ['pylib', 'test/lib'] + sys.path + blacklist = PYLINT_BLACKLIST + if sys.platform == 'win32': + blacklist = [os.path.normpath(x).replace('\\', '\\\\') + for x in PYLINT_BLACKLIST] report.extend(input_api.canned_checks.RunPylint( input_api, output_api, - black_list=PYLINT_BLACKLIST, + black_list=blacklist, disabled_warnings=PYLINT_DISABLED_WARNINGS)) finally: sys.path = old_sys_path diff --git a/buildbot/buildbot_run.py b/buildbot/buildbot_run.py index 398eb87a..979073c7 100755 --- a/buildbot/buildbot_run.py +++ b/buildbot/buildbot_run.py @@ -23,6 +23,8 @@ BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__)) TRUNK_DIR = os.path.dirname(BUILDBOT_DIR) ROOT_DIR = os.path.dirname(TRUNK_DIR) ANDROID_DIR = os.path.join(ROOT_DIR, 'android') +CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake') +CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin') OUT_DIR = os.path.join(TRUNK_DIR, 'out') @@ -34,6 +36,43 @@ def CallSubProcess(*args, **kwargs): sys.exit(1) +def PrepareCmake(): + """Build CMake 2.8.8 since the version in Precise is 2.8.7.""" + if os.environ['BUILDBOT_CLOBBER'] == '1': + print '@@@BUILD_STEP Clobber CMake checkout@@@' + shutil.rmtree(CMAKE_DIR) + + # We always build CMake 2.8.8, so no need to do anything + # if the directory already exists. + if os.path.isdir(CMAKE_DIR): + return + + print '@@@BUILD_STEP Initialize CMake checkout@@@' + os.mkdir(CMAKE_DIR) + CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot']) + CallSubProcess(['git', 'config', '--global', + 'user.email', 'chrome-bot@google.com']) + CallSubProcess(['git', 'config', '--global', 'color.ui', 'false']) + + print '@@@BUILD_STEP Sync CMake@@@' + CallSubProcess( + ['git', 'clone', + '--depth', '1', + '--single-branch', + '--branch', 'v2.8.8', + '--', + 'git://cmake.org/cmake.git', + CMAKE_DIR], + cwd=CMAKE_DIR) + + print '@@@BUILD_STEP Build CMake@@@' + CallSubProcess( + ['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR], + cwd=CMAKE_DIR) + + CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR) + + def PrepareAndroidTree(): """Prepare an Android tree to run 'android' format tests.""" if os.environ['BUILDBOT_CLOBBER'] == '1': @@ -91,6 +130,7 @@ def GypTestFormat(title, format=None, msvs_version=None): '--all', '--passed', '--format', format, + '--path', CMAKE_BIN_DIR, '--chdir', 'trunk']) if format == 'android': # gyptest needs the environment setup from envsetup/lunch in order to build @@ -124,6 +164,8 @@ def GypBuild(): elif sys.platform.startswith('linux'): retcode += GypTestFormat('ninja') retcode += GypTestFormat('make') + PrepareCmake() + retcode += GypTestFormat('cmake') elif sys.platform == 'darwin': retcode += GypTestFormat('ninja') retcode += GypTestFormat('xcode') @@ -176,7 +176,7 @@ def main(argv=None): if opts.path: extra_path = [os.path.abspath(p) for p in opts.path] extra_path = os.pathsep.join(extra_path) - os.environ['PATH'] += os.pathsep + extra_path + os.environ['PATH'] = extra_path + os.pathsep + os.environ['PATH'] if not args: if not opts.all: diff --git a/pylib/gyp/MSVSSettings.py b/pylib/gyp/MSVSSettings.py index f93dab98..0c9532d8 100644 --- a/pylib/gyp/MSVSSettings.py +++ b/pylib/gyp/MSVSSettings.py @@ -813,6 +813,7 @@ _Same(_link, 'UACExecutionLevel', 'HighestAvailable', # /level='highestAvailable' 'RequireAdministrator'])) # /level='requireAdministrator' _Same(_link, 'MinimumRequiredVersion', _string) +_Same(_link, 'TreatLinkerWarningAsErrors', _boolean) # /WX # Options found in MSVS that have been renamed in MSBuild. @@ -851,7 +852,6 @@ _MSBuildOnly(_link, 'LinkStatus', _boolean) # /LTCG:STATUS _MSBuildOnly(_link, 'PreventDllBinding', _boolean) # /ALLOWBIND _MSBuildOnly(_link, 'SupportNobindOfDelayLoadedDLL', _boolean) # /DELAY:NOBIND _MSBuildOnly(_link, 'TrackerLogDirectory', _folder_name) -_MSBuildOnly(_link, 'TreatLinkerWarningAsErrors', _boolean) # /WX _MSBuildOnly(_link, 'MSDOSStubFileName', _file_name) # /STUB Visible='false' _MSBuildOnly(_link, 'SectionAlignment', _integer) # /ALIGN _MSBuildOnly(_link, 'SpecifySectionAttributes', _string) # /SECTION diff --git a/pylib/gyp/generator/cmake.py b/pylib/gyp/generator/cmake.py new file mode 100644 index 00000000..16118999 --- /dev/null +++ b/pylib/gyp/generator/cmake.py @@ -0,0 +1,1150 @@ +# Copyright (c) 2013 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. + +"""cmake output module + +This module is under development and should be considered experimental. + +This module produces cmake (2.8.8+) input as its output. One CMakeLists.txt is +created for each configuration. + +This module's original purpose was to support editing in IDEs like KDevelop +which use CMake for project management. It is also possible to use CMake to +generate projects for other IDEs such as eclipse cdt and code::blocks. QtCreator +will convert the CMakeLists.txt to a code::blocks cbp for the editor to read, +but build using CMake. As a result QtCreator editor is unaware of compiler +defines. The generated CMakeLists.txt can also be used to build on Linux. There +is currently no support for building on platforms other than Linux. + +The generated CMakeLists.txt should properly compile all projects. However, +there is a mismatch between gyp and cmake with regard to linking. All attempts +are made to work around this, but CMake sometimes sees -Wl,--start-group as a +library and incorrectly repeats it. As a result the output of this generator +should not be relied on for building. + +When using with kdevelop, use version 4.4+. Previous versions of kdevelop will +not be able to find the header file directories described in the generated +CMakeLists.txt file. +""" + +import multiprocessing +import os +import signal +import string +import subprocess +import gyp.common + +generator_default_variables = { + 'EXECUTABLE_PREFIX': '', + 'EXECUTABLE_SUFFIX': '', + 'STATIC_LIB_PREFIX': 'lib', + 'STATIC_LIB_SUFFIX': '.a', + 'SHARED_LIB_PREFIX': 'lib', + 'SHARED_LIB_SUFFIX': '.so', + 'SHARED_LIB_DIR': '${builddir}/lib.${TOOLSET}', + 'LIB_DIR': '${obj}.${TOOLSET}', + 'INTERMEDIATE_DIR': '${obj}.${TOOLSET}/${TARGET}/geni', + 'SHARED_INTERMEDIATE_DIR': '${obj}/gen', + 'PRODUCT_DIR': '${builddir}', + 'RULE_INPUT_PATH': '${RULE_INPUT_PATH}', + 'RULE_INPUT_DIRNAME': '${RULE_INPUT_DIRNAME}', + 'RULE_INPUT_NAME': '${RULE_INPUT_NAME}', + 'RULE_INPUT_ROOT': '${RULE_INPUT_ROOT}', + 'RULE_INPUT_EXT': '${RULE_INPUT_EXT}', + 'CONFIGURATION_NAME': '${configuration}', +} + +FULL_PATH_VARS = ('${CMAKE_SOURCE_DIR}', '${builddir}', '${obj}') + +generator_supports_multiple_toolsets = True +generator_wants_static_library_dependencies_adjusted = True + +COMPILABLE_EXTENSIONS = { + '.c': 'cc', + '.cc': 'cxx', + '.cpp': 'cxx', + '.cxx': 'cxx', + '.s': 's', # cc + '.S': 's', # cc +} + + +def RemovePrefix(a, prefix): + """Returns 'a' without 'prefix' if it starts with 'prefix'.""" + return a[len(prefix):] if a.startswith(prefix) else a + + +def CalculateVariables(default_variables, params): + """Calculate additional variables for use in the build (called by gyp).""" + default_variables.setdefault('OS', gyp.common.GetFlavor(params)) + + +def Compilable(filename): + """Return true if the file is compilable (should be in OBJS).""" + return any(filename.endswith(e) for e in COMPILABLE_EXTENSIONS) + + +def Linkable(filename): + """Return true if the file is linkable (should be on the link line).""" + return filename.endswith('.o') + + +def NormjoinPathForceCMakeSource(base_path, rel_path): + """Resolves rel_path against base_path and returns the result. + + If rel_path is an absolute path it is returned unchanged. + Otherwise it is resolved against base_path and normalized. + If the result is a relative path, it is forced to be relative to the + CMakeLists.txt. + """ + if os.path.isabs(rel_path): + return rel_path + if any([rel_path.startswith(var) for var in FULL_PATH_VARS]): + return rel_path + # TODO: do we need to check base_path for absolute variables as well? + return os.path.join('${CMAKE_SOURCE_DIR}', + os.path.normpath(os.path.join(base_path, rel_path))) + + +def NormjoinPath(base_path, rel_path): + """Resolves rel_path against base_path and returns the result. + TODO: what is this really used for? + If rel_path begins with '$' it is returned unchanged. + Otherwise it is resolved against base_path if relative, then normalized. + """ + if rel_path.startswith('$') and not rel_path.startswith('${configuration}'): + return rel_path + return os.path.normpath(os.path.join(base_path, rel_path)) + + +def EnsureDirectoryExists(path): + """Python version of 'mkdir -p'.""" + dirPath = os.path.dirname(path) + if dirPath and not os.path.exists(dirPath): + os.makedirs(dirPath) + + +def CMakeStringEscape(a): + """Escapes the string 'a' for use inside a CMake string. + + This means escaping + '\' otherwise it may be seen as modifying the next character + '"' otherwise it will end the string + ';' otherwise the string becomes a list + + The following do not need to be escaped + '#' when the lexer is in string state, this does not start a comment + + The following are yet unknown + '$' generator variables (like ${obj}) must not be escaped, + but text $ should be escaped + what is wanted is to know which $ come from generator variables + """ + return a.replace('\\', '\\\\').replace(';', '\\;').replace('"', '\\"') + + +def SetFileProperty(output, source_name, property_name, values, sep): + """Given a set of source file, sets the given property on them.""" + output.write('set_source_files_properties(') + output.write(source_name) + output.write(' PROPERTIES ') + output.write(property_name) + output.write(' "') + for value in values: + output.write(CMakeStringEscape(value)) + output.write(sep) + output.write('")\n') + + +def SetFilesProperty(output, source_names, property_name, values, sep): + """Given a set of source files, sets the given property on them.""" + output.write('set_source_files_properties(\n') + for source_name in source_names: + output.write(' ') + output.write(source_name) + output.write('\n') + output.write(' PROPERTIES\n ') + output.write(property_name) + output.write(' "') + for value in values: + output.write(CMakeStringEscape(value)) + output.write(sep) + output.write('"\n)\n') + + +def SetTargetProperty(output, target_name, property_name, values, sep=''): + """Given a target, sets the given property.""" + output.write('set_target_properties(') + output.write(target_name) + output.write(' PROPERTIES ') + output.write(property_name) + output.write(' "') + for value in values: + output.write(CMakeStringEscape(value)) + output.write(sep) + output.write('")\n') + + +def SetVariable(output, variable_name, value): + """Sets a CMake variable.""" + output.write('set(') + output.write(variable_name) + output.write(' "') + output.write(CMakeStringEscape(value)) + output.write('")\n') + + +def SetVariableList(output, variable_name, values): + """Sets a CMake variable to a list.""" + if not values: + return SetVariable(output, variable_name, "") + if len(values) == 1: + return SetVariable(output, variable_name, values[0]) + output.write('list(APPEND ') + output.write(variable_name) + output.write('\n "') + output.write('"\n "'.join([CMakeStringEscape(value) for value in values])) + output.write('")\n') + + +def UnsetVariable(output, variable_name): + """Unsets a CMake variable.""" + output.write('unset(') + output.write(variable_name) + output.write(')\n') + + +def WriteVariable(output, variable_name, prepend=None): + if prepend: + output.write(prepend) + output.write('${') + output.write(variable_name) + output.write('}') + + +class CMakeTargetType: + def __init__(self, command, modifier, property_modifier): + self.command = command + self.modifier = modifier + self.property_modifier = property_modifier + + +cmake_target_type_from_gyp_target_type = { + 'executable': CMakeTargetType('add_executable', None, 'RUNTIME'), + 'static_library': CMakeTargetType('add_library', 'STATIC', 'ARCHIVE'), + 'shared_library': CMakeTargetType('add_library', 'SHARED', 'LIBRARY'), + 'loadable_module': CMakeTargetType('add_library', 'MODULE', 'LIBRARY'), + 'none': CMakeTargetType('add_custom_target', 'SOURCES', None), +} + + +def StringToCMakeTargetName(a): + """Converts the given string 'a' to a valid CMake target name. + + All invalid characters are replaced by '_'. + Invalid for cmake: ' ', '/', '(', ')' + Invalid for make: ':' + Invalid for unknown reasons but cause failures: '.' + """ + return a.translate(string.maketrans(' /():.', '______')) + + +def WriteActions(target_name, actions, extra_sources, extra_deps, + path_to_gyp, output): + """Write CMake for the 'actions' in the target. + + Args: + target_name: the name of the CMake target being generated. + actions: the Gyp 'actions' dict for this target. + extra_sources: [(<cmake_src>, <src>)] to append with generated source files. + extra_deps: [<cmake_taget>] to append with generated targets. + path_to_gyp: relative path from CMakeLists.txt being generated to + the Gyp file in which the target being generated is defined. + """ + for action in actions: + action_name = StringToCMakeTargetName(action['action_name']) + action_target_name = '%s__%s' % (target_name, action_name) + + inputs = action['inputs'] + inputs_name = action_target_name + '__input' + SetVariableList(output, inputs_name, + [NormjoinPathForceCMakeSource(path_to_gyp, dep) for dep in inputs]) + + outputs = action['outputs'] + cmake_outputs = [NormjoinPathForceCMakeSource(path_to_gyp, out) + for out in outputs] + outputs_name = action_target_name + '__output' + SetVariableList(output, outputs_name, cmake_outputs) + + # Build up a list of outputs. + # Collect the output dirs we'll need. + dirs = set(dir for dir in (os.path.dirname(o) for o in outputs) if dir) + + if int(action.get('process_outputs_as_sources', False)): + extra_sources.extend(zip(cmake_outputs, outputs)) + + # add_custom_command + output.write('add_custom_command(OUTPUT ') + WriteVariable(output, outputs_name) + output.write('\n') + + if len(dirs) > 0: + for directory in dirs: + output.write(' COMMAND ${CMAKE_COMMAND} -E make_directory ') + output.write(directory) + output.write('\n') + + output.write(' COMMAND ') + output.write(gyp.common.EncodePOSIXShellList(action['action'])) + output.write('\n') + + output.write(' DEPENDS ') + WriteVariable(output, inputs_name) + output.write('\n') + + output.write(' WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/') + output.write(path_to_gyp) + output.write('\n') + + output.write(' COMMENT ') + if 'message' in action: + output.write(action['message']) + else: + output.write(action_target_name) + output.write('\n') + + output.write(' VERBATIM\n') + output.write(')\n') + + # add_custom_target + output.write('add_custom_target(') + output.write(action_target_name) + output.write('\n DEPENDS ') + WriteVariable(output, outputs_name) + output.write('\n SOURCES ') + WriteVariable(output, inputs_name) + output.write('\n)\n') + + extra_deps.append(action_target_name) + + +def NormjoinRulePathForceCMakeSource(base_path, rel_path, rule_source): + if rel_path.startswith(("${RULE_INPUT_PATH}","${RULE_INPUT_DIRNAME}")): + if any([rule_source.startswith(var) for var in FULL_PATH_VARS]): + return rel_path + return NormjoinPathForceCMakeSource(base_path, rel_path) + + +def WriteRules(target_name, rules, extra_sources, extra_deps, + path_to_gyp, output): + """Write CMake for the 'rules' in the target. + + Args: + target_name: the name of the CMake target being generated. + actions: the Gyp 'actions' dict for this target. + extra_sources: [(<cmake_src>, <src>)] to append with generated source files. + extra_deps: [<cmake_taget>] to append with generated targets. + path_to_gyp: relative path from CMakeLists.txt being generated to + the Gyp file in which the target being generated is defined. + """ + for rule in rules: + rule_name = StringToCMakeTargetName(target_name + '__' + rule['rule_name']) + + inputs = rule.get('inputs', []) + inputs_name = rule_name + '__input' + SetVariableList(output, inputs_name, + [NormjoinPathForceCMakeSource(path_to_gyp, dep) for dep in inputs]) + outputs = rule['outputs'] + var_outputs = [] + + for count, rule_source in enumerate(rule.get('rule_sources', [])): + action_name = rule_name + '_' + str(count) + + rule_source_dirname, rule_source_basename = os.path.split(rule_source) + rule_source_root, rule_source_ext = os.path.splitext(rule_source_basename) + + SetVariable(output, 'RULE_INPUT_PATH', rule_source) + SetVariable(output, 'RULE_INPUT_DIRNAME', rule_source_dirname) + SetVariable(output, 'RULE_INPUT_NAME', rule_source_basename) + SetVariable(output, 'RULE_INPUT_ROOT', rule_source_root) + SetVariable(output, 'RULE_INPUT_EXT', rule_source_ext) + + # Build up a list of outputs. + # Collect the output dirs we'll need. + dirs = set(dir for dir in (os.path.dirname(o) for o in outputs) if dir) + + # Create variables for the output, as 'local' variable will be unset. + these_outputs = [] + for output_index, out in enumerate(outputs): + output_name = action_name + '_' + str(output_index) + SetVariable(output, output_name, + NormjoinRulePathForceCMakeSource(path_to_gyp, out, + rule_source)) + if int(rule.get('process_outputs_as_sources', False)): + extra_sources.append(('${' + output_name + '}', out)) + these_outputs.append('${' + output_name + '}') + var_outputs.append('${' + output_name + '}') + + # add_custom_command + output.write('add_custom_command(OUTPUT\n') + for out in these_outputs: + output.write(' ') + output.write(out) + output.write('\n') + + for directory in dirs: + output.write(' COMMAND ${CMAKE_COMMAND} -E make_directory ') + output.write(directory) + output.write('\n') + + output.write(' COMMAND ') + output.write(gyp.common.EncodePOSIXShellList(rule['action'])) + output.write('\n') + + output.write(' DEPENDS ') + WriteVariable(output, inputs_name) + output.write(' ') + output.write(NormjoinPath(path_to_gyp, rule_source)) + output.write('\n') + + # CMAKE_SOURCE_DIR is where the CMakeLists.txt lives. + # The cwd is the current build directory. + output.write(' WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/') + output.write(path_to_gyp) + output.write('\n') + + output.write(' COMMENT ') + if 'message' in rule: + output.write(rule['message']) + else: + output.write(action_name) + output.write('\n') + + output.write(' VERBATIM\n') + output.write(')\n') + + UnsetVariable(output, 'RULE_INPUT_PATH') + UnsetVariable(output, 'RULE_INPUT_DIRNAME') + UnsetVariable(output, 'RULE_INPUT_NAME') + UnsetVariable(output, 'RULE_INPUT_ROOT') + UnsetVariable(output, 'RULE_INPUT_EXT') + + # add_custom_target + output.write('add_custom_target(') + output.write(rule_name) + output.write(' DEPENDS\n') + for out in var_outputs: + output.write(' ') + output.write(out) + output.write('\n') + output.write('SOURCES ') + WriteVariable(output, inputs_name) + output.write('\n') + for rule_source in rule.get('rule_sources', []): + output.write(' ') + output.write(NormjoinPath(path_to_gyp, rule_source)) + output.write('\n') + output.write(')\n') + + extra_deps.append(rule_name) + + +def WriteCopies(target_name, copies, extra_deps, path_to_gyp, output): + """Write CMake for the 'copies' in the target. + + Args: + target_name: the name of the CMake target being generated. + actions: the Gyp 'actions' dict for this target. + extra_deps: [<cmake_taget>] to append with generated targets. + path_to_gyp: relative path from CMakeLists.txt being generated to + the Gyp file in which the target being generated is defined. + """ + copy_name = target_name + '__copies' + + # CMake gets upset with custom targets with OUTPUT which specify no output. + have_copies = any(copy['files'] for copy in copies) + if not have_copies: + output.write('add_custom_target(') + output.write(copy_name) + output.write(')\n') + extra_deps.append(copy_name) + return + + class Copy: + def __init__(self, ext, command): + self.cmake_inputs = [] + self.cmake_outputs = [] + self.gyp_inputs = [] + self.gyp_outputs = [] + self.ext = ext + self.inputs_name = None + self.outputs_name = None + self.command = command + + file_copy = Copy('', 'copy') + dir_copy = Copy('_dirs', 'copy_directory') + + for copy in copies: + files = copy['files'] + destination = copy['destination'] + for src in files: + path = os.path.normpath(src) + basename = os.path.split(path)[1] + dst = os.path.join(destination, basename) + + copy = file_copy if os.path.basename(src) else dir_copy + + copy.cmake_inputs.append(NormjoinPath(path_to_gyp, src)) + copy.cmake_outputs.append(NormjoinPathForceCMakeSource(path_to_gyp, dst)) + copy.gyp_inputs.append(src) + copy.gyp_outputs.append(dst) + + for copy in (file_copy, dir_copy): + if copy.cmake_inputs: + copy.inputs_name = copy_name + '__input' + copy.ext + SetVariableList(output, copy.inputs_name, copy.cmake_inputs) + + copy.outputs_name = copy_name + '__output' + copy.ext + SetVariableList(output, copy.outputs_name, copy.cmake_outputs) + + # add_custom_command + output.write('add_custom_command(\n') + + output.write('OUTPUT') + for copy in (file_copy, dir_copy): + if copy.outputs_name: + WriteVariable(output, copy.outputs_name, ' ') + output.write('\n') + + for copy in (file_copy, dir_copy): + for src, dst in zip(copy.gyp_inputs, copy.gyp_outputs): + # 'cmake -E copy src dst' will create the 'dst' directory if needed. + output.write('COMMAND ${CMAKE_COMMAND} -E %s ' % copy.command) + output.write(src) + output.write(' ') + output.write(dst) + output.write("\n") + + output.write('DEPENDS') + for copy in (file_copy, dir_copy): + if copy.inputs_name: + WriteVariable(output, copy.inputs_name, ' ') + output.write('\n') + + output.write('WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/') + output.write(path_to_gyp) + output.write('\n') + + output.write('COMMENT Copying for ') + output.write(target_name) + output.write('\n') + + output.write('VERBATIM\n') + output.write(')\n') + + # add_custom_target + output.write('add_custom_target(') + output.write(copy_name) + output.write('\n DEPENDS') + for copy in (file_copy, dir_copy): + if copy.outputs_name: + WriteVariable(output, copy.outputs_name, ' ') + output.write('\n SOURCES') + if file_copy.inputs_name: + WriteVariable(output, file_copy.inputs_name, ' ') + output.write('\n)\n') + + extra_deps.append(copy_name) + + +def CreateCMakeTargetBaseName(qualified_target): + """This is the name we would like the target to have.""" + _, gyp_target_name, gyp_target_toolset = ( + gyp.common.ParseQualifiedTarget(qualified_target)) + cmake_target_base_name = gyp_target_name + if gyp_target_toolset and gyp_target_toolset != 'target': + cmake_target_base_name += '_' + gyp_target_toolset + return StringToCMakeTargetName(cmake_target_base_name) + + +def CreateCMakeTargetFullName(qualified_target): + """An unambiguous name for the target.""" + gyp_file, gyp_target_name, gyp_target_toolset = ( + gyp.common.ParseQualifiedTarget(qualified_target)) + cmake_target_full_name = gyp_file + ':' + gyp_target_name + if gyp_target_toolset and gyp_target_toolset != 'target': + cmake_target_full_name += '_' + gyp_target_toolset + return StringToCMakeTargetName(cmake_target_full_name) + + +class CMakeNamer(object): + """Converts Gyp target names into CMake target names. + + CMake requires that target names be globally unique. One way to ensure + this is to fully qualify the names of the targets. Unfortunatly, this + ends up with all targets looking like "chrome_chrome_gyp_chrome" instead + of just "chrome". If this generator were only interested in building, it + would be possible to fully qualify all target names, then create + unqualified target names which depend on all qualified targets which + should have had that name. This is more or less what the 'make' generator + does with aliases. However, one goal of this generator is to create CMake + files for use with IDEs, and fully qualified names are not as user + friendly. + + Since target name collision is rare, we do the above only when required. + + Toolset variants are always qualified from the base, as this is required for + building. However, it also makes sense for an IDE, as it is possible for + defines to be different. + """ + def __init__(self, target_list): + self.cmake_target_base_names_conficting = set() + + cmake_target_base_names_seen = set() + for qualified_target in target_list: + cmake_target_base_name = CreateCMakeTargetBaseName(qualified_target) + + if cmake_target_base_name not in cmake_target_base_names_seen: + cmake_target_base_names_seen.add(cmake_target_base_name) + else: + self.cmake_target_base_names_conficting.add(cmake_target_base_name) + + def CreateCMakeTargetName(self, qualified_target): + base_name = CreateCMakeTargetBaseName(qualified_target) + if base_name in self.cmake_target_base_names_conficting: + return CreateCMakeTargetFullName(qualified_target) + return base_name + + +def WriteTarget(namer, qualified_target, target_dicts, build_dir, config_to_use, + options, generator_flags, all_qualified_targets, output): + + # The make generator does this always. + # TODO: It would be nice to be able to tell CMake all dependencies. + circular_libs = generator_flags.get('circular', True) + + if not generator_flags.get('standalone', False): + output.write('\n#') + output.write(qualified_target) + output.write('\n') + + gyp_file, _, _ = gyp.common.ParseQualifiedTarget(qualified_target) + rel_gyp_file = gyp.common.RelativePath(gyp_file, options.toplevel_dir) + rel_gyp_dir = os.path.dirname(rel_gyp_file) + + # Relative path from build dir to top dir. + build_to_top = gyp.common.InvertRelativePath(build_dir, options.toplevel_dir) + # Relative path from build dir to gyp dir. + build_to_gyp = os.path.join(build_to_top, rel_gyp_dir) + + path_from_cmakelists_to_gyp = build_to_gyp + + spec = target_dicts.get(qualified_target, {}) + config = spec.get('configurations', {}).get(config_to_use, {}) + + target_name = spec.get('target_name', '<missing target name>') + target_type = spec.get('type', '<missing target type>') + target_toolset = spec.get('toolset') + + SetVariable(output, 'TARGET', target_name) + SetVariable(output, 'TOOLSET', target_toolset) + + cmake_target_name = namer.CreateCMakeTargetName(qualified_target) + + extra_sources = [] + extra_deps = [] + + # Actions must come first, since they can generate more OBJs for use below. + if 'actions' in spec: + WriteActions(cmake_target_name, spec['actions'], extra_sources, extra_deps, + path_from_cmakelists_to_gyp, output) + + # Rules must be early like actions. + if 'rules' in spec: + WriteRules(cmake_target_name, spec['rules'], extra_sources, extra_deps, + path_from_cmakelists_to_gyp, output) + + # Copies + if 'copies' in spec: + WriteCopies(cmake_target_name, spec['copies'], extra_deps, + path_from_cmakelists_to_gyp, output) + + # Target and sources + srcs = spec.get('sources', []) + + # Gyp separates the sheep from the goats based on file extensions. + def partition(l, p): + return reduce(lambda x, e: x[not p(e)].append(e) or x, l, ([], [])) + compilable_srcs, other_srcs = partition(srcs, Compilable) + + # CMake gets upset when executable targets provide no sources. + if target_type == 'executable' and not compilable_srcs and not extra_sources: + print ('Executable %s has no complilable sources, treating as "none".' % + target_name ) + target_type = 'none' + + cmake_target_type = cmake_target_type_from_gyp_target_type.get(target_type) + if cmake_target_type is None: + print ('Target %s has unknown target type %s, skipping.' % + ( target_name, target_type ) ) + return + + other_srcs_name = None + if other_srcs: + other_srcs_name = cmake_target_name + '__other_srcs' + SetVariableList(output, other_srcs_name, + [NormjoinPath(path_from_cmakelists_to_gyp, src) for src in other_srcs]) + + # CMake is opposed to setting linker directories and considers the practice + # of setting linker directories dangerous. Instead, it favors the use of + # find_library and passing absolute paths to target_link_libraries. + # However, CMake does provide the command link_directories, which adds + # link directories to targets defined after it is called. + # As a result, link_directories must come before the target definition. + # CMake unfortunately has no means of removing entries from LINK_DIRECTORIES. + library_dirs = config.get('library_dirs') + if library_dirs is not None: + output.write('link_directories(') + for library_dir in library_dirs: + output.write(' ') + output.write(NormjoinPath(path_from_cmakelists_to_gyp, library_dir)) + output.write('\n') + output.write(')\n') + + output.write(cmake_target_type.command) + output.write('(') + output.write(cmake_target_name) + + if cmake_target_type.modifier is not None: + output.write(' ') + output.write(cmake_target_type.modifier) + + if other_srcs_name: + WriteVariable(output, other_srcs_name, ' ') + + output.write('\n') + + for src in compilable_srcs: + output.write(' ') + output.write(NormjoinPath(path_from_cmakelists_to_gyp, src)) + output.write('\n') + for extra_source in extra_sources: + output.write(' ') + src, _ = extra_source + output.write(NormjoinPath(path_from_cmakelists_to_gyp, src)) + output.write('\n') + + output.write(')\n') + + # Output name and location. + if target_type != 'none': + # Mark uncompiled sources as uncompiled. + if other_srcs_name: + output.write('set_source_files_properties(') + WriteVariable(output, other_srcs_name, '') + output.write(' PROPERTIES HEADER_FILE_ONLY "TRUE")\n') + + # Output directory + target_output_directory = spec.get('product_dir') + if target_output_directory is None: + if target_type in ('executable', 'loadable_module'): + target_output_directory = generator_default_variables['PRODUCT_DIR'] + elif target_type in ('shared_library'): + target_output_directory = '${builddir}/lib.${TOOLSET}' + elif spec.get('standalone_static_library', False): + target_output_directory = generator_default_variables['PRODUCT_DIR'] + else: + base_path = gyp.common.RelativePath(os.path.dirname(gyp_file), + options.toplevel_dir) + target_output_directory = '${obj}.${TOOLSET}' + target_output_directory = ( + os.path.join(target_output_directory, base_path)) + + cmake_target_output_directory = NormjoinPathForceCMakeSource( + path_from_cmakelists_to_gyp, + target_output_directory) + SetTargetProperty(output, + cmake_target_name, + cmake_target_type.property_modifier + '_OUTPUT_DIRECTORY', + cmake_target_output_directory) + + # Output name + default_product_prefix = '' + default_product_name = target_name + default_product_ext = '' + if target_type == 'static_library': + static_library_prefix = generator_default_variables['STATIC_LIB_PREFIX'] + default_product_name = RemovePrefix(default_product_name, + static_library_prefix) + default_product_prefix = static_library_prefix + default_product_ext = generator_default_variables['STATIC_LIB_SUFFIX'] + + elif target_type in ('loadable_module', 'shared_library'): + shared_library_prefix = generator_default_variables['SHARED_LIB_PREFIX'] + default_product_name = RemovePrefix(default_product_name, + shared_library_prefix) + default_product_prefix = shared_library_prefix + default_product_ext = generator_default_variables['SHARED_LIB_SUFFIX'] + + elif target_type != 'executable': + print ('ERROR: What output file should be generated?', + 'type', target_type, 'target', target_name) + + product_prefix = spec.get('product_prefix', default_product_prefix) + product_name = spec.get('product_name', default_product_name) + product_ext = spec.get('product_extension') + if product_ext: + product_ext = '.' + product_ext + else: + product_ext = default_product_ext + + SetTargetProperty(output, cmake_target_name, 'PREFIX', product_prefix) + SetTargetProperty(output, cmake_target_name, + cmake_target_type.property_modifier + '_OUTPUT_NAME', + product_name) + SetTargetProperty(output, cmake_target_name, 'SUFFIX', product_ext) + + # Make the output of this target referenceable as a source. + cmake_target_output_basename = product_prefix + product_name + product_ext + cmake_target_output = os.path.join(cmake_target_output_directory, + cmake_target_output_basename) + SetFileProperty(output, cmake_target_output, 'GENERATED', ['TRUE'], '') + + # Let CMake know if the 'all' target should depend on this target. + exclude_from_all = ('TRUE' if qualified_target not in all_qualified_targets + else 'FALSE') + SetTargetProperty(output, cmake_target_name, + 'EXCLUDE_FROM_ALL', exclude_from_all) + for extra_target_name in extra_deps: + SetTargetProperty(output, extra_target_name, + 'EXCLUDE_FROM_ALL', exclude_from_all) + + # Includes + includes = config.get('include_dirs') + if includes: + # This (target include directories) is what requires CMake 2.8.8 + includes_name = cmake_target_name + '__include_dirs' + SetVariableList(output, includes_name, + [NormjoinPathForceCMakeSource(path_from_cmakelists_to_gyp, include) + for include in includes]) + output.write('set_property(TARGET ') + output.write(cmake_target_name) + output.write(' APPEND PROPERTY INCLUDE_DIRECTORIES ') + WriteVariable(output, includes_name, '') + output.write(')\n') + + # Defines + defines = config.get('defines') + if defines is not None: + SetTargetProperty(output, + cmake_target_name, + 'COMPILE_DEFINITIONS', + defines, + ';') + + # Compile Flags - http://www.cmake.org/Bug/view.php?id=6493 + # CMake currently does not have target C and CXX flags. + # So, instead of doing... + + # cflags_c = config.get('cflags_c') + # if cflags_c is not None: + # SetTargetProperty(output, cmake_target_name, + # 'C_COMPILE_FLAGS', cflags_c, ' ') + + # cflags_cc = config.get('cflags_cc') + # if cflags_cc is not None: + # SetTargetProperty(output, cmake_target_name, + # 'CXX_COMPILE_FLAGS', cflags_cc, ' ') + + # Instead we must... + s_sources = [] + c_sources = [] + cxx_sources = [] + for src in srcs: + _, ext = os.path.splitext(src) + src_type = COMPILABLE_EXTENSIONS.get(ext, None) + + if src_type == 's': + s_sources.append(NormjoinPath(path_from_cmakelists_to_gyp, src)) + + if src_type == 'cc': + c_sources.append(NormjoinPath(path_from_cmakelists_to_gyp, src)) + + if src_type == 'cxx': + cxx_sources.append(NormjoinPath(path_from_cmakelists_to_gyp, src)) + + for extra_source in extra_sources: + src, real_source = extra_source + _, ext = os.path.splitext(real_source) + src_type = COMPILABLE_EXTENSIONS.get(ext, None) + + if src_type == 's': + s_sources.append(NormjoinPath(path_from_cmakelists_to_gyp, src)) + + if src_type == 'cc': + c_sources.append(NormjoinPath(path_from_cmakelists_to_gyp, src)) + + if src_type == 'cxx': + cxx_sources.append(NormjoinPath(path_from_cmakelists_to_gyp, src)) + + cflags = config.get('cflags', []) + cflags_c = config.get('cflags_c', []) + cflags_cxx = config.get('cflags_cc', []) + if c_sources and not (s_sources or cxx_sources): + flags = [] + flags.extend(cflags) + flags.extend(cflags_c) + SetTargetProperty(output, cmake_target_name, 'COMPILE_FLAGS', flags, ' ') + + elif cxx_sources and not (s_sources or c_sources): + flags = [] + flags.extend(cflags) + flags.extend(cflags_cxx) + SetTargetProperty(output, cmake_target_name, 'COMPILE_FLAGS', flags, ' ') + + else: + if s_sources and cflags: + SetFilesProperty(output, s_sources, 'COMPILE_FLAGS', cflags, ' ') + + if c_sources and (cflags or cflags_c): + flags = [] + flags.extend(cflags) + flags.extend(cflags_c) + SetFilesProperty(output, c_sources, 'COMPILE_FLAGS', flags, ' ') + + if cxx_sources and (cflags or cflags_cxx): + flags = [] + flags.extend(cflags) + flags.extend(cflags_cxx) + SetFilesProperty(output, cxx_sources, 'COMPILE_FLAGS', flags, ' ') + + # Have assembly link as c if there are no other files + if not c_sources and not cxx_sources and s_sources: + SetTargetProperty(output, cmake_target_name, 'LINKER_LANGUAGE', ['C']) + + # Linker flags + ldflags = config.get('ldflags') + if ldflags is not None: + SetTargetProperty(output, cmake_target_name, 'LINK_FLAGS', ldflags, ' ') + + # Note on Dependencies and Libraries: + # CMake wants to handle link order, resolving the link line up front. + # Gyp does not retain or enforce specifying enough information to do so. + # So do as other gyp generators and use --start-group and --end-group. + # Give CMake as little information as possible so that it doesn't mess it up. + + # Dependencies + rawDeps = spec.get('dependencies', []) + + static_deps = [] + shared_deps = [] + other_deps = [] + for rawDep in rawDeps: + dep_cmake_name = namer.CreateCMakeTargetName(rawDep) + dep_spec = target_dicts.get(rawDep, {}) + dep_target_type = dep_spec.get('type', None) + + if dep_target_type == 'static_library': + static_deps.append(dep_cmake_name) + elif dep_target_type == 'shared_library': + shared_deps.append(dep_cmake_name) + else: + other_deps.append(dep_cmake_name) + + # ensure all external dependencies are complete before internal dependencies + # extra_deps currently only depend on their own deps, so otherwise run early + if static_deps or shared_deps or other_deps: + for extra_dep in extra_deps: + output.write('add_dependencies(') + output.write(extra_dep) + output.write('\n') + for deps in (static_deps, shared_deps, other_deps): + for dep in gyp.common.uniquer(deps): + output.write(' ') + output.write(dep) + output.write('\n') + output.write(')\n') + + linkable = target_type in ('executable', 'loadable_module', 'shared_library') + other_deps.extend(extra_deps) + if other_deps or (not linkable and (static_deps or shared_deps)): + output.write('add_dependencies(') + output.write(cmake_target_name) + output.write('\n') + for dep in gyp.common.uniquer(other_deps): + output.write(' ') + output.write(dep) + output.write('\n') + if not linkable: + for deps in (static_deps, shared_deps): + for lib_dep in gyp.common.uniquer(deps): + output.write(' ') + output.write(lib_dep) + output.write('\n') + output.write(')\n') + + # Libraries + if linkable: + external_libs = [lib for lib in spec.get('libraries', []) if len(lib) > 0] + if external_libs or static_deps or shared_deps: + output.write('target_link_libraries(') + output.write(cmake_target_name) + output.write('\n') + if static_deps: + write_group = circular_libs and len(static_deps) > 1 + if write_group: + output.write('-Wl,--start-group\n') + for dep in gyp.common.uniquer(static_deps): + output.write(' ') + output.write(dep) + output.write('\n') + if write_group: + output.write('-Wl,--end-group\n') + if shared_deps: + for dep in gyp.common.uniquer(shared_deps): + output.write(' ') + output.write(dep) + output.write('\n') + if external_libs: + for lib in gyp.common.uniquer(external_libs): + output.write(' ') + output.write(lib) + output.write('\n') + + output.write(')\n') + + UnsetVariable(output, 'TOOLSET') + UnsetVariable(output, 'TARGET') + + +def GenerateOutputForConfig(target_list, target_dicts, data, + params, config_to_use): + options = params['options'] + generator_flags = params['generator_flags'] + + # generator_dir: relative path from pwd to where make puts build files. + # Makes migrating from make to cmake easier, cmake doesn't put anything here. + # Each Gyp configuration creates a different CMakeLists.txt file + # to avoid incompatibilities between Gyp and CMake configurations. + generator_dir = os.path.relpath(options.generator_output or '.') + + # output_dir: relative path from generator_dir to the build directory. + output_dir = generator_flags.get('output_dir', 'out') + + # build_dir: relative path from source root to our output files. + # e.g. "out/Debug" + build_dir = os.path.normpath(os.path.join(generator_dir, + output_dir, + config_to_use)) + + toplevel_build = os.path.join(options.toplevel_dir, build_dir) + + output_file = os.path.join(toplevel_build, 'CMakeLists.txt') + EnsureDirectoryExists(output_file) + + output = open(output_file, 'w') + output.write('cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n') + output.write('cmake_policy(VERSION 2.8.8)\n') + + _, project_target, _ = gyp.common.ParseQualifiedTarget(target_list[-1]) + output.write('project(') + output.write(project_target) + output.write(')\n') + + SetVariable(output, 'configuration', config_to_use) + + # The following appears to be as-yet undocumented. + # http://public.kitware.com/Bug/view.php?id=8392 + output.write('enable_language(ASM)\n') + # ASM-ATT does not support .S files. + # output.write('enable_language(ASM-ATT)\n') + + SetVariable(output, 'builddir', '${CMAKE_BINARY_DIR}') + SetVariable(output, 'obj', '${builddir}/obj') + output.write('\n') + + # TODO: Undocumented/unsupported (the CMake Java generator depends on it). + # CMake by default names the object resulting from foo.c to be foo.c.o. + # Gyp traditionally names the object resulting from foo.c foo.o. + # This should be irrelevant, but some targets extract .o files from .a + # and depend on the name of the extracted .o files. + output.write('set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)\n') + output.write('set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)\n') + output.write('\n') + + namer = CMakeNamer(target_list) + + # The list of targets upon which the 'all' target should depend. + # CMake has it's own implicit 'all' target, one is not created explicitly. + all_qualified_targets = set() + for build_file in params['build_files']: + for qualified_target in gyp.common.AllTargets(target_list, + target_dicts, + os.path.normpath(build_file)): + all_qualified_targets.add(qualified_target) + + for qualified_target in target_list: + WriteTarget(namer, qualified_target, target_dicts, build_dir, config_to_use, + options, generator_flags, all_qualified_targets, output) + + output.close() + + +def PerformBuild(data, configurations, params): + options = params['options'] + generator_flags = params['generator_flags'] + + # generator_dir: relative path from pwd to where make puts build files. + # Makes migrating from make to cmake easier, cmake doesn't put anything here. + generator_dir = os.path.relpath(options.generator_output or '.') + + # output_dir: relative path from generator_dir to the build directory. + output_dir = generator_flags.get('output_dir', 'out') + + for config_name in configurations: + # build_dir: relative path from source root to our output files. + # e.g. "out/Debug" + build_dir = os.path.normpath(os.path.join(generator_dir, + output_dir, + config_name)) + arguments = ['cmake', '-G', 'Ninja'] + print 'Generating [%s]: %s' % (config_name, arguments) + subprocess.check_call(arguments, cwd=build_dir) + + arguments = ['ninja', '-C', build_dir] + print 'Building [%s]: %s' % (config_name, arguments) + subprocess.check_call(arguments) + + +def CallGenerateOutputForConfig(arglist): + # Ignore the interrupt signal so that the parent process catches it and + # kills all multiprocessing children. + signal.signal(signal.SIGINT, signal.SIG_IGN) + + target_list, target_dicts, data, params, config_name = arglist + GenerateOutputForConfig(target_list, target_dicts, data, params, config_name) + + +def GenerateOutput(target_list, target_dicts, data, params): + user_config = params.get('generator_flags', {}).get('config', None) + if user_config: + GenerateOutputForConfig(target_list, target_dicts, data, + params, user_config) + else: + config_names = target_dicts[target_list[0]]['configurations'].keys() + if params['parallel']: + try: + pool = multiprocessing.Pool(len(config_names)) + arglists = [] + for config_name in config_names: + arglists.append((target_list, target_dicts, data, + params, config_name)) + pool.map(CallGenerateOutputForConfig, arglists) + except KeyboardInterrupt, e: + pool.terminate() + raise e + else: + for config_name in config_names: + GenerateOutputForConfig(target_list, target_dicts, data, + params, config_name) diff --git a/pylib/gyp/generator/make.py b/pylib/gyp/generator/make.py index 7bef217f..d4078433 100644 --- a/pylib/gyp/generator/make.py +++ b/pylib/gyp/generator/make.py @@ -57,6 +57,7 @@ generator_wants_sorted_dependencies = False generator_additional_non_configuration_keys = [] generator_additional_path_sections = [] generator_extra_sources_for_rules = [] +generator_filelist_paths = None def CalculateVariables(default_variables, params): @@ -103,6 +104,18 @@ def CalculateGeneratorInputInfo(params): global generator_wants_sorted_dependencies generator_wants_sorted_dependencies = True + output_dir = params['options'].generator_output or \ + params['options'].toplevel_dir + builddir_name = generator_flags.get('output_dir', 'out') + qualified_out_dir = os.path.normpath(os.path.join( + output_dir, builddir_name, 'gypfiles')) + + global generator_filelist_paths + generator_filelist_paths = { + 'toplevel': params['options'].toplevel_dir, + 'qualified_out_dir': qualified_out_dir, + } + def ensure_directory_exists(path): dir = os.path.dirname(path) diff --git a/pylib/gyp/generator/msvs.py b/pylib/gyp/generator/msvs.py index 2f2c3cff..0287eb19 100644 --- a/pylib/gyp/generator/msvs.py +++ b/pylib/gyp/generator/msvs.py @@ -1412,6 +1412,11 @@ def _AdjustSourcesAndConvertToFilterHierarchy( sources = _ConvertSourcesToFilterHierarchy(sources, excluded=fully_excluded, list_excluded=list_excluded) + # Prune filters with a single child to flatten ugly directory structures + # such as ../../src/modules/module1 etc. + while len(sources) == 1 and isinstance(sources[0], MSVSProject.Filter): + sources = sources[0].contents + return sources, excluded_sources, excluded_idl diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py index 1d21d4db..a40c7fe2 100644 --- a/pylib/gyp/generator/ninja.py +++ b/pylib/gyp/generator/ninja.py @@ -814,15 +814,18 @@ class NinjaWriter: cflags_c = self.msvs_settings.GetCflagsC(config_name) cflags_cc = self.msvs_settings.GetCflagsCC(config_name) extra_defines = self.msvs_settings.GetComputedDefines(config_name) - pdbpath = self.msvs_settings.GetCompilerPdbName( + # See comment at cc_command for why there's two .pdb files. + pdbpath_c = pdbpath_cc = self.msvs_settings.GetCompilerPdbName( config_name, self.ExpandSpecial) - if not pdbpath: + if not pdbpath_c: obj = 'obj' if self.toolset != 'target': obj += '.' + self.toolset - pdbpath = os.path.normpath(os.path.join(obj, self.base_dir, - self.name + '.pdb')) - self.WriteVariableList(ninja_file, 'pdbname', [pdbpath]) + pdbpath = os.path.normpath(os.path.join(obj, self.base_dir, self.name)) + pdbpath_c = pdbpath + '.c.pdb' + pdbpath_cc = pdbpath + '.cc.pdb' + self.WriteVariableList(ninja_file, 'pdbname_c', [pdbpath_c]) + self.WriteVariableList(ninja_file, 'pdbname_cc', [pdbpath_cc]) self.WriteVariableList(ninja_file, 'pchprefix', [self.name]) else: cflags = config.get('cflags', []) @@ -1578,18 +1581,24 @@ def _GetWinLinkRuleNameSuffix(embed_manifest, link_incremental): def _AddWinLinkRules(master_ninja, embed_manifest, link_incremental): """Adds link rules for Windows platform to |master_ninja|.""" def FullLinkCommand(ldcmd, out, binary_type): - cmd = ('cmd /c %(ldcmd)s' - ' && %(python)s gyp-win-tool manifest-wrapper $arch' - ' cmd /c if exist %(out)s.manifest del %(out)s.manifest' - ' && %(python)s gyp-win-tool manifest-wrapper $arch' - ' $mt -nologo -manifest $manifests') + """Returns a one-liner written for cmd.exe to handle multiphase linker + operations including manifest file generation. The command will be + structured as follows: + cmd /c (linkcmd1 a b) && (linkcmd2 x y) && ... && + if not "$manifests"=="" ((manifestcmd1 a b) && (manifestcmd2 x y) && ... ) + Note that $manifests becomes empty when no manifest file is generated.""" + link_commands = ['%(ldcmd)s', + 'if exist %(out)s.manifest del %(out)s.manifest'] + mt_cmd = ('%(python)s gyp-win-tool manifest-wrapper' + ' $arch $mt -nologo -manifest $manifests') if embed_manifest and not link_incremental: # Embed manifest into a binary. If incremental linking is enabled, # embedding is postponed to the re-linking stage (see below). - cmd += ' -outputresource:%(out)s;%(resname)s' + mt_cmd += ' -outputresource:%(out)s;%(resname)s' else: # Save manifest as an external file. - cmd += ' -out:%(out)s.manifest' + mt_cmd += ' -out:%(out)s.manifest' + manifest_commands = [mt_cmd] if link_incremental: # There is no point in generating separate rule for the case when # incremental linking is enabled, but manifest embedding is disabled. @@ -1597,11 +1606,14 @@ def _AddWinLinkRules(master_ninja, embed_manifest, link_incremental): # See also implementation of _GetWinLinkRuleNameSuffix(). assert embed_manifest # Make .rc file out of manifest, compile it to .res file and re-link. - cmd += (' && %(python)s gyp-win-tool manifest-to-rc $arch' - ' %(out)s.manifest %(out)s.manifest.rc %(resname)s' - ' && %(python)s gyp-win-tool rc-wrapper $arch $rc' - ' %(out)s.manifest.rc' - ' && %(ldcmd)s %(out)s.manifest.res') + manifest_commands += [ + ('%(python)s gyp-win-tool manifest-to-rc $arch %(out)s.manifest' + ' %(out)s.manifest.rc %(resname)s'), + '%(python)s gyp-win-tool rc-wrapper $arch $rc %(out)s.manifest.rc', + '%(ldcmd)s %(out)s.manifest.res'] + cmd = 'cmd /c %s && if not "$manifests"=="" (%s)' % ( + ' && '.join(['(%s)' % c for c in link_commands]), + ' && '.join(['(%s)' % c for c in manifest_commands])) resource_name = { 'exe': '1', 'dll': '2', @@ -1797,14 +1809,20 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, depfile='$out.d', deps=deps) else: + # TODO(scottmg) Separate pdb names is a test to see if it works around + # http://crbug.com/142362. It seems there's a race between the creation of + # the .pdb by the precompiled header step for .cc and the compilation of + # .c files. This should be handled by mspdbsrv, but rarely errors out with + # c1xx : fatal error C1033: cannot open program database + # By making the rules target separate pdb files this might be avoided. cc_command = ('ninja -t msvc -e $arch ' + '-- ' '$cc /nologo /showIncludes /FC ' - '@$out.rsp /c $in /Fo$out /Fd$pdbname ') + '@$out.rsp /c $in /Fo$out /Fd$pdbname_c ') cxx_command = ('ninja -t msvc -e $arch ' + '-- ' '$cxx /nologo /showIncludes /FC ' - '@$out.rsp /c $in /Fo$out /Fd$pdbname ') + '@$out.rsp /c $in /Fo$out /Fd$pdbname_cc ') master_ninja.rule( 'cc', description='CC $out', diff --git a/pylib/gyp/mac_tool.py b/pylib/gyp/mac_tool.py index 20b3a486..c61a3ef6 100755 --- a/pylib/gyp/mac_tool.py +++ b/pylib/gyp/mac_tool.py @@ -9,6 +9,8 @@ These functions are executed via gyp-mac-tool when using the Makefile generator. """ import fcntl +import fnmatch +import glob import json import os import plistlib @@ -17,6 +19,7 @@ import shutil import string import subprocess import sys +import tempfile def main(args): @@ -259,6 +262,249 @@ class MacTool(object): os.remove(link) os.symlink(dest, link) + def ExecCodeSignBundle(self, key, resource_rules, entitlements, provisioning): + """Code sign a bundle. + + This function tries to code sign an iOS bundle, following the same + algorithm as Xcode: + 1. copy ResourceRules.plist from the user or the SDK into the bundle, + 2. pick the provisioning profile that best match the bundle identifier, + and copy it into the bundle as embedded.mobileprovision, + 3. copy Entitlements.plist from user or SDK next to the bundle, + 4. code sign the bundle. + """ + resource_rules_path = self._InstallResourceRules(resource_rules) + substitutions, overrides = self._InstallProvisioningProfile( + provisioning, self._GetCFBundleIdentifier()) + entitlements_path = self._InstallEntitlements( + entitlements, substitutions, overrides) + subprocess.check_call([ + 'codesign', '--force', '--sign', key, '--resource-rules', + resource_rules_path, '--entitlements', entitlements_path, + os.path.join( + os.environ['TARGET_BUILD_DIR'], + os.environ['FULL_PRODUCT_NAME'])]) + + def _InstallResourceRules(self, resource_rules): + """Installs ResourceRules.plist from user or SDK into the bundle. + + Args: + resource_rules: string, optional, path to the ResourceRules.plist file + to use, default to "${SDKROOT}/ResourceRules.plist" + + Returns: + Path to the copy of ResourceRules.plist into the bundle. + """ + source_path = resource_rules + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['CONTENTS_FOLDER_PATH'], + 'ResourceRules.plist') + if not source_path: + source_path = os.path.join( + os.environ['SDKROOT'], 'ResourceRules.plist') + shutil.copy2(source_path, target_path) + return target_path + + def _InstallProvisioningProfile(self, profile, bundle_identifier): + """Installs embedded.mobileprovision into the bundle. + + Args: + profile: string, optional, short name of the .mobileprovision file + to use, if empty or the file is missing, the best file installed + will be used + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + + Returns: + A tuple containing two dictionary: variables substitutions and values + to overrides when generating the entitlements file. + """ + source_path, provisioning_data, team_id = self._FindProvisioningProfile( + profile, bundle_identifier) + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['CONTENTS_FOLDER_PATH'], + 'embedded.mobileprovision') + shutil.copy2(source_path, target_path) + substitutions = self._GetSubstitutions(bundle_identifier, team_id + '.') + return substitutions, provisioning_data['Entitlements'] + + def _FindProvisioningProfile(self, profile, bundle_identifier): + """Finds the .mobileprovision file to use for signing the bundle. + + Checks all the installed provisioning profiles (or if the user specified + the PROVISIONING_PROFILE variable, only consult it) and select the most + specific that correspond to the bundle identifier. + + Args: + profile: string, optional, short name of the .mobileprovision file + to use, if empty or the file is missing, the best file installed + will be used + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + + Returns: + A tuple of the path to the selected provisioning profile, the data of + the embedded plist in the provisioning profile and the team identifier + to use for code signing. + + Raises: + SystemExit: if no .mobileprovision can be used to sign the bundle. + """ + profiles_dir = os.path.join( + os.environ['HOME'], 'Library', 'MobileDevice', 'Provisioning Profiles') + if not os.path.isdir(profiles_dir): + print >>sys.stderr, ( + 'cannot find mobile provisioning for %s' % bundle_identifier) + sys.exit(1) + provisioning_profiles = None + if profile: + profile_path = os.path.join(profiles_dir, profile + '.mobileprovision') + if os.path.exists(profile_path): + provisioning_profiles = [profile_path] + if not provisioning_profiles: + provisioning_profiles = glob.glob( + os.path.join(profiles_dir, '*.mobileprovision')) + valid_provisioning_profiles = {} + for profile_path in provisioning_profiles: + profile_data = self._LoadProvisioningProfile(profile_path) + app_id_pattern = profile_data.get( + 'Entitlements', {}).get('application-identifier', '') + for team_identifier in profile_data.get('TeamIdentifier', []): + app_id = '%s.%s' % (team_identifier, bundle_identifier) + if fnmatch.fnmatch(app_id, app_id_pattern): + valid_provisioning_profiles[app_id_pattern] = ( + profile_path, profile_data, team_identifier) + if not valid_provisioning_profiles: + print >>sys.stderr, ( + 'cannot find mobile provisioning for %s' % bundle_identifier) + sys.exit(1) + # If the user has multiple provisioning profiles installed that can be + # used for ${bundle_identifier}, pick the most specific one (ie. the + # provisioning profile whose pattern is the longest). + selected_key = max(valid_provisioning_profiles, key=lambda v: len(v)) + return valid_provisioning_profiles[selected_key] + + def _LoadProvisioningProfile(self, profile_path): + """Extracts the plist embedded in a provisioning profile. + + Args: + profile_path: string, path to the .mobileprovision file + + Returns: + Content of the plist embedded in the provisioning profile as a dictionary. + """ + with tempfile.NamedTemporaryFile() as temp: + subprocess.check_call([ + 'security', 'cms', '-D', '-i', profile_path, '-o', temp.name]) + return self._LoadPlistMaybeBinary(temp.name) + + def _LoadPlistMaybeBinary(self, plist_path): + """Loads into a memory a plist possibly encoded in binary format. + + This is a wrapper around plistlib.readPlist that tries to convert the + plist to the XML format if it can't be parsed (assuming that it is in + the binary format). + + Args: + plist_path: string, path to a plist file, in XML or binary format + + Returns: + Content of the plist as a dictionary. + """ + try: + # First, try to read the file using plistlib that only supports XML, + # and if an exception is raised, convert a temporary copy to XML and + # load that copy. + return plistlib.readPlist(plist_path) + except: + pass + with tempfile.NamedTemporaryFile() as temp: + shutil.copy2(plist_path, temp.name) + subprocess.check_call(['plutil', '-convert', 'xml1', temp.name]) + return plistlib.readPlist(temp.name) + + def _GetSubstitutions(self, bundle_identifier, app_identifier_prefix): + """Constructs a dictionary of variable substitutions for Entitlements.plist. + + Args: + bundle_identifier: string, value of CFBundleIdentifier from Info.plist + app_identifier_prefix: string, value for AppIdentifierPrefix + + Returns: + Dictionary of substitutions to apply when generating Entitlements.plist. + """ + return { + 'CFBundleIdentifier': bundle_identifier, + 'AppIdentifierPrefix': app_identifier_prefix, + } + + def _GetCFBundleIdentifier(self): + """Extracts CFBundleIdentifier value from Info.plist in the bundle. + + Returns: + Value of CFBundleIdentifier in the Info.plist located in the bundle. + """ + info_plist_path = os.path.join( + os.environ['TARGET_BUILD_DIR'], + os.environ['INFOPLIST_PATH']) + info_plist_data = self._LoadPlistMaybeBinary(info_plist_path) + return info_plist_data['CFBundleIdentifier'] + + def _InstallEntitlements(self, entitlements, substitutions, overrides): + """Generates and install the ${BundleName}.xcent entitlements file. + + Expands variables "$(variable)" pattern in the source entitlements file, + add extra entitlements defined in the .mobileprovision file and the copy + the generated plist to "${BundlePath}.xcent". + + Args: + entitlements: string, optional, path to the Entitlements.plist template + to use, defaults to "${SDKROOT}/Entitlements.plist" + substitutions: dictionary, variable substitutions + overrides: dictionary, values to add to the entitlements + + Returns: + Path to the generated entitlements file. + """ + source_path = entitlements + target_path = os.path.join( + os.environ['BUILT_PRODUCTS_DIR'], + os.environ['PRODUCT_NAME'] + '.xcent') + if not source_path: + source_path = os.path.join( + os.environ['SDKROOT'], + 'Entitlements.plist') + shutil.copy2(source_path, target_path) + data = self._LoadPlistMaybeBinary(target_path) + data = self._ExpandVariables(data, substitutions) + if overrides: + for key in overrides: + if key not in data: + data[key] = overrides[key] + plistlib.writePlist(data, target_path) + return target_path + + def _ExpandVariables(self, data, substitutions): + """Expands variables "$(variable)" in data. + + Args: + data: object, can be either string, list or dictionary + substitutions: dictionary, variable substitutions to perform + + Returns: + Copy of data where each references to "$(variable)" has been replaced + by the corresponding value found in substitutions, or left intact if + the key was not found. + """ + if isinstance(data, str): + for key, value in substitutions.iteritems(): + data = data.replace('$(%s)' % key, value) + return data + if isinstance(data, list): + return [self._ExpandVariables(v, substitutions) for v in data] + if isinstance(data, dict): + return {k: self._ExpandVariables(data[k], substitutions) for k in data} + return data if __name__ == '__main__': sys.exit(main(sys.argv[1:])) diff --git a/pylib/gyp/msvs_emulation.py b/pylib/gyp/msvs_emulation.py index 9ea86dbd..723201eb 100644 --- a/pylib/gyp/msvs_emulation.py +++ b/pylib/gyp/msvs_emulation.py @@ -442,6 +442,17 @@ class MsvsSettings(object): if def_file: ldflags.append('/DEF:"%s"' % def_file) + def GetPGDName(self, config, expand_special): + """Gets the explicitly overridden pgd name for a target or returns None + if it's not overridden.""" + config = self._TargetConfig(config) + output_file = self._Setting( + ('VCLinkerTool', 'ProfileGuidedDatabase'), config) + if output_file: + output_file = expand_special(self.ConvertVSMacros( + output_file, config=config)) + return output_file + def GetLdflags(self, config, gyp_to_build_path, expand_special, manifest_base_name, is_executable): """Returns the flags that need to be added to link commands, and the @@ -456,12 +467,17 @@ class MsvsSettings(object): ldflags.extend(self._GetAdditionalLibraryDirectories( 'VCLinkerTool', config, gyp_to_build_path)) ld('DelayLoadDLLs', prefix='/DELAYLOAD:') + ld('TreatLinkerWarningAsErrors', prefix='/WX', + map={'true': '', 'false': ':NO'}) out = self.GetOutputName(config, expand_special) if out: ldflags.append('/OUT:' + out) pdb = self.GetPDBName(config, expand_special) if pdb: ldflags.append('/PDB:' + pdb) + pgd = self.GetPGDName(config, expand_special) + if pgd: + ldflags.append('/PGD:' + pgd) map_file = self.GetMapFileName(config, expand_special) ld('GenerateMapFile', map={'true': '/MAP:' + map_file if map_file else '/MAP'}) @@ -487,7 +503,10 @@ class MsvsSettings(object): map={'1': ':NO', '2': ''}, prefix='/NXCOMPAT') ld('OptimizeReferences', map={'1': 'NOREF', '2': 'REF'}, prefix='/OPT:') ld('EnableCOMDATFolding', map={'1': 'NOICF', '2': 'ICF'}, prefix='/OPT:') - ld('LinkTimeCodeGeneration', map={'1': '/LTCG'}) + ld('LinkTimeCodeGeneration', + map={'1': '', '2': ':PGINSTRUMENT', '3': ':PGOPTIMIZE', + '4': ':PGUPDATE'}, + prefix='/LTCG') ld('IgnoreDefaultLibraryNames', prefix='/NODEFAULTLIB:') ld('ResourceOnlyDLL', map={'true': '/NOENTRY'}) ld('EntryPointSymbol', prefix='/ENTRY:') @@ -512,18 +531,26 @@ class MsvsSettings(object): ldflags.append('/NXCOMPAT') have_def_file = filter(lambda x: x.startswith('/DEF:'), ldflags) - manifest_flags, intermediate_manifest_file = self._GetLdManifestFlags( - config, manifest_base_name, is_executable and not have_def_file) + manifest_flags, manifest_files = self._GetLdManifestFlags( + config, manifest_base_name, gyp_to_build_path, + is_executable and not have_def_file) ldflags.extend(manifest_flags) - manifest_files = self._GetAdditionalManifestFiles(config, gyp_to_build_path) - manifest_files.append(intermediate_manifest_file) - return ldflags, manifest_files - def _GetLdManifestFlags(self, config, name, allow_isolation): + def _GetLdManifestFlags(self, config, name, gyp_to_build_path, + allow_isolation): """Returns the set of flags that need to be added to the link to generate - a default manifest, as well as the name of the generated file.""" - # The manifest is generated by default. + a default manifest, as well as the list of all the manifest files to be + merged by the manifest tool.""" + generate_manifest = self._Setting(('VCLinkerTool', 'GenerateManifest'), + config, + default='true') + if generate_manifest != 'true': + # This means not only that the linker should not generate the intermediate + # manifest but also that the manifest tool should do nothing even when + # additional manifests are specified. + return ['/MANIFEST:NO'], [] + output_name = name + '.intermediate.manifest' flags = [ '/MANIFEST', @@ -551,7 +578,11 @@ class MsvsSettings(object): if allow_isolation: flags.append('/ALLOWISOLATION') - return flags, output_name + + manifest_files = [output_name] + manifest_files += self._GetAdditionalManifestFiles(config, + gyp_to_build_path) + return flags, manifest_files def _GetAdditionalManifestFiles(self, config, gyp_to_build_path): """Gets additional manifest files that are added to the default one diff --git a/pylib/gyp/win_tool.py b/pylib/gyp/win_tool.py index 3424c015..7f3b0a54 100755 --- a/pylib/gyp/win_tool.py +++ b/pylib/gyp/win_tool.py @@ -10,12 +10,16 @@ These functions are executed via gyp-win-tool when using the ninja generator. """ import os +import re import shutil import subprocess import sys BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +# A regex matching an argument corresponding to a PDB filename passed as an +# argument to link.exe. +_LINK_EXE_PDB_ARG = re.compile('/PDB:(?P<pdb>.+\.exe\.pdb)$', re.IGNORECASE) def main(args): executor = WinTool() @@ -28,6 +32,35 @@ class WinTool(object): """This class performs all the Windows tooling steps. The methods can either be executed directly, or dispatched from an argument list.""" + def _MaybeUseSeparateMspdbsrv(self, env, args): + """Allows to use a unique instance of mspdbsrv.exe for the linkers linking + an .exe target if GYP_USE_SEPARATE_MSPDBSRV has been set.""" + if not os.environ.get('GYP_USE_SEPARATE_MSPDBSRV'): + return + + if len(args) < 1: + raise Exception("Not enough arguments") + + if args[0] != 'link.exe': + return + + # Checks if this linker produces a PDB for an .exe target. If so use the + # name of this PDB to generate an endpoint name for mspdbsrv.exe. + endpoint_name = None + for arg in args: + m = _LINK_EXE_PDB_ARG.match(arg) + if m: + endpoint_name = '%s_%d' % (m.group('pdb'), os.getpid()) + break + + if endpoint_name is None: + return + + # Adds the appropriate environment variable. This will be read by link.exe + # to know which instance of mspdbsrv.exe it should connect to (if it's + # not set then the default endpoint is used). + env['_MSPDBSRV_ENDPOINT_'] = endpoint_name + def Dispatch(self, args): """Dispatches a string command to a method.""" if len(args) < 1: @@ -71,13 +104,17 @@ class WinTool(object): This happens when there are exports from the dll or exe. """ env = self._GetEnv(arch) - popen = subprocess.Popen(args, shell=True, env=env, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - out, _ = popen.communicate() + self._MaybeUseSeparateMspdbsrv(env, args) + link = subprocess.Popen(args, + shell=True, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + out, _ = link.communicate() for line in out.splitlines(): if not line.startswith(' Creating library '): print line - return popen.returncode + return link.returncode def ExecManifestWrapper(self, arch, *args): """Run manifest tool with environment set. Strip out undesirable warning @@ -168,9 +205,7 @@ class WinTool(object): env = self._GetEnv(arch) args = open(rspfile).read() dir = dir[0] if dir else None - popen = subprocess.Popen(args, shell=True, env=env, cwd=dir) - popen.wait() - return popen.returncode + return subprocess.call(args, shell=True, env=env, cwd=dir) if __name__ == '__main__': sys.exit(main(sys.argv[1:])) diff --git a/pylib/gyp/xcode_emulation.py b/pylib/gyp/xcode_emulation.py index 8070bb89..5e50f10d 100644 --- a/pylib/gyp/xcode_emulation.py +++ b/pylib/gyp/xcode_emulation.py @@ -9,11 +9,13 @@ other build systems, such as make and ninja. import copy import gyp.common +import os import os.path import re import shlex import subprocess import sys +import tempfile from gyp.common import GypError class XcodeSettings(object): @@ -784,33 +786,38 @@ class XcodeSettings(object): if not (self.isIOS and self.spec['type'] == "executable"): return [] - identity = self.xcode_settings[configname].get('CODE_SIGN_IDENTITY', '') - if identity == '': + settings = self.xcode_settings[configname] + key = self._GetIOSCodeSignIdentityKey(settings) + if not key: return [] + + # Warn for any unimplemented signing xcode keys. + unimpl = ['OTHER_CODE_SIGN_FLAGS'] + unimpl = set(unimpl) & set(self.xcode_settings[configname].keys()) + if unimpl: + print 'Warning: Some codesign keys not implemented, ignoring: %s' % ( + ', '.join(sorted(unimpl))) + + return ['%s code-sign-bundle "%s" "%s" "%s" "%s"' % ( + os.path.join('${TARGET_BUILD_DIR}', 'gyp-mac-tool'), key, + settings.get('CODE_SIGN_RESOURCE_RULES_PATH', ''), + settings.get('CODE_SIGN_ENTITLEMENTS', ''), + settings.get('PROVISIONING_PROFILE', '')) + ] + + def _GetIOSCodeSignIdentityKey(self, settings): + identity = settings.get('CODE_SIGN_IDENTITY') + if not identity: + return None if identity not in XcodeSettings._codesigning_key_cache: - proc = subprocess.Popen(['security', 'find-identity', '-p', 'codesigning', - '-v'], stdout=subprocess.PIPE) - output = proc.communicate()[0].strip() - key = None - for item in output.split("\n"): - if identity in item: - assert key == None, ( - "Multiple codesigning identities for identity: %s" % - identity) - key = item.split(' ')[1] - XcodeSettings._codesigning_key_cache[identity] = key - key = XcodeSettings._codesigning_key_cache[identity] - if key: - # Warn for any unimplemented signing xcode keys. - unimpl = ['CODE_SIGN_RESOURCE_RULES_PATH', 'OTHER_CODE_SIGN_FLAGS', - 'CODE_SIGN_ENTITLEMENTS'] - keys = set(self.xcode_settings[configname].keys()) - unimpl = set(unimpl) & keys - if unimpl: - print 'Warning: Some codesign keys not implemented, ignoring:', \ - ' '.join(unimpl) - return ['codesign --force --sign %s %s' % (key, output_binary)] - return [] + output = subprocess.check_output( + ['security', 'find-identity', '-p', 'codesigning', '-v']) + for line in output.splitlines(): + if identity in line: + assert identity not in XcodeSettings._codesigning_key_cache, ( + "Multiple codesigning identities for identity: %s" % identity) + XcodeSettings._codesigning_key_cache[identity] = line.split()[1] + return XcodeSettings._codesigning_key_cache.get(identity, '') def AddImplicitPostbuilds(self, configname, output, output_binary, postbuilds=[], quiet=False): @@ -903,8 +910,23 @@ class XcodeSettings(object): return items def _DefaultArch(self): - # The default value for ARCHS changed from ['i386'] to ['x86_64'] in - # Xcode 5. + # For Mac projects, Xcode changed the default value used when ARCHS is not + # set from "i386" to "x86_64". + # + # For iOS projects, if ARCHS is unset, it defaults to "armv7 armv7s" when + # building for a device, and the simulator binaries are always build for + # "i386". + # + # For new projects, ARCHS is set to $(ARCHS_STANDARD_INCLUDING_64_BIT), + # which correspond to "armv7 armv7s arm64", and when building the simulator + # the architecture is either "i386" or "x86_64" depending on the simulated + # device (respectively 32-bit or 64-bit device). + # + # Since the value returned by this function is only used when ARCHS is not + # set, then on iOS we return "i386", as the default xcode project generator + # does not set ARCHS if it is not set in the .gyp file. + if self.isIOS: + return 'i386' version, build = self._XcodeVersion() if version >= '0500': return 'x86_64' diff --git a/test/additional-targets/gyptest-additional.py b/test/additional-targets/gyptest-additional.py index e56e8a9b..a9bd4027 100755 --- a/test/additional-targets/gyptest-additional.py +++ b/test/additional-targets/gyptest-additional.py @@ -33,7 +33,7 @@ test.built_file_must_not_exist('foolib1', chdir=chdir) # TODO(mmoss) Make consistent with msvs, with 'dir1' before 'out/Default'? -if test.format in ('make', 'ninja', 'android'): +if test.format in ('make', 'ninja', 'android', 'cmake'): chdir='relocate/src' else: chdir='relocate/src/dir1' diff --git a/test/builddir/gyptest-all.py b/test/builddir/gyptest-all.py index b8a6dbdd..f7294b57 100755 --- a/test/builddir/gyptest-all.py +++ b/test/builddir/gyptest-all.py @@ -23,9 +23,8 @@ import TestGyp # its sources. I'm not sure if make is wrong for writing outside the current # directory, or if the test is wrong for assuming everything generated is under # the current directory. -# Android does not support setting the build directory. -# Ninja does not support relocation. -test = TestGyp.TestGyp(formats=['!make', '!ninja', '!android']) +# Android, Ninja, and CMake do not support setting the build directory. +test = TestGyp.TestGyp(formats=['!make', '!ninja', '!android', '!cmake']) test.run_gyp('prog1.gyp', '--depth=..', chdir='src') if test.format == 'msvs': diff --git a/test/builddir/gyptest-default.py b/test/builddir/gyptest-default.py index 53cdfd9b..1b47443f 100755 --- a/test/builddir/gyptest-default.py +++ b/test/builddir/gyptest-default.py @@ -23,9 +23,8 @@ import TestGyp # its sources. I'm not sure if make is wrong for writing outside the current # directory, or if the test is wrong for assuming everything generated is under # the current directory. -# Android does not support setting the build directory. -# Ninja does not support relocation. -test = TestGyp.TestGyp(formats=['!make', '!ninja', '!android']) +# Android, Ninja, and CMake do not support setting the build directory. +test = TestGyp.TestGyp(formats=['!make', '!ninja', '!android', '!cmake']) test.run_gyp('prog1.gyp', '--depth=..', chdir='src') if test.format == 'msvs': diff --git a/test/defines/gyptest-define-override.py b/test/defines/gyptest-define-override.py index 82e325af..9730455b 100755 --- a/test/defines/gyptest-define-override.py +++ b/test/defines/gyptest-define-override.py @@ -13,22 +13,31 @@ import TestGyp test = TestGyp.TestGyp() +# CMake loudly warns about passing '#' to the compiler and drops the define. +expect_stderr = '' +if test.format == 'cmake': + expect_stderr = ( +"""WARNING: Preprocessor definitions containing '#' may not be passed on the""" +""" compiler command line because many compilers do not support it.\n""" +"""CMake is dropping a preprocessor definition: HASH_VALUE="a#1"\n""" +"""Consider defining the macro in a (configured) header file.\n\n""") + # Command-line define test.run_gyp('defines.gyp', '-D', 'OS=fakeos') -test.build('defines.gyp') +test.build('defines.gyp', stderr=expect_stderr) test.built_file_must_exist('fakeosprogram', type=test.EXECUTABLE) # Clean up the exe so subsequent tests don't find an old exe. os.remove(test.built_file_path('fakeosprogram', type=test.EXECUTABLE)) # Without "OS" override, fokeosprogram shouldn't be built. test.run_gyp('defines.gyp') -test.build('defines.gyp') +test.build('defines.gyp', stderr=expect_stderr) test.built_file_must_not_exist('fakeosprogram', type=test.EXECUTABLE) # Environment define os.environ['GYP_DEFINES'] = 'OS=fakeos' test.run_gyp('defines.gyp') -test.build('defines.gyp') +test.build('defines.gyp', stderr=expect_stderr) test.built_file_must_exist('fakeosprogram', type=test.EXECUTABLE) test.pass_test() diff --git a/test/defines/gyptest-defines.py b/test/defines/gyptest-defines.py index 33e50f8c..77a3af53 100755 --- a/test/defines/gyptest-defines.py +++ b/test/defines/gyptest-defines.py @@ -14,14 +14,26 @@ test = TestGyp.TestGyp() test.run_gyp('defines.gyp') -test.build('defines.gyp') - expect = """\ FOO is defined VALUE is 1 2*PAREN_VALUE is 12 -HASH_VALUE is a#1 """ + +#CMake loudly warns about passing '#' to the compiler and drops the define. +expect_stderr = '' +if test.format == 'cmake': + expect_stderr = ( +"""WARNING: Preprocessor definitions containing '#' may not be passed on the""" +""" compiler command line because many compilers do not support it.\n""" +"""CMake is dropping a preprocessor definition: HASH_VALUE="a#1"\n""" +"""Consider defining the macro in a (configured) header file.\n\n""") +else: + expect += """HASH_VALUE is a#1 +""" + +test.build('defines.gyp', stderr=expect_stderr) + test.run_built_executable('defines', stdout=expect) test.pass_test() diff --git a/test/generator-output/gyptest-copies.py b/test/generator-output/gyptest-copies.py index 33c5a3b5..7524b17e 100755 --- a/test/generator-output/gyptest-copies.py +++ b/test/generator-output/gyptest-copies.py @@ -12,8 +12,7 @@ target of 'all'. import TestGyp # Android doesn't support --generator-output. -# Ninja doesn't support relocation. -test = TestGyp.TestGyp(formats=['!ninja', '!android']) +test = TestGyp.TestGyp(formats=['!android']) test.writable(test.workpath('copies'), False) @@ -40,7 +39,7 @@ test.must_match(['relocate', 'copies', 'copies-out', 'file1'], if test.format == 'xcode': chdir = 'relocate/copies/build' -elif test.format == 'make': +elif test.format in ['make', 'ninja', 'cmake']: chdir = 'relocate/gypfiles/out' else: chdir = 'relocate/gypfiles' @@ -51,7 +50,7 @@ test.must_match(['relocate', 'copies', 'subdir', 'copies-out', 'file3'], if test.format == 'xcode': chdir = 'relocate/copies/subdir/build' -elif test.format == 'make': +elif test.format in ['make', 'ninja', 'cmake']: chdir = 'relocate/gypfiles/out' else: chdir = 'relocate/gypfiles' diff --git a/test/ios/app-bundle/TestApp/only-compile-in-32-bits.m b/test/ios/app-bundle/TestApp/only-compile-in-32-bits.m new file mode 100644 index 00000000..28bb1177 --- /dev/null +++ b/test/ios/app-bundle/TestApp/only-compile-in-32-bits.m @@ -0,0 +1,7 @@ +// Copyright (c) 2013 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. + +#if defined(__LP64__) +# error 64-bit build +#endif diff --git a/test/ios/app-bundle/TestApp/only-compile-in-64-bits.m b/test/ios/app-bundle/TestApp/only-compile-in-64-bits.m new file mode 100644 index 00000000..e6d25584 --- /dev/null +++ b/test/ios/app-bundle/TestApp/only-compile-in-64-bits.m @@ -0,0 +1,7 @@ +// Copyright (c) 2013 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. + +#if !defined(__LP64__) +# error 32-bit build +#endif diff --git a/test/ios/app-bundle/test-archs.gyp b/test/ios/app-bundle/test-archs.gyp new file mode 100644 index 00000000..761fd6b1 --- /dev/null +++ b/test/ios/app-bundle/test-archs.gyp @@ -0,0 +1,105 @@ +# Copyright (c) 2013 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. +{ + 'make_global_settings': [ + ['CC', '/usr/bin/clang'], + ], + 'targets': [ + { + 'target_name': 'test_no_archs', + 'product_name': 'Test No Archs', + 'type': 'executable', + 'product_extension': 'bundle', + 'mac_bundle': 1, + 'sources': [ + 'TestApp/main.m', + 'TestApp/only-compile-in-32-bits.m', + ], + 'mac_bundle_resources': [ + 'TestApp/English.lproj/InfoPlist.strings', + 'TestApp/English.lproj/MainMenu.xib', + ], + 'link_settings': { + 'libraries': [ + '$(SDKROOT)/System/Library/Frameworks/Foundation.framework', + '$(SDKROOT)/System/Library/Frameworks/UIKit.framework', + ], + }, + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-fobjc-abi-version=2', + ], + 'SDKROOT': 'iphonesimulator', # -isysroot + 'TARGETED_DEVICE_FAMILY': '1,2', + 'INFOPLIST_FILE': 'TestApp/TestApp-Info.plist', + 'IPHONEOS_DEPLOYMENT_TARGET': '7.0', + 'CONFIGURATION_BUILD_DIR':'build/Default', + }, + }, + { + 'target_name': 'test_archs_i386', + 'product_name': 'Test Archs i386', + 'type': 'executable', + 'product_extension': 'bundle', + 'mac_bundle': 1, + 'sources': [ + 'TestApp/main.m', + 'TestApp/only-compile-in-32-bits.m', + ], + 'mac_bundle_resources': [ + 'TestApp/English.lproj/InfoPlist.strings', + 'TestApp/English.lproj/MainMenu.xib', + ], + 'link_settings': { + 'libraries': [ + '$(SDKROOT)/System/Library/Frameworks/Foundation.framework', + '$(SDKROOT)/System/Library/Frameworks/UIKit.framework', + ], + }, + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-fobjc-abi-version=2', + ], + 'SDKROOT': 'iphonesimulator', # -isysroot + 'TARGETED_DEVICE_FAMILY': '1,2', + 'INFOPLIST_FILE': 'TestApp/TestApp-Info.plist', + 'IPHONEOS_DEPLOYMENT_TARGET': '7.0', + 'CONFIGURATION_BUILD_DIR':'build/Default', + 'ARCHS': ['i386'], + }, + }, + { + 'target_name': 'test_archs_x86_64', + 'product_name': 'Test Archs x86_64', + 'type': 'executable', + 'product_extension': 'bundle', + 'mac_bundle': 1, + 'sources': [ + 'TestApp/main.m', + 'TestApp/only-compile-in-64-bits.m', + ], + 'mac_bundle_resources': [ + 'TestApp/English.lproj/InfoPlist.strings', + 'TestApp/English.lproj/MainMenu.xib', + ], + 'link_settings': { + 'libraries': [ + '$(SDKROOT)/System/Library/Frameworks/Foundation.framework', + '$(SDKROOT)/System/Library/Frameworks/UIKit.framework', + ], + }, + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-fobjc-abi-version=2', + ], + 'SDKROOT': 'iphonesimulator', # -isysroot + 'TARGETED_DEVICE_FAMILY': '1,2', + 'INFOPLIST_FILE': 'TestApp/TestApp-Info.plist', + 'IPHONEOS_DEPLOYMENT_TARGET': '7.0', + 'CONFIGURATION_BUILD_DIR':'build/Default', + 'ARCHS': ['x86_64'], + }, + }, + ], +} diff --git a/test/ios/gyptest-archs.py b/test/ios/gyptest-archs.py new file mode 100644 index 00000000..87d0657d --- /dev/null +++ b/test/ios/gyptest-archs.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python + +# Copyright (c) 2013 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 device and simulator bundles are built correctly. +""" + +import plistlib +import TestGyp +import os +import struct +import subprocess +import sys +import tempfile + + +def CheckFileType(file, expected): + proc = subprocess.Popen(['lipo', '-info', file], stdout=subprocess.PIPE) + o = proc.communicate()[0].strip() + assert not proc.returncode + if not expected in o: + print 'File: Expected %s, got %s' % (expected, o) + test.fail_test() + + +def XcodeVersion(): + xcode, build = GetStdout(['xcodebuild', '-version']).splitlines() + xcode = xcode.split()[-1].replace('.', '') + xcode = (xcode + '0' * (3 - len(xcode))).zfill(4) + return xcode + + +def GetStdout(cmdlist): + proc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE) + o = proc.communicate()[0].strip() + assert not proc.returncode + return o + + +if sys.platform == 'darwin': + test = TestGyp.TestGyp() + + test.run_gyp('test-archs.gyp', chdir='app-bundle') + test.set_configuration('Default') + + # TODO(sdefresne): add 'Test Archs x86_64' once bots have been updated to + # a SDK version that supports "x86_64" architecture. + filenames = ['Test No Archs', 'Test Archs i386'] + if XcodeVersion() >= '0500': + filenames.append('Test Archs x86_64') + + for filename in filenames: + target = filename.replace(' ', '_').lower() + test.build('test-archs.gyp', target, chdir='app-bundle') + result_file = test.built_file_path( + '%s.bundle/%s' % (filename, filename), chdir='app-bundle') + test.must_exist(result_file) + + expected = 'i386' + if 'x86_64' in filename: + expected = 'x86_64' + CheckFileType(result_file, expected) + + test.pass_test() diff --git a/test/ios/gyptest-per-config-settings.py b/test/ios/gyptest-per-config-settings.py index 20913294..d15907e7 100644 --- a/test/ios/gyptest-per-config-settings.py +++ b/test/ios/gyptest-per-config-settings.py @@ -10,8 +10,11 @@ Verifies that device and simulator bundles are built correctly. import plistlib import TestGyp +import os +import struct import subprocess import sys +import tempfile def CheckFileType(file, expected): @@ -37,6 +40,29 @@ def CheckSignature(file): print 'File %s not properly signed.' % (file) test.fail_test() +def CheckEntitlements(file, expected_entitlements): + with tempfile.NamedTemporaryFile() as temp: + proc = subprocess.Popen(['codesign', '--display', '--entitlements', + temp.name, file], stdout=subprocess.PIPE) + o = proc.communicate()[0].strip() + assert not proc.returncode + data = temp.read() + entitlements = ParseEntitlements(data) + if not entitlements: + print 'No valid entitlements found in %s.' % (file) + test.fail_test() + if entitlements != expected_entitlements: + print 'Unexpected entitlements found in %s.' % (file) + test.fail_test() + +def ParseEntitlements(data): + if len(data) < 8: + return None + magic, length = struct.unpack('>II', data[:8]) + if magic != 0xfade7171 or length != len(data): + return None + return data[8:] + def GetProductVersion(): args = ['xcodebuild','-version','-sdk','iphoneos','ProductVersion'] job = subprocess.Popen(args, stdout=subprocess.PIPE) @@ -104,7 +130,7 @@ if sys.platform == 'darwin': if HasCerts() and configuration == 'Default-iphoneos': test.build('test-device.gyp', 'sig_test', chdir='app-bundle') result_file = test.built_file_path('sig_test.bundle/sig_test', - chdir='app-bundle') + chdir='app-bundle') CheckSignature(result_file) info_plist = test.built_file_path('sig_test.bundle/Info.plist', chdir='app-bundle') @@ -112,4 +138,10 @@ if sys.platform == 'darwin': plist = plistlib.readPlist(info_plist) CheckPlistvalue(plist, 'UIDeviceFamily', [1]) + entitlements_file = test.built_file_path('sig_test.xcent', + chdir='app-bundle') + if os.path.isfile(entitlements_file): + expected_entitlements = open(entitlements_file).read() + CheckEntitlements(result_file, expected_entitlements) + test.pass_test() diff --git a/test/lib/TestGyp.py b/test/lib/TestGyp.py index dfb54f4e..306bf3d3 100644 --- a/test/lib/TestGyp.py +++ b/test/lib/TestGyp.py @@ -6,6 +6,8 @@ TestGyp.py: a testing framework for GYP integration tests. """ +import collections +import itertools import os import re import shutil @@ -532,6 +534,108 @@ class TestGypAndroid(TestGypBase): kw['match'] = self.match_single_line return self.build(gyp_file, target, **kw) + +class TestGypCMake(TestGypBase): + """ + Subclass for testing the GYP CMake generator, using cmake's ninja backend. + """ + format = 'cmake' + build_tool_list = ['cmake'] + ALL = 'all' + + def cmake_build(self, gyp_file, target=None, **kw): + arguments = kw.get('arguments', [])[:] + + self.build_tool_list = ['cmake'] + self.initialize_build_tool() + + chdir = os.path.join(kw.get('chdir', '.'), + 'out', + self.configuration_dirname()) + kw['chdir'] = chdir + + arguments.append('-G') + arguments.append('Ninja') + + kw['arguments'] = arguments + + stderr = kw.get('stderr', None) + if stderr: + kw['stderr'] = stderr.split('$$$')[0] + + self.run(program=self.build_tool, **kw) + + def ninja_build(self, gyp_file, target=None, **kw): + arguments = kw.get('arguments', [])[:] + + self.build_tool_list = ['ninja'] + self.initialize_build_tool() + + # Add a -C output/path to the command line. + arguments.append('-C') + arguments.append(os.path.join('out', self.configuration_dirname())) + + if target not in (None, self.DEFAULT): + arguments.append(target) + + kw['arguments'] = arguments + + stderr = kw.get('stderr', None) + if stderr: + stderrs = stderr.split('$$$') + kw['stderr'] = stderrs[1] if len(stderrs) > 1 else '' + + return self.run(program=self.build_tool, **kw) + + def build(self, gyp_file, target=None, status=0, **kw): + # Two tools must be run to build, cmake and the ninja. + # Allow cmake to succeed when the overall expectation is to fail. + if status is None: + kw['status'] = None + else: + if not isinstance(status, collections.Iterable): status = (status,) + kw['status'] = list(itertools.chain((0,), status)) + self.cmake_build(gyp_file, target, **kw) + kw['status'] = status + self.ninja_build(gyp_file, target, **kw) + + def run_built_executable(self, name, *args, **kw): + # 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': + configuration = self.configuration_dirname() + os.environ['DYLD_LIBRARY_PATH'] = os.path.join('out', configuration) + return self.run(program=program, *args, **kw) + + def built_file_path(self, name, type=None, **kw): + result = [] + chdir = kw.get('chdir') + if chdir: + result.append(chdir) + result.append('out') + result.append(self.configuration_dirname()) + if type == self.STATIC_LIB: + if sys.platform != 'darwin': + result.append('obj.target') + elif type == self.SHARED_LIB: + if sys.platform != 'darwin' and sys.platform != 'win32': + result.append('lib.target') + subdir = kw.get('subdir') + if subdir and type != self.SHARED_LIB: + result.append(subdir) + result.append(self.built_file_basename(name, type, **kw)) + return self.workpath(*result) + + def up_to_date(self, gyp_file, target=None, **kw): + result = self.ninja_build(gyp_file, target, **kw) + if not result: + stdout = self.stdout() + if 'ninja: no work to do' not in stdout: + self.report_not_up_to_date() + self.fail_test() + return result + + class TestGypMake(TestGypBase): """ Subclass for testing the GYP Make generator. @@ -995,6 +1099,7 @@ class TestGypXcode(TestGypBase): format_class_list = [ TestGypGypd, TestGypAndroid, + TestGypCMake, TestGypMake, TestGypMSVS, TestGypNinja, diff --git a/test/no-cpp/gyptest-no-cpp.py b/test/no-cpp/gyptest-no-cpp.py index 97f759e1..432fe779 100644 --- a/test/no-cpp/gyptest-no-cpp.py +++ b/test/no-cpp/gyptest-no-cpp.py @@ -41,6 +41,7 @@ if sys.platform != 'win32' and test.format not in ('make', 'android'): 'xcode': [1, 65], # 1 for xcode 3, 65 for xcode 4 (see `man sysexits`) 'make': 2, 'ninja': 1, + 'cmake': 0, # CMake picks the compiler driver based on transitive checks. }[test.format] test.build('test.gyp', 'no_cpp_dep_on_cc_lib', chdir=CHDIR, diff --git a/test/prune_targets/gyptest-prune-targets.py b/test/prune_targets/gyptest-prune-targets.py index 99d7a9a4..4f1e64a3 100644 --- a/test/prune_targets/gyptest-prune-targets.py +++ b/test/prune_targets/gyptest-prune-targets.py @@ -14,6 +14,7 @@ test = TestGyp.TestGyp() build_error_code = { 'android': 2, + 'cmake': 1, 'make': 2, 'msvs': 1, 'ninja': 1, diff --git a/test/sibling/gyptest-all.py b/test/sibling/gyptest-all.py index f858c317..4fa8e97a 100755 --- a/test/sibling/gyptest-all.py +++ b/test/sibling/gyptest-all.py @@ -21,7 +21,7 @@ chdir = 'src/build' # TODO(mmoss) Should the Makefile go in the directory of the passed in .gyp # file? What about when passing in multiple .gyp files? Would sub-project # Makefiles (see http://codereview.chromium.org/340008 comments) solve this? -if test.format in ('make', 'ninja'): +if test.format in ('make', 'ninja', 'cmake'): chdir = 'src' if test.format == 'xcode': diff --git a/test/sibling/gyptest-relocate.py b/test/sibling/gyptest-relocate.py index b1b3a3d3..7296d725 100755 --- a/test/sibling/gyptest-relocate.py +++ b/test/sibling/gyptest-relocate.py @@ -23,7 +23,7 @@ chdir = 'relocate/src/build' # TODO(mmoss) Should the Makefile go in the directory of the passed in .gyp # file? What about when passing in multiple .gyp files? Would sub-project # Makefiles (see http://codereview.chromium.org/340008 comments) solve this? -if test.format in ('make', 'ninja'): +if test.format in ('make', 'ninja', 'cmake'): chdir = 'relocate/src' if test.format == 'xcode': diff --git a/test/standalone-static-library/gyptest-standalone-static-library.py b/test/standalone-static-library/gyptest-standalone-static-library.py index 2db299ac..ff12570b 100644 --- a/test/standalone-static-library/gyptest-standalone-static-library.py +++ b/test/standalone-static-library/gyptest-standalone-static-library.py @@ -44,7 +44,8 @@ expect = 'hello from mylib.c\n' test.run_built_executable('prog', stdout=expect) # Verify that libmylib.a contains symbols. "ar -x" fails on a 'thin' archive. -if test.format in ('make', 'ninja') and sys.platform.startswith('linux'): +supports_thick = ('make', 'ninja', 'cmake') +if test.format in supports_thick and sys.platform.startswith('linux'): retcode = subprocess.call(['ar', '-x', path]) assert retcode == 0 diff --git a/test/subdirectory/gyptest-subdir-all.py b/test/subdirectory/gyptest-subdir-all.py index 4db9e843..93a865af 100755 --- a/test/subdirectory/gyptest-subdir-all.py +++ b/test/subdirectory/gyptest-subdir-all.py @@ -14,7 +14,8 @@ import TestGyp # Android doesn't support running from subdirectories. # Ninja doesn't support relocation. -test = TestGyp.TestGyp(formats=['!ninja', '!android']) +# CMake produces a single CMakeLists.txt in the output directory. +test = TestGyp.TestGyp(formats=['!ninja', '!android', '!cmake']) test.run_gyp('prog1.gyp', chdir='src') diff --git a/test/subdirectory/gyptest-subdir-default.py b/test/subdirectory/gyptest-subdir-default.py index 6ecc99e2..5d262f80 100755 --- a/test/subdirectory/gyptest-subdir-default.py +++ b/test/subdirectory/gyptest-subdir-default.py @@ -15,7 +15,8 @@ import errno # Android doesn't support running from subdirectories. # Ninja doesn't support relocation. -test = TestGyp.TestGyp(formats=['!ninja', '!android']) +# CMake produces a single CMakeLists.txt in the output directory. +test = TestGyp.TestGyp(formats=['!ninja', '!android', '!cmake']) test.run_gyp('prog1.gyp', chdir='src') diff --git a/test/win/gyptest-cl-pdbname.py b/test/win/gyptest-cl-pdbname.py index f7fd3322..f09ac233 100644 --- a/test/win/gyptest-cl-pdbname.py +++ b/test/win/gyptest-cl-pdbname.py @@ -21,7 +21,7 @@ if sys.platform == 'win32': # Confirm that the default behaviour is to name the .pdb per-target (rather # than per .cc file). - test.built_file_must_exist('obj/test_pdbname.pdb', chdir=CHDIR) + test.built_file_must_exist('obj/test_pdbname.cc.pdb', chdir=CHDIR) # Confirm that there should be a .pdb alongside the executable. test.built_file_must_exist('test_pdbname.exe', chdir=CHDIR) diff --git a/test/win/gyptest-link-generate-manifest.py b/test/win/gyptest-link-generate-manifest.py index e7d9bc75..ff03afd3 100644 --- a/test/win/gyptest-link-generate-manifest.py +++ b/test/win/gyptest-link-generate-manifest.py @@ -14,31 +14,106 @@ import TestGyp import sys if sys.platform == 'win32': + import pywintypes + import win32api + import winerror + + RT_MANIFEST = 24 + + class LoadLibrary(object): + """Context manager for loading and releasing binaries in Windows. + Yields the handle of the binary loaded.""" + def __init__(self, path): + self._path = path + self._handle = None + + def __enter__(self): + self._handle = win32api.LoadLibrary(self._path) + return self._handle + + def __exit__(self, type, value, traceback): + win32api.FreeLibrary(self._handle) + + def extract_manifest(path, resource_name): + """Reads manifest from |path| and returns it as a string. + Returns None is there is no such manifest.""" + with LoadLibrary(path) as handle: + try: + return win32api.LoadResource(handle, RT_MANIFEST, resource_name) + except pywintypes.error as error: + if error.args[0] == winerror.ERROR_RESOURCE_DATA_NOT_FOUND: + return None + else: + raise + test = TestGyp.TestGyp(formats=['msvs', 'ninja']) CHDIR = 'linker-flags' test.run_gyp('generate-manifest.gyp', chdir=CHDIR) test.build('generate-manifest.gyp', test.ALL, chdir=CHDIR) - test.built_file_must_exist('test_manifest_exe.exe.manifest', chdir=CHDIR) - test.built_file_must_exist('test_manifest_dll.dll.manifest', chdir=CHDIR) - - # Must contain the Win7 support GUID, but not the Vista one (from - # extra2.manifest). - extra1_manifest = test.built_file_path( - 'test_manifest_extra1.exe.manifest', chdir=CHDIR) - test.must_contain(extra1_manifest, '35138b9a-5d96-4fbd-8e2d-a2440225f93a') - test.must_not_contain(extra1_manifest, 'e2011457-1546-43c5-a5fe-008deee3d3f0') - - # Must contain both. - extra2_manifest = test.built_file_path( - 'test_manifest_extra2.exe.manifest', chdir=CHDIR) - test.must_contain(extra2_manifest, '35138b9a-5d96-4fbd-8e2d-a2440225f93a') - test.must_contain(extra2_manifest, 'e2011457-1546-43c5-a5fe-008deee3d3f0') - - # Same as extra2, but using list syntax instead. - extra_list_manifest = test.built_file_path( - 'test_manifest_extra_list.exe.manifest', chdir=CHDIR) - test.must_contain(extra_list_manifest, '35138b9a-5d96-4fbd-8e2d-a2440225f93a') - test.must_contain(extra_list_manifest, 'e2011457-1546-43c5-a5fe-008deee3d3f0') + def test_manifest(filename, generate_manifest, embedded_manifest, + extra_manifest): + exe_file = test.built_file_path(filename, chdir=CHDIR) + if not generate_manifest: + test.must_not_exist(exe_file + '.manifest') + manifest = extract_manifest(exe_file, 1) + test.fail_test(manifest) + return + if embedded_manifest: + manifest = extract_manifest(exe_file, 1) + test.fail_test(not manifest) + else: + test.must_exist(exe_file + '.manifest') + manifest = test.read(exe_file + '.manifest') + test.fail_test(not manifest) + test.fail_test(extract_manifest(exe_file, 1)) + if generate_manifest: + test.must_contain_any_line(manifest, 'requestedExecutionLevel') + if extra_manifest: + test.must_contain_any_line(manifest, + '35138b9a-5d96-4fbd-8e2d-a2440225f93a') + test.must_contain_any_line(manifest, + 'e2011457-1546-43c5-a5fe-008deee3d3f0') + + test_manifest('test_generate_manifest_true.exe', + generate_manifest=True, + embedded_manifest=False, + extra_manifest=False) + test_manifest('test_generate_manifest_false.exe', + generate_manifest=False, + embedded_manifest=False, + extra_manifest=False) + test_manifest('test_generate_manifest_default.exe', + generate_manifest=True, + embedded_manifest=False, + extra_manifest=False) + test_manifest('test_generate_manifest_true_as_embedded.exe', + generate_manifest=True, + embedded_manifest=True, + extra_manifest=False) + test_manifest('test_generate_manifest_false_as_embedded.exe', + generate_manifest=False, + embedded_manifest=True, + extra_manifest=False) + test_manifest('test_generate_manifest_default_as_embedded.exe', + generate_manifest=True, + embedded_manifest=True, + extra_manifest=False) + test_manifest('test_generate_manifest_true_with_extra_manifest.exe', + generate_manifest=True, + embedded_manifest=False, + extra_manifest=True) + test_manifest('test_generate_manifest_false_with_extra_manifest.exe', + generate_manifest=False, + embedded_manifest=False, + extra_manifest=True) + test_manifest('test_generate_manifest_true_with_extra_manifest_list.exe', + generate_manifest=True, + embedded_manifest=False, + extra_manifest=True) + test_manifest('test_generate_manifest_false_with_extra_manifest_list.exe', + generate_manifest=False, + embedded_manifest=False, + extra_manifest=True) test.pass_test() diff --git a/test/win/gyptest-link-ltcg.py b/test/win/gyptest-link-ltcg.py new file mode 100644 index 00000000..529e06e4 --- /dev/null +++ b/test/win/gyptest-link-ltcg.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +# Copyright (c) 2013 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. + +""" +Make sure LTCG is working properly. +""" + +import TestGyp + +import sys + +if sys.platform == 'win32': + test = TestGyp.TestGyp(formats=['msvs', 'ninja']) + + CHDIR = 'linker-flags' + test.run_gyp('ltcg.gyp', chdir=CHDIR) + + # Here we expect LTCG is able to inline functions beyond compile unit. + # Note: This marker is embedded in 'inline_test_main.cc' + INLINE_MARKER = '==== inlined ====' + + # test 'LinkTimeCodeGenerationOptionDefault' + test.build('ltcg.gyp', 'test_ltcg_off', chdir=CHDIR) + test.run_built_executable('test_ltcg_off', chdir=CHDIR) + test.must_not_contain_any_line(test.stdout(), [INLINE_MARKER]) + + # test 'LinkTimeCodeGenerationOptionUse' + test.build('ltcg.gyp', 'test_ltcg_on', chdir=CHDIR) + test.must_contain_any_line(test.stdout(), ['Generating code']) + test.run_built_executable('test_ltcg_on', chdir=CHDIR) + test.must_contain_any_line(test.stdout(), [INLINE_MARKER]) + + test.pass_test() diff --git a/test/win/gyptest-link-pgo.py b/test/win/gyptest-link-pgo.py new file mode 100644 index 00000000..d742047a --- /dev/null +++ b/test/win/gyptest-link-pgo.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +# Copyright (c) 2013 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. + +""" +Make sure PGO is working properly. +""" + +import TestGyp + +import os +import sys + +if sys.platform == 'win32': + test = TestGyp.TestGyp(formats=['msvs', 'ninja']) + + CHDIR = 'linker-flags' + test.run_gyp('pgo.gyp', chdir=CHDIR) + + def IsPGOAvailable(): + """Returns true if the Visual Studio available here supports PGO.""" + test.build('pgo.gyp', 'gen_linker_option', chdir=CHDIR) + tmpfile = test.read(test.built_file_path('linker_options.txt', chdir=CHDIR)) + return any(line.find('PGOPTIMIZE') for line in tmpfile) + + # Test generated build files look fine. + if test.format == 'ninja': + ninja = test.built_file_path('obj/test_pgo_instrument.ninja', chdir=CHDIR) + test.must_contain(ninja, '/LTCG:PGINSTRUMENT') + test.must_contain(ninja, 'test_pgo.pgd') + ninja = test.built_file_path('obj/test_pgo_optimize.ninja', chdir=CHDIR) + test.must_contain(ninja, '/LTCG:PGOPTIMIZE') + test.must_contain(ninja, 'test_pgo.pgd') + ninja = test.built_file_path('obj/test_pgo_update.ninja', chdir=CHDIR) + test.must_contain(ninja, '/LTCG:PGUPDATE') + test.must_contain(ninja, 'test_pgo.pgd') + elif test.format == 'msvs': + LTCG_FORMAT = '<LinkTimeCodeGeneration>%s</LinkTimeCodeGeneration>' + vcproj = test.workpath('linker-flags/test_pgo_instrument.vcxproj') + test.must_contain(vcproj, LTCG_FORMAT % 'PGInstrument') + test.must_contain(vcproj, 'test_pgo.pgd') + vcproj = test.workpath('linker-flags/test_pgo_optimize.vcxproj') + test.must_contain(vcproj, LTCG_FORMAT % 'PGOptimization') + test.must_contain(vcproj, 'test_pgo.pgd') + vcproj = test.workpath('linker-flags/test_pgo_update.vcxproj') + test.must_contain(vcproj, LTCG_FORMAT % 'PGUpdate') + test.must_contain(vcproj, 'test_pgo.pgd') + + # When PGO is available, try building binaries with PGO. + if IsPGOAvailable(): + pgd_path = test.built_file_path('test_pgo.pgd', chdir=CHDIR) + + # Test if 'PGInstrument' generates PGD (Profile-Guided Database) file. + if os.path.exists(pgd_path): + test.unlink(pgd_path) + test.must_not_exist(pgd_path) + test.build('pgo.gyp', 'test_pgo_instrument', chdir=CHDIR) + test.must_exist(pgd_path) + + # Test if 'PGOptimize' works well + test.build('pgo.gyp', 'test_pgo_optimize', chdir=CHDIR) + test.must_contain_any_line(test.stdout(), ['profiled functions']) + + # Test if 'PGUpdate' works well + test.build('pgo.gyp', 'test_pgo_update', chdir=CHDIR) + # With 'PGUpdate', linker should not complain that sources are changed after + # the previous training run. + test.touch(test.workpath('linker-flags/inline_test_main.cc')) + test.unlink(test.built_file_path('test_pgo_update.exe', chdir=CHDIR)) + test.build('pgo.gyp', 'test_pgo_update', chdir=CHDIR) + test.must_contain_any_line(test.stdout(), ['profiled functions']) + + test.pass_test() diff --git a/test/win/gyptest-link-warnings-as-errors.py b/test/win/gyptest-link-warnings-as-errors.py new file mode 100644 index 00000000..d6a64736 --- /dev/null +++ b/test/win/gyptest-link-warnings-as-errors.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +# Copyright (c) 2013 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. + +""" +Make sure linker warnings-as-errors setting is extracted properly. +""" + +import TestGyp + +import sys + +if sys.platform == 'win32': + test = TestGyp.TestGyp(formats=['msvs', 'ninja']) + + CHDIR = 'linker-flags' + test.run_gyp('warn-as-error.gyp', chdir=CHDIR) + + test.build('warn-as-error.gyp', 'test_on', chdir=CHDIR, status=1) + test.build('warn-as-error.gyp', 'test_off', chdir=CHDIR) + test.build('warn-as-error.gyp', 'test_default', chdir=CHDIR) + test.pass_test() diff --git a/test/win/linker-flags/generate-manifest.gyp b/test/win/linker-flags/generate-manifest.gyp index fe5ee741..41f888fa 100644 --- a/test/win/linker-flags/generate-manifest.gyp +++ b/test/win/linker-flags/generate-manifest.gyp @@ -1,64 +1,156 @@ -# 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_manifest_exe',
- 'type': 'executable',
- 'sources': ['hello.cc'],
- 'msvs_settings': {
- 'VCManifestTool': {
- 'EmbedManifest': 'false',
- }
- },
- },
- {
- 'target_name': 'test_manifest_dll',
- 'type': 'shared_library',
- 'sources': ['hello.cc'],
- 'msvs_settings': {
- 'VCManifestTool': {
- 'EmbedManifest': 'false',
- }
- },
- },
- {
- 'target_name': 'test_manifest_extra1',
- 'type': 'executable',
- 'sources': ['hello.cc'],
- 'msvs_settings': {
- 'VCManifestTool': {
- 'EmbedManifest': 'false',
- 'AdditionalManifestFiles': 'extra.manifest',
- }
- },
- },
- {
- 'target_name': 'test_manifest_extra2',
- 'type': 'executable',
- 'sources': ['hello.cc'],
- 'msvs_settings': {
- 'VCManifestTool': {
- 'EmbedManifest': 'false',
- 'AdditionalManifestFiles': 'extra.manifest;extra2.manifest',
- }
- },
- },
- {
- 'target_name': 'test_manifest_extra_list',
- 'type': 'executable',
- 'sources': ['hello.cc'],
- 'msvs_settings': {
- 'VCManifestTool': {
- 'EmbedManifest': 'false',
- 'AdditionalManifestFiles': [
- 'extra.manifest',
- 'extra2.manifest'
- ],
- }
- },
- },
- ]
-}
+# 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_generate_manifest_true', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'true', + }, + 'VCManifestTool': { + 'EmbedManifest': 'false', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_false', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'false', + }, + 'VCManifestTool': { + 'EmbedManifest': 'false', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_default', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + }, + 'VCManifestTool': { + 'EmbedManifest': 'false', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_true_as_embedded', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'true', + }, + 'VCManifestTool': { + 'EmbedManifest': 'true', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_false_as_embedded', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'false', + }, + 'VCManifestTool': { + 'EmbedManifest': 'true', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_default_as_embedded', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + }, + 'VCManifestTool': { + 'EmbedManifest': 'true', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_true_with_extra_manifest', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'true', + }, + 'VCManifestTool': { + 'EmbedManifest': 'false', + 'AdditionalManifestFiles': 'extra.manifest;extra2.manifest', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_false_with_extra_manifest', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'false', + }, + 'VCManifestTool': { + 'EmbedManifest': 'false', + 'AdditionalManifestFiles': 'extra.manifest;extra2.manifest', + }, + }, + }, + { + 'target_name': 'test_generate_manifest_true_with_extra_manifest_list', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'true', + }, + 'VCManifestTool': { + 'EmbedManifest': 'false', + 'AdditionalManifestFiles': [ + 'extra.manifest', + 'extra2.manifest', + ], + }, + }, + }, + { + 'target_name': 'test_generate_manifest_false_with_extra_manifest_list', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'GenerateManifest': 'false', + }, + 'VCManifestTool': { + 'EmbedManifest': 'false', + 'AdditionalManifestFiles': [ + 'extra.manifest', + 'extra2.manifest', + ], + }, + }, + }, + ] +} diff --git a/test/win/linker-flags/inline_test.cc b/test/win/linker-flags/inline_test.cc new file mode 100644 index 00000000..a9f177e4 --- /dev/null +++ b/test/win/linker-flags/inline_test.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2013 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 "inline_test.h" + +#include <intrin.h> +#pragma intrinsic(_ReturnAddress) + +bool IsFunctionInlined(void* caller_return_address) { + return _ReturnAddress() == caller_return_address; +} diff --git a/test/win/linker-flags/inline_test.h b/test/win/linker-flags/inline_test.h new file mode 100644 index 00000000..117913c4 --- /dev/null +++ b/test/win/linker-flags/inline_test.h @@ -0,0 +1,5 @@ +// Copyright (c) 2013 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. + +bool IsFunctionInlined(void* current_return_address); diff --git a/test/win/linker-flags/inline_test_main.cc b/test/win/linker-flags/inline_test_main.cc new file mode 100644 index 00000000..23cafe8f --- /dev/null +++ b/test/win/linker-flags/inline_test_main.cc @@ -0,0 +1,15 @@ +// Copyright (c) 2013 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 "inline_test.h" + +#include <intrin.h> +#include <stdio.h> + +#pragma intrinsic(_ReturnAddress) + +int main() { + if (IsFunctionInlined(_ReturnAddress())) + puts("==== inlined ====\n"); +} diff --git a/test/win/linker-flags/link-warning.cc b/test/win/linker-flags/link-warning.cc new file mode 100644 index 00000000..4b34277b --- /dev/null +++ b/test/win/linker-flags/link-warning.cc @@ -0,0 +1,10 @@ +// Copyright (c) 2013 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 will cause LNK4254. +#pragma comment(linker, "/merge:.data=.text") + +int main() { + return 0; +} diff --git a/test/win/linker-flags/ltcg.gyp b/test/win/linker-flags/ltcg.gyp new file mode 100644 index 00000000..ddb0d9b4 --- /dev/null +++ b/test/win/linker-flags/ltcg.gyp @@ -0,0 +1,42 @@ +# Copyright (c) 2013 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_ltcg_off', + 'type': 'executable', + 'msvs_settings': { + 'VCCLCompilerTool': { + 'WholeProgramOptimization': 'false', + }, + 'VCLinkerTool': { + 'LinkTimeCodeGeneration': '0', + }, + }, + 'sources': [ + 'inline_test.h', + 'inline_test.cc', + 'inline_test_main.cc', + ], + }, + { + 'target_name': 'test_ltcg_on', + 'type': 'executable', + 'msvs_settings': { + 'VCCLCompilerTool': { + 'WholeProgramOptimization': 'true', # /GL + }, + 'VCLinkerTool': { + 'LinkTimeCodeGeneration': '1', # /LTCG + }, + }, + 'sources': [ + 'inline_test.h', + 'inline_test.cc', + 'inline_test_main.cc', + ], + }, + ] +} diff --git a/test/win/linker-flags/pgo.gyp b/test/win/linker-flags/pgo.gyp new file mode 100644 index 00000000..da326399 --- /dev/null +++ b/test/win/linker-flags/pgo.gyp @@ -0,0 +1,143 @@ +# Copyright (c) 2013 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. + +{ + 'variables': { + 'pgd_basename': 'test_pgo', + }, + 'targets': [ + # In the PGO (Profile-Guided Optimization) build flow, we need to build the + # target binary multiple times. To implement this flow with gyp, here we + # define multiple 'executable' targets, each of which represents one build + # particular build/profile stage. On tricky part to do this is that these + # 'executable' targets should share the code itself so that profile data + # can be reused among these 'executable' files. In other words, the only + # differences among below 'executable' targets are: + # 1) PGO (Profile-Guided Optimization) database, and + # 2) linker options. + # The following static library contains all the logic including entry point. + # Basically we don't need to rebuild this target once we enter profiling + # phase of PGO. + { + 'target_name': 'test_pgo_main', + 'type': 'static_library', + 'msvs_settings': { + 'VCCLCompilerTool': { + 'WholeProgramOptimization': 'true', # /GL + }, + 'VCLibrarianTool': { + 'LinkTimeCodeGeneration': 'true', + }, + }, + 'link_settings': { + 'msvs_settings': { + 'VCLinkerTool': { + 'ProfileGuidedDatabase': '$(OutDir)\\<(pgd_basename).pgd', + 'TargetMachine': '1', # x86 - 32 + 'SubSystem': '1', # /SUBSYSTEM:CONSOLE
+ # Tell ninja generator not to pass /ManifestFile:<filename> option + # to the linker, because it causes LNK1268 error in PGO biuld. + 'GenerateManifest': 'false', + # We need to specify 'libcmt.lib' here so that the linker can pick + # up a valid entry point. + 'AdditionalDependencies': [ + 'libcmt.lib', + ], + }, + }, + }, + 'sources': [ + 'inline_test.h', + 'inline_test.cc', + 'inline_test_main.cc', + ], + }, + { + 'target_name': 'test_pgo_instrument', + 'type': 'executable', + 'msvs_settings': { + 'VCLinkerTool': { + 'LinkTimeCodeGeneration': '2', + }, + }, + 'dependencies': [ + 'test_pgo_main', + ], + }, + { + 'target_name': 'gen_profile_guided_database', + 'type': 'none', + 'msvs_cygwin_shell': 0, + 'actions': [ + { + 'action_name': 'action_main', + 'inputs': [], + 'outputs': [ + '$(OutDir)\\<(pgd_basename).pgd', + ], + 'action': [ + 'python', 'update_pgd.py', + '--vcbindir', '$(VCInstallDir)bin', + '--exe', '$(OutDir)\\test_pgo_instrument.exe', + '--pgd', '$(OutDir)\\<(pgd_basename).pgd', + ], + }, + ], + 'dependencies': [ + 'test_pgo_instrument', + ], + }, + { + 'target_name': 'test_pgo_optimize', + 'type': 'executable', + 'msvs_settings': { + 'VCLinkerTool': { + 'LinkTimeCodeGeneration': '3', + }, + }, + 'sources': [ + '$(OutDir)\\<(pgd_basename).pgd', + ], + 'dependencies': [ + 'test_pgo_main', + 'gen_profile_guided_database', + ], + }, + { + 'target_name': 'test_pgo_update', + 'type': 'executable', + 'msvs_settings': { + 'VCLinkerTool': { + 'LinkTimeCodeGeneration': '4', + }, + }, + 'sources': [ + '$(OutDir)\\<(pgd_basename).pgd', + ], + 'dependencies': [ + 'test_pgo_main', + ], + }, + # A helper target to dump link.exe's command line options. We can use the + # output to determine if PGO (Profile-Guided Optimization) is available on + # the test environment. + { + 'target_name': 'gen_linker_option', + 'type': 'none', + 'msvs_cygwin_shell': 0, + 'actions': [ + { + 'action_name': 'action_main', + 'inputs': [], + 'outputs': [ + '$(OutDir)\\linker_options.txt', + ], + 'action': [ + 'cmd.exe', '/c link.exe > $(OutDir)\\linker_options.txt & exit 0', + ], + }, + ], + }, + ] +} diff --git a/test/win/linker-flags/update_pgd.py b/test/win/linker-flags/update_pgd.py new file mode 100644 index 00000000..34f56ee9 --- /dev/null +++ b/test/win/linker-flags/update_pgd.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# Copyright (c) 2013 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 optparse import OptionParser +import glob +import os +import subprocess + +parser = OptionParser() +parser.add_option('--exe', dest='exe') +parser.add_option('--vcbindir', dest='vcbindir') +parser.add_option('--pgd', dest='pgd') +(options, args) = parser.parse_args() + +# Instrumented binaries fail to run unless the Visual C++'s bin dir is included +# in the PATH environment variable. +os.environ['PATH'] = os.environ['PATH'] + os.pathsep + options.vcbindir + +# Run Instrumented binary. The profile will be recorded into *.pgc file. +subprocess.call([options.exe]) + +# Merge *.pgc files into a *.pgd (Profile-Guided Database) file. +subprocess.call(['pgomgr', '/merge', options.pgd]) + +# *.pgc files are no longer necessary. Clear all of them. +pgd_file = os.path.abspath(options.pgd) +pgd_dir = os.path.dirname(pgd_file) +(pgd_basename, _) = os.path.splitext(os.path.basename(pgd_file)) +pgc_filepattern = os.path.join(pgd_dir, '%s!*.pgc' % pgd_basename) +pgc_files= glob.glob(pgc_filepattern)
+for pgc_file in pgc_files:
+ os.unlink(pgc_file)
diff --git a/test/win/linker-flags/warn-as-error.gyp b/test/win/linker-flags/warn-as-error.gyp new file mode 100644 index 00000000..83c67e9d --- /dev/null +++ b/test/win/linker-flags/warn-as-error.gyp @@ -0,0 +1,33 @@ +# Copyright (c) 2013 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_on',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCLinkerTool': {
+ 'TreatLinkerWarningAsErrors': 'true',
+ }
+ },
+ 'sources': ['link-warning.cc'],
+ },
+ {
+ 'target_name': 'test_off',
+ 'type': 'executable',
+ 'msvs_settings': {
+ 'VCLinkerTool': {
+ 'TreatLinkerWarningAsErrors': 'false',
+ }
+ },
+ 'sources': ['link-warning.cc'],
+ },
+ {
+ 'target_name': 'test_default',
+ 'type': 'executable',
+ 'sources': ['link-warning.cc'],
+ },
+ ]
+}
|