gyptest-xcode-gcc.py 1.7 KB

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