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)
8 # Test the 'glob' rule in Jamfile context.
12 # Create a temporary working directory.
13 t = BoostBuild.Tester()
15 t.write("jamroot.jam", """
18 t.write("d1/a.cpp", """
22 t.write("d1/jamfile.jam", """
23 exe a : [ glob *.cpp ] ../d2/d//l ;
26 t.write("d2/d/l.cpp", """
29 void force_import_lib_creation() {}
33 t.write("d2/d/jamfile.jam", """
34 lib l : [ glob *.cpp ] ;
37 t.write("d3/d/jamfile.jam", """
38 exe a : [ glob ../*.cpp ] ;
41 t.write("d3/a.cpp", """
45 t.run_build_system(subdir="d1")
46 t.expect_addition("d1/bin/$toolset/debug/a.exe")
48 t.run_build_system(subdir="d3/d")
49 t.expect_addition("d3/d/bin/$toolset/debug/a.exe")
53 t.run_build_system(subdir="d2/d")
54 t.expect_addition("d2/d/bin/$toolset/debug/l.dll")
57 # Test that when 'source-location' is explicitly-specified glob works relatively
58 # to the source location.
61 t.write("d1/src/a.cpp", """
65 t.write("d1/jamfile.jam", """
66 project : source-location src ;
67 exe a : [ glob *.cpp ] ../d2/d//l ;
70 t.run_build_system(subdir="d1")
71 t.expect_addition("d1/bin/$toolset/debug/a.exe")
73 # Test that wildcards can include directories. Also test exclusion patterns.
76 t.write("d1/src/foo/a.cpp", """
81 t.write("d1/src/bar/b.cpp", """
85 t.write("d1/src/bar/bad.cpp", """
86 very bad non-compilable file
89 t.write("d1/jamfile.jam", """
90 project : source-location src ;
91 exe a : [ glob foo/*.cpp bar/*.cpp : bar/bad* ] ../d2/d//l ;
94 t.run_build_system(subdir="d1")
95 t.expect_addition("d1/bin/$toolset/debug/a.exe")
98 # Test that 'glob-tree' works.
99 t.rm("d1/bin/$toolset/debug/a.exe")
101 t.write("d1/jamfile.jam", """
102 project : source-location src ;
103 exe a : [ glob-tree *.cpp : bad* ] ../d2/d//l ;
106 t.run_build_system(subdir="d1")
107 t.expect_addition("d1/bin/$toolset/debug/a.exe")
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 ;
116 t.run_build_system(subdir="d1", status=1)
117 t.expect_output_line("error: The patterns * may not include directory")
120 t.rm("d1/src/bar/bad.cpp")
122 # Test that 'glob' works with absolute names.
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 ;
134 t.run_build_system(subdir="d1")
135 t.expect_addition("d1/bin/$toolset/debug/a.exe")
138 # Regression test: glob excludes used to be broken when building from a
142 t.write("jamroot.jam", """
150 t.write("p/p_x.c", """
154 t.write("p/jamfile.jam", """
155 exe p : [ glob *.c : p_x.c ] ;
158 t.run_build_system(subdir="p")
159 t.expect_addition("p/bin/$toolset/debug/p.exe")