project_glob.py 6.0 KB

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