Support Java when using Repository and SConscriptChdir(0). (Charles Crain)
[scons.git] / test / Repository / LIBPATH.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 import string
28 import TestSCons
29
30 test = TestSCons.TestSCons()
31
32 test.subdir('foo', ['foo', 'zzz'], 'bar', ['bar', 'yyy'], 'work')
33
34 workpath_foo = test.workpath('foo')
35 workpath_foo_yyy = test.workpath('foo', 'yyy')
36 workpath_foo_zzz = test.workpath('foo', 'zzz')
37 workpath_bar = test.workpath('bar')
38 workpath_bar_yyy = test.workpath('bar', 'yyy')
39 workpath_bar_zzz = test.workpath('bar', 'zzz')
40 workpath_work = test.workpath('work')
41
42 test.write(['work', 'SConstruct'], r"""
43 import string
44 env_zzz = Environment(LIBPATH = ['.', 'zzz'])
45 env_yyy = Environment(LIBPATH = ['yyy', '.'])
46 aaa_exe = env_zzz.Program('aaa', 'aaa.c')
47 bbb_exe = env_yyy.Program('bbb', 'bbb.c')
48 def write_LIBDIRFLAGS(env, target, source):
49     pre = env.subst('$LIBDIRPREFIX')
50     suf = env.subst('$LIBDIRSUFFIX')
51     f = open(str(target[0]), 'wb')
52     for arg in string.split(env.subst('$_LIBDIRFLAGS')):
53         if arg[:len(pre)] == pre:
54             arg = arg[len(pre):]
55         if arg[-len(suf):] == suf:
56             arg = arg[:-len(pre)]
57         f.write(arg + '\n')
58     f.close()
59     return 0
60 env_zzz.Command('zzz.out', aaa_exe, write_LIBDIRFLAGS)
61 env_yyy.Command('yyy.out', bbb_exe, write_LIBDIRFLAGS)
62 """)
63
64 test.write(['work', 'aaa.c'], r"""
65 int
66 main(int argc, char *argv[])
67 {
68         argv[argc++] = "--";
69         printf("work/aaa.c\n");
70         exit (0);
71 }
72 """)
73
74 test.write(['work', 'bbb.c'], r"""
75 int
76 main(int argc, char *argv[])
77 {
78         argv[argc++] = "--";
79         printf("work/bbb.c\n");
80         exit (0);
81 }
82 """)
83
84 #
85 opts = "-Y %s -Y %s -Y %s" % (workpath_foo, workpath_work, workpath_bar)
86 test.run(chdir = 'work', options = opts, arguments = ".")
87
88 #dirs = ['.', workpath_foo, workpath_bar, workpath_foo_zzz]
89 dirs = ['.', workpath_foo, workpath_bar,
90         'zzz', workpath_foo_zzz, workpath_bar_zzz]
91 test.fail_test(test.read(['work', 'zzz.out']) !=
92                string.join(dirs, '\n') + '\n')
93
94 #dirs = [workpath_bar_yyy, '.', workpath_foo, workpath_bar]
95 dirs = ['yyy', workpath_foo_yyy, workpath_bar_yyy,
96         '.', workpath_foo, workpath_bar]
97 test.fail_test(test.read(['work', 'yyy.out']) !=
98                string.join(dirs, '\n') + '\n')
99
100 #
101 test.run(chdir = 'work', options = '-c', arguments = ".")
102
103 test.subdir(['work', 'zzz'], ['work', 'yyy'])
104
105 #
106 test.run(chdir = 'work', options = opts, arguments = ".")
107
108 #dirs = ['.', workpath_foo, workpath_bar, 'zzz', workpath_foo_zzz]
109 dirs = ['.', workpath_foo, workpath_bar,
110         'zzz', workpath_foo_zzz, workpath_bar_zzz]
111 test.fail_test(test.read(['work', 'zzz.out']) !=
112                string.join(dirs, '\n') + '\n')
113
114 #dirs = ['yyy', workpath_bar_yyy, '.', workpath_foo, workpath_bar]
115 dirs = ['yyy', workpath_foo_yyy, workpath_bar_yyy,
116         '.', workpath_foo, workpath_bar]
117 test.fail_test(test.read(['work', 'yyy.out']) !=
118                string.join(dirs, '\n') + '\n')
119
120 #
121 test.pass_test()