Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / v2 / test / alias.py
1 #!/usr/bin/python
2
3 # Copyright 2003 Dave Abrahams
4 # Copyright 2003 Vladimir Prus
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7
8 import BoostBuild
9
10
11 ################################################################################
12 #
13 # test_alias_rule()
14 # -----------------
15 #
16 ################################################################################
17
18 def test_alias_rule(t):
19     """Basic alias rule test.
20     """
21
22     t.write("jamroot.jam", """
23 exe a : a.cpp ;
24 exe b : b.cpp ;
25 exe c : c.cpp ;
26
27 alias bin1 : a ;
28 alias bin2 : a b ;
29
30 alias src : s.cpp ;
31 exe hello : hello.cpp src ;
32 """)
33
34     t.write("a.cpp", "int main() {}\n")
35     t.copy("a.cpp", "b.cpp")
36     t.copy("a.cpp", "c.cpp")
37     t.copy("a.cpp", "hello.cpp")
38     t.write("s.cpp", "")
39
40     # Check that targets to which "bin1" refers are updated, and only those.
41     t.run_build_system("bin1")
42     t.expect_addition(BoostBuild.List("bin/$toolset/debug/") * "a.exe a.obj")
43     t.expect_nothing_more()
44
45     # Try again with "bin2"
46     t.run_build_system("bin2")
47     t.expect_addition(BoostBuild.List("bin/$toolset/debug/") * "b.exe b.obj")
48     t.expect_nothing_more()
49
50     # Try building everything, making sure 'hello' target is created.
51     t.run_build_system()
52     t.expect_addition(BoostBuild.List("bin/$toolset/debug/") * \
53         "hello.exe hello.obj")
54     t.expect_addition("bin/$toolset/debug/s.obj")
55     t.expect_addition(BoostBuild.List("bin/$toolset/debug/") * "c.exe c.obj")
56     t.expect_nothing_more()
57
58
59 ################################################################################
60 #
61 # test_alias_source_usage_requirements()
62 # --------------------------------------
63 #
64 ################################################################################
65
66 def test_alias_source_usage_requirements(t):
67     """Check whether usage requirements are propagated via "alias". In case they
68     are not, linking will fail as there will be no main() function defined
69     anywhere in the source.
70     """
71
72     t.write("jamroot.jam", """
73 lib l : l.cpp : : : <define>WANT_MAIN ;
74 alias la : l ;
75 exe main : main.cpp la ;
76 """)
77
78     t.write("l.cpp", """
79 void
80 #if defined(_WIN32)
81 __declspec(dllexport)
82 #endif
83 foo() {}
84 """)
85
86     t.write("main.cpp", """
87 #ifdef WANT_MAIN
88 int main() {}
89 #endif
90 """)
91
92     t.run_build_system()
93
94
95 ################################################################################
96 #
97 # main()
98 # ------
99 #
100 ################################################################################
101
102 t = BoostBuild.Tester()
103
104 test_alias_rule(t)
105 test_alias_source_usage_requirements(t)
106
107 t.cleanup()