OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 Google Inc. All rights reserved. | 3 # Copyright (c) 2012 Google Inc. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ | 7 """ |
8 Verifies that xcode-style GCC_... settings are handled properly. | 8 Verifies that xcode-style GCC_... settings are handled properly. |
9 """ | 9 """ |
10 | 10 |
11 import TestGyp | 11 import TestGyp |
12 | 12 |
13 import os | 13 import os |
| 14 import subprocess |
14 import sys | 15 import sys |
15 | 16 |
16 def IgnoreOutput(string, expected_string): | 17 def IgnoreOutput(string, expected_string): |
17 return True | 18 return True |
18 | 19 |
| 20 def CompilerVersion(compiler): |
| 21 stdout = subprocess.check_output([compiler, '-v'], stderr=subprocess.STDOUT) |
| 22 return stdout.rstrip('\n') |
| 23 |
| 24 def CompilerSupportsWarnAboutInvalidOffsetOfMacro(test): |
| 25 # "clang" does not support the "-Winvalid-offsetof" flag, and silently |
| 26 # ignore it. Starting with Xcode 5.0.0, "gcc" is just a "clang" binary with |
| 27 # some hard-coded include path hack, so use the output of "-v" to detect if |
| 28 # the compiler supports the flag or not. |
| 29 return 'clang' not in CompilerVersion('/usr/bin/cc') |
| 30 |
19 if sys.platform == 'darwin': | 31 if sys.platform == 'darwin': |
20 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) | 32 test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) |
21 | 33 |
22 CHDIR = 'xcode-gcc' | 34 CHDIR = 'xcode-gcc' |
23 test.run_gyp('test.gyp', chdir=CHDIR) | 35 test.run_gyp('test.gyp', chdir=CHDIR) |
24 | 36 |
25 # List of targets that'll pass. It expects targets of the same name with | 37 # List of targets that'll pass. It expects targets of the same name with |
26 # '-fail' appended that'll fail to build. | 38 # '-fail' appended that'll fail to build. |
27 targets = [ | 39 targets = [ |
28 'warn_about_missing_newline', | 40 'warn_about_missing_newline', |
29 ] | 41 ] |
30 | 42 |
31 # clang doesn't warn on invalid offsetofs, it silently ignores | 43 # clang doesn't warn on invalid offsetofs, it silently ignores |
32 # -Wno-invalid-offsetof. | 44 # -Wno-invalid-offsetof. |
33 # TODO(thakis): This isn't really the right way to detect the compiler, | 45 if CompilerSupportsWarnAboutInvalidOffsetOfMacro(test): |
34 # Xcode has some embedded compiler, but it's a reliable proxy at least on | |
35 # the bots. The compiler is forced to gcc/g++ in the gyp file in a | |
36 # make_global_settings section for ninja and make. | |
37 if test.format != 'xcode' or os.readlink('/usr/bin/cc') != 'clang': | |
38 targets.append('warn_about_invalid_offsetof_macro') | 46 targets.append('warn_about_invalid_offsetof_macro') |
39 | 47 |
40 for target in targets: | 48 for target in targets: |
41 test.build('test.gyp', target, chdir=CHDIR) | 49 test.build('test.gyp', target, chdir=CHDIR) |
42 test.built_file_must_exist(target, chdir=CHDIR) | 50 test.built_file_must_exist(target, chdir=CHDIR) |
43 fail_target = target + '-fail' | 51 fail_target = target + '-fail' |
44 test.build('test.gyp', fail_target, chdir=CHDIR, status=None, | 52 test.build('test.gyp', fail_target, chdir=CHDIR, status=None, |
45 stderr=None, match=IgnoreOutput) | 53 stderr=None, match=IgnoreOutput) |
46 test.built_file_must_not_exist(fail_target, chdir=CHDIR) | 54 test.built_file_must_not_exist(fail_target, chdir=CHDIR) |
47 | 55 |
48 test.pass_test() | 56 test.pass_test() |
OLD | NEW |