summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/build/test/package.py
blob: 7cc5e33c01fece0f7b68a599d453fa30f5c0a234 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/python

# Copyright 2018 Steven Watanabe
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)

# Test the package module.

import BoostBuild
import os

def setup():
    t = BoostBuild.Tester(["p//install", "p//data"],
                          use_test_config=False)

    t.write("p/jamroot.jam", "")
    t.write("p/jamfile.jam", """\
    import package ;
    exe a : a.cpp ;
    lib b : b.cpp ;
    package.install install Test :
      : a
      : b/<link>static b/<link>shared
      : a.h ;
    package.install-data data : Test : a.txt ;
    """)
    t.write("p/a.cpp", "int main() {}")
    t.write("p/b.cpp", """
    int
    #ifdef _WIN32
    __declspec(dllexport)
    #endif
    must_export_something;
    """)
    t.write("p/a.h", "")
    t.write("p/a.txt", "")
    return t

def test_defaults():
    t = setup()

    # Since the default install location is outside out test area,
    # we don't want to actually execute the build.
    t.run_build_system(["-n", "-d1"])

    installdir = "C:/Test" if os.name == 'nt' else "/usr/local"
    t.expect_output_lines([
        x.replace('/', os.sep) for x in
        ["common.copy %s/bin/%s" % (installdir, t.adjust_name("a.exe")),
         "common.copy %s/lib/%s" % (installdir, t.adjust_name("b.dll")),
         "common.copy %s/lib/%s" % (installdir, t.adjust_name("b.lib")),
         "common.copy %s/include/a.h" % installdir,
         "common.copy %s/share/Test/a.txt" % installdir]])

    t.cleanup()

def test_prefix():
    t = setup()
    # An explicit --prefix on the command should override all of these:
    t.write("project-config.jam", """
    option.set prefix : bad ;
    option.set bindir : bad/bin ;
    option.set libdir : bad/lib ;
    option.set includedir : bad/include ;
    option.set datarootdir : bad/share ;
    """)

    t.run_build_system(["--prefix=installdir"])
    t.expect_addition("installdir/bin/a.exe")
    t.expect_addition("installdir/lib/b.dll")
    t.expect_addition("installdir/lib/b.lib")
    t.expect_addition("installdir/include/a.h")
    t.expect_addition("installdir/share/Test/a.txt")

    t.cleanup()

def test_subdirs():
    t = setup()
    # Command line options override config files
    t.write("project-config.jam", """
    option.set prefix : bad ;
    option.set bindir : bad/bin ;
    option.set libdir : bad/lib ;
    option.set includedir : bad/include ;
    option.set datarootdir : bad/share ;
    """)

    t.run_build_system(["--libdir=installdir/lib64",
                        "--bindir=installdir/binx",
                        "--includedir=installdir/includex",
                        "--datarootdir=installdir/sharex"])
    t.expect_addition("installdir/binx/a.exe")
    t.expect_addition("installdir/lib64/b.dll")
    t.expect_addition("installdir/lib64/b.lib")
    t.expect_addition("installdir/includex/a.h")
    t.expect_addition("installdir/sharex/Test/a.txt")

    t.cleanup()

def test_subdirs_with_prefix():
    t = setup()
    # Command line options override config files
    t.write("project-config.jam", """
    option.set prefix : bad ;
    option.set bindir : bad/bin ;
    option.set libdir : bad/lib ;
    option.set includedir : bad/include ;
    option.set datarootdir : bad/share ;
    """)

    t.run_build_system(["--prefix=bad",
                        "--libdir=installdir/lib64",
                        "--bindir=installdir/binx",
                        "--includedir=installdir/includex",
                        "--datarootdir=installdir/sharex"])
    t.expect_addition("installdir/binx/a.exe")
    t.expect_addition("installdir/lib64/b.dll")
    t.expect_addition("installdir/lib64/b.lib")
    t.expect_addition("installdir/includex/a.h")
    t.expect_addition("installdir/sharex/Test/a.txt")

    t.cleanup()

def test_prefix_config_file():
    t = setup()
    # An explicit --prefix on the command should override all of these:
    t.write("project-config.jam", """
    option.set prefix : installdir ;
    """)

    t.run_build_system()
    t.expect_addition("installdir/bin/a.exe")
    t.expect_addition("installdir/lib/b.dll")
    t.expect_addition("installdir/lib/b.lib")
    t.expect_addition("installdir/include/a.h")
    t.expect_addition("installdir/share/Test/a.txt")

    t.cleanup()

def test_subdirs_config_file():
    t = setup()
    # An explicit --prefix on the command should override all of these:
    t.write("project-config.jam", """
    option.set prefix : installdir ;
    option.set libdir : installdir/lib64 ;
    option.set bindir : installdir/binx ;
    option.set includedir : installdir/includex ;
    option.set datarootdir : installdir/sharex ;
    """)

    t.run_build_system()
    t.expect_addition("installdir/binx/a.exe")
    t.expect_addition("installdir/lib64/b.dll")
    t.expect_addition("installdir/lib64/b.lib")
    t.expect_addition("installdir/includex/a.h")
    t.expect_addition("installdir/sharex/Test/a.txt")

    t.cleanup()

def test_multiple():
    '''If no prefix is specified, we might use several default
    install prefixes.'''
    t = BoostBuild.Tester(use_test_config=False)

    t.write("p/jamroot.jam", "")
    t.write("p/jamfile.jam", """\
    import package ;
    exe a : a.cpp ;
    lib b : b.cpp ;
    package.install installx TestX : <install-default-prefix>xxx
      : a
      : b/<link>static b/<link>shared
      : a.h ;
    package.install instally TestY : <install-default-prefix>yyy
      : a
      : b/<link>static b/<link>shared
      : a.h ;
    """)
    t.write("p/a.cpp", "int main() {}")
    t.write("p/b.cpp", """
    int
    #ifdef _WIN32
    __declspec(dllexport)
    #endif
    must_export_something;
    """)
    t.write("p/a.h", "")
    t.run_build_system(["p//installx", "p//instally"])
    t.expect_addition("p/xxx/bin/a.exe")
    t.expect_addition("p/xxx/lib/b.dll")
    t.expect_addition("p/xxx/lib/b.lib")
    t.expect_addition("p/xxx/include/a.h")
    t.expect_addition("p/yyy/bin/a.exe")
    t.expect_addition("p/yyy/lib/b.dll")
    t.expect_addition("p/yyy/lib/b.lib")
    t.expect_addition("p/yyy/include/a.h")

def test_paths():
    t = BoostBuild.Tester(pass_toolset=False)
    t.write("Jamroot.jam", """\
    import package ;
    import assert ;
    import os ;
    if [ os.name ] = NT
    {
        default-prefix = "/C:/Test" ;
    }
    else
    {
        default-prefix = /usr/local ;
    }
    paths = [ package.paths Test ] ;
    assert.result $(default-prefix) : $(paths).prefix ;
    assert.result $(default-prefix)/lib : $(paths).libdir ;
    assert.result $(default-prefix)/bin : $(paths).bindir ;
    assert.result $(default-prefix)/include : $(paths).includedir ;
    assert.result $(default-prefix)/share : $(paths).datarootdir ;
    package.add-path-option bardir : bar : libdir ;
    assert.result $(default-prefix)/lib/bar : $(paths).get bardir ;
    """)
    t.run_build_system()
    t.cleanup()

test_defaults()
test_prefix()
test_subdirs()
test_subdirs_with_prefix()
test_prefix_config_file()
test_subdirs_config_file()
test_multiple()
test_paths()