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