gyptest-postbuild-fail.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. # Copyright (c) 2011 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 a failing postbuild step lets the build fail.
  7. """
  8. import TestGyp
  9. import sys
  10. if sys.platform == 'darwin':
  11. # set |match| to ignore build stderr output.
  12. test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode'],
  13. match = lambda a, b: True)
  14. test.run_gyp('test.gyp', chdir='postbuild-fail')
  15. build_error_code = {
  16. 'xcode': [1, 65], # 1 for xcode 3, 65 for xcode 4 (see `man sysexits`)
  17. 'make': 2,
  18. 'ninja': 1,
  19. 'xcode-ninja': [1, 65],
  20. }[test.format]
  21. # If a postbuild fails, all postbuilds should be re-run on the next build.
  22. # In Xcode 3, even if the first postbuild fails the other postbuilds were
  23. # still executed. In Xcode 4, postbuilds are stopped after the first
  24. # failing postbuild. This test checks for the Xcode 4 behavior.
  25. # Ignore this test on Xcode 3.
  26. import subprocess
  27. job = subprocess.Popen(['xcodebuild', '-version'],
  28. stdout=subprocess.PIPE,
  29. stderr=subprocess.STDOUT)
  30. out, err = job.communicate()
  31. if job.returncode != 0:
  32. print out
  33. raise Exception('Error %d running xcodebuild' % job.returncode)
  34. if out.startswith('Xcode 3.'):
  35. test.pass_test()
  36. # Non-bundles
  37. test.build('test.gyp', 'nonbundle', chdir='postbuild-fail',
  38. status=build_error_code)
  39. test.built_file_must_not_exist('static_touch',
  40. chdir='postbuild-fail')
  41. # Check for non-up-to-date-ness by checking if building again produces an
  42. # error.
  43. test.build('test.gyp', 'nonbundle', chdir='postbuild-fail',
  44. status=build_error_code)
  45. # Bundles
  46. test.build('test.gyp', 'bundle', chdir='postbuild-fail',
  47. status=build_error_code)
  48. test.built_file_must_not_exist('dynamic_touch',
  49. chdir='postbuild-fail')
  50. # Check for non-up-to-date-ness by checking if building again produces an
  51. # error.
  52. test.build('test.gyp', 'bundle', chdir='postbuild-fail',
  53. status=build_error_code)
  54. test.pass_test()