| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- #!/usr/bin/python
- # Copyright 2017 Steven Watanabe
- # Distributed under the Boost Software License, Version 1.0.
- # (See accompanying file LICENSE.txt or copy at
- # https://www.bfgroup.xyz/b2/LICENSE.txt)
- # Tests configure.check-target-builds and friends
- import BoostBuild
- def test_check_target_builds():
- t = BoostBuild.Tester(use_test_config=0)
- t.write("Jamroot", """
- import configure ;
- obj pass : pass.cpp ;
- obj fail : fail.cpp ;
- explicit pass fail ;
- obj foo : foo.cpp :
- [ configure.check-target-builds pass : <define>PASS : <define>FAIL ] ;
- obj bar : foo.cpp :
- [ configure.check-target-builds fail : <define>FAIL : <define>PASS ] ;
- """)
- t.write("pass.cpp", "void f() {}\n")
- t.write("fail.cpp", "#error fail.cpp\n")
- t.write("foo.cpp", """
- #ifndef PASS
- #error PASS not defined
- #endif
- #ifdef FAIL
- #error FAIL is defined
- #endif
- """)
- t.run_build_system()
- t.expect_output_lines([
- " - pass builds : yes*",
- " - fail builds : no*"])
- t.expect_addition("bin/$toolset/debug*/pass.obj")
- t.expect_addition("bin/$toolset/debug*/foo.obj")
- t.expect_addition("bin/$toolset/debug*/bar.obj")
- t.expect_nothing_more()
- # An up-to-date build should use the cache
- t.run_build_system()
- t.expect_output_lines([
- " - pass builds : yes (cached)*",
- " - fail builds : no (cached)*"])
- t.expect_nothing_more()
- # -a should re-run everything, including configuration checks
- t.run_build_system(["-a"])
- t.expect_output_lines([
- " - pass builds : yes*",
- " - fail builds : no*"])
- t.expect_touch("bin/$toolset/debug*/pass.obj")
- t.expect_touch("bin/$toolset/debug*/foo.obj")
- t.expect_touch("bin/$toolset/debug*/bar.obj")
- t.expect_nothing_more()
- # --reconfigure should re-run configuration checks only
- t.run_build_system(["--reconfigure"])
- t.expect_output_lines([
- " - pass builds : yes*",
- " - fail builds : no*"])
- t.expect_touch("bin/$toolset/debug*/pass.obj")
- t.expect_nothing_more()
- # -a -n should not rebuild configuration checks
- t.run_build_system(["-a", "-n"])
- t.expect_output_lines([
- " - pass builds : yes (cached)*",
- " - fail builds : no (cached)*"])
- t.expect_nothing_more()
- # --clean-all should clear all configuration checks
- t.run_build_system(["--clean-all"])
- t.expect_output_lines([
- " - pass builds : yes (cached)*",
- " - fail builds : no (cached)*"])
- t.expect_removal("bin/$toolset/debug*/pass.obj")
- t.expect_removal("bin/$toolset/debug*/foo.obj")
- t.expect_removal("bin/$toolset/debug*/bar.obj")
- t.expect_nothing_more()
- # If configuration checks are absent, then --clean-all
- # should create them and then delete them again. This
- # currently fails because clean cannot remove targets
- # that were created in the same build.
- #t.run_build_system(["--clean-all"])
- #t.expect_output_lines([
- # " - pass builds : yes",
- # " - fail builds : no"])
- #t.expect_nothing_more()
- # Just verify that we're actually in the initial
- # state here.
- t.run_build_system()
- t.expect_output_lines([
- " - pass builds : yes*",
- " - fail builds : no*"])
- t.expect_addition("bin/$toolset/debug*/pass.obj")
- t.expect_addition("bin/$toolset/debug*/foo.obj")
- t.expect_addition("bin/$toolset/debug*/bar.obj")
- t.expect_nothing_more()
- t.cleanup()
- def test_choose():
- t = BoostBuild.Tester(use_test_config=0)
- t.write("Jamroot", """
- import configure ;
- obj pass : pass.cpp ;
- obj fail : fail.cpp ;
- explicit pass fail ;
- obj foo : foo.cpp :
- [ configure.choose "which one?" : fail <define>FAIL : pass <define>PASS ] ;
- """)
- t.write("pass.cpp", "void f() {}\n")
- t.write("fail.cpp", "#error fail.cpp\n")
- t.write("foo.cpp", """
- #ifndef PASS
- #error PASS not defined
- #endif
- #ifdef FAIL
- #error FAIL is defined
- #endif
- """)
- t.run_build_system()
- t.expect_output_lines([
- " - which one? : pass*"])
- t.expect_addition("bin/$toolset/debug*/pass.obj")
- t.expect_addition("bin/$toolset/debug*/foo.obj")
- t.expect_nothing_more()
- # An up-to-date build should use the cache
- t.run_build_system()
- t.expect_output_lines([
- " - which one? : pass (cached)*"])
- t.expect_nothing_more()
- # -a should re-run everything, including configuration checks
- t.run_build_system(["-a"])
- t.expect_output_lines([
- " - which one? : pass*"])
- t.expect_touch("bin/$toolset/debug*/pass.obj")
- t.expect_touch("bin/$toolset/debug*/foo.obj")
- t.expect_nothing_more()
- # --reconfigure should re-run configuration checks only
- t.run_build_system(["--reconfigure"])
- t.expect_output_lines([
- " - which one? : pass*"])
- t.expect_touch("bin/$toolset/debug*/pass.obj")
- t.expect_nothing_more()
- # -a -n should not rebuild configuration checks
- t.run_build_system(["-a", "-n"])
- t.expect_output_lines([
- " - which one? : pass (cached)*"])
- t.expect_nothing_more()
- # --clean-all should clear all configuration checks
- t.run_build_system(["--clean-all"])
- t.expect_output_lines([
- " - which one? : pass (cached)*"])
- t.expect_removal("bin/$toolset/debug*/pass.obj")
- t.expect_removal("bin/$toolset/debug*/foo.obj")
- t.expect_nothing_more()
- # If configuration checks are absent, then --clean-all
- # should create them and then delete them again. This
- # currently fails because clean cannot remove targets
- # that were created in the same build.
- #t.run_build_system(["--clean-all"])
- #t.expect_output_lines([
- # " - which one? : pass"])
- #t.expect_nothing_more()
- # Just verify that we're actually in the initial
- # state here.
- t.run_build_system()
- t.expect_output_lines([
- " - which one? : pass*"])
- t.expect_addition("bin/$toolset/debug*/pass.obj")
- t.expect_addition("bin/$toolset/debug*/foo.obj")
- t.expect_nothing_more()
- t.cleanup()
- def test_translation():
- """Tests scoping for targets, paths, and rules within check-target-builds"""
- t = BoostBuild.Tester(use_test_config=0)
- t.write("Jamroot", "")
- t.write("subdir/Jamfile", """
- import configure ;
- obj pass : pass.cpp ;
- obj fail : fail.cpp ;
- explicit pass fail ;
- obj foo : :
- [ configure.check-target-builds pass
- : [ configure.check-target-builds fail : <define>FAIL
- : <define>PASS <include>include1 <conditional>@c1 ]
- : <define>FAIL ] ;
- obj bar : :
- [ configure.choose "which one?" : pass
- [ configure.choose "Try again?" : pass
- <define>PASS <include>include1 <conditional>@c1 ] ] ;
- rule c1 ( properties * )
- {
- return <include>include2 <source>foo.cpp ;
- }
- """)
- t.write("subdir/include1/a.h", "")
- t.write("subdir/include2/b.h", "")
- t.write("subdir/pass.cpp", "void f() {}\n")
- t.write("subdir/fail.cpp", "#error fail.cpp\n")
- t.write("subdir/foo.cpp", """
- #include <a.h>
- #include <b.h>
- #ifndef PASS
- #error PASS not defined
- #endif
- #ifdef FAIL
- #error FAIL is defined
- #endif
- """)
- t.run_build_system(["subdir"])
- t.expect_output_lines([
- " - pass builds : yes*",
- " - fail builds : no*"])
- t.expect_addition("subdir/bin/$toolset/debug*/pass.obj")
- t.expect_addition("subdir/bin/$toolset/debug*/foo.obj")
- t.expect_addition("subdir/bin/$toolset/debug*/bar.obj")
- t.expect_nothing_more()
- t.cleanup()
- def test_choose_none():
- """Tests choose when none of the alternatives match."""
- t = BoostBuild.Tester(use_test_config=0)
- t.write("Jamroot", """
- import configure ;
- obj fail : fail.cpp ;
- explicit pass fail ;
- obj foo : foo.cpp :
- [ configure.choose "which one?" : fail <define>FAIL ] ;
- """)
- t.write("fail.cpp", "#error fail.cpp\n")
- t.write("foo.cpp", """
- #ifdef FAIL
- #error FAIL is defined
- #endif
- """)
- t.run_build_system()
- t.expect_output_lines([
- " - which one? : none*"])
- # An up-to-date build should use the cache
- t.run_build_system()
- t.expect_output_lines([
- " - which one? : none (cached)*"])
- t.expect_nothing_more()
- t.cleanup()
- test_check_target_builds()
- test_choose()
- test_translation()
- test_choose_none()
|