library_chain.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/usr/bin/python
  2. # Copyright 2003, 2004, 2005, 2006 Vladimir Prus
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
  5. # Test that a chain of libraries works ok, no matter if we use static or shared
  6. # linking.
  7. import BoostBuild
  8. import os
  9. import string
  10. import sys
  11. t = BoostBuild.Tester(use_test_config=False)
  12. # Stage the binary, so that it will be relinked without hardcode-dll-paths.
  13. # That will check that we pass correct -rpath-link, even if not passing -rpath.
  14. t.write("jamfile.jam", """\
  15. stage dist : main ;
  16. exe main : main.cpp b ;
  17. """)
  18. t.write("main.cpp", """\
  19. void foo();
  20. int main() { foo(); }
  21. """)
  22. t.write("jamroot.jam", "")
  23. t.write("a/a.cpp", """\
  24. void
  25. #if defined(_WIN32)
  26. __declspec(dllexport)
  27. #endif
  28. gee() {}
  29. void
  30. #if defined(_WIN32)
  31. __declspec(dllexport)
  32. #endif
  33. geek() {}
  34. """)
  35. t.write("a/jamfile.jam", "lib a : a.cpp ;")
  36. t.write("b/b.cpp", """\
  37. void geek();
  38. void
  39. #if defined(_WIN32)
  40. __declspec(dllexport)
  41. #endif
  42. foo() { geek(); }
  43. """)
  44. t.write("b/jamfile.jam", "lib b : b.cpp ../a//a ;")
  45. t.run_build_system(["-d2"], stderr=None)
  46. t.expect_addition("bin/$toolset/debug*/main.exe")
  47. t.rm(["bin", "a/bin", "b/bin"])
  48. t.run_build_system(["link=static"])
  49. t.expect_addition("bin/$toolset/debug/link-static*/main.exe")
  50. t.rm(["bin", "a/bin", "b/bin"])
  51. # Check that <library> works for static linking.
  52. t.write("b/jamfile.jam", "lib b : b.cpp : <library>../a//a ;")
  53. t.run_build_system(["link=static"])
  54. t.expect_addition("bin/$toolset/debug/link-static*/main.exe")
  55. t.rm(["bin", "a/bin", "b/bin"])
  56. t.write("b/jamfile.jam", "lib b : b.cpp ../a//a/<link>shared : <link>static ;")
  57. t.run_build_system()
  58. t.expect_addition("bin/$toolset/debug*/main.exe")
  59. t.rm(["bin", "a/bin", "b/bin"])
  60. # Test that putting a library in sources of a searched library works.
  61. t.write("jamfile.jam", """\
  62. exe main : main.cpp png ;
  63. lib png : z : <name>png ;
  64. lib z : : <name>zzz ;
  65. """)
  66. t.run_build_system(["-a", "-d+2"], status=None, stderr=None)
  67. # Try to find the "zzz" string either in response file (for Windows compilers),
  68. # or in the standard output.
  69. rsp = t.adjust_names("bin/$toolset/debug*/main.exe.rsp")[0]
  70. if os.path.exists(rsp) and ( open(rsp).read().find("zzz") != -1 ):
  71. pass
  72. elif t.stdout().find("zzz") != -1:
  73. pass
  74. else:
  75. t.fail_test(1)
  76. # Test main -> libb -> liba chain in the case where liba is a file and not a
  77. # B2 target.
  78. t.rm(".")
  79. t.write("jamroot.jam", "")
  80. t.write("a/jamfile.jam", """\
  81. lib a : a.cpp ;
  82. install dist : a ;
  83. """)
  84. t.write("a/a.cpp", """\
  85. #if defined(_WIN32)
  86. __declspec(dllexport)
  87. #endif
  88. void a() {}
  89. """)
  90. t.run_build_system(subdir="a")
  91. t.expect_addition("a/dist/a.dll")
  92. if sys.platform == 'win32':
  93. # This is a Windows import library.
  94. file = t.adjust_name("a.implib")
  95. else:
  96. file = t.adjust_name("a.dll")
  97. t.write("b/jamfile.jam", "lib b : b.cpp ../a/dist/%s ;" % file)
  98. t.write("b/b.cpp", """\
  99. #if defined(_WIN32)
  100. __declspec(dllimport)
  101. #endif
  102. void a();
  103. #if defined(_WIN32)
  104. __declspec(dllexport)
  105. #endif
  106. void b() { a(); }
  107. """)
  108. t.write("jamroot.jam", "exe main : main.cpp b//b ;")
  109. t.write("main.cpp", """\
  110. #if defined(_WIN32)
  111. __declspec(dllimport)
  112. #endif
  113. void b();
  114. int main() { b(); }
  115. """)
  116. t.run_build_system()
  117. t.expect_addition("bin/$toolset/debug*/main.exe")
  118. t.cleanup()