Home | History | Annotate | Download | only in mac
      1 #!/usr/bin/env python
      2 
      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
      5 # found in the LICENSE file.
      6 
      7 """
      8 Verifies that xcode-style GCC_... settings are handled properly.
      9 """
     10 
     11 import TestGyp
     12 
     13 import os
     14 import subprocess
     15 import sys
     16 
     17 def IgnoreOutput(string, expected_string):
     18   return True
     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 
     31 if sys.platform == 'darwin':
     32   test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'])
     33 
     34   CHDIR = 'xcode-gcc'
     35   test.run_gyp('test.gyp', chdir=CHDIR)
     36 
     37   # List of targets that'll pass. It expects targets of the same name with
     38   # '-fail' appended that'll fail to build.
     39   targets = [
     40     'warn_about_missing_newline',
     41   ]
     42 
     43   # clang doesn't warn on invalid offsetofs, it silently ignores
     44   # -Wno-invalid-offsetof.
     45   if CompilerSupportsWarnAboutInvalidOffsetOfMacro(test):
     46     targets.append('warn_about_invalid_offsetof_macro')
     47 
     48   for target in targets:
     49     test.build('test.gyp', target, chdir=CHDIR)
     50     test.built_file_must_exist(target, chdir=CHDIR)
     51     fail_target = target + '-fail'
     52     test.build('test.gyp', fail_target, chdir=CHDIR, status=None,
     53                stderr=None, match=IgnoreOutput)
     54     test.built_file_must_not_exist(fail_target, chdir=CHDIR)
     55 
     56   test.pass_test()
     57