dll_path.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/python
  2. # Copyright (C) 2003. 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. # Test that the <dll-path> property is correctly set when using
  7. # <hardcode-dll-paths>true.
  8. import BoostBuild
  9. t = BoostBuild.Tester(use_test_config=False)
  10. # The point of this test is to have exe "main" which uses library "b", which
  11. # uses library "a". When "main" is built with <hardcode-dll-paths>true, paths
  12. # to both libraries should be present as values of <dll-path> feature. We
  13. # create a special target type which reports <dll-path> values on its sources
  14. # and compare the list of found values with out expectations.
  15. t.write("jamroot.jam", "using dll_paths ;")
  16. t.write("jamfile.jam", """\
  17. exe main : main.cpp b//b ;
  18. explicit main ;
  19. path-list mp : main ;
  20. """)
  21. t.write("main.cpp", "int main() {}\n")
  22. t.write("dll_paths.jam", """\
  23. import "class" : new ;
  24. import feature ;
  25. import generators ;
  26. import print ;
  27. import sequence ;
  28. import type ;
  29. rule init ( )
  30. {
  31. type.register PATH_LIST : pathlist ;
  32. class dll-paths-list-generator : generator
  33. {
  34. rule __init__ ( )
  35. {
  36. generator.__init__ dll_paths.list : EXE : PATH_LIST ;
  37. }
  38. rule generated-targets ( sources + : property-set : project name ? )
  39. {
  40. local dll-paths ;
  41. for local s in $(sources)
  42. {
  43. local a = [ $(s).action ] ;
  44. if $(a)
  45. {
  46. local p = [ $(a).properties ] ;
  47. dll-paths += [ $(p).get <dll-path> ] ;
  48. }
  49. }
  50. return [ generator.generated-targets $(sources) :
  51. [ $(property-set).add-raw $(dll-paths:G=<dll-path>) ] :
  52. $(project) $(name) ] ;
  53. }
  54. }
  55. generators.register [ new dll-paths-list-generator ] ;
  56. }
  57. rule list ( target : sources * : properties * )
  58. {
  59. local paths = [ feature.get-values <dll-path> : $(properties) ] ;
  60. paths = [ sequence.insertion-sort $(paths) ] ;
  61. print.output $(target) ;
  62. print.text $(paths) ;
  63. }
  64. """)
  65. t.write("dll_paths.py", """\
  66. import bjam
  67. import b2.build.type as type
  68. import b2.build.generators as generators
  69. from b2.manager import get_manager
  70. def init():
  71. type.register("PATH_LIST", ["pathlist"])
  72. class DllPathsListGenerator(generators.Generator):
  73. def __init__(self):
  74. generators.Generator.__init__(self, "dll_paths.list", False,
  75. ["EXE"], ["PATH_LIST"])
  76. def generated_targets(self, sources, ps, project, name):
  77. dll_paths = []
  78. for s in sources:
  79. a = s.action()
  80. if a:
  81. p = a.properties()
  82. dll_paths += p.get('dll-path')
  83. dll_paths.sort()
  84. return generators.Generator.generated_targets(self, sources,
  85. ps.add_raw(["<dll-path>" + p for p in dll_paths]), project,
  86. name)
  87. generators.register(DllPathsListGenerator())
  88. command = \"\"\"
  89. echo $(PATHS) > $(<[1])
  90. \"\"\"
  91. def function(target, sources, ps):
  92. bjam.call('set-target-variable', target, "PATHS", ps.get('dll-path'))
  93. get_manager().engine().register_action("dll_paths.list", command,
  94. function=function)
  95. """)
  96. t.write("a/jamfile.jam", "lib a : a.cpp ;")
  97. t.write("a/a.cpp", """\
  98. void
  99. #if defined(_WIN32)
  100. __declspec(dllexport)
  101. #endif
  102. foo() {}
  103. """)
  104. t.write("b/jamfile.jam", "lib b : b.cpp ../a//a ;")
  105. t.write("b/b.cpp", """\
  106. void
  107. #if defined(_WIN32)
  108. __declspec(dllexport)
  109. #endif
  110. bar() {}
  111. """)
  112. t.run_build_system(["hardcode-dll-paths=true"])
  113. t.expect_addition("bin/$toolset/debug*/mp.pathlist")
  114. es1 = t.adjust_name("a/bin/$toolset/debug*")
  115. es2 = t.adjust_name("b/bin/$toolset/debug*")
  116. t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es1)
  117. t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es2)
  118. t.rm("bin/$toolset/debug*/mp.pathlist")
  119. # Now run the same checks with pre-built libraries
  120. adll = t.glob_file("a/bin/$toolset/debug*/a.dll")
  121. bdll = t.glob_file("b/bin/$toolset/debug*/b.dll")
  122. t.write("b/jamfile.jam", """
  123. local bdll = %s ;
  124. # Make sure that it is found even with multiple source-locations
  125. project : source-location c $(bdll:D) ;
  126. lib b : ../a//a : <file>$(bdll:D=) ;
  127. """ % bdll.replace("\\", "\\\\"))
  128. t.run_build_system(["hardcode-dll-paths=true"])
  129. t.expect_addition("bin/$toolset/debug*/mp.pathlist")
  130. t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es1)
  131. t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es2)
  132. t.cleanup()