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