gyptest-compiler-global-settings.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 make_global_settings can be used to override the
  7. compiler settings.
  8. """
  9. import TestGyp
  10. import os
  11. import copy
  12. import sys
  13. from string import Template
  14. if sys.platform == 'win32':
  15. # cross compiling not support by ninja on windows
  16. # and make not supported on windows at all.
  17. sys.exit(0)
  18. test = TestGyp.TestGyp(formats=['ninja', 'make'])
  19. gypfile = 'compiler-global-settings.gyp'
  20. replacements = { 'PYTHON': '/usr/bin/python', 'PWD': os.getcwd()}
  21. # Process the .in gyp file to produce the final gyp file
  22. # since we need to include absolute paths in the make_global_settings
  23. # section.
  24. replacements['TOOLSET'] = 'target'
  25. s = Template(open(gypfile + '.in').read())
  26. output = open(gypfile, 'w')
  27. output.write(s.substitute(replacements))
  28. output.close()
  29. old_env = dict(os.environ)
  30. os.environ['GYP_CROSSCOMPILE'] = '1'
  31. test.run_gyp(gypfile)
  32. os.environ.clear()
  33. os.environ.update(old_env)
  34. test.build(gypfile)
  35. test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'FOO'])
  36. # The xcode generator chokes on the 'host' toolset. Skip the rest of
  37. # this test (cf. https://code.google.com/p/gyp/issues/detail?id=454).
  38. if test.format == 'xcode-ninja':
  39. test.pass_test()
  40. # Same again but with the host toolset.
  41. replacements['TOOLSET'] = 'host'
  42. s = Template(open(gypfile + '.in').read())
  43. output = open(gypfile, 'w')
  44. output.write(s.substitute(replacements))
  45. output.close()
  46. old_env = dict(os.environ)
  47. os.environ['GYP_CROSSCOMPILE'] = '1'
  48. test.run_gyp(gypfile)
  49. os.environ.clear()
  50. os.environ.update(old_env)
  51. test.build(gypfile)
  52. test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'BAR'])
  53. # Check that CC_host overrides make_global_settings
  54. old_env = dict(os.environ)
  55. os.environ['CC_host'] = '%s %s/my_cc.py SECRET' % (replacements['PYTHON'],
  56. replacements['PWD'])
  57. test.run_gyp(gypfile)
  58. os.environ.clear()
  59. os.environ.update(old_env)
  60. test.build(gypfile)
  61. test.must_contain_all_lines(test.stdout(), ['SECRET', 'my_cxx.py', 'BAR'])
  62. test.pass_test()