gyptest-cxxflags.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 build of an executable with C++ define specified by a gyp define, and
  7. the use of the environment during regeneration when the gyp file changes.
  8. """
  9. import os
  10. import TestGyp
  11. env_stack = []
  12. def PushEnv():
  13. env_copy = os.environ.copy()
  14. env_stack.append(env_copy)
  15. def PopEnv():
  16. os.eniron=env_stack.pop()
  17. # Regenerating build files when a gyp file changes is currently only supported
  18. # by the make generator.
  19. test = TestGyp.TestGyp(formats=['make'])
  20. try:
  21. PushEnv()
  22. os.environ['CXXFLAGS'] = '-O0'
  23. test.run_gyp('cxxflags.gyp')
  24. finally:
  25. # We clear the environ after calling gyp. When the auto-regeneration happens,
  26. # the same define should be reused anyway. Reset to empty string first in
  27. # case the platform doesn't support unsetenv.
  28. PopEnv()
  29. test.build('cxxflags.gyp')
  30. expect = """\
  31. Using no optimization flag
  32. """
  33. test.run_built_executable('cxxflags', stdout=expect)
  34. test.sleep()
  35. try:
  36. PushEnv()
  37. os.environ['CXXFLAGS'] = '-O2'
  38. test.run_gyp('cxxflags.gyp')
  39. finally:
  40. # We clear the environ after calling gyp. When the auto-regeneration happens,
  41. # the same define should be reused anyway. Reset to empty string first in
  42. # case the platform doesn't support unsetenv.
  43. PopEnv()
  44. test.build('cxxflags.gyp')
  45. expect = """\
  46. Using an optimization flag
  47. """
  48. test.run_built_executable('cxxflags', stdout=expect)
  49. test.pass_test()