Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / v2 / test / project_glob.py
1 #!/usr/bin/python
2
3 # Copyright (C) Vladimir Prus 2003.
4 # Distributed under the Boost Software License, Version 1.0.
5 #    (See accompanying file LICENSE_1_0.txt or copy at
6 #         http://www.boost.org/LICENSE_1_0.txt)
7
8 # Test the 'glob' rule in Jamfile context.
9
10 import BoostBuild
11
12 # Create a temporary working directory.
13 t = BoostBuild.Tester()
14
15 t.write("jamroot.jam", """
16 """)
17
18 t.write("d1/a.cpp", """
19 int main() {}
20 """)
21
22 t.write("d1/jamfile.jam", """
23 exe a : [ glob *.cpp ] ../d2/d//l ;
24 """)
25
26 t.write("d2/d/l.cpp", """
27 #if defined(_WIN32)
28 __declspec(dllexport)
29 void force_import_lib_creation() {}
30 #endif
31 """)
32
33 t.write("d2/d/jamfile.jam", """
34 lib l : [ glob *.cpp ] ;
35 """)
36
37 t.write("d3/d/jamfile.jam", """
38 exe a : [ glob ../*.cpp ] ;
39 """)
40
41 t.write("d3/a.cpp", """
42 int main() {}
43 """)
44
45 t.run_build_system(subdir="d1")
46 t.expect_addition("d1/bin/$toolset/debug/a.exe")
47
48 t.run_build_system(subdir="d3/d")
49 t.expect_addition("d3/d/bin/$toolset/debug/a.exe")
50
51 t.rm("d2/d/bin")
52
53 t.run_build_system(subdir="d2/d")
54 t.expect_addition("d2/d/bin/$toolset/debug/l.dll")
55
56
57 # Test that when 'source-location' is explicitly-specified glob works relatively
58 # to the source location.
59 t.rm("d1")
60
61 t.write("d1/src/a.cpp", """
62 int main() {}
63 """)
64
65 t.write("d1/jamfile.jam", """
66 project : source-location src ;
67 exe a : [ glob *.cpp ] ../d2/d//l ;
68 """)
69
70 t.run_build_system(subdir="d1")
71 t.expect_addition("d1/bin/$toolset/debug/a.exe")
72
73 # Test that wildcards can include directories. Also test exclusion patterns.
74 t.rm("d1")
75
76 t.write("d1/src/foo/a.cpp", """
77 void bar();
78 int main() { bar(); }
79 """)
80
81 t.write("d1/src/bar/b.cpp", """
82 void bar() {}
83 """)
84
85 t.write("d1/src/bar/bad.cpp", """
86 very bad non-compilable file
87 """)
88
89 t.write("d1/jamfile.jam", """
90 project : source-location src ;
91 exe a : [ glob foo/*.cpp bar/*.cpp : bar/bad* ] ../d2/d//l ;
92 """)
93
94 t.run_build_system(subdir="d1")
95 t.expect_addition("d1/bin/$toolset/debug/a.exe")
96
97
98 # Test that 'glob-tree' works.
99 t.rm("d1/bin/$toolset/debug/a.exe")
100
101 t.write("d1/jamfile.jam", """
102 project : source-location src ;
103 exe a : [ glob-tree *.cpp : bad* ] ../d2/d//l ;
104 """)
105
106 t.run_build_system(subdir="d1")
107 t.expect_addition("d1/bin/$toolset/debug/a.exe")
108
109
110 # Test that directory names in patterns for 'glob-tree' are rejected.
111 t.write("d1/jamfile.jam", """
112 project : source-location src ;
113 exe a : [ glob-tree foo/*.cpp bar/*.cpp : bad* ] ../d2/d//l ;
114 """)
115
116 t.run_build_system(subdir="d1", status=1)
117 t.expect_output_line("error: The patterns * may not include directory")
118
119
120 t.rm("d1/src/bar/bad.cpp")
121
122 # Test that 'glob' works with absolute names.
123 t.rm("d1/bin")
124
125 # Note that to get current dir, we use bjam's PWD, not Python's os.getcwd(),
126 # because the former will always return long path while the latter might return
127 # a short path, and that will confuse path.glob.
128 t.write("d1/jamfile.jam", """
129 project : source-location src ;
130 local pwd = [ PWD ] ;  # Always absolute
131 exe a : [ glob $(pwd)/src/foo/*.cpp $(pwd)/src/bar/*.cpp ] ../d2/d//l ;
132 """)
133
134 t.run_build_system(subdir="d1")
135 t.expect_addition("d1/bin/$toolset/debug/a.exe")
136
137
138 # Regression test: glob excludes used to be broken when building from a
139 # subdirectory.
140 t.rm(".")
141
142 t.write("jamroot.jam", """
143 build-project p ;
144 """)
145
146 t.write("p/p.c", """
147 int main() {}
148 """)
149
150 t.write("p/p_x.c", """
151 int main() {}
152 """)
153
154 t.write("p/jamfile.jam", """
155 exe p : [ glob *.c : p_x.c ] ;
156 """)
157
158 t.run_build_system(subdir="p")
159 t.expect_addition("p/bin/$toolset/debug/p.exe")
160
161 t.cleanup()