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"""
8Verify the settings that cause a set of programs to be created in
9a specific build directory, and that no intermediate built files
10get created outside of that build directory hierarchy even when
11referred to with deeply-nested ../../.. paths.
12"""
13
14import TestGyp
15
16# TODO(mmoss): Make only supports (theoretically) a single, global build
17# directory (through GYP_GENERATOR_FLAGS 'output_dir'), rather than
18# gyp-file-specific settings (e.g. the stuff in builddir.gypi) that the other
19# generators support, so this doesn't work yet for make.
20# TODO(mmoss) Make also has the issue that the top-level Makefile is written to
21# the "--depth" location, which is one level above 'src', but then this test
22# moves 'src' somewhere else, leaving the Makefile behind, so make can't find
23# its sources. I'm not sure if make is wrong for writing outside the current
24# directory, or if the test is wrong for assuming everything generated is under
25# the current directory.
26# Android, Ninja, and CMake do not support setting the build directory.
27test = TestGyp.TestGyp(formats=['!make', '!ninja', '!android', '!cmake'])
28
29test.run_gyp('prog1.gyp', '--depth=..', chdir='src')
30if test.format == 'msvs':
31  if test.uses_msbuild:
32    test.must_contain('src/prog1.vcxproj',
33      '<OutDir>..\\builddir\\Default\\</OutDir>')
34  else:
35    test.must_contain('src/prog1.vcproj',
36      'OutputDirectory="..\\builddir\\Default\\"')
37
38test.relocate('src', 'relocate/src')
39
40test.subdir('relocate/builddir')
41
42# Make sure that all the built ../../etc. files only get put under builddir,
43# by making all of relocate read-only and then making only builddir writable.
44test.writable('relocate', False)
45test.writable('relocate/builddir', True)
46
47# Suppress the test infrastructure's setting SYMROOT on the command line.
48test.build('prog1.gyp', test.ALL, SYMROOT=None, chdir='relocate/src')
49
50expect1 = """\
51Hello from prog1.c
52Hello from func1.c
53"""
54
55expect2 = """\
56Hello from subdir2/prog2.c
57Hello from func2.c
58"""
59
60expect3 = """\
61Hello from subdir2/subdir3/prog3.c
62Hello from func3.c
63"""
64
65expect4 = """\
66Hello from subdir2/subdir3/subdir4/prog4.c
67Hello from func4.c
68"""
69
70expect5 = """\
71Hello from subdir2/subdir3/subdir4/subdir5/prog5.c
72Hello from func5.c
73"""
74
75def run_builddir(prog, expect):
76  dir = 'relocate/builddir/Default/'
77  test.run(program=test.workpath(dir + prog), stdout=expect)
78
79run_builddir('prog1', expect1)
80run_builddir('prog2', expect2)
81run_builddir('prog3', expect3)
82run_builddir('prog4', expect4)
83run_builddir('prog5', expect5)
84
85test.pass_test()
86