gyptest-no-cpp.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. Checks that C-only targets aren't linked against libstdc++.
  7. """
  8. import TestGyp
  9. import re
  10. import subprocess
  11. import sys
  12. # set |match| to ignore build stderr output.
  13. test = TestGyp.TestGyp(match = lambda a, b: True)
  14. if sys.platform != 'win32' and test.format not in ('make', 'android'):
  15. # TODO: This doesn't pass with make.
  16. # TODO: Does a test like this make sense with Windows? Android?
  17. CHDIR = 'src'
  18. test.run_gyp('test.gyp', chdir=CHDIR)
  19. test.build('test.gyp', 'no_cpp', chdir=CHDIR)
  20. def LinksLibStdCpp(path):
  21. path = test.built_file_path(path, chdir=CHDIR)
  22. if sys.platform == 'darwin':
  23. proc = subprocess.Popen(['otool', '-L', path], stdout=subprocess.PIPE)
  24. else:
  25. proc = subprocess.Popen(['ldd', path], stdout=subprocess.PIPE)
  26. output = proc.communicate()[0]
  27. assert not proc.returncode
  28. return 'libstdc++' in output or 'libc++' in output
  29. if LinksLibStdCpp('no_cpp'):
  30. test.fail_test()
  31. build_error_code = {
  32. 'xcode': [1, 65], # 1 for xcode 3, 65 for xcode 4 (see `man sysexits`)
  33. 'make': 2,
  34. 'ninja': 1,
  35. 'cmake': 0, # CMake picks the compiler driver based on transitive checks.
  36. 'xcode-ninja': [1, 65],
  37. }[test.format]
  38. test.build('test.gyp', 'no_cpp_dep_on_cc_lib', chdir=CHDIR,
  39. status=build_error_code)
  40. test.pass_test()