PageRenderTime 50ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/package/boost_1_58_0/tools/build/test/rescan_header.py

https://gitlab.com/cdeclare/intcrypt
Python | 265 lines | 255 code | 5 blank | 5 comment | 0 complexity | 0ba8047a910bed825883210dda0627ab MD5 | raw file
  1. #!/usr/bin/python
  2. # Copyright 2012 Steven Watanabe
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.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/$toolset/debug/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/$toolset/debug/header1.h")
  60. t.expect_addition("bin/$toolset/debug/header2.h")
  61. t.expect_addition("bin/$toolset/debug/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/$toolset/debug/header1.h")
  101. t.expect_addition("bin/$toolset/debug/header2.h")
  102. t.expect_addition("bin/$toolset/debug/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/$toolset/debug/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.expect_nothing_more()
  155. t.touch("header3.in")
  156. t.run_build_system(["-j2", "test"])
  157. t.expect_touch("bin/$toolset/debug/header3.h")
  158. t.expect_touch("bin/$toolset/debug/test1.obj")
  159. t.expect_touch("bin/$toolset/debug/test2.obj")
  160. t.expect_touch("bin/$toolset/debug/test.exe")
  161. t.expect_nothing_more()
  162. t.rm(".")
  163. # Test a loop that includes a generated header
  164. t.write("test1.cpp", '#include "header1.h"\n')
  165. t.write("test2.cpp", """\
  166. #include "header2.h"
  167. int main() {}
  168. """)
  169. t.write("header1.h", """\
  170. #ifndef HEADER1_H
  171. #define HEADER1_H
  172. #include "header2.h"
  173. #endif
  174. """)
  175. t.write("header2.in", """\
  176. #ifndef HEADER2_H
  177. #define HEADER2_H
  178. #include "header3.h"
  179. #endif
  180. """)
  181. t.write("header3.h", """\
  182. #ifndef HEADER3_H
  183. #define HEADER3_H
  184. #include "header1.h"
  185. #endif
  186. """)
  187. t.write("sleep.bat", """\
  188. ::@timeout /T %1 /NOBREAK >nul
  189. @ping 127.0.0.1 -n 2 -w 1000 >nul
  190. @ping 127.0.0.1 -n %1 -w 1000 >nul
  191. @exit /B 0
  192. """)
  193. t.write("jamroot.jam", """\
  194. import common ;
  195. import os ;
  196. if [ os.name ] = NT
  197. {
  198. SLEEP = call sleep.bat ;
  199. }
  200. else
  201. {
  202. SLEEP = sleep ;
  203. }
  204. rule copy { common.copy $(<) : $(>) ; }
  205. actions copy { $(SLEEP) 1 }
  206. make header2.h : header2.in : @copy ;
  207. exe test : test2.cpp test1.cpp : <implicit-dependency>header2.h <include>. ;
  208. """)
  209. t.run_build_system(["-j2", "test"])
  210. t.expect_addition("bin/$toolset/debug/header2.h")
  211. t.expect_addition("bin/$toolset/debug/test1.obj")
  212. t.expect_addition("bin/$toolset/debug/test2.obj")
  213. t.expect_addition("bin/$toolset/debug/test.exe")
  214. t.expect_nothing_more()
  215. t.cleanup()