1#!/usr/bin/python 2 3# Copyright (C) 2013 Steven Watanabe 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 8import BoostBuild 9import MockToolset 10 11t = BoostBuild.Tester(arguments=['toolset=mock', '--ignore-site-config', '--user-config='], pass_toolset=0) 12 13MockToolset.create(t) 14 15# Build from source 16t.write("zlib/zlib.h", 'zlib') 17t.write("zlib/deflate.c", 'deflate') 18 19t.write("Jamroot.jam", """ 20path-constant here : . ; 21using zlib : : <source>$(here)/zlib ; 22alias zlib : /zlib//zlib : : <link>static <link>shared ; 23""") 24 25MockToolset.set_expected(t, ''' 26source_file('deflate.c', 'deflate') 27action('-c -x c -I./zlib -o $deflate.o $deflate.c') 28action('-c -x c -I./zlib -DZLIB_DLL -o $deflate-shared.o $deflate.c') 29action('--dll $deflate-shared.o -o $deflate.so') 30action('--archive $deflate.o -o $deflate.a') 31''') 32 33t.run_build_system() 34t.expect_addition('bin/standalone/zlib/mock/debug/z.dll') 35t.expect_addition('bin/standalone/zlib/mock/debug/link-static/z.lib') 36 37# Build from source specified in the environment 38t.rm('bin') 39t.rm('zlib') 40 41t.write("zlib root/zlib.h", 'zlib') 42t.write("zlib root/deflate.c", 'deflate') 43 44t.write("Jamroot.jam", """ 45using zlib ; 46alias zlib : /zlib//zlib : : <link>static <link>shared ; 47""") 48 49MockToolset.set_expected(t, ''' 50source_file('deflate.c', 'deflate') 51action(['-c', '-x', 'c', '-I./zlib root', '-o', '$deflate.o', '$deflate.c']) 52action(['-c', '-x', 'c', '-I./zlib root', '-DZLIB_DLL', '-o', '$deflate-shared.o', '$deflate.c']) 53action('--dll $deflate-shared.o -o $deflate.so') 54action('--archive $deflate.o -o $deflate.a') 55''') 56t.run_build_system(['-sZLIB_SOURCE=zlib root']) 57t.expect_addition('bin/standalone/zlib/mock/debug/z.dll') 58t.expect_addition('bin/standalone/zlib/mock/debug/link-static/z.lib') 59 60 61t.rm('zlib root') 62 63# Generic definitions that aren't configuration specific 64common_stuff = ''' 65source_file('test.cpp', 'test.cpp') 66source_file('main.cpp', 'int main() {}') 67source_file('zlib.h.cpp', '#include <zlib.h>\\n') 68action('-c -x c++ $main.cpp -o $main.o') 69''' 70t.write('test.cpp', 'test.cpp') 71 72# Default initialization - static library 73t.rm('bin') 74t.write("Jamroot.jam", """ 75path-constant here : . ; 76using zlib ; 77exe test : test.cpp /zlib//zlib : : <link>static <link>shared ; 78""") 79 80MockToolset.set_expected(t, common_stuff + ''' 81action('$main.o --static-lib=z -o $config.exe') 82action('-c -x c++ $zlib.h.cpp -o $zlib.h.o') 83action('-c -x c++ $test.cpp -o $test.o') 84action('$test.o --static-lib=z -o $test') 85''') 86t.run_build_system() 87t.expect_addition('bin/mock/debug/test.exe') 88t.expect_addition('bin/mock/debug/link-static/test.exe') 89 90# Default initialization - shared library 91t.rm('bin') 92t.write("Jamroot.jam", """ 93path-constant here : . ; 94using zlib ; 95exe test : test.cpp /zlib//zlib : : <link>static <link>shared ; 96""") 97 98MockToolset.set_expected(t, common_stuff + ''' 99action('$main.o --shared-lib=z -o $config.exe') 100action('-c -x c++ $zlib.h.cpp -o $zlib.h.o') 101action('-c -x c++ $test.cpp -o $test.o') 102action('$test.o --shared-lib=z -o $test') 103''') 104t.run_build_system() 105t.expect_addition('bin/mock/debug/test.exe') 106t.expect_addition('bin/mock/debug/link-static/test.exe') 107 108# Initialization in explicit location - static library 109t.rm('bin') 110t.write("Jamroot.jam", """ 111path-constant here : . ; 112using zlib : : <name>myzlib <include>$(here)/zlib <search>$(here)/zlib ; 113exe test : test.cpp /zlib//zlib : : <link>static <link>shared ; 114""") 115 116t.write('zlib/zlib.h', 'zlib') 117 118MockToolset.set_expected(t, common_stuff + ''' 119action('$main.o -L./zlib --static-lib=myzlib -o $config.exe') 120action('-c -x c++ $test.cpp -I./zlib -o $test.o') 121action('$test.o -L./zlib --static-lib=myzlib -o $test') 122''') 123t.run_build_system() 124t.expect_addition('bin/mock/debug/test.exe') 125t.expect_addition('bin/mock/debug/link-static/test.exe') 126 127# Initialization in explicit location - shared library 128t.rm('bin') 129t.write("Jamroot.jam", """ 130path-constant here : . ; 131using zlib : : <name>myzlib <include>$(here)/zlib <search>$(here)/zlib ; 132exe test : test.cpp /zlib//zlib : : <link>static <link>shared ; 133""") 134 135MockToolset.set_expected(t, common_stuff + ''' 136action('$main.o -L./zlib --shared-lib=myzlib -o $config.exe') 137action('-c -x c++ $test.cpp -I./zlib -o $test.o') 138action('$test.o -L./zlib --shared-lib=myzlib -o $test') 139''') 140t.run_build_system() 141t.expect_addition('bin/mock/debug/test.exe') 142t.expect_addition('bin/mock/debug/link-static/test.exe') 143 144# Initialization in explicit location - both static and shared libraries 145t.rm('bin') 146t.write("Jamroot.jam", """ 147path-constant here : . ; 148using zlib : : <name>myzlib <include>$(here)/zlib <search>$(here)/zlib ; 149exe test : test.cpp /zlib//zlib 150 : <link>shared:<define>SHARED : <link>static <link>shared ; 151""") 152 153MockToolset.set_expected(t, common_stuff + ''' 154action('$main.o -L./zlib --static-lib=myzlib -o $config.exe') 155action('$main.o -L./zlib --shared-lib=myzlib -o $config.exe') 156action('-c -x c++ $test.cpp -I./zlib -o $test-static.o') 157action('-c -x c++ $test.cpp -I./zlib -DSHARED -o $test-shared.o') 158action('$test-static.o -L./zlib --static-lib=myzlib -o $test') 159action('$test-shared.o -L./zlib --shared-lib=myzlib -o $test') 160''') 161t.run_build_system() 162t.expect_addition('bin/mock/debug/test.exe') 163t.expect_addition('bin/mock/debug/link-static/test.exe') 164 165# Initialization from the environment 166t.rm('bin') 167t.write('Jamroot.jam', """ 168using zlib ; 169exe test : test.cpp /zlib//zlib 170 : : <link>static <link>shared ; 171""") 172t.write('zlib root/zlib.h', 'zlib') 173MockToolset.set_expected(t, common_stuff + ''' 174action(['$main.o', '-L./zlib root', '--shared-lib=myzlib', '-o', '$config.exe']) 175action(['-c', '-x', 'c++', '$test.cpp', '-I./zlib root', '-o', '$test.o']) 176action(['$test.o', '-L./zlib root', '--shared-lib=myzlib', '-o', '$test']) 177''') 178t.run_build_system(['-sZLIB_INCLUDE=zlib root', 179 '-sZLIB_LIBRARY_PATH=zlib root', 180 '-sZLIB_NAME=myzlib']) 181t.expect_addition('bin/mock/debug/test.exe') 182t.expect_addition('bin/mock/debug/link-static/test.exe') 183 184t.cleanup() 185