diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/mac/gyptest-app.py | 15 | ||||
-rw-r--r-- | test/mac/gyptest-sdkroot.py | 37 | ||||
-rwxr-xr-x | test/mac/gyptest-xcode-env-order.py | 13 | ||||
-rw-r--r-- | test/mac/gyptest-xcode-gcc.py | 18 | ||||
-rwxr-xr-x | test/mac/sdkroot/test_shorthand.sh | 12 | ||||
-rw-r--r-- | test/mac/xcode-gcc/test.gyp | 5 | ||||
-rw-r--r-- | test/win/gyptest-link-generate-manifest.py | 8 | ||||
-rw-r--r-- | test/win/gyptest-link-ordering.py | 75 | ||||
-rw-r--r-- | test/win/gyptest-link-unsupported-manifest.py | 27 | ||||
-rw-r--r-- | test/win/gyptest-link-update-manifest.py | 103 | ||||
-rw-r--r-- | test/win/linker-flags/a/z.cc | 7 | ||||
-rw-r--r-- | test/win/linker-flags/b/y.cc | 7 | ||||
-rw-r--r-- | test/win/linker-flags/generate-manifest.gyp | 10 | ||||
-rw-r--r-- | test/win/linker-flags/link-ordering.gyp | 65 | ||||
-rw-r--r-- | test/win/linker-flags/main-crt.c | 8 | ||||
-rw-r--r-- | test/win/linker-flags/manifest-in-comment.cc | 13 | ||||
-rw-r--r-- | test/win/linker-flags/unsupported-manifest.gyp | 13 | ||||
-rw-r--r-- | test/win/linker-flags/x.cc | 7 | ||||
-rw-r--r-- | test/win/linker-flags/y.cc | 7 | ||||
-rw-r--r-- | test/win/linker-flags/z.cc | 7 |
20 files changed, 428 insertions, 29 deletions
diff --git a/test/mac/gyptest-app.py b/test/mac/gyptest-app.py index c84c92fd..b50e1a84 100755 --- a/test/mac/gyptest-app.py +++ b/test/mac/gyptest-app.py @@ -32,6 +32,11 @@ def ls(path): result.append(os.path.join(dirpath, f)[len(path) + 1:]) return result +def XcodeVersion(): + stdout = subprocess.check_output(['xcodebuild', '-version']) + version = stdout.splitlines()[0].split()[-1].replace('.', '') + return (version + '0' * (3 - len(version))).zfill(4) + if sys.platform == 'darwin': test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) @@ -56,7 +61,15 @@ if sys.platform == 'darwin': plist = plistlib.readPlist(info_plist) ExpectEq(GetStdout(['sw_vers', '-buildVersion']), plist['BuildMachineOSBuild']) - ExpectEq('', plist['DTSDKName']) + + # Prior to Xcode 5.0.0, SDKROOT (and thus DTSDKName) was only defined if + # set in the Xcode project file. Starting with that version, it is always + # defined. + expected = '' + if XcodeVersion() >= '0500': + version = GetStdout(['xcodebuild', '-version', '-sdk', '', 'SDKVersion']) + expected = 'macosx' + version + ExpectEq(expected, plist['DTSDKName']) sdkbuild = GetStdout( ['xcodebuild', '-version', '-sdk', '', 'ProductBuildVersion']) if not sdkbuild: diff --git a/test/mac/gyptest-sdkroot.py b/test/mac/gyptest-sdkroot.py index 20edd365..711726ed 100644 --- a/test/mac/gyptest-sdkroot.py +++ b/test/mac/gyptest-sdkroot.py @@ -17,22 +17,29 @@ import sys if sys.platform == 'darwin': test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) + def GetSDKPath(sdk): + """Return SDKROOT if the SDK version |sdk| is installed or empty string.""" + DEVNULL = open(os.devnull, 'wb') + try: + proc = subprocess.Popen( + ['xcodebuild', '-version', '-sdk', 'macosx' + sdk, 'Path'], + stdout=subprocess.PIPE, stderr=DEVNULL) + return proc.communicate()[0].rstrip('\n') + finally: + DEVNULL.close() + + def SelectSDK(): + """Select the oldest SDK installed (greater than 10.6).""" + for sdk in ['10.6', '10.7', '10.8', '10.9']: + path = GetSDKPath(sdk) + if path: + return True, sdk, path + return False, '', '' + # Make sure this works on the bots, which only have the 10.6 sdk, and on - # dev machines, which usually don't have the 10.6 sdk. - sdk = '10.6' - DEVNULL = open(os.devnull, 'wb') - proc = subprocess.Popen(['xcodebuild', '-version', '-sdk', 'macosx' + sdk], - stdout=DEVNULL, stderr=DEVNULL) - proc.communicate() - DEVNULL.close() - if proc.returncode: - sdk = '10.7' - - proc = subprocess.Popen(['xcodebuild', '-version', - '-sdk', 'macosx' + sdk, 'Path'], - stdout=subprocess.PIPE) - sdk_path = proc.communicate()[0].rstrip('\n') - if proc.returncode != 0: + # dev machines which usually don't have the 10.6 sdk. + sdk_found, sdk, sdk_path = SelectSDK() + if not sdk_found: test.fail_test() test.write('sdkroot/test.gyp', test.read('sdkroot/test.gyp') % sdk) diff --git a/test/mac/gyptest-xcode-env-order.py b/test/mac/gyptest-xcode-env-order.py index 58b146c1..decf2b3c 100755 --- a/test/mac/gyptest-xcode-env-order.py +++ b/test/mac/gyptest-xcode-env-order.py @@ -10,8 +10,14 @@ Verifies that dependent Xcode settings are processed correctly. import TestGyp +import subprocess import sys +def XcodeVersion(): + stdout = subprocess.check_output(['xcodebuild', '-version']) + version = stdout.splitlines()[0].split()[-1].replace('.', '') + return (version + '0' * (3 - len(version))).zfill(4) + if sys.platform == 'darwin': test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) @@ -71,10 +77,15 @@ if sys.platform == 'darwin': # if it's not right at the start of the string (e.g. ':$PRODUCT_TYPE'), so # this looks like an Xcode bug. This bug isn't emulated (yet?), so check this # only for Xcode. - if test.format == 'xcode': + if test.format == 'xcode' and XcodeVersion() < '0500': test.must_contain(info_plist, '''\ \t<key>BareProcessedKey3</key> \t<string>$PRODUCT_TYPE:D:/Source/Project/Test</string>''') + else: + # The bug has been fixed by Xcode version 5.0.0. + test.must_contain(info_plist, '''\ +\t<key>BareProcessedKey3</key> +\t<string>com.apple.product-type.application:D:/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>MixedProcessedKey</key> diff --git a/test/mac/gyptest-xcode-gcc.py b/test/mac/gyptest-xcode-gcc.py index abd88489..e45d0b5e 100644 --- a/test/mac/gyptest-xcode-gcc.py +++ b/test/mac/gyptest-xcode-gcc.py @@ -11,11 +11,23 @@ Verifies that xcode-style GCC_... settings are handled properly. import TestGyp import os +import subprocess import sys def IgnoreOutput(string, expected_string): return True +def CompilerVersion(compiler): + stdout = subprocess.check_output([compiler, '-v'], stderr=subprocess.STDOUT) + return stdout.rstrip('\n') + +def CompilerSupportsWarnAboutInvalidOffsetOfMacro(test): + # "clang" does not support the "-Winvalid-offsetof" flag, and silently + # ignore it. Starting with Xcode 5.0.0, "gcc" is just a "clang" binary with + # some hard-coded include path hack, so use the output of "-v" to detect if + # the compiler supports the flag or not. + return 'clang' not in CompilerVersion('/usr/bin/cc') + if sys.platform == 'darwin': test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) @@ -30,11 +42,7 @@ if sys.platform == 'darwin': # clang doesn't warn on invalid offsetofs, it silently ignores # -Wno-invalid-offsetof. - # TODO(thakis): This isn't really the right way to detect the compiler, - # Xcode has some embedded compiler, but it's a reliable proxy at least on - # the bots. The compiler is forced to gcc/g++ in the gyp file in a - # make_global_settings section for ninja and make. - if test.format != 'xcode' or os.readlink('/usr/bin/cc') != 'clang': + if CompilerSupportsWarnAboutInvalidOffsetOfMacro(test): targets.append('warn_about_invalid_offsetof_macro') for target in targets: diff --git a/test/mac/sdkroot/test_shorthand.sh b/test/mac/sdkroot/test_shorthand.sh index d768fba0..ac4ac229 100755 --- a/test/mac/sdkroot/test_shorthand.sh +++ b/test/mac/sdkroot/test_shorthand.sh @@ -5,8 +5,16 @@ set -e -if ! expected=$(xcodebuild -version -sdk macosx10.6 Path 2>/dev/null) ; then - expected=$(xcodebuild -version -sdk macosx10.7 Path) +found=false +for sdk in 10.6 10.7 10.8 10.9 ; do + if expected=$(xcodebuild -version -sdk macosx$sdk Path 2>/dev/null) ; then + found=true + break + fi +done +if ! $found ; then + echo >&2 "cannot find installed SDK" + exit 1 fi test $SDKROOT = $expected diff --git a/test/mac/xcode-gcc/test.gyp b/test/mac/xcode-gcc/test.gyp index c0fcb504..1ca8b215 100644 --- a/test/mac/xcode-gcc/test.gyp +++ b/test/mac/xcode-gcc/test.gyp @@ -2,11 +2,6 @@ # 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/gcc'], - ['CXX', '/usr/bin/g++'], - ], - 'target_defaults': { 'xcode_settings': { 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', diff --git a/test/win/gyptest-link-generate-manifest.py b/test/win/gyptest-link-generate-manifest.py index ff03afd3..77c9228e 100644 --- a/test/win/gyptest-link-generate-manifest.py +++ b/test/win/gyptest-link-generate-manifest.py @@ -52,6 +52,10 @@ if sys.platform == 'win32': test.run_gyp('generate-manifest.gyp', chdir=CHDIR) test.build('generate-manifest.gyp', test.ALL, chdir=CHDIR) + # Make sure that generation of .generated.manifest does not cause a relink. + test.run_gyp('generate-manifest.gyp', chdir=CHDIR) + test.up_to_date('generate-manifest.gyp', test.ALL, chdir=CHDIR) + def test_manifest(filename, generate_manifest, embedded_manifest, extra_manifest): exe_file = test.built_file_path(filename, chdir=CHDIR) @@ -116,4 +120,8 @@ if sys.platform == 'win32': generate_manifest=False, embedded_manifest=False, extra_manifest=True) + test_manifest('test_generate_manifest_default_embed_default.exe', + generate_manifest=True, + embedded_manifest=True, + extra_manifest=False) test.pass_test() diff --git a/test/win/gyptest-link-ordering.py b/test/win/gyptest-link-ordering.py new file mode 100644 index 00000000..4928583a --- /dev/null +++ b/test/win/gyptest-link-ordering.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 the link order of object files is the same between msvs and ninja. +""" + +import TestGyp + +import sys + +if sys.platform == 'win32': + test = TestGyp.TestGyp(formats=['msvs', 'ninja']) + + CHDIR = 'linker-flags' + test.run_gyp('link-ordering.gyp', chdir=CHDIR) + test.build('link-ordering.gyp', test.ALL, chdir=CHDIR) + + def GetDisasm(exe): + full_path = test.built_file_path(exe, chdir=CHDIR) + # Get disassembly and drop int3 padding between functions. + return '\n'.join( + x for x in test.run_dumpbin('/disasm', full_path).splitlines() + if 'CC' not in x) + + # This is the full dump that we expect. The source files in the .gyp match + # this order which is what determines the ordering in the binary. + + expected_disasm_basic = ''' +_mainCRTStartup: + 00401000: B8 05 00 00 00 mov eax,5 + 00401005: C3 ret +?z@@YAHXZ: + 00401010: B8 03 00 00 00 mov eax,3 + 00401015: C3 ret +?x@@YAHXZ: + 00401020: B8 01 00 00 00 mov eax,1 + 00401025: C3 ret +?y@@YAHXZ: + 00401030: B8 02 00 00 00 mov eax,2 + 00401035: C3 ret +_main: + 00401040: 33 C0 xor eax,eax + 00401042: C3 ret +''' + + if expected_disasm_basic not in GetDisasm('test_ordering_exe.exe'): + print GetDisasm('test_ordering_exe.exe') + test.fail_test() + + # Similar to above. The VS generator handles subdirectories differently. + + expected_disasm_subdirs = ''' +_mainCRTStartup: + 00401000: B8 05 00 00 00 mov eax,5 + 00401005: C3 ret +_main: + 00401010: 33 C0 xor eax,eax + 00401012: C3 ret +?y@@YAHXZ: + 00401020: B8 02 00 00 00 mov eax,2 + 00401025: C3 ret +?z@@YAHXZ: + 00401030: B8 03 00 00 00 mov eax,3 + 00401035: C3 ret +''' + + if expected_disasm_subdirs not in GetDisasm('test_ordering_subdirs.exe'): + print GetDisasm('test_ordering_subdirs.exe') + test.fail_test() + + test.pass_test() diff --git a/test/win/gyptest-link-unsupported-manifest.py b/test/win/gyptest-link-unsupported-manifest.py new file mode 100644 index 00000000..8f7e12bc --- /dev/null +++ b/test/win/gyptest-link-unsupported-manifest.py @@ -0,0 +1,27 @@ +#!/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 we error out if #pragma comments are used to modify manifests. +""" + +import TestGyp + +import sys + +if sys.platform == 'win32': + # This assertion only applies to the ninja build. + test = TestGyp.TestGyp(formats=['ninja']) + + CHDIR = 'linker-flags' + test.run_gyp('unsupported-manifest.gyp', chdir=CHDIR) + + # Just needs to fail to build. + test.build('unsupported-manifest.gyp', + 'test_unsupported', chdir=CHDIR, status=1) + test.must_not_exist(test.built_file_path('test_unsupported.exe', chdir=CHDIR)) + + test.pass_test() diff --git a/test/win/gyptest-link-update-manifest.py b/test/win/gyptest-link-update-manifest.py new file mode 100644 index 00000000..4f8b2b91 --- /dev/null +++ b/test/win/gyptest-link-update-manifest.py @@ -0,0 +1,103 @@ +#!/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 binary is relinked when manifest settings are changed. +""" + +import TestGyp + +import os +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' + + gyp_template = ''' +{ + 'targets': [ + { + 'target_name': 'test_update_manifest', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + 'UACExecutionLevel': '%(uac_execution_level)d', + }, + 'VCManifestTool': { + 'EmbedManifest': 'true', + 'AdditionalManifestFiles': '%(additional_manifest_files)s', + }, + }, + }, + ], +} +''' + + gypfile = 'update-manifest.gyp' + + def WriteAndUpdate(uac_execution_level, additional_manifest_files, do_build): + with open(os.path.join(CHDIR, gypfile), 'wb') as f: + f.write(gyp_template % { + 'uac_execution_level': uac_execution_level, + 'additional_manifest_files': additional_manifest_files, + }) + test.run_gyp(gypfile, chdir=CHDIR) + if do_build: + test.build(gypfile, chdir=CHDIR) + exe_file = test.built_file_path('test_update_manifest.exe', chdir=CHDIR) + return extract_manifest(exe_file, 1) + + manifest = WriteAndUpdate(0, '', True) + test.fail_test('asInvoker' not in manifest) + test.fail_test('35138b9a-5d96-4fbd-8e2d-a2440225f93a' in manifest) + + # Make sure that updating .gyp and regenerating doesn't cause a rebuild. + WriteAndUpdate(0, '', False) + test.up_to_date(gypfile, test.ALL, chdir=CHDIR) + + # But make sure that changing a manifest property does cause a relink. + manifest = WriteAndUpdate(2, '', True) + test.fail_test('requireAdministrator' not in manifest) + + # Adding a manifest causes a rebuild. + manifest = WriteAndUpdate(2, 'extra.manifest', True) + test.fail_test('35138b9a-5d96-4fbd-8e2d-a2440225f93a' not in manifest) diff --git a/test/win/linker-flags/a/z.cc b/test/win/linker-flags/a/z.cc new file mode 100644 index 00000000..8a435012 --- /dev/null +++ b/test/win/linker-flags/a/z.cc @@ -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. + +int z() { + return 3; +} diff --git a/test/win/linker-flags/b/y.cc b/test/win/linker-flags/b/y.cc new file mode 100644 index 00000000..bd884119 --- /dev/null +++ b/test/win/linker-flags/b/y.cc @@ -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. + +int y() { + return 2; +} diff --git a/test/win/linker-flags/generate-manifest.gyp b/test/win/linker-flags/generate-manifest.gyp index 41f888fa..34a68d1a 100644 --- a/test/win/linker-flags/generate-manifest.gyp +++ b/test/win/linker-flags/generate-manifest.gyp @@ -152,5 +152,15 @@ }, }, }, + { + 'target_name': 'test_generate_manifest_default_embed_default', + 'type': 'executable', + 'sources': ['hello.cc'], + 'msvs_settings': { + 'VCLinkerTool': { + 'EnableUAC': 'true', + }, + }, + }, ] } diff --git a/test/win/linker-flags/link-ordering.gyp b/test/win/linker-flags/link-ordering.gyp new file mode 100644 index 00000000..36a7e54f --- /dev/null +++ b/test/win/linker-flags/link-ordering.gyp @@ -0,0 +1,65 @@ +# 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_ordering_exe', + 'type': 'executable', + # These are so the names of the functions appear in the disassembly. + 'msvs_settings': { + 'VCCLCompilerTool': { + 'DebugInformationFormat': '3', + 'Optimization': '2', + }, + 'VCLinkerTool': { + 'GenerateDebugInformation': 'true', + 'LinkIncremental': '1', + 'GenerateManifest': 'false', + # Minimize the disassembly to just our code. + 'AdditionalOptions': [ + '/NODEFAULTLIB', + ], + }, + }, + 'sources': [ + # Explicitly sorted the same way as the disassembly in the test .py. + 'main-crt.c', + 'z.cc', + 'x.cc', + 'y.cc', + 'hello.cc', + ], + }, + + { + 'target_name': 'test_ordering_subdirs', + 'type': 'executable', + # These are so the names of the functions appear in the disassembly. + 'msvs_settings': { + 'VCCLCompilerTool': { + 'DebugInformationFormat': '3', + 'Optimization': '2', + }, + 'VCLinkerTool': { + 'GenerateDebugInformation': 'true', + 'LinkIncremental': '1', + 'GenerateManifest': 'false', + # Minimize the disassembly to just our code. + 'AdditionalOptions': [ + '/NODEFAULTLIB', + ], + }, + }, + 'sources': [ + # Explicitly sorted the same way as the disassembly in the test .py. + 'main-crt.c', + 'hello.cc', + 'b/y.cc', + 'a/z.cc', + ], + }, + + ] +} diff --git a/test/win/linker-flags/main-crt.c b/test/win/linker-flags/main-crt.c new file mode 100644 index 00000000..bdc80c54 --- /dev/null +++ b/test/win/linker-flags/main-crt.c @@ -0,0 +1,8 @@ +// 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. + +// Stub so we can link with /NODEFAULTLIB when checking disasm. +int mainCRTStartup() { + return 5; +} diff --git a/test/win/linker-flags/manifest-in-comment.cc b/test/win/linker-flags/manifest-in-comment.cc new file mode 100644 index 00000000..ae54ae54 --- /dev/null +++ b/test/win/linker-flags/manifest-in-comment.cc @@ -0,0 +1,13 @@ +// Copyright 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. + +#pragma comment(linker, \ + "\"/manifestdependency:type='Win32' " \ + "name='Test.Research.SampleAssembly' version='6.0.0.0' " \ + "processorArchitecture='X86' " \ + "publicKeyToken='0000000000000000' language='*'\"") + +int main() { + return 0; +} diff --git a/test/win/linker-flags/unsupported-manifest.gyp b/test/win/linker-flags/unsupported-manifest.gyp new file mode 100644 index 00000000..5549e7cb --- /dev/null +++ b/test/win/linker-flags/unsupported-manifest.gyp @@ -0,0 +1,13 @@ +# 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_unsupported', + 'type': 'executable', + 'sources': ['manifest-in-comment.cc'], + }, + ], +} diff --git a/test/win/linker-flags/x.cc b/test/win/linker-flags/x.cc new file mode 100644 index 00000000..f5f763b0 --- /dev/null +++ b/test/win/linker-flags/x.cc @@ -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. + +int x() { + return 1; +} diff --git a/test/win/linker-flags/y.cc b/test/win/linker-flags/y.cc new file mode 100644 index 00000000..bd884119 --- /dev/null +++ b/test/win/linker-flags/y.cc @@ -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. + +int y() { + return 2; +} diff --git a/test/win/linker-flags/z.cc b/test/win/linker-flags/z.cc new file mode 100644 index 00000000..8a435012 --- /dev/null +++ b/test/win/linker-flags/z.cc @@ -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. + +int z() { + return 3; +} |