searched_lib.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/usr/bin/python
  2. # Copyright 2003 Dave Abrahams
  3. # Copyright 2003, 2004, 2005, 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 usage of searched-libs: one which are found via -l
  7. # switch to the linker/compiler.
  8. import BoostBuild
  9. import os
  10. import string
  11. t = BoostBuild.Tester(use_test_config=False)
  12. # To start with, we have to prepare a library to link with.
  13. t.write("lib/jamroot.jam", "")
  14. t.write("lib/jamfile.jam", "lib test_lib : test_lib.cpp ;")
  15. t.write("lib/test_lib.cpp", """\
  16. #ifdef _WIN32
  17. __declspec(dllexport)
  18. #endif
  19. void foo() {}
  20. """);
  21. t.run_build_system(subdir="lib")
  22. t.expect_addition("lib/bin/$toolset/debug*/test_lib.dll")
  23. # Auto adjusting of suffixes does not work, since we need to
  24. # change dll to lib.
  25. if ( ( os.name == "nt" ) or os.uname()[0].lower().startswith("cygwin") ) and \
  26. ( BoostBuild.get_toolset() != "gcc" ):
  27. t.copy("lib/bin/$toolset/debug*/test_lib.implib", "lib/test_lib.implib")
  28. t.copy("lib/bin/$toolset/debug*/test_lib.dll", "lib/test_lib.dll")
  29. else:
  30. t.copy("lib/bin/$toolset/debug*/test_lib.dll", "lib/test_lib.dll")
  31. # Test that the simplest usage of searched library works.
  32. t.write("jamroot.jam", "")
  33. t.write("jamfile.jam", """\
  34. import path ;
  35. import project ;
  36. exe main : main.cpp helper ;
  37. lib helper : helper.cpp test_lib ;
  38. lib test_lib : : <name>test_lib <search>lib ;
  39. """)
  40. t.write("main.cpp", """\
  41. void helper();
  42. int main() { helper(); }
  43. """)
  44. t.write("helper.cpp", """\
  45. void foo();
  46. void
  47. #if defined(_WIN32)
  48. __declspec(dllexport)
  49. #endif
  50. helper() { foo(); }
  51. """)
  52. t.run_build_system(["-d2"])
  53. t.expect_addition("bin/$toolset/debug*/main.exe")
  54. t.rm("bin/$toolset/debug/main.exe")
  55. t.rm("bin/$toolset/debug/*/main.exe")
  56. # Test that 'unit-test' will correctly add runtime paths to searched libraries.
  57. t.write("jamfile.jam", """\
  58. import path ;
  59. import project ;
  60. import testing ;
  61. project : requirements <hardcode-dll-paths>false ;
  62. unit-test main : main.cpp helper ;
  63. lib helper : helper.cpp test_lib ;
  64. lib test_lib : : <name>test_lib <search>lib ;
  65. """)
  66. t.run_build_system()
  67. t.expect_addition("bin/$toolset/debug*/main.passed")
  68. t.rm("bin/$toolset/debug/main.exe")
  69. t.rm("bin/$toolset/debug/*/main.exe")
  70. # Now try using searched lib from static lib. Request shared version of searched
  71. # lib, since we do not have a static one handy.
  72. t.write("jamfile.jam", """\
  73. exe main : main.cpp helper ;
  74. lib helper : helper.cpp test_lib/<link>shared : <link>static ;
  75. lib test_lib : : <name>test_lib <search>lib ;
  76. """)
  77. t.run_build_system(stderr=None)
  78. t.expect_addition("bin/$toolset/debug*/main.exe")
  79. t.expect_addition("bin/$toolset/debug/link-static*/helper.lib")
  80. t.rm("bin/$toolset/debug/main.exe")
  81. t.rm("bin/$toolset/debug/*/main.exe")
  82. # A regression test: <library>property referring to searched-lib was being
  83. # mishandled. As the result, we were putting target name to the command line!
  84. # Note that
  85. # g++ ...... <.>z
  86. # works nicely in some cases, sending output from compiler to file 'z'. This
  87. # problem shows up when searched libs are in usage requirements.
  88. t.write("jamfile.jam", "exe main : main.cpp d/d2//a ;")
  89. t.write("main.cpp", """\
  90. void foo();
  91. int main() { foo(); }
  92. """)
  93. t.write("d/d2/jamfile.jam", """\
  94. lib test_lib : : <name>test_lib <search>../../lib ;
  95. lib a : a.cpp : : : <library>test_lib ;
  96. """)
  97. t.write("d/d2/a.cpp", """\
  98. #ifdef _WIN32
  99. __declspec(dllexport) int force_library_creation_for_a;
  100. #endif
  101. """)
  102. t.run_build_system()
  103. # A regression test. Searched targets were not associated with any properties.
  104. # For that reason, if the same searched lib is generated with two different
  105. # properties, we had an error saying they are actualized to the same Jam target
  106. # name.
  107. t.write("jamroot.jam", "")
  108. t.write("a.cpp", "")
  109. # The 'l' library will be built in two variants: 'debug' (directly requested)
  110. # and 'release' (requested from 'a').
  111. t.write("jamfile.jam", """\
  112. exe a : a.cpp l/<variant>release ;
  113. lib l : : <name>l_d <variant>debug ;
  114. lib l : : <name>l_r <variant>release ;
  115. """)
  116. t.run_build_system(["-n"])
  117. # A regression test. Two virtual target with the same properties were created
  118. # for 'l' target, which caused and error to be reported when actualizing
  119. # targets. The final error is correct, but we should not create two duplicated
  120. # targets. Thanks to Andre Hentz for finding this bug.
  121. t.write("jamroot.jam", "")
  122. t.write("a.cpp", "")
  123. t.write("jamfile.jam", """\
  124. project a : requirements <runtime-link>static ;
  125. static-lib a : a.cpp l ;
  126. lib l : : <name>l_f ;
  127. """)
  128. t.run_build_system(["-n"])
  129. # A regression test. Virtual targets distinguished by their search paths were
  130. # not differentiated when registered, which caused search paths to be selected
  131. # incorrectly for build requests with multiple feature values.
  132. t.write("jamroot.jam", "")
  133. t.write("a.cpp", "")
  134. t.write("jamfile.jam", """\
  135. exe a : a.cpp l ;
  136. lib l : : <name>l <search>lib32 <address-model>32 ;
  137. lib l : : <name>l <search>lib64 <address-model>64 ;
  138. """)
  139. t.run_build_system(["-n","address-model=32,64"])
  140. t.fail_test(t.stdout().find("lib32") == -1)
  141. t.fail_test(t.stdout().find("lib64") == -1)
  142. # Make sure plain "lib foobar ; " works.
  143. t.write("jamfile.jam", """\
  144. exe a : a.cpp foobar ;
  145. lib foobar ;
  146. """)
  147. t.run_build_system(["-n", "-d2"])
  148. t.fail_test(t.stdout().find("foobar") == -1)
  149. # Make sure plain "lib foo bar ; " works.
  150. t.write("jamfile.jam", """\
  151. exe a : a.cpp foo bar ;
  152. lib foo bar ;
  153. """)
  154. t.run_build_system(["-n", "-d2"])
  155. t.fail_test(t.stdout().find("foo") == -1)
  156. t.fail_test(t.stdout().find("bar") == -1)
  157. t.cleanup()