summaryrefslogtreecommitdiff
path: root/tools/build/test/project_glob.py
blob: 95e3f30cfed138ac4ce1fc25df30b2280ae7a105 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/python

# Copyright (C) 2003. Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

# Test the 'glob' rule in Jamfile context.

import BoostBuild


def test_basic():
    t = BoostBuild.Tester(use_test_config=False)

    t.write("jamroot.jam", "")
    t.write("d1/a.cpp", "int main() {}\n")
    t.write("d1/jamfile.jam", "exe a : [ glob *.cpp ] ../d2/d//l ;")
    t.write("d2/d/l.cpp", """\
#if defined(_WIN32)
__declspec(dllexport)
void force_import_lib_creation() {}
#endif
""")
    t.write("d2/d/jamfile.jam", "lib l : [ glob *.cpp ] ;")
    t.write("d3/d/jamfile.jam", "exe a : [ glob ../*.cpp ] ;")
    t.write("d3/a.cpp", "int main() {}\n")

    t.run_build_system(subdir="d1")
    t.expect_addition("d1/bin/$toolset/debug/a.exe")

    t.run_build_system(subdir="d3/d")
    t.expect_addition("d3/d/bin/$toolset/debug/a.exe")

    t.rm("d2/d/bin")
    t.run_build_system(subdir="d2/d")
    t.expect_addition("d2/d/bin/$toolset/debug/l.dll")

    t.cleanup()


def test_source_location():
    """
      Test that when 'source-location' is explicitly-specified glob works
    relative to the source location.

    """
    t = BoostBuild.Tester(use_test_config=False)

    t.write("jamroot.jam", "")
    t.write("d1/a.cpp", "very bad non-compilable file\n")
    t.write("d1/src/a.cpp", "int main() {}\n")
    t.write("d1/jamfile.jam", """\
project : source-location src ;
exe a : [ glob *.cpp ] ../d2/d//l ;
""")
    t.write("d2/d/l.cpp", """\
#if defined(_WIN32)
__declspec(dllexport)
void force_import_lib_creation() {}
#endif
""")
    t.write("d2/d/jamfile.jam", "lib l : [ glob *.cpp ] ;")

    t.run_build_system(subdir="d1")
    t.expect_addition("d1/bin/$toolset/debug/a.exe")

    t.cleanup()


def test_wildcards_and_exclusion_patterns():
    """
        Test that wildcards can include directories. Also test exclusion
     patterns.

    """
    t = BoostBuild.Tester(use_test_config=False)

    t.write("jamroot.jam", "")
    t.write("d1/src/foo/a.cpp", "void bar(); int main() { bar(); }\n")
    t.write("d1/src/bar/b.cpp", "void bar() {}\n")
    t.write("d1/src/bar/bad.cpp", "very bad non-compilable file\n")
    t.write("d1/jamfile.jam", """\
project : source-location src ;
exe a : [ glob foo/*.cpp bar/*.cpp : bar/bad* ] ../d2/d//l ;
""")
    t.write("d2/d/l.cpp", """\
#if defined(_WIN32)
__declspec(dllexport)
void force_import_lib_creation() {}
#endif
""")
    t.write("d2/d/jamfile.jam", "lib l : [ glob *.cpp ] ;")

    t.run_build_system(subdir="d1")
    t.expect_addition("d1/bin/$toolset/debug/a.exe")

    t.cleanup()


def test_glob_tree():
    """Test that 'glob-tree' works."""

    t = BoostBuild.Tester(use_test_config=False)

    t.write("jamroot.jam", "")
    t.write("d1/src/foo/a.cpp", "void bar(); int main() { bar(); }\n")
    t.write("d1/src/bar/b.cpp", "void bar() {}\n")
    t.write("d1/src/bar/bad.cpp", "very bad non-compilable file\n")
    t.write("d1/jamfile.jam", """\
project : source-location src ;
exe a : [ glob-tree *.cpp : bad* ] ../d2/d//l ;
""")
    t.write("d2/d/l.cpp", """\
#if defined(_WIN32)
__declspec(dllexport)
void force_import_lib_creation() {}
#endif
""")
    t.write("d2/d/jamfile.jam", "lib l : [ glob *.cpp ] ;")

    t.run_build_system(subdir="d1")
    t.expect_addition("d1/bin/$toolset/debug/a.exe")

    t.cleanup()


def test_directory_names_in_glob_tree():
    """Test that directory names in patterns for 'glob-tree' are rejected."""

    t = BoostBuild.Tester(use_test_config=False)

    t.write("jamroot.jam", "")
    t.write("d1/src/a.cpp", "very bad non-compilable file\n")
    t.write("d1/src/foo/a.cpp", "void bar(); int main() { bar(); }\n")
    t.write("d1/src/bar/b.cpp", "void bar() {}\n")
    t.write("d1/src/bar/bad.cpp", "very bad non-compilable file\n")
    t.write("d1/jamfile.jam", """\
project : source-location src ;
exe a : [ glob-tree foo/*.cpp bar/*.cpp : bad* ] ../d2/d//l ;
""")
    t.write("d2/d/l.cpp", """\
#if defined(_WIN32)
__declspec(dllexport)
void force_import_lib_creation() {}
#endif
""")
    t.write("d2/d/jamfile.jam", "lib l : [ glob *.cpp ] ;")

    t.run_build_system(subdir="d1", status=1)
    t.expect_output_lines("error: The patterns * may not include directory")

    t.cleanup()


def test_glob_with_absolute_names():
    """Test that 'glob' works with absolute names."""

    t = BoostBuild.Tester(use_test_config=False)

    t.write("jamroot.jam", "")
    t.write("d1/src/a.cpp", "very bad non-compilable file\n")
    t.write("d1/src/foo/a.cpp", "void bar(); int main() { bar(); }\n")
    t.write("d1/src/bar/b.cpp", "void bar() {}\n")
    # Note that to get the current dir, we use bjam's PWD, not Python's
    # os.getcwd(), because the former will always return a long path while the
    # latter might return a short path, which would confuse path.glob.
    t.write("d1/jamfile.jam", """\
project : source-location src ;
local pwd = [ PWD ] ;  # Always absolute.
exe a : [ glob $(pwd)/src/foo/*.cpp $(pwd)/src/bar/*.cpp ] ../d2/d//l ;
""")
    t.write("d2/d/l.cpp", """\
#if defined(_WIN32)
__declspec(dllexport)
void force_import_lib_creation() {}
#endif
""")
    t.write("d2/d/jamfile.jam", "lib l : [ glob *.cpp ] ;")

    t.run_build_system(subdir="d1")
    t.expect_addition("d1/bin/$toolset/debug/a.exe")

    t.cleanup()


def test_glob_excludes_in_subdirectory():
    """
      Regression test: glob excludes used to be broken when building from a
    subdirectory.

    """
    t = BoostBuild.Tester(use_test_config=False)

    t.write("jamroot.jam", "build-project p ;")
    t.write("p/p.c", "int main() {}\n")
    t.write("p/p_x.c", "very bad non-compilable file\n")
    t.write("p/jamfile.jam", "exe p : [ glob *.c : p_x.c ] ;")

    t.run_build_system(subdir="p")
    t.expect_addition("p/bin/$toolset/debug/p.exe")

    t.cleanup()


test_basic()
test_source_location()
test_wildcards_and_exclusion_patterns()
test_glob_tree()
test_directory_names_in_glob_tree()
test_glob_with_absolute_names()
test_glob_excludes_in_subdirectory()