• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
25# Android also can't do this as it doesn't have order-only dependencies.
26if test.format in ['ninja', 'android']:
27  test.build('actions.gyp', test.ALL, chdir='relocate/src')
28else:
29  # Test that an "always run" action increases a counter on multiple
30  # invocations, and that a dependent action updates in step.
31  test.build('actions.gyp', test.ALL, chdir='relocate/src')
32  test.must_match('relocate/src/subdir1/actions-out/action-counter.txt', '1')
33  test.must_match('relocate/src/subdir1/actions-out/action-counter_2.txt', '1')
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
38  # The "always run" action only counts to 2, but the dependent target
39  # will count forever if it's allowed to run. This verifies that the
40  # dependent target only runs when the "always run" action generates
41  # new output, not just because the "always run" ran.
42  test.build('actions.gyp', test.ALL, chdir='relocate/src')
43  test.must_match('relocate/src/subdir1/actions-out/action-counter.txt', '2')
44  test.must_match('relocate/src/subdir1/actions-out/action-counter_2.txt', '2')
45
46expect = """\
47Hello from program.c
48Hello from make-prog1.py
49Hello from make-prog2.py
50"""
51
52if test.format == 'xcode':
53  chdir = 'relocate/src/subdir1'
54else:
55  chdir = 'relocate/src'
56test.run_built_executable('program', chdir=chdir, stdout=expect)
57
58
59test.must_match('relocate/src/subdir2/file.out', "Hello from make-file.py\n")
60
61
62expect = "Hello from generate_main.py\n"
63
64if test.format == 'xcode':
65  chdir = 'relocate/src/subdir3'
66else:
67  chdir = 'relocate/src'
68test.run_built_executable('null_input', chdir=chdir, stdout=expect)
69
70
71# Clean out files which may have been created if test.ALL was run.
72def clean_dep_files():
73  for file in (glob.glob('relocate/src/dep_*.txt') +
74               glob.glob('relocate/src/deps_all_done_*.txt')):
75    if os.path.exists(file):
76      os.remove(file)
77
78# Confirm our clean.
79clean_dep_files()
80test.must_not_exist('relocate/src/dep_1.txt')
81test.must_not_exist('relocate/src/deps_all_done_first_123.txt')
82
83# Make sure all deps finish before an action is run on a 'None' target.
84# If using the Make builder, add -j to make things more difficult.
85arguments = []
86if test.format == 'make':
87  arguments = ['-j']
88test.build('actions.gyp', 'action_with_dependencies_123', chdir='relocate/src',
89           arguments=arguments)
90test.must_exist('relocate/src/deps_all_done_first_123.txt')
91
92# Try again with a target that has deps in reverse.  Output files from
93# previous tests deleted.  Confirm this execution did NOT run the ALL
94# target which would mess up our dep tests.
95clean_dep_files()
96test.build('actions.gyp', 'action_with_dependencies_321', chdir='relocate/src',
97           arguments=arguments)
98test.must_exist('relocate/src/deps_all_done_first_321.txt')
99test.must_not_exist('relocate/src/deps_all_done_first_123.txt')
100
101
102test.pass_test()
103