1#!/usr/bin/python 2 3# Copyright 2018 Steven Watanabe 4# Distributed under the Boost Software License, Version 1.0. 5# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 6 7# Test the package module. 8 9import BoostBuild 10import os 11 12def setup(): 13 t = BoostBuild.Tester(["p//install", "p//data"], 14 use_test_config=False) 15 16 t.write("p/jamroot.jam", "") 17 t.write("p/jamfile.jam", """\ 18 import package ; 19 exe a : a.cpp ; 20 lib b : b.cpp ; 21 package.install install Test : 22 : a 23 : b/<link>static b/<link>shared 24 : a.h ; 25 package.install-data data : Test : a.txt ; 26 """) 27 t.write("p/a.cpp", "int main() {}") 28 t.write("p/b.cpp", """ 29 int 30 #ifdef _WIN32 31 __declspec(dllexport) 32 #endif 33 must_export_something; 34 """) 35 t.write("p/a.h", "") 36 t.write("p/a.txt", "") 37 return t 38 39def test_defaults(): 40 t = setup() 41 42 # Since the default install location is outside out test area, 43 # we don't want to actually execute the build. 44 t.run_build_system(["-n", "-d1"]) 45 46 installdir = "C:/Test" if os.name == 'nt' else "/usr/local" 47 t.expect_output_lines([ 48 x.replace('/', os.sep) for x in 49 ["common.copy %s/bin/%s" % (installdir, t.adjust_name("a.exe")), 50 "common.copy %s/lib/%s" % (installdir, t.adjust_name("b.dll")), 51 "common.copy %s/lib/%s" % (installdir, t.adjust_name("b.lib")), 52 "common.copy %s/include/a.h" % installdir, 53 "common.copy %s/share/Test/a.txt" % installdir]]) 54 55 t.cleanup() 56 57def test_prefix(): 58 t = setup() 59 # An explicit --prefix on the command should override all of these: 60 t.write("project-config.jam", """ 61 option.set prefix : bad ; 62 option.set bindir : bad/bin ; 63 option.set libdir : bad/lib ; 64 option.set includedir : bad/include ; 65 option.set datarootdir : bad/share ; 66 """) 67 68 t.run_build_system(["--prefix=installdir"]) 69 t.expect_addition("installdir/bin/a.exe") 70 t.expect_addition("installdir/lib/b.dll") 71 t.expect_addition("installdir/lib/b.lib") 72 t.expect_addition("installdir/include/a.h") 73 t.expect_addition("installdir/share/Test/a.txt") 74 75 t.cleanup() 76 77def test_subdirs(): 78 t = setup() 79 # Command line options override config files 80 t.write("project-config.jam", """ 81 option.set prefix : bad ; 82 option.set bindir : bad/bin ; 83 option.set libdir : bad/lib ; 84 option.set includedir : bad/include ; 85 option.set datarootdir : bad/share ; 86 """) 87 88 t.run_build_system(["--libdir=installdir/lib64", 89 "--bindir=installdir/binx", 90 "--includedir=installdir/includex", 91 "--datarootdir=installdir/sharex"]) 92 t.expect_addition("installdir/binx/a.exe") 93 t.expect_addition("installdir/lib64/b.dll") 94 t.expect_addition("installdir/lib64/b.lib") 95 t.expect_addition("installdir/includex/a.h") 96 t.expect_addition("installdir/sharex/Test/a.txt") 97 98 t.cleanup() 99 100def test_subdirs_with_prefix(): 101 t = setup() 102 # Command line options override config files 103 t.write("project-config.jam", """ 104 option.set prefix : bad ; 105 option.set bindir : bad/bin ; 106 option.set libdir : bad/lib ; 107 option.set includedir : bad/include ; 108 option.set datarootdir : bad/share ; 109 """) 110 111 t.run_build_system(["--prefix=bad", 112 "--libdir=installdir/lib64", 113 "--bindir=installdir/binx", 114 "--includedir=installdir/includex", 115 "--datarootdir=installdir/sharex"]) 116 t.expect_addition("installdir/binx/a.exe") 117 t.expect_addition("installdir/lib64/b.dll") 118 t.expect_addition("installdir/lib64/b.lib") 119 t.expect_addition("installdir/includex/a.h") 120 t.expect_addition("installdir/sharex/Test/a.txt") 121 122 t.cleanup() 123 124def test_prefix_config_file(): 125 t = setup() 126 # An explicit --prefix on the command should override all of these: 127 t.write("project-config.jam", """ 128 option.set prefix : installdir ; 129 """) 130 131 t.run_build_system() 132 t.expect_addition("installdir/bin/a.exe") 133 t.expect_addition("installdir/lib/b.dll") 134 t.expect_addition("installdir/lib/b.lib") 135 t.expect_addition("installdir/include/a.h") 136 t.expect_addition("installdir/share/Test/a.txt") 137 138 t.cleanup() 139 140def test_subdirs_config_file(): 141 t = setup() 142 # An explicit --prefix on the command should override all of these: 143 t.write("project-config.jam", """ 144 option.set prefix : installdir ; 145 option.set libdir : installdir/lib64 ; 146 option.set bindir : installdir/binx ; 147 option.set includedir : installdir/includex ; 148 option.set datarootdir : installdir/sharex ; 149 """) 150 151 t.run_build_system() 152 t.expect_addition("installdir/binx/a.exe") 153 t.expect_addition("installdir/lib64/b.dll") 154 t.expect_addition("installdir/lib64/b.lib") 155 t.expect_addition("installdir/includex/a.h") 156 t.expect_addition("installdir/sharex/Test/a.txt") 157 158 t.cleanup() 159 160def test_multiple(): 161 '''If no prefix is specified, we might use several default 162 install prefixes.''' 163 t = BoostBuild.Tester(use_test_config=False) 164 165 t.write("p/jamroot.jam", "") 166 t.write("p/jamfile.jam", """\ 167 import package ; 168 exe a : a.cpp ; 169 lib b : b.cpp ; 170 package.install installx TestX : <install-default-prefix>xxx 171 : a 172 : b/<link>static b/<link>shared 173 : a.h ; 174 package.install instally TestY : <install-default-prefix>yyy 175 : a 176 : b/<link>static b/<link>shared 177 : a.h ; 178 """) 179 t.write("p/a.cpp", "int main() {}") 180 t.write("p/b.cpp", """ 181 int 182 #ifdef _WIN32 183 __declspec(dllexport) 184 #endif 185 must_export_something; 186 """) 187 t.write("p/a.h", "") 188 t.run_build_system(["p//installx", "p//instally"]) 189 t.expect_addition("p/xxx/bin/a.exe") 190 t.expect_addition("p/xxx/lib/b.dll") 191 t.expect_addition("p/xxx/lib/b.lib") 192 t.expect_addition("p/xxx/include/a.h") 193 t.expect_addition("p/yyy/bin/a.exe") 194 t.expect_addition("p/yyy/lib/b.dll") 195 t.expect_addition("p/yyy/lib/b.lib") 196 t.expect_addition("p/yyy/include/a.h") 197 198def test_paths(): 199 t = BoostBuild.Tester(pass_toolset=False) 200 t.write("Jamroot.jam", """\ 201 import package ; 202 import assert ; 203 import os ; 204 if [ os.name ] = NT 205 { 206 default-prefix = "/C:/Test" ; 207 } 208 else 209 { 210 default-prefix = /usr/local ; 211 } 212 paths = [ package.paths Test ] ; 213 assert.result $(default-prefix) : $(paths).prefix ; 214 assert.result $(default-prefix)/lib : $(paths).libdir ; 215 assert.result $(default-prefix)/bin : $(paths).bindir ; 216 assert.result $(default-prefix)/include : $(paths).includedir ; 217 assert.result $(default-prefix)/share : $(paths).datarootdir ; 218 package.add-path-option bardir : bar : libdir ; 219 assert.result $(default-prefix)/lib/bar : $(paths).get bardir ; 220 """) 221 t.run_build_system() 222 t.cleanup() 223 224test_defaults() 225test_prefix() 226test_subdirs() 227test_subdirs_with_prefix() 228test_prefix_config_file() 229test_subdirs_config_file() 230test_multiple() 231test_paths() 232