gyptest-all.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 simple actions when using an explicit build target of 'all'.
  7. """
  8. import glob
  9. import os
  10. import TestGyp
  11. test = TestGyp.TestGyp(workdir='workarea_all')
  12. test.run_gyp('actions.gyp', chdir='src')
  13. test.relocate('src', 'relocate/src')
  14. # Some gyp files use an action that mentions an output but never
  15. # writes it as a means to making the action run on every build. That
  16. # doesn't mesh well with ninja's semantics. TODO(evan): figure out
  17. # how to work always-run actions in to ninja.
  18. # Android also can't do this as it doesn't have order-only dependencies.
  19. if test.format in ['ninja', 'android', 'xcode-ninja']:
  20. test.build('actions.gyp', test.ALL, chdir='relocate/src')
  21. else:
  22. # Test that an "always run" action increases a counter on multiple
  23. # invocations, and that a dependent action updates in step.
  24. test.build('actions.gyp', test.ALL, chdir='relocate/src')
  25. test.must_match('relocate/src/subdir1/actions-out/action-counter.txt', '1')
  26. test.must_match('relocate/src/subdir1/actions-out/action-counter_2.txt', '1')
  27. test.build('actions.gyp', test.ALL, chdir='relocate/src')
  28. test.must_match('relocate/src/subdir1/actions-out/action-counter.txt', '2')
  29. test.must_match('relocate/src/subdir1/actions-out/action-counter_2.txt', '2')
  30. # The "always run" action only counts to 2, but the dependent target
  31. # will count forever if it's allowed to run. This verifies that the
  32. # dependent target only runs when the "always run" action generates
  33. # new output, not just because the "always run" ran.
  34. test.build('actions.gyp', test.ALL, chdir='relocate/src')
  35. test.must_match('relocate/src/subdir1/actions-out/action-counter.txt', '2')
  36. test.must_match('relocate/src/subdir1/actions-out/action-counter_2.txt', '2')
  37. expect = """\
  38. Hello from program.c
  39. Hello from make-prog1.py
  40. Hello from make-prog2.py
  41. """
  42. if test.format == 'xcode':
  43. chdir = 'relocate/src/subdir1'
  44. else:
  45. chdir = 'relocate/src'
  46. test.run_built_executable('program', chdir=chdir, stdout=expect)
  47. test.must_match('relocate/src/subdir2/file.out', "Hello from make-file.py\n")
  48. expect = "Hello from generate_main.py\n"
  49. if test.format == 'xcode':
  50. chdir = 'relocate/src/subdir3'
  51. else:
  52. chdir = 'relocate/src'
  53. test.run_built_executable('null_input', chdir=chdir, stdout=expect)
  54. # Clean out files which may have been created if test.ALL was run.
  55. def clean_dep_files():
  56. for file in (glob.glob('relocate/src/dep_*.txt') +
  57. glob.glob('relocate/src/deps_all_done_*.txt')):
  58. if os.path.exists(file):
  59. os.remove(file)
  60. # Confirm our clean.
  61. clean_dep_files()
  62. test.must_not_exist('relocate/src/dep_1.txt')
  63. test.must_not_exist('relocate/src/deps_all_done_first_123.txt')
  64. # Make sure all deps finish before an action is run on a 'None' target.
  65. # If using the Make builder, add -j to make things more difficult.
  66. arguments = []
  67. if test.format == 'make':
  68. arguments = ['-j']
  69. test.build('actions.gyp', 'action_with_dependencies_123', chdir='relocate/src',
  70. arguments=arguments)
  71. test.must_exist('relocate/src/deps_all_done_first_123.txt')
  72. # Try again with a target that has deps in reverse. Output files from
  73. # previous tests deleted. Confirm this execution did NOT run the ALL
  74. # target which would mess up our dep tests.
  75. clean_dep_files()
  76. test.build('actions.gyp', 'action_with_dependencies_321', chdir='relocate/src',
  77. arguments=arguments)
  78. test.must_exist('relocate/src/deps_all_done_first_321.txt')
  79. test.must_not_exist('relocate/src/deps_all_done_first_123.txt')
  80. test.pass_test()