gyptest-defines-env.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # Copyright (c) 2009 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.
  7. """
  8. import os
  9. import TestGyp
  10. test = TestGyp.TestGyp()
  11. # With the value only given in environment, it should be used.
  12. try:
  13. os.environ['GYP_DEFINES'] = 'value=10'
  14. test.run_gyp('defines-env.gyp')
  15. finally:
  16. del os.environ['GYP_DEFINES']
  17. test.build('defines-env.gyp')
  18. expect = """\
  19. VALUE is 10
  20. """
  21. test.run_built_executable('defines', stdout=expect)
  22. # With the value given in both command line and environment,
  23. # command line should take precedence.
  24. try:
  25. os.environ['GYP_DEFINES'] = 'value=20'
  26. test.run_gyp('defines-env.gyp', '-Dvalue=25')
  27. finally:
  28. del os.environ['GYP_DEFINES']
  29. test.sleep()
  30. test.touch('defines.c')
  31. test.build('defines-env.gyp')
  32. expect = """\
  33. VALUE is 25
  34. """
  35. test.run_built_executable('defines', stdout=expect)
  36. # With the value only given in environment, it should be ignored if
  37. # --ignore-environment is specified.
  38. try:
  39. os.environ['GYP_DEFINES'] = 'value=30'
  40. test.run_gyp('defines-env.gyp', '--ignore-environment')
  41. finally:
  42. del os.environ['GYP_DEFINES']
  43. test.sleep()
  44. test.touch('defines.c')
  45. test.build('defines-env.gyp')
  46. expect = """\
  47. VALUE is 5
  48. """
  49. test.run_built_executable('defines', stdout=expect)
  50. # With the value given in both command line and environment, and
  51. # --ignore-environment also specified, command line should still be used.
  52. try:
  53. os.environ['GYP_DEFINES'] = 'value=40'
  54. test.run_gyp('defines-env.gyp', '--ignore-environment', '-Dvalue=45')
  55. finally:
  56. del os.environ['GYP_DEFINES']
  57. test.sleep()
  58. test.touch('defines.c')
  59. test.build('defines-env.gyp')
  60. expect = """\
  61. VALUE is 45
  62. """
  63. test.run_built_executable('defines', stdout=expect)
  64. test.pass_test()