fbd135e8cdc572e4e215df56a9d39b00819173eb
[scons.git] / test / Repository / SharedLibrary.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 Verify that we can create a local shared library containing shared
29 object files built in a repository.
30 """
31
32 import os
33 import string
34 import sys
35
36 import TestSCons
37
38 test = TestSCons.TestSCons()
39
40 #
41 test.subdir('repository', 'work')
42
43 #
44 opts = '-Y ' + test.workpath('repository')
45
46 #
47 test.write(['repository', 'SConstruct'], """\
48 env = Environment()
49 f1 = env.SharedObject('f1.c')
50 f2 = env.SharedObject('f2.c')
51 f3 = env.SharedObject('f3.c')
52 if ARGUMENTS.get('PROGRAM'):
53     lib = env.SharedLibrary(target = 'foo',
54                             source = f1 + f2 + f3,
55                             WINDOWS_INSERT_DEF = 1)
56     env.Program(target='prog', source='prog.c', LIBS='foo', LIBPATH=['.'])
57 """)
58
59 for fx in ['1', '2', '3']:
60     test.write(['repository', 'f%s.c' % (fx)], r"""
61 #include <stdio.h>
62
63 void
64 f%s(void)
65 {
66         printf("f%s.c\n");
67         fflush(stdout);
68 }
69 """ % (fx,fx))
70
71 test.write(['repository', "foo.def"], r"""
72 LIBRARY        "foo"
73 DESCRIPTION    "Foo Shared Library"
74
75 EXPORTS
76    f1
77    f2
78    f3
79 """)
80
81 test.write(['repository', 'prog.c'], r"""
82 #include <stdio.h>
83 void f1(void);
84 void f2(void);
85 void f3(void);
86 int
87 main(int argc, char *argv[])
88 {
89         argv[argc++] = "--";
90         f1();
91         f2();
92         f3();
93         printf("prog.c\n");
94         return 0;
95 }
96 """)
97
98 # Build the relocatable objects within the repository
99 test.run(chdir = 'repository', arguments = '.')
100
101 # Make the repository non-writable,
102 # so we'll detect if we try to write into it accidentally.
103 test.writable('repository', 0)
104
105 # Build the library and the program within the work area
106 test.run(chdir='work',
107          options=opts,
108          arguments='PROGRAM=1',
109          stderr=TestSCons.noisy_ar,
110          match=TestSCons.match_re_dotall)
111
112 # Run the program and verify that the library worked
113 if os.name == 'posix':
114     if sys.platform[:6] == 'darwin':
115         os.environ['DYLD_LIBRARY_PATH'] = test.workpath('work')
116     else:
117         os.environ['LD_LIBRARY_PATH'] = test.workpath('work')
118 if string.find(sys.platform, 'irix') != -1:
119     os.environ['LD_LIBRARYN32_PATH'] = test.workpath('work')
120
121 test.run(program = test.workpath('work', 'prog'),
122          stdout = "f1.c\nf2.c\nf3.c\nprog.c\n")
123
124 test.pass_test()
125
126 # Local Variables:
127 # tab-width:4
128 # indent-tabs-mode:nil
129 # End:
130 # vim: set expandtab tabstop=4 shiftwidth=4: