Issue 1287: copy File attributes from the local Node to a Repository
[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 TestCmd
37 import TestSCons
38
39 test = TestSCons.TestSCons()
40
41 #
42 test.subdir('repository', 'work')
43
44 #
45 workpath_repository = test.workpath('repository')
46
47 #
48 opts = '-Y ' + workpath_repository
49
50 #
51 test.write(['repository', 'SConstruct'], """\
52 env = Environment()
53 f1 = env.SharedObject('f1.c')
54 f2 = env.SharedObject('f2.c')
55 f3 = env.SharedObject('f3.c')
56 if ARGUMENTS.get('PROGRAM'):
57     lib = env.SharedLibrary(target = 'foo',
58                             source = ['f1.os', 'f2.os', 'f3.os'],
59                             WINDOWS_INSERT_DEF = 1)
60     env.Program(target='prog', source='prog.c', LIBS='foo', LIBPATH=['.'])
61 """)
62
63 test.write(['repository', 'f1.c'], r"""
64 #include <stdio.h>
65
66 void
67 f1(void)
68 {
69         printf("f1.c\n");
70         fflush(stdout);
71 }
72 """)
73
74 test.write(['repository', 'f2.c'], r"""
75 #include <stdio.h>
76
77 void
78 f2(void)
79 {
80         printf("f2.c\n");
81         fflush(stdout);
82 }
83 """)
84
85 test.write(['repository', 'f3.c'], r"""
86 #include <stdio.h>
87
88 void
89 f3(void)
90 {
91         printf("f3.c\n");
92         fflush(stdout);
93 }
94 """)
95
96 test.write(['repository', "foo.def"], r"""
97 LIBRARY        "foo"
98 DESCRIPTION    "Foo Shared Library"
99
100 EXPORTS
101    f1
102    f2
103    f3
104 """)
105
106 test.write(['repository', 'prog.c'], r"""
107 #include <stdio.h>
108 void f1(void);
109 void f2(void);
110 void f3(void);
111 int
112 main(int argc, char *argv[])
113 {
114         argv[argc++] = "--";
115         f1();
116         f2();
117         f3();
118         printf("prog.c\n");
119         return 0;
120 }
121 """)
122
123 test.run(chdir = 'repository', arguments = '.')
124
125 # Make the repository non-writable,
126 # so we'll detect if we try to write into it accidentally.
127 test.writable('repository', 0)
128
129 #
130 test.run(chdir='work',
131          options=opts,
132          arguments='PROGRAM=1',
133          stderr=TestSCons.noisy_ar,
134          match=TestSCons.match_re_dotall)
135
136 if os.name == 'posix':
137     os.environ['LD_LIBRARY_PATH'] = test.workpath('work')
138 if string.find(sys.platform, 'irix') != -1:
139     os.environ['LD_LIBRARYN32_PATH'] = test.workpath('work')
140
141 test.run(program = test.workpath('work', 'prog'),
142          stdout = "f1.c\nf2.c\nf3.c\nprog.c\n")
143
144 test.pass_test()