summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/build/test/dll_path.py
blob: f7331cdfb63678d19d68f9fda8a16e100ca99eba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python

# Copyright (C) 2003. Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

# Test that the <dll-path> property is correctly set when using
# <hardcode-dll-paths>true.

import BoostBuild

t = BoostBuild.Tester(use_test_config=False)

# The point of this test is to have exe "main" which uses library "b", which
# uses library "a". When "main" is built with <hardcode-dll-paths>true, paths
# to both libraries should be present as values of <dll-path> feature. We
# create a special target type which reports <dll-path> values on its sources
# and compare the list of found values with out expectations.

t.write("jamroot.jam", "using dll_paths ;")
t.write("jamfile.jam", """\
exe main : main.cpp b//b ;
explicit main ;
path-list mp : main ;
""")

t.write("main.cpp", "int main() {}\n")
t.write("dll_paths.jam", """\
import "class" : new ;
import feature ;
import generators ;
import print ;
import sequence ;
import type ;

rule init ( )
{
    type.register PATH_LIST : pathlist ;

    class dll-paths-list-generator : generator
    {
        rule __init__ ( )
        {
            generator.__init__ dll_paths.list : EXE : PATH_LIST ;
        }

        rule generated-targets ( sources + : property-set : project name ? )
        {
            local dll-paths ;
            for local s in $(sources)
            {
                local a = [ $(s).action ] ;
                if $(a)
                {
                    local p = [ $(a).properties ] ;
                    dll-paths += [ $(p).get <dll-path> ] ;
                }
            }
            return [ generator.generated-targets $(sources) :
                [ $(property-set).add-raw $(dll-paths:G=<dll-path>) ] :
                $(project) $(name) ] ;
        }
    }
    generators.register [ new dll-paths-list-generator ] ;
}

rule list ( target : sources * : properties * )
{
    local paths = [ feature.get-values <dll-path> : $(properties) ] ;
    paths = [ sequence.insertion-sort $(paths) ] ;
    print.output $(target) ;
    print.text $(paths) ;
}
""")

t.write("dll_paths.py", """\
import bjam

import b2.build.type as type
import b2.build.generators as generators

from b2.manager import get_manager

def init():
    type.register("PATH_LIST", ["pathlist"])

    class DllPathsListGenerator(generators.Generator):

        def __init__(self):
            generators.Generator.__init__(self, "dll_paths.list", False,
                ["EXE"], ["PATH_LIST"])

        def generated_targets(self, sources, ps, project, name):
            dll_paths = []
            for s in sources:
                a = s.action()
                if a:
                    p = a.properties()
                    dll_paths += p.get('dll-path')
            dll_paths.sort()
            return generators.Generator.generated_targets(self, sources,
                ps.add_raw(["<dll-path>" + p for p in dll_paths]), project,
                name)

    generators.register(DllPathsListGenerator())

command = \"\"\"
echo $(PATHS) > $(<[1])
\"\"\"
def function(target, sources, ps):
    bjam.call('set-target-variable', target, "PATHS", ps.get('dll-path'))

get_manager().engine().register_action("dll_paths.list", command,
    function=function)
""")

t.write("a/jamfile.jam", "lib a : a.cpp ;")
t.write("a/a.cpp", """\
void
#if defined(_WIN32)
__declspec(dllexport)
#endif
foo() {}
""")

t.write("b/jamfile.jam", "lib b : b.cpp ../a//a ;")
t.write("b/b.cpp", """\
void
#if defined(_WIN32)
__declspec(dllexport)
#endif
bar() {}
""")

t.run_build_system(["hardcode-dll-paths=true"])

t.expect_addition("bin/$toolset/debug*/mp.pathlist")

es1 = t.adjust_name("a/bin/$toolset/debug*")
es2 = t.adjust_name("b/bin/$toolset/debug*")

t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es1)
t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es2)

t.rm("bin/$toolset/debug*/mp.pathlist")

# Now run the same checks with pre-built libraries
adll = t.glob_file("a/bin/$toolset/debug*/a.dll")
bdll = t.glob_file("b/bin/$toolset/debug*/b.dll")
t.write("b/jamfile.jam", """
local bdll = %s ;
# Make sure that it is found even with multiple source-locations
project : source-location c $(bdll:D) ;
lib b : ../a//a : <file>$(bdll:D=) ;
""" % bdll.replace("\\", "\\\\"))
t.run_build_system(["hardcode-dll-paths=true"])
t.expect_addition("bin/$toolset/debug*/mp.pathlist")

t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es1)
t.expect_content_lines("bin/$toolset/debug*/mp.pathlist", "*" + es2)

t.cleanup()