gyptest-cflags.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 the use of the environment during regeneration when the gyp file
  7. changes, specifically via build of an executable with C preprocessor
  8. definition specified by CFLAGS.
  9. In this test, gyp and build both run in same local environment.
  10. """
  11. import TestGyp
  12. # CPPFLAGS works in ninja but not make; CFLAGS works in both
  13. FORMATS = ('make', 'ninja')
  14. test = TestGyp.TestGyp(formats=FORMATS)
  15. # First set CFLAGS to blank in case the platform doesn't support unsetenv.
  16. with TestGyp.LocalEnv({'CFLAGS': '',
  17. 'GYP_CROSSCOMPILE': '1'}):
  18. test.run_gyp('cflags.gyp')
  19. test.build('cflags.gyp')
  20. expect = """FOO not defined\n"""
  21. test.run_built_executable('cflags', stdout=expect)
  22. test.run_built_executable('cflags_host', stdout=expect)
  23. test.sleep()
  24. with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1',
  25. 'GYP_CROSSCOMPILE': '1'}):
  26. test.run_gyp('cflags.gyp')
  27. test.build('cflags.gyp')
  28. expect = """FOO defined\n"""
  29. test.run_built_executable('cflags', stdout=expect)
  30. # Environment variables shouldn't influence the flags for the host.
  31. expect = """FOO not defined\n"""
  32. test.run_built_executable('cflags_host', stdout=expect)
  33. test.sleep()
  34. with TestGyp.LocalEnv({'CFLAGS': ''}):
  35. test.run_gyp('cflags.gyp')
  36. test.build('cflags.gyp')
  37. expect = """FOO not defined\n"""
  38. test.run_built_executable('cflags', stdout=expect)
  39. test.sleep()
  40. with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1'}):
  41. test.run_gyp('cflags.gyp')
  42. test.build('cflags.gyp')
  43. expect = """FOO defined\n"""
  44. test.run_built_executable('cflags', stdout=expect)
  45. test.pass_test()