1#!/usr/bin/python 2 3# Copyright 2012 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 7import BoostBuild 8 9t = BoostBuild.Tester(use_test_config=False) 10 11# Test a header loop that depends on (but does not contain) a generated header. 12t.write("test.cpp", '#include "header1.h"\n') 13 14t.write("header1.h", """\ 15#ifndef HEADER1_H 16#define HEADER1_H 17#include "header2.h" 18#endif 19""") 20 21t.write("header2.h", """\ 22#ifndef HEADER2_H 23#define HEADER2_H 24#include "header1.h" 25#include "header3.h" 26#endif 27""") 28 29t.write("header3.in", "/* empty file */\n") 30 31t.write("jamroot.jam", """\ 32import common ; 33make header3.h : header3.in : @common.copy ; 34obj test : test.cpp : <implicit-dependency>header3.h ; 35""") 36 37t.run_build_system(["-j2"]) 38t.expect_addition("bin/header3.h") 39t.expect_addition("bin/$toolset/debug*/test.obj") 40t.expect_nothing_more() 41 42t.rm(".") 43 44# Test a linear sequence of generated headers. 45t.write("test.cpp", '#include "header1.h"\n') 46 47t.write("header1.in", """\ 48#ifndef HEADER1_H 49#define HEADER1_H 50#include "header2.h" 51#endif 52""") 53 54t.write("header2.in", """\ 55#ifndef HEADER2_H 56#define HEADER2_H 57#include "header3.h" 58#endif 59""") 60 61t.write("header3.in", "/* empty file */\n") 62 63t.write("jamroot.jam", """\ 64import common ; 65make header1.h : header1.in : @common.copy ; 66make header2.h : header2.in : @common.copy ; 67make header3.h : header3.in : @common.copy ; 68obj test : test.cpp : 69 <implicit-dependency>header1.h 70 <implicit-dependency>header2.h 71 <implicit-dependency>header3.h ; 72""") 73 74t.run_build_system(["-j2", "test"]) 75t.expect_addition("bin/header1.h") 76t.expect_addition("bin/header2.h") 77t.expect_addition("bin/header3.h") 78t.expect_addition("bin/$toolset/debug*/test.obj") 79t.expect_nothing_more() 80 81t.rm(".") 82 83# Test a loop in generated headers. 84t.write("test.cpp", '#include "header1.h"\n') 85 86t.write("header1.in", """\ 87#ifndef HEADER1_H 88#define HEADER1_H 89#include "header2.h" 90#endif 91""") 92 93t.write("header2.in", """\ 94#ifndef HEADER2_H 95#define HEADER2_H 96#include "header3.h" 97#endif 98""") 99 100t.write("header3.in", """\ 101#ifndef HEADER2_H 102#define HEADER2_H 103#include "header1.h" 104#endif 105""") 106 107t.write("jamroot.jam", """\ 108import common ; 109 110actions copy { 111 sleep 1 112 cp $(>) $(<) 113} 114 115make header1.h : header1.in : @common.copy ; 116make header2.h : header2.in : @common.copy ; 117make header3.h : header3.in : @common.copy ; 118obj test : test.cpp : 119 <implicit-dependency>header1.h 120 <implicit-dependency>header2.h 121 <implicit-dependency>header3.h ; 122""") 123 124t.run_build_system(["-j2", "test"]) 125t.expect_addition("bin/header1.h") 126t.expect_addition("bin/header2.h") 127t.expect_addition("bin/header3.h") 128t.expect_addition("bin/$toolset/debug*/test.obj") 129t.expect_nothing_more() 130 131t.rm(".") 132 133# Test that all the dependencies of a loop are updated before any of the 134# dependents. 135t.write("test1.cpp", '#include "header1.h"\n') 136 137t.write("test2.cpp", """\ 138#include "header2.h" 139int main() {} 140""") 141 142t.write("header1.h", """\ 143#ifndef HEADER1_H 144#define HEADER1_H 145#include "header2.h" 146#endif 147""") 148 149t.write("header2.h", """\ 150#ifndef HEADER2_H 151#define HEADER2_H 152#include "header1.h" 153#include "header3.h" 154#endif 155""") 156 157t.write("header3.in", "\n") 158 159t.write("sleep.bat", """\ 160::@timeout /T %1 /NOBREAK >nul 161@ping 127.0.0.1 -n 2 -w 1000 >nul 162@ping 127.0.0.1 -n %1 -w 1000 >nul 163@exit /B 0 164""") 165 166t.write("jamroot.jam", """\ 167import common ; 168import os ; 169 170if [ os.name ] = NT 171{ 172 SLEEP = call sleep.bat ; 173} 174else 175{ 176 SLEEP = sleep ; 177} 178 179rule copy { common.copy $(<) : $(>) ; } 180actions copy { $(SLEEP) 1 } 181 182make header3.h : header3.in : @copy ; 183exe test : test2.cpp test1.cpp : <implicit-dependency>header3.h ; 184""") 185 186t.run_build_system(["-j2", "test"]) 187t.expect_addition("bin/header3.h") 188t.expect_addition("bin/$toolset/debug*/test1.obj") 189t.expect_addition("bin/$toolset/debug*/test2.obj") 190t.expect_addition("bin/$toolset/debug*/test.exe") 191t.ignore_addition("bin/*/test.rsp") 192t.expect_nothing_more() 193 194t.touch("header3.in") 195t.run_build_system(["-j2", "test"]) 196t.expect_touch("bin/header3.h") 197t.expect_touch("bin/$toolset/debug*/test1.obj") 198t.expect_touch("bin/$toolset/debug*/test2.obj") 199t.expect_touch("bin/$toolset/debug*/test.exe") 200t.ignore_touch("bin/*/test.rsp") 201t.expect_nothing_more() 202 203t.rm(".") 204 205# Test a loop that includes a generated header 206t.write("test1.cpp", '#include "header1.h"\n') 207t.write("test2.cpp", """\ 208#include "header2.h" 209int main() {} 210""") 211 212t.write("header1.h", """\ 213#ifndef HEADER1_H 214#define HEADER1_H 215#include "header2.h" 216#endif 217""") 218 219t.write("header2.in", """\ 220#ifndef HEADER2_H 221#define HEADER2_H 222#include "header3.h" 223#endif 224""") 225 226t.write("header3.h", """\ 227#ifndef HEADER3_H 228#define HEADER3_H 229#include "header1.h" 230#endif 231""") 232 233t.write("sleep.bat", """\ 234::@timeout /T %1 /NOBREAK >nul 235@ping 127.0.0.1 -n 2 -w 1000 >nul 236@ping 127.0.0.1 -n %1 -w 1000 >nul 237@exit /B 0 238""") 239 240t.write("jamroot.jam", """\ 241import common ; 242import os ; 243 244if [ os.name ] = NT 245{ 246 SLEEP = call sleep.bat ; 247} 248else 249{ 250 SLEEP = sleep ; 251} 252 253rule copy { common.copy $(<) : $(>) ; } 254actions copy { $(SLEEP) 1 } 255 256make header2.h : header2.in : @copy ; 257exe test : test2.cpp test1.cpp : <implicit-dependency>header2.h <include>. ; 258""") 259 260t.run_build_system(["-j2", "test"]) 261t.expect_addition("bin/header2.h") 262t.expect_addition("bin/$toolset/debug*/test1.obj") 263t.expect_addition("bin/$toolset/debug*/test2.obj") 264t.expect_addition("bin/$toolset/debug*/test.exe") 265t.ignore_addition("bin/*/test.rsp") 266t.expect_nothing_more() 267 268t.cleanup() 269