alternatives.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/python
  2. # Copyright 2003 Dave Abrahams
  3. # Copyright 2003, 2006 Vladimir Prus
  4. # Distributed under the Boost Software License, Version 1.0.
  5. # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
  6. # Test main target alternatives.
  7. import BoostBuild
  8. import string
  9. t = BoostBuild.Tester(use_test_config=False)
  10. # Test that basic alternatives selection works.
  11. t.write("jamroot.jam", "")
  12. t.write("jamfile.jam", """
  13. exe a : a_empty.cpp ;
  14. exe a : a.cpp : <variant>release ;
  15. """)
  16. t.write("a_empty.cpp", "")
  17. t.write("a.cpp", "int main() {}\n")
  18. t.run_build_system(["release"])
  19. t.expect_addition("bin/$toolset/release*/a.exe")
  20. # Test that alternative selection works for ordinary properties, in particular
  21. # user-defined.
  22. t.write("jamroot.jam", "")
  23. t.write("jamfile.jam", """
  24. import feature ;
  25. feature.feature X : off on : propagated ;
  26. exe a : b.cpp ;
  27. exe a : a.cpp : <X>on ;
  28. """)
  29. t.write("b.cpp", "int main() {}\n")
  30. t.rm("bin")
  31. t.run_build_system()
  32. t.expect_addition("bin/$toolset/debug*/b.obj")
  33. t.run_build_system(["X=on"])
  34. t.expect_addition("bin/$toolset/debug/X-on*/a.obj")
  35. t.rm("bin")
  36. # Test that everything works ok even with the default build.
  37. t.write("jamfile.jam", """\
  38. exe a : a_empty.cpp : <variant>release ;
  39. exe a : a.cpp : <variant>debug ;
  40. """)
  41. t.run_build_system()
  42. t.expect_addition("bin/$toolset/debug*/a.exe")
  43. # Test that only properties which are in the build request matter for
  44. # alternative selection. IOW, alternative with <variant>release is better than
  45. # one with <variant>debug when building the release variant.
  46. t.write("jamfile.jam", """\
  47. exe a : a_empty.cpp : <variant>debug ;
  48. exe a : a.cpp : <variant>release ;
  49. """)
  50. t.run_build_system(["release"])
  51. t.expect_addition("bin/$toolset/release*/a.exe")
  52. # Test that free properties do not matter. We really do not want <cxxflags>
  53. # property in build request to affect alternative selection.
  54. t.write("jamfile.jam", """
  55. exe a : a_empty.cpp : <variant>debug <define>FOO <include>BAR ;
  56. exe a : a.cpp : <variant>release ;
  57. """)
  58. t.rm("bin/$toolset/release/a.exe")
  59. t.rm("bin/$toolset/release/*/a.exe")
  60. t.run_build_system(["release", "define=FOO"])
  61. t.expect_addition("bin/$toolset/release*/a.exe")
  62. # Test that ambiguity is reported correctly.
  63. t.write("jamfile.jam", """\
  64. exe a : a_empty.cpp ;
  65. exe a : a.cpp ;
  66. """)
  67. t.run_build_system(["--no-error-backtrace"], status=None)
  68. t.expect_output_lines("error: No best alternative for ./a")
  69. # Another ambiguity test: two matches properties in one alternative are neither
  70. # better nor worse than a single one in another alternative.
  71. t.write("jamfile.jam", """\
  72. exe a : a_empty.cpp : <optimization>off <profiling>off ;
  73. exe a : a.cpp : <debug-symbols>on ;
  74. """)
  75. t.run_build_system(["--no-error-backtrace"], status=None)
  76. t.expect_output_lines("error: No best alternative for ./a")
  77. t.rm("bin")
  78. # Test that we can have alternative without sources.
  79. t.write("jamfile.jam", """\
  80. alias specific-sources ;
  81. import feature ;
  82. feature.extend os : MAGIC ;
  83. alias specific-sources : b.cpp : <os>MAGIC ;
  84. exe a : a.cpp specific-sources ;
  85. """)
  86. t.run_build_system()
  87. t.expect_addition("bin/$toolset/debug*/a.exe")
  88. t.rm("bin")
  89. # Test that subfeatures are expanded in alternatives
  90. # and that unknown subfeatures fail to match instead of
  91. # causing errors.
  92. t.write("jamfile.jam", """\
  93. import feature : feature subfeature ;
  94. feature X : off on : propagated ;
  95. subfeature X on : version : 1 : propagated ;
  96. exe a : a.cpp : <X>on-1 ;
  97. exe a : a_empty.cpp ;
  98. exe a : a_empty.cpp : <X>on-2 ;
  99. """)
  100. t.run_build_system(["X=on-1"])
  101. t.cleanup()