1#!/usr/local/bin/python3.8 2 3# Copyright 2006 Vladimir Prus. 4# Distributed under the Boost Software License, Version 1.0. (See 5# accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7 8import BoostBuild 9from time import sleep 10 11 12t = BoostBuild.Tester() 13 14t.write("jamroot.jam", """ 15import pch ; 16project : requirements <warnings-as-errors>on ; 17cpp-pch pch : pch.hpp : <toolset>msvc:<source>pch.cpp <include>. ; 18cpp-pch pch-afx : pch.hpp : <define>HELLO <toolset>msvc:<source>pch.cpp <include>. ; 19exe hello : hello.cpp pch : <include>. ; 20exe hello-afx : hello-afx.cpp pch-afx : <define>HELLO <include>. ; 21""") 22 23t.write("pch.hpp.bad", """ 24THIS WILL NOT COMPILE 25""") 26 27# Note that pch.hpp is written after pch.hpp.bad, so its timestamp will not be 28# less than timestamp of pch.hpp.bad. 29sleep(1) 30t.write("pch.hpp", """ 31#undef HELLO 32class TestClass 33{ 34public: 35 TestClass( int, int ) {} 36}; 37""") 38 39t.write("pch.cpp", """#include <pch.hpp> 40""") 41 42for name in ("hello.cpp", "hello-afx.cpp"): 43 t.write(name, """#include <pch.hpp> 44int main() { TestClass c(1, 2); } 45""") 46 47t.run_build_system() 48t.expect_addition("bin/$toolset/debug*/hello.exe") 49t.expect_addition("bin/$toolset/debug*/hello-afx.exe") 50 51 52# Now make the header unusable, without changing timestamp. If everything is OK, 53# B2 will not recreate PCH, and compiler will happily use pre-compiled 54# header, not noticing that the real header is bad. 55 56t.copy_preserving_timestamp("pch.hpp.bad", "pch.hpp") 57 58t.rm("bin/$toolset/debug*/hello.obj") 59t.rm("bin/$toolset/debug*/hello-afx.obj") 60 61t.run_build_system() 62t.expect_addition("bin/$toolset/debug*/hello.obj") 63t.expect_addition("bin/$toolset/debug*/hello-afx.obj") 64 65t.cleanup() 66