rescan_header.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #!/usr/bin/python
  2. # Copyright 2012 Steven Watanabe
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
  5. import BoostBuild
  6. t = BoostBuild.Tester(use_test_config=False)
  7. # Test a header loop that depends on (but does not contain) a generated header.
  8. t.write("test.cpp", '#include "header1.h"\n')
  9. t.write("header1.h", """\
  10. #ifndef HEADER1_H
  11. #define HEADER1_H
  12. #include "header2.h"
  13. #endif
  14. """)
  15. t.write("header2.h", """\
  16. #ifndef HEADER2_H
  17. #define HEADER2_H
  18. #include "header1.h"
  19. #include "header3.h"
  20. #endif
  21. """)
  22. t.write("header3.in", "/* empty file */\n")
  23. t.write("jamroot.jam", """\
  24. import common ;
  25. make header3.h : header3.in : @common.copy ;
  26. obj test : test.cpp : <implicit-dependency>header3.h ;
  27. """)
  28. t.run_build_system(["-j2"])
  29. t.expect_addition("bin/header3.h")
  30. t.expect_addition("bin/$toolset/debug*/test.obj")
  31. t.expect_nothing_more()
  32. t.rm(".")
  33. # Test a linear sequence of generated headers.
  34. t.write("test.cpp", '#include "header1.h"\n')
  35. t.write("header1.in", """\
  36. #ifndef HEADER1_H
  37. #define HEADER1_H
  38. #include "header2.h"
  39. #endif
  40. """)
  41. t.write("header2.in", """\
  42. #ifndef HEADER2_H
  43. #define HEADER2_H
  44. #include "header3.h"
  45. #endif
  46. """)
  47. t.write("header3.in", "/* empty file */\n")
  48. t.write("jamroot.jam", """\
  49. import common ;
  50. make header1.h : header1.in : @common.copy ;
  51. make header2.h : header2.in : @common.copy ;
  52. make header3.h : header3.in : @common.copy ;
  53. obj test : test.cpp :
  54. <implicit-dependency>header1.h
  55. <implicit-dependency>header2.h
  56. <implicit-dependency>header3.h ;
  57. """)
  58. t.run_build_system(["-j2", "test"])
  59. t.expect_addition("bin/header1.h")
  60. t.expect_addition("bin/header2.h")
  61. t.expect_addition("bin/header3.h")
  62. t.expect_addition("bin/$toolset/debug*/test.obj")
  63. t.expect_nothing_more()
  64. t.rm(".")
  65. # Test a loop in generated headers.
  66. t.write("test.cpp", '#include "header1.h"\n')
  67. t.write("header1.in", """\
  68. #ifndef HEADER1_H
  69. #define HEADER1_H
  70. #include "header2.h"
  71. #endif
  72. """)
  73. t.write("header2.in", """\
  74. #ifndef HEADER2_H
  75. #define HEADER2_H
  76. #include "header3.h"
  77. #endif
  78. """)
  79. t.write("header3.in", """\
  80. #ifndef HEADER2_H
  81. #define HEADER2_H
  82. #include "header1.h"
  83. #endif
  84. """)
  85. t.write("jamroot.jam", """\
  86. import common ;
  87. actions copy {
  88. sleep 1
  89. cp $(>) $(<)
  90. }
  91. make header1.h : header1.in : @common.copy ;
  92. make header2.h : header2.in : @common.copy ;
  93. make header3.h : header3.in : @common.copy ;
  94. obj test : test.cpp :
  95. <implicit-dependency>header1.h
  96. <implicit-dependency>header2.h
  97. <implicit-dependency>header3.h ;
  98. """)
  99. t.run_build_system(["-j2", "test"])
  100. t.expect_addition("bin/header1.h")
  101. t.expect_addition("bin/header2.h")
  102. t.expect_addition("bin/header3.h")
  103. t.expect_addition("bin/$toolset/debug*/test.obj")
  104. t.expect_nothing_more()
  105. t.rm(".")
  106. # Test that all the dependencies of a loop are updated before any of the
  107. # dependents.
  108. t.write("test1.cpp", '#include "header1.h"\n')
  109. t.write("test2.cpp", """\
  110. #include "header2.h"
  111. int main() {}
  112. """)
  113. t.write("header1.h", """\
  114. #ifndef HEADER1_H
  115. #define HEADER1_H
  116. #include "header2.h"
  117. #endif
  118. """)
  119. t.write("header2.h", """\
  120. #ifndef HEADER2_H
  121. #define HEADER2_H
  122. #include "header1.h"
  123. #include "header3.h"
  124. #endif
  125. """)
  126. t.write("header3.in", "\n")
  127. t.write("sleep.bat", """\
  128. ::@timeout /T %1 /NOBREAK >nul
  129. @ping 127.0.0.1 -n 2 -w 1000 >nul
  130. @ping 127.0.0.1 -n %1 -w 1000 >nul
  131. @exit /B 0
  132. """)
  133. t.write("jamroot.jam", """\
  134. import common ;
  135. import os ;
  136. if [ os.name ] = NT
  137. {
  138. SLEEP = call sleep.bat ;
  139. }
  140. else
  141. {
  142. SLEEP = sleep ;
  143. }
  144. rule copy { common.copy $(<) : $(>) ; }
  145. actions copy { $(SLEEP) 1 }
  146. make header3.h : header3.in : @copy ;
  147. exe test : test2.cpp test1.cpp : <implicit-dependency>header3.h ;
  148. """)
  149. t.run_build_system(["-j2", "test"])
  150. t.expect_addition("bin/header3.h")
  151. t.expect_addition("bin/$toolset/debug*/test1.obj")
  152. t.expect_addition("bin/$toolset/debug*/test2.obj")
  153. t.expect_addition("bin/$toolset/debug*/test.exe")
  154. t.ignore_addition("bin/*/test.rsp")
  155. t.expect_nothing_more()
  156. t.touch("header3.in")
  157. t.run_build_system(["-j2", "test"])
  158. t.expect_touch("bin/header3.h")
  159. t.expect_touch("bin/$toolset/debug*/test1.obj")
  160. t.expect_touch("bin/$toolset/debug*/test2.obj")
  161. t.expect_touch("bin/$toolset/debug*/test.exe")
  162. t.ignore_touch("bin/*/test.rsp")
  163. t.expect_nothing_more()
  164. t.rm(".")
  165. # Test a loop that includes a generated header
  166. t.write("test1.cpp", '#include "header1.h"\n')
  167. t.write("test2.cpp", """\
  168. #include "header2.h"
  169. int main() {}
  170. """)
  171. t.write("header1.h", """\
  172. #ifndef HEADER1_H
  173. #define HEADER1_H
  174. #include "header2.h"
  175. #endif
  176. """)
  177. t.write("header2.in", """\
  178. #ifndef HEADER2_H
  179. #define HEADER2_H
  180. #include "header3.h"
  181. #endif
  182. """)
  183. t.write("header3.h", """\
  184. #ifndef HEADER3_H
  185. #define HEADER3_H
  186. #include "header1.h"
  187. #endif
  188. """)
  189. t.write("sleep.bat", """\
  190. ::@timeout /T %1 /NOBREAK >nul
  191. @ping 127.0.0.1 -n 2 -w 1000 >nul
  192. @ping 127.0.0.1 -n %1 -w 1000 >nul
  193. @exit /B 0
  194. """)
  195. t.write("jamroot.jam", """\
  196. import common ;
  197. import os ;
  198. if [ os.name ] = NT
  199. {
  200. SLEEP = call sleep.bat ;
  201. }
  202. else
  203. {
  204. SLEEP = sleep ;
  205. }
  206. rule copy { common.copy $(<) : $(>) ; }
  207. actions copy { $(SLEEP) 1 }
  208. make header2.h : header2.in : @copy ;
  209. exe test : test2.cpp test1.cpp : <implicit-dependency>header2.h <include>. ;
  210. """)
  211. t.run_build_system(["-j2", "test"])
  212. t.expect_addition("bin/header2.h")
  213. t.expect_addition("bin/$toolset/debug*/test1.obj")
  214. t.expect_addition("bin/$toolset/debug*/test2.obj")
  215. t.expect_addition("bin/$toolset/debug*/test.exe")
  216. t.ignore_addition("bin/*/test.rsp")
  217. t.expect_nothing_more()
  218. t.cleanup()