configure.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #!/usr/bin/python
  2. # Copyright 2017 Steven Watanabe
  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. # Tests configure.check-target-builds and friends
  7. import BoostBuild
  8. def test_check_target_builds():
  9. t = BoostBuild.Tester(use_test_config=0)
  10. t.write("Jamroot", """
  11. import configure ;
  12. obj pass : pass.cpp ;
  13. obj fail : fail.cpp ;
  14. explicit pass fail ;
  15. obj foo : foo.cpp :
  16. [ configure.check-target-builds pass : <define>PASS : <define>FAIL ] ;
  17. obj bar : foo.cpp :
  18. [ configure.check-target-builds fail : <define>FAIL : <define>PASS ] ;
  19. """)
  20. t.write("pass.cpp", "void f() {}\n")
  21. t.write("fail.cpp", "#error fail.cpp\n")
  22. t.write("foo.cpp", """
  23. #ifndef PASS
  24. #error PASS not defined
  25. #endif
  26. #ifdef FAIL
  27. #error FAIL is defined
  28. #endif
  29. """)
  30. t.run_build_system()
  31. t.expect_output_lines([
  32. " - pass builds : yes*",
  33. " - fail builds : no*"])
  34. t.expect_addition("bin/$toolset/debug*/pass.obj")
  35. t.expect_addition("bin/$toolset/debug*/foo.obj")
  36. t.expect_addition("bin/$toolset/debug*/bar.obj")
  37. t.expect_nothing_more()
  38. # An up-to-date build should use the cache
  39. t.run_build_system()
  40. t.expect_output_lines([
  41. " - pass builds : yes (cached)*",
  42. " - fail builds : no (cached)*"])
  43. t.expect_nothing_more()
  44. # -a should re-run everything, including configuration checks
  45. t.run_build_system(["-a"])
  46. t.expect_output_lines([
  47. " - pass builds : yes*",
  48. " - fail builds : no*"])
  49. t.expect_touch("bin/$toolset/debug*/pass.obj")
  50. t.expect_touch("bin/$toolset/debug*/foo.obj")
  51. t.expect_touch("bin/$toolset/debug*/bar.obj")
  52. t.expect_nothing_more()
  53. # --reconfigure should re-run configuration checks only
  54. t.run_build_system(["--reconfigure"])
  55. t.expect_output_lines([
  56. " - pass builds : yes*",
  57. " - fail builds : no*"])
  58. t.expect_touch("bin/$toolset/debug*/pass.obj")
  59. t.expect_nothing_more()
  60. # -a -n should not rebuild configuration checks
  61. t.run_build_system(["-a", "-n"])
  62. t.expect_output_lines([
  63. " - pass builds : yes (cached)*",
  64. " - fail builds : no (cached)*"])
  65. t.expect_nothing_more()
  66. # --clean-all should clear all configuration checks
  67. t.run_build_system(["--clean-all"])
  68. t.expect_output_lines([
  69. " - pass builds : yes (cached)*",
  70. " - fail builds : no (cached)*"])
  71. t.expect_removal("bin/$toolset/debug*/pass.obj")
  72. t.expect_removal("bin/$toolset/debug*/foo.obj")
  73. t.expect_removal("bin/$toolset/debug*/bar.obj")
  74. t.expect_nothing_more()
  75. # If configuration checks are absent, then --clean-all
  76. # should create them and then delete them again. This
  77. # currently fails because clean cannot remove targets
  78. # that were created in the same build.
  79. #t.run_build_system(["--clean-all"])
  80. #t.expect_output_lines([
  81. # " - pass builds : yes",
  82. # " - fail builds : no"])
  83. #t.expect_nothing_more()
  84. # Just verify that we're actually in the initial
  85. # state here.
  86. t.run_build_system()
  87. t.expect_output_lines([
  88. " - pass builds : yes*",
  89. " - fail builds : no*"])
  90. t.expect_addition("bin/$toolset/debug*/pass.obj")
  91. t.expect_addition("bin/$toolset/debug*/foo.obj")
  92. t.expect_addition("bin/$toolset/debug*/bar.obj")
  93. t.expect_nothing_more()
  94. t.cleanup()
  95. def test_choose():
  96. t = BoostBuild.Tester(use_test_config=0)
  97. t.write("Jamroot", """
  98. import configure ;
  99. obj pass : pass.cpp ;
  100. obj fail : fail.cpp ;
  101. explicit pass fail ;
  102. obj foo : foo.cpp :
  103. [ configure.choose "which one?" : fail <define>FAIL : pass <define>PASS ] ;
  104. """)
  105. t.write("pass.cpp", "void f() {}\n")
  106. t.write("fail.cpp", "#error fail.cpp\n")
  107. t.write("foo.cpp", """
  108. #ifndef PASS
  109. #error PASS not defined
  110. #endif
  111. #ifdef FAIL
  112. #error FAIL is defined
  113. #endif
  114. """)
  115. t.run_build_system()
  116. t.expect_output_lines([
  117. " - which one? : pass*"])
  118. t.expect_addition("bin/$toolset/debug*/pass.obj")
  119. t.expect_addition("bin/$toolset/debug*/foo.obj")
  120. t.expect_nothing_more()
  121. # An up-to-date build should use the cache
  122. t.run_build_system()
  123. t.expect_output_lines([
  124. " - which one? : pass (cached)*"])
  125. t.expect_nothing_more()
  126. # -a should re-run everything, including configuration checks
  127. t.run_build_system(["-a"])
  128. t.expect_output_lines([
  129. " - which one? : pass*"])
  130. t.expect_touch("bin/$toolset/debug*/pass.obj")
  131. t.expect_touch("bin/$toolset/debug*/foo.obj")
  132. t.expect_nothing_more()
  133. # --reconfigure should re-run configuration checks only
  134. t.run_build_system(["--reconfigure"])
  135. t.expect_output_lines([
  136. " - which one? : pass*"])
  137. t.expect_touch("bin/$toolset/debug*/pass.obj")
  138. t.expect_nothing_more()
  139. # -a -n should not rebuild configuration checks
  140. t.run_build_system(["-a", "-n"])
  141. t.expect_output_lines([
  142. " - which one? : pass (cached)*"])
  143. t.expect_nothing_more()
  144. # --clean-all should clear all configuration checks
  145. t.run_build_system(["--clean-all"])
  146. t.expect_output_lines([
  147. " - which one? : pass (cached)*"])
  148. t.expect_removal("bin/$toolset/debug*/pass.obj")
  149. t.expect_removal("bin/$toolset/debug*/foo.obj")
  150. t.expect_nothing_more()
  151. # If configuration checks are absent, then --clean-all
  152. # should create them and then delete them again. This
  153. # currently fails because clean cannot remove targets
  154. # that were created in the same build.
  155. #t.run_build_system(["--clean-all"])
  156. #t.expect_output_lines([
  157. # " - which one? : pass"])
  158. #t.expect_nothing_more()
  159. # Just verify that we're actually in the initial
  160. # state here.
  161. t.run_build_system()
  162. t.expect_output_lines([
  163. " - which one? : pass*"])
  164. t.expect_addition("bin/$toolset/debug*/pass.obj")
  165. t.expect_addition("bin/$toolset/debug*/foo.obj")
  166. t.expect_nothing_more()
  167. t.cleanup()
  168. def test_translation():
  169. """Tests scoping for targets, paths, and rules within check-target-builds"""
  170. t = BoostBuild.Tester(use_test_config=0)
  171. t.write("Jamroot", "")
  172. t.write("subdir/Jamfile", """
  173. import configure ;
  174. obj pass : pass.cpp ;
  175. obj fail : fail.cpp ;
  176. explicit pass fail ;
  177. obj foo : :
  178. [ configure.check-target-builds pass
  179. : [ configure.check-target-builds fail : <define>FAIL
  180. : <define>PASS <include>include1 <conditional>@c1 ]
  181. : <define>FAIL ] ;
  182. obj bar : :
  183. [ configure.choose "which one?" : pass
  184. [ configure.choose "Try again?" : pass
  185. <define>PASS <include>include1 <conditional>@c1 ] ] ;
  186. rule c1 ( properties * )
  187. {
  188. return <include>include2 <source>foo.cpp ;
  189. }
  190. """)
  191. t.write("subdir/include1/a.h", "")
  192. t.write("subdir/include2/b.h", "")
  193. t.write("subdir/pass.cpp", "void f() {}\n")
  194. t.write("subdir/fail.cpp", "#error fail.cpp\n")
  195. t.write("subdir/foo.cpp", """
  196. #include <a.h>
  197. #include <b.h>
  198. #ifndef PASS
  199. #error PASS not defined
  200. #endif
  201. #ifdef FAIL
  202. #error FAIL is defined
  203. #endif
  204. """)
  205. t.run_build_system(["subdir"])
  206. t.expect_output_lines([
  207. " - pass builds : yes*",
  208. " - fail builds : no*"])
  209. t.expect_addition("subdir/bin/$toolset/debug*/pass.obj")
  210. t.expect_addition("subdir/bin/$toolset/debug*/foo.obj")
  211. t.expect_addition("subdir/bin/$toolset/debug*/bar.obj")
  212. t.expect_nothing_more()
  213. t.cleanup()
  214. def test_choose_none():
  215. """Tests choose when none of the alternatives match."""
  216. t = BoostBuild.Tester(use_test_config=0)
  217. t.write("Jamroot", """
  218. import configure ;
  219. obj fail : fail.cpp ;
  220. explicit pass fail ;
  221. obj foo : foo.cpp :
  222. [ configure.choose "which one?" : fail <define>FAIL ] ;
  223. """)
  224. t.write("fail.cpp", "#error fail.cpp\n")
  225. t.write("foo.cpp", """
  226. #ifdef FAIL
  227. #error FAIL is defined
  228. #endif
  229. """)
  230. t.run_build_system()
  231. t.expect_output_lines([
  232. " - which one? : none*"])
  233. # An up-to-date build should use the cache
  234. t.run_build_system()
  235. t.expect_output_lines([
  236. " - which one? : none (cached)*"])
  237. t.expect_nothing_more()
  238. t.cleanup()
  239. test_check_target_builds()
  240. test_choose()
  241. test_translation()
  242. test_choose_none()