Fix tests on systems where 'ar' prints warnings about creating archives. (Kevin...
[scons.git] / test / HeaderInstall.py
1 #!/usr/bin/env python
2 # __COPYRIGHT__
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
23
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25
26 """
27 Test that dependencies in installed header files get re-scanned correctly.
28 """
29
30 import os.path
31
32 import TestSCons
33
34 test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
35
36 test.subdir('work1', ['work1', 'dist'])
37
38 test.write(['work1', 'SConstruct'], """
39 env = Environment(CPPPATH=['#include'])
40 Export('env')
41 SConscript('dist/SConscript')
42 libfoo = env.StaticLibrary('foo', ['foo.c'])
43 Default(libfoo)
44 """)
45
46 test.write(['work1', 'foo.c'], """
47 #include <h1.h>
48 """)
49
50 test.write(['work1', 'dist', 'SConscript'], """\
51 Import('env')
52 env.Install('#include', ['h1.h', 'h2.h', 'h3.h'])
53 """)
54
55 test.write(['work1', 'dist', 'h1.h'], """\
56 #include "h2.h"
57 """)
58
59 test.write(['work1', 'dist', 'h2.h'], """\
60 #include "h3.h"
61 """)
62
63 test.write(['work1', 'dist', 'h3.h'], """\
64 int foo = 3;
65 """)
66
67 test.run(chdir = 'work1', arguments = ".", stderr=TestSCons.noisy_ar)
68
69 test.up_to_date(chdir = 'work1', arguments = ".")
70
71 #
72 test.subdir('ref', 'work2', ['work2', 'src'])
73
74 test.write(['work2', 'SConstruct'], """
75 env = Environment(CPPPATH=['build', r'%s'])
76 env.Install('build', 'src/in1.h')
77 env.Install('build', 'src/in2.h')
78 env.Install('build', 'src/in3.h')
79 """ % test.workpath('ref'))
80
81 test.write(['ref', 'in1.h'], '#define FILE "ref/in1.h"\n#include <in2.h>\n')
82 test.write(['ref', 'in2.h'], '#define FILE "ref/in2.h"\n#include <in3.h>\n')
83 test.write(['ref', 'in3.h'], '#define FILE "ref/in3.h"\n#define FOO 0\n')
84
85 src_in1_h = '#define FILE "src/in1.h"\n#include <in2.h>\n'
86 src_in2_h = '#define FILE "src/in2.h"\n#include <in3.h>\n'
87 src_in3_h = '#define FILE "src/in3.h"\n#define FOO 0\n'
88 test.write(['work2', 'src', 'in1.h'], src_in1_h)
89 test.write(['work2', 'src', 'in2.h'], src_in2_h)
90 test.write(['work2', 'src', 'in3.h'], src_in3_h)
91
92 test.run(chdir = 'work2', arguments = 'build')
93
94 test.must_match(['work2', 'build', 'in1.h'], src_in1_h)
95 test.must_match(['work2', 'build', 'in2.h'], src_in2_h)
96 test.must_match(['work2', 'build', 'in3.h'], src_in3_h)
97
98 test.up_to_date(chdir = 'work2', arguments = 'build')
99
100 src_in3_h = '#define FILE "src/in3.h"\n#define FOO 1\n'
101 test.write(['work2', 'src', 'in3.h'], src_in3_h)
102
103 test.run(chdir = 'work2', arguments = 'build', stdout=test.wrap_stdout("""\
104 Install file: "%s" as "%s"
105 """ % (os.path.join('src', 'in3.h'),
106        os.path.join('build', 'in3.h'))))
107
108 test.must_match(['work2', 'build', 'in1.h'], src_in1_h)
109 test.must_match(['work2', 'build', 'in2.h'], src_in2_h)
110 test.must_match(['work2', 'build', 'in3.h'], src_in3_h)
111
112 test.up_to_date(chdir = 'work2', arguments = 'build')
113
114 test.pass_test()