[ci skip] update generated files
[scons.git] / test / Repository / SharedLibrary.py
blob04ce1a5bb3e33fb0770575a88014abeb16e3a4fd
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify that we can create a local shared library containing shared
29 object files built in a repository.
30 """
32 import os
33 import sys
35 import TestSCons
37 test = TestSCons.TestSCons()
40 test.subdir('repository', 'work')
43 opts = '-Y ' + test.workpath('repository')
46 test.write(['repository', 'SConstruct'], """\
47 env = Environment()
48 f1 = env.SharedObject('f1.c')
49 f2 = env.SharedObject('f2.c')
50 f3 = env.SharedObject('f3.c')
51 if ARGUMENTS.get('PROGRAM'):
52 lib = env.SharedLibrary(target = 'foo',
53 source = f1 + f2 + f3,
54 WINDOWS_INSERT_DEF = 1)
55 env.Program(target='prog', source='prog.c', LIBS='foo', LIBPATH=['.'])
56 """)
58 for fx in ['1', '2', '3']:
59 test.write(['repository', 'f%s.c' % fx], r"""
60 #include <stdio.h>
62 void
63 f%s(void)
65 printf("f%s.c\n");
66 fflush(stdout);
68 """ % (fx,fx))
70 test.write(['repository', "foo.def"], r"""
71 LIBRARY "foo"
72 DESCRIPTION "Foo Shared Library"
74 EXPORTS
78 """)
80 test.write(['repository', 'prog.c'], r"""
81 #include <stdio.h>
82 void f1(void);
83 void f2(void);
84 void f3(void);
85 int
86 main(int argc, char *argv[])
88 argv[argc++] = "--";
89 f1();
90 f2();
91 f3();
92 printf("prog.c\n");
93 return 0;
95 """)
97 # Build the relocatable objects within the repository
98 test.run(chdir = 'repository', arguments = '.')
100 # Make the repository non-writable,
101 # so we'll detect if we try to write into it accidentally.
102 test.writable('repository', 0)
104 # Build the library and the program within the work area
105 test.run(chdir='work',
106 options=opts,
107 arguments='PROGRAM=1',
108 stderr=TestSCons.noisy_ar,
109 match=TestSCons.match_re_dotall)
111 # Run the program and verify that the library worked
112 if os.name == 'posix':
113 if sys.platform[:6] == 'darwin':
114 os.environ['DYLD_LIBRARY_PATH'] = test.workpath('work')
115 else:
116 os.environ['LD_LIBRARY_PATH'] = test.workpath('work')
117 if sys.platform.find('irix') != -1:
118 os.environ['LD_LIBRARYN32_PATH'] = test.workpath('work')
120 test.run(program = test.workpath('work', 'prog'),
121 stdout = "f1.c\nf2.c\nf3.c\nprog.c\n")
123 test.pass_test()
125 # Local Variables:
126 # tab-width:4
127 # indent-tabs-mode:nil
128 # End:
129 # vim: set expandtab tabstop=4 shiftwidth=4: