inherited_dependency.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #!/usr/bin/python
  2. #
  3. # Copyright (c) 2008 Steven Watanabe
  4. #
  5. # Distributed under the Boost Software License, Version 1.0. (See
  6. # accompanying file LICENSE.txt) or copy at
  7. # https://www.bfgroup.xyz/b2/LICENSE.txt)
  8. import BoostBuild
  9. tester = BoostBuild.Tester(use_test_config=False)
  10. ################################################################################
  11. #
  12. # Test without giving the project an explicit id.
  13. #
  14. ################################################################################
  15. tester.write("jamroot.jam", """
  16. lib test : test.cpp ;
  17. project : requirements <library>test ;
  18. build-project a ;
  19. """)
  20. tester.write("test.cpp", """
  21. #ifdef _WIN32
  22. __declspec(dllexport)
  23. #endif
  24. void foo() {}
  25. """)
  26. tester.write("a/test1.cpp", """
  27. int main() {}
  28. """)
  29. tester.write("a/jamfile.jam", """
  30. exe test1 : test1.cpp ;
  31. """)
  32. tester.run_build_system()
  33. tester.expect_addition("bin/$toolset/debug*/test.obj")
  34. tester.expect_addition("a/bin/$toolset/debug*/test1.exe")
  35. tester.rm("bin")
  36. tester.rm("a/bin")
  37. ################################################################################
  38. #
  39. # Run the same test from the "a" directory.
  40. #
  41. ################################################################################
  42. tester.run_build_system(subdir="a")
  43. tester.expect_addition("bin/$toolset/debug*/test.obj")
  44. tester.expect_addition("a/bin/$toolset/debug*/test1.exe")
  45. tester.rm("bin")
  46. tester.rm("a/bin")
  47. ################################################################################
  48. #
  49. # This time, do give the project an id.
  50. #
  51. ################################################################################
  52. tester.write("jamroot.jam", """
  53. lib test : test.cpp ;
  54. project test_project : requirements <library>test ;
  55. build-project a ;
  56. """)
  57. tester.run_build_system()
  58. tester.expect_addition("bin/$toolset/debug*/test.obj")
  59. tester.expect_addition("a/bin/$toolset/debug*/test1.exe")
  60. tester.rm("bin")
  61. tester.rm("a/bin")
  62. ################################################################################
  63. #
  64. # Now, give the project an id in its attributes.
  65. #
  66. ################################################################################
  67. tester.write("jamroot.jam", """
  68. lib test : test.cpp ;
  69. project : id test_project : requirements <library>test ;
  70. build-project a ;
  71. """)
  72. tester.run_build_system()
  73. tester.expect_addition("bin/$toolset/debug*/test.obj")
  74. tester.expect_addition("a/bin/$toolset/debug*/test1.exe")
  75. tester.rm("bin")
  76. tester.rm("a/bin")
  77. ################################################################################
  78. #
  79. # Give the project an id in both ways at once.
  80. #
  81. ################################################################################
  82. tester.write("jamroot.jam", """
  83. lib test : test.cpp ;
  84. project test_project1 : id test_project : requirements <library>test ;
  85. build-project a ;
  86. """)
  87. tester.run_build_system()
  88. tester.expect_addition("bin/$toolset/debug*/test.obj")
  89. tester.expect_addition("a/bin/$toolset/debug*/test1.exe")
  90. tester.rm("bin")
  91. tester.rm("a/bin")
  92. ################################################################################
  93. #
  94. # Test an absolute path in native format.
  95. #
  96. ################################################################################
  97. tester.write("jamroot.jam", """
  98. import path ;
  99. path-constant here : . ;
  100. current-location = [ path.native [ path.root [ path.make $(here) ] [ path.pwd ]
  101. ] ] ;
  102. project test : requirements <source>$(current-location)/a/test1.cpp ;
  103. exe test : test.cpp ;
  104. """)
  105. tester.run_build_system()
  106. tester.expect_addition("bin/$toolset/debug*/test.exe")
  107. tester.rm("bin")
  108. tester.rm("a/bin")
  109. ################################################################################
  110. #
  111. # Test an absolute path in canonical format.
  112. #
  113. ################################################################################
  114. tester.write("jamroot.jam", """
  115. import path ;
  116. path-constant here : . ;
  117. current-location = [ path.root [ path.make $(here) ] [ path.pwd ] ] ;
  118. project test : requirements <source>$(current-location)/a/test1.cpp ;
  119. exe test : test.cpp ;
  120. """)
  121. tester.run_build_system()
  122. tester.expect_addition("bin/$toolset/debug*/test.exe")
  123. tester.rm("bin")
  124. tester.rm("a/bin")
  125. ################################################################################
  126. #
  127. # Test dependency properties (e.g. <source>) whose targets are specified using a
  128. # relative path.
  129. #
  130. ################################################################################
  131. # Use jamroot.jam rather than jamfile.jam to avoid inheriting the <source> from
  132. # the parent as that would would make test3 a source of itself.
  133. tester.write("b/jamroot.jam", """
  134. obj test3 : test3.cpp ;
  135. """)
  136. tester.write("b/test3.cpp", """
  137. void bar() {}
  138. """)
  139. tester.write("jamroot.jam", """
  140. project test : requirements <source>b//test3 ;
  141. build-project a ;
  142. """)
  143. tester.write("a/jamfile.jam", """
  144. exe test : test1.cpp ;
  145. """)
  146. tester.write("a/test1.cpp", """
  147. void bar();
  148. int main() { bar(); }
  149. """)
  150. tester.run_build_system()
  151. tester.expect_addition("b/bin/$toolset/debug*/test3.obj")
  152. tester.expect_addition("a/bin/$toolset/debug*/test.exe")
  153. tester.rm("bin")
  154. tester.rm("a")
  155. tester.rm("jamroot.jam")
  156. tester.rm("test.cpp")
  157. ################################################################################
  158. #
  159. # Test that source-location is respected.
  160. #
  161. ################################################################################
  162. tester.write("build/jamroot.jam", """
  163. project : requirements <source>test.cpp : source-location ../src ;
  164. """)
  165. tester.write("src/test.cpp", """
  166. int main() {}
  167. """)
  168. tester.write("build/a/jamfile.jam", """
  169. project : source-location ../../a_src ;
  170. exe test : test1.cpp ;
  171. """)
  172. tester.write("a_src/test1.cpp", """
  173. """)
  174. tester.run_build_system(subdir="build/a")
  175. tester.expect_addition("build/a/bin/$toolset/debug*/test.exe")
  176. tester.cleanup()