pch.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/python
  2. # Copyright 2006 Vladimir Prus.
  3. # Copyright Nikita Kniazev 2020.
  4. # Distributed under the Boost Software License, Version 1.0. (See
  5. # accompanying file LICENSE.txt or copy at
  6. # https://www.bfgroup.xyz/b2/LICENSE.txt)
  7. import BoostBuild
  8. from time import sleep
  9. t = BoostBuild.Tester()
  10. t.write("jamroot.jam", """
  11. import pch ;
  12. project : requirements <warnings-as-errors>on ;
  13. cpp-pch pch : pch.hpp ;
  14. cpp-pch pch-afx : pch.hpp : <define>HELLO ;
  15. cpp-pch pch-msvc-source : pch.hpp : <toolset>msvc:<source>pch.cpp ;
  16. exe hello : hello.cpp pch ;
  17. exe hello-afx : hello-afx.cpp pch-afx : <define>HELLO ;
  18. exe hello-msvc-source : hello-msvc-source.cpp pch-msvc-source ;
  19. """)
  20. pch_content = """\
  21. #undef HELLO
  22. class TestClass
  23. {
  24. public:
  25. TestClass( int, int ) {}
  26. };
  27. """
  28. t.write("pch.hpp", pch_content)
  29. t.write("pch.cpp", """#include <pch.hpp>
  30. """)
  31. toolset = BoostBuild.get_toolset()
  32. for name in ("hello.cpp", "hello-afx.cpp", "hello-msvc-source.cpp"):
  33. t.write(name, """int main() { TestClass c(1, 2); }
  34. """)
  35. t.run_build_system()
  36. t.expect_addition("bin/$toolset/debug*/hello.exe")
  37. t.expect_addition("bin/$toolset/debug*/hello-afx.exe")
  38. t.expect_addition("bin/$toolset/debug*/hello-msvc-source.exe")
  39. # Now make the header unusable, replace its content with some garbage, but
  40. # preserve the size and timestamp to fool the compiler. If everything is OK,
  41. # B2 will not recreate PCH, and compiler will happily use pre-compiled
  42. # header, not noticing that the real header is bad.
  43. t.rename("pch.hpp", "pch.hpp.orig")
  44. s = "THIS WILL NOT COMPILE. "
  45. t.write("pch.hpp", s + (len(pch_content) - len(s)) * 'x')
  46. t.copy_timestamp("pch.hpp.orig", "pch.hpp")
  47. t.rm("bin/$toolset/debug*/hello.obj")
  48. t.rm("bin/$toolset/debug*/hello-afx.obj")
  49. t.rm("bin/$toolset/debug*/hello-msvc-source.obj")
  50. t.run_build_system()
  51. t.expect_addition("bin/$toolset/debug*/hello.obj")
  52. t.expect_addition("bin/$toolset/debug*/hello-afx.obj")
  53. t.expect_addition("bin/$toolset/debug*/hello-msvc-source.obj")
  54. t.cleanup()