indirect_conditional.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/python
  2. # Copyright (C) 2006. 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. import BoostBuild
  7. def test_basic():
  8. t = BoostBuild.Tester(use_test_config=False)
  9. t.write("jamroot.jam", """\
  10. exe a1 : a1.cpp : <conditional>@a1-rule ;
  11. rule a1-rule ( properties * )
  12. {
  13. if <variant>debug in $(properties)
  14. {
  15. return <define>OK ;
  16. }
  17. }
  18. exe a2 : a2.cpp : <conditional>@$(__name__).a2-rule
  19. <variant>debug:<optimization>speed ;
  20. rule a2-rule ( properties * )
  21. {
  22. if <optimization>speed in $(properties)
  23. {
  24. return <define>OK ;
  25. }
  26. }
  27. exe a3 : a3.cpp :
  28. <conditional>@$(__name__).a3-rule-1
  29. <conditional>@$(__name__).a3-rule-2 ;
  30. rule a3-rule-1 ( properties * )
  31. {
  32. if <optimization>speed in $(properties)
  33. {
  34. return <define>OK ;
  35. }
  36. }
  37. rule a3-rule-2 ( properties * )
  38. {
  39. if <variant>debug in $(properties)
  40. {
  41. return <optimization>speed ;
  42. }
  43. }
  44. """)
  45. t.write("a1.cpp", "#ifdef OK\nint main() {}\n#endif\n")
  46. t.write("a2.cpp", "#ifdef OK\nint main() {}\n#endif\n")
  47. t.write("a3.cpp", "#ifdef OK\nint main() {}\n#endif\n")
  48. t.run_build_system()
  49. t.expect_addition("bin/$toolset/debug*/a1.exe")
  50. t.expect_addition("bin/$toolset/debug/optimization-speed*/a2.exe")
  51. t.expect_addition("bin/$toolset/debug/optimization-speed*/a3.exe")
  52. t.cleanup()
  53. def test_inherit():
  54. """Tests that paths etc. are handled correctly when an indirect
  55. conditional is inherited by a subproject."""
  56. t = BoostBuild.Tester(use_test_config=False)
  57. t.write("Jamroot.jam", """
  58. import feature ;
  59. import indirect ;
  60. exe d1 : d1.cpp ;
  61. explicit d1 ;
  62. project : requirements <conditional>@c1 ;
  63. build-project subdir ;
  64. feature.feature myrule : : free ;
  65. rule c1 ( properties * )
  66. {
  67. return <dependency>d1 <include>include <myrule>@parent-generate ;
  68. }
  69. rule parent-generate ( project name : property-set : sources * )
  70. {
  71. return $(sources) ;
  72. }
  73. rule my-generate ( project name : property-set : sources * )
  74. {
  75. local r = [ $(property-set).get <myrule> ] ;
  76. r = [ MATCH @(.*) : $(r) ] ;
  77. return [ indirect.call
  78. $(r) $(project) $(name) : $(property-set) : $(sources) ] ;
  79. }
  80. """)
  81. t.write("d1.cpp", "int main(){}\n")
  82. t.write("subdir/Jamfile", """
  83. generate srcs : main.cpp : <generating-rule>@my-generate ;
  84. exe main : srcs ;
  85. """)
  86. t.write("include/a.h", "")
  87. t.write("subdir/main.cpp", "#include <a.h>\nint main() {}\n")
  88. t.run_build_system()
  89. t.expect_addition("bin/$toolset/debug*/d1.obj")
  90. t.expect_addition("bin/$toolset/debug*/d1.exe")
  91. t.ignore_addition("bin/*/d1.rsp")
  92. t.expect_addition("subdir/bin/$toolset/debug*/main.obj")
  93. t.expect_addition("subdir/bin/$toolset/debug*/main.exe")
  94. t.ignore_addition("subdir/bin/*/main.rsp")
  95. t.expect_nothing_more()
  96. t.cleanup()
  97. def test_glob_in_indirect_conditional():
  98. """
  99. Regression test: project-rules.glob rule run from inside an indirect
  100. conditional should report an error as it depends on the 'currently loaded
  101. project' concept and indirect conditional rules get called only after all
  102. the project modules have already finished loading.
  103. """
  104. t = BoostBuild.Tester(use_test_config=False)
  105. t.write("jamroot.jam", """\
  106. use-project /library-example/foo : util/foo ;
  107. build-project app ;
  108. """)
  109. t.write("app/app.cpp", "int main() {}\n");
  110. t.write("app/jamfile.jam", "exe app : app.cpp /library-example/foo//bar ;")
  111. t.write("util/foo/bar.cpp", """\
  112. #ifdef _WIN32
  113. __declspec(dllexport)
  114. #endif
  115. void foo() {}
  116. """)
  117. t.write("util/foo/jamfile.jam", """\
  118. rule print-my-sources ( properties * )
  119. {
  120. ECHO My sources: ;
  121. ECHO [ glob *.cpp ] ;
  122. }
  123. lib bar : bar.cpp : <conditional>@print-my-sources ;
  124. """)
  125. t.run_build_system(status=1)
  126. t.expect_output_lines(["My sources:", "bar.cpp"], False)
  127. t.expect_output_lines("error: Reference to the project currently being "
  128. "loaded requested when there was no project module being loaded.")
  129. t.cleanup()
  130. test_basic()
  131. test_inherit()
  132. test_glob_in_indirect_conditional()