ad3a90740f9d9f94100df3fb9bcc8dd708472e23
[scons.git] / test / CXX / SHCXXCOMSTR.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test that the $SHCXXCOMSTR construction variable allows you to customize
29 the shared object C++ compilation output.
30 """
31
32 import os
33 import string
34 import sys
35 import TestSCons
36
37 python = TestSCons.python
38 _exe   = TestSCons._exe
39
40 test = TestSCons.TestSCons()
41
42
43
44 test.write('mycc.py', r"""
45 import sys
46 outfile = open(sys.argv[1], 'wb')
47 infile = open(sys.argv[2], 'rb')
48 for l in filter(lambda l: l != '/*c++*/\n', infile.readlines()):
49     outfile.write(l)
50 sys.exit(0)
51 """)
52
53 if os.path.normcase('.c') == os.path.normcase('.C'):
54     alt_cpp_suffix = '.cpp'
55 else:
56     alt_cpp_suffix = '.C'
57
58 test.write('SConstruct', """
59 env = Environment(SHCXXCOM = r'%(python)s mycc.py $TARGET $SOURCE',
60                   SHCXXCOMSTR = 'Building shared object $TARGET from $SOURCE',
61                   SHOBJSUFFIX='.obj')
62 env.SharedObject(target = 'test1', source = 'test1.cpp')
63 env.SharedObject(target = 'test2', source = 'test2.cc')
64 env.SharedObject(target = 'test3', source = 'test3.cxx')
65 env.SharedObject(target = 'test4', source = 'test4.c++')
66 env.SharedObject(target = 'test5', source = 'test5.C++')
67 env.SharedObject(target = 'test6', source = 'test6%(alt_cpp_suffix)s')
68 """ % locals())
69
70 test.write('test1.cpp', "test1.cpp\n/*c++*/\n")
71 test.write('test2.cc',  "test2.cc\n/*c++*/\n")
72 test.write('test3.cxx', "test3.cxx\n/*c++*/\n")
73 test.write('test4.c++', "test4.c++\n/*c++*/\n")
74 test.write('test5.C++', "test5.C++\n/*c++*/\n")
75 test.write('test6'+alt_cpp_suffix, "test6.C\n/*c++*/\n")
76
77 test.run(stdout = test.wrap_stdout("""\
78 Building shared object test1.obj from test1.cpp
79 Building shared object test2.obj from test2.cc
80 Building shared object test3.obj from test3.cxx
81 Building shared object test4.obj from test4.c++
82 Building shared object test5.obj from test5.C++
83 Building shared object test6.obj from test6%(alt_cpp_suffix)s
84 """ % locals()))
85
86 test.must_match('test1.obj', "test1.cpp\n")
87 test.must_match('test2.obj', "test2.cc\n")
88 test.must_match('test3.obj', "test3.cxx\n")
89 test.must_match('test4.obj', "test4.c++\n")
90 test.must_match('test5.obj', "test5.C++\n")
91 test.must_match('test6.obj', "test6.C\n")
92
93
94
95 test.pass_test()