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