path_features.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/python
  2. # Copyright 2003 Dave Abrahams
  3. # Copyright 2002, 2003, 2004 Vladimir Prus
  4. # Distributed under the Boost Software License, Version 1.0.
  5. # (See accompanying file LICENSE.txt or copy at
  6. # https://www.bfgroup.xyz/b2/LICENSE.txt)
  7. import BoostBuild
  8. def test_basic():
  9. t = BoostBuild.Tester(use_test_config=False)
  10. t.write("jamroot.jam", "lib a : a.cpp : <include>. ;")
  11. t.write("a.cpp", """\
  12. #include <a.h>
  13. void
  14. # ifdef _WIN32
  15. __declspec(dllexport)
  16. # endif
  17. foo() {}
  18. """)
  19. t.write("a.h", "//empty file\n")
  20. t.write("d/jamfile.jam", "exe b : b.cpp ..//a ;")
  21. t.write("d/b.cpp", """\
  22. void foo();
  23. int main() { foo(); }
  24. """)
  25. t.run_build_system(subdir="d")
  26. # Path features with condition.
  27. t.write("jamroot.jam", "lib a : a.cpp : <variant>debug:<include>. ;")
  28. t.rm("bin")
  29. t.run_build_system(subdir="d")
  30. # Path features with condition in usage requirements.
  31. t.write("jamroot.jam", """\
  32. lib a : a.cpp : <include>. : : <variant>debug:<include>. ;
  33. """)
  34. t.write("d/b.cpp", """\
  35. #include <a.h>
  36. void foo();
  37. int main() { foo(); }
  38. """)
  39. t.rm("d/bin")
  40. t.run_build_system(subdir="d")
  41. t.cleanup()
  42. def test_absolute_paths():
  43. """
  44. Test that absolute paths inside requirements are ok. The problems
  45. appeared only when building targets in subprojects.
  46. """
  47. t = BoostBuild.Tester(use_test_config=False)
  48. t.write("jamroot.jam", "build-project x ;")
  49. t.write("x/jamfile.jam", """\
  50. local pwd = [ PWD ] ;
  51. project : requirements <include>$(pwd)/x/include ;
  52. exe m : m.cpp : <include>$(pwd)/x/include2 ;
  53. """)
  54. t.write("x/m.cpp", """\
  55. #include <h1.hpp>
  56. #include <h2.hpp>
  57. int main() {}
  58. """)
  59. t.write("x/include/h1.hpp", "\n")
  60. t.write("x/include2/h2.hpp", "\n")
  61. t.run_build_system()
  62. t.expect_addition("x/bin/$toolset/debug*/m.exe")
  63. t.cleanup()
  64. def test_ordered_paths():
  65. """Test that "&&" in path features is handled correctly."""
  66. t = BoostBuild.Tester(use_test_config=False)
  67. t.write("jamroot.jam", "build-project sub ;")
  68. t.write("sub/jamfile.jam", "exe a : a.cpp : <include>../h1&&../h2 ;")
  69. t.write("sub/a.cpp", """\
  70. #include <header.h>
  71. int main() { return OK; }
  72. """)
  73. t.write("h2/header.h", "int const OK = 0;\n")
  74. t.run_build_system()
  75. t.expect_addition("sub/bin/$toolset/debug*/a.exe")
  76. t.cleanup()
  77. def test_paths_set_by_indirect_conditionals():
  78. t = BoostBuild.Tester(use_test_config=False)
  79. header = "child_dir/folder_to_include/some_header.h"
  80. t.write("jamroot.jam", """
  81. build-project child_dir ;
  82. rule attach-include-parent ( properties * )
  83. {
  84. return <include>another_folder ;
  85. }
  86. # requirements inherited from a parent project will bind paths
  87. # relative to the project that actually names the rule.
  88. project : requirements <conditional>@attach-include-parent ;
  89. """)
  90. t.write("child_dir/jamfile.jam", """\
  91. import remote/remote ;
  92. # If we set the <include>folder_to_include property directly, it will work
  93. obj x1 : x.cpp : <conditional>@attach-include-local ;
  94. obj x2 : x.cpp : <conditional>@remote.attach-include-remote ;
  95. rule attach-include-local ( properties * )
  96. {
  97. return <include>folder_to_include ;
  98. }
  99. """)
  100. t.write("child_dir/remote/remote.jam", """\
  101. rule attach-include-remote ( properties * )
  102. {
  103. return <include>folder_to_include ;
  104. }
  105. """)
  106. t.write("child_dir/x.cpp", """\
  107. #include <some_header.h>
  108. #include <header2.h>
  109. int main() {}
  110. """)
  111. t.write(header, "int some_func();\n")
  112. t.write("another_folder/header2.h", "int f2();\n")
  113. t.write("child_dir/folder_to_include/jamfile.jam", "")
  114. expected_x1 = "child_dir/bin/$toolset/debug*/x1.obj"
  115. expected_x2 = "child_dir/bin/$toolset/debug*/x2.obj"
  116. t.run_build_system()
  117. t.expect_addition(expected_x1)
  118. t.expect_addition(expected_x2)
  119. t.touch(header)
  120. t.run_build_system(subdir="child_dir")
  121. t.expect_touch(expected_x1)
  122. t.expect_touch(expected_x2)
  123. t.touch(header)
  124. t.run_build_system([".."], subdir="child_dir/folder_to_include")
  125. t.expect_touch(expected_x1)
  126. t.expect_touch(expected_x2)
  127. t.cleanup()
  128. test_basic()
  129. test_absolute_paths()
  130. test_ordered_paths()
  131. test_paths_set_by_indirect_conditionals()