5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Verify that the Install() Builder works
34 from TestCmd
import IS_ROOT
36 test
= TestSCons
.TestSCons()
38 test
.subdir('outside', 'work', ['work', 'sub'])
40 f1_out
= test
.workpath('work', 'export', 'f1.out')
41 f2_out
= test
.workpath('work', 'export', 'f2.out')
42 f3_out
= test
.workpath('work', 'export', 'f3.out')
43 f4_out
= test
.workpath('work', 'export', 'f4.out')
44 f5_txt
= test
.workpath('outside', 'f5.txt')
45 f6_txt
= test
.workpath('outside', 'f6.txt')
46 f6_sep
= f6_txt
.replace(os
.sep
, '/')
48 _SUBDIR_f4_out
= os
.path
.join('$SUBDIR', 'f4.out')
50 test
.write(['work', 'SConstruct'], """\
51 DefaultEnvironment(tools=[])
52 def cat(env, source, target):
53 target = str(target[0])
54 with open(target, 'wb') as ofp:
56 with open(str(src), 'rb') as ifp:
59 def my_install(dest, source, env):
61 shutil.copy2(source, dest)
62 with open('my_install.out', 'a') as f:
65 env1 = Environment(tools=[])
66 env1.Append(BUILDERS={'Cat':Builder(action=cat)})
67 env3 = env1.Clone(INSTALL = my_install)
69 t = env1.Cat(target='f1.out', source='f1.in')
70 env1.Install(dir='export', source=t)
71 t = env1.Cat(target='f2.out', source='f2.in')
72 Install(dir='export', source=t)
74 t = env3.Cat(target='f3.out', source='f3.in')
75 env3.Install(dir='export', source=t)
77 env4 = env1.Clone(EXPORT='export', SUBDIR='sub')
78 t = env4.Cat(target='sub/f4.out', source='sub/f4.in')
79 env4.Install(dir='$EXPORT', source=r'%(_SUBDIR_f4_out)s')
81 env1.Install('.', r'%(f5_txt)s')
82 env1.Install('export', r'%(f5_txt)s')
83 env1.Install('.', r'%(f6_sep)s')
84 env1.Install('export', r'%(f6_sep)s')
86 # test passing a keyword arg (not used, but should be accepted)
87 env7 = env1.Clone(EXPORT='export')
88 env7.Install(dir='$EXPORT', source='./f1.in', FOO="bar")
92 test
.write(['work', 'f1.in'], "f1.in\n")
93 test
.write(['work', 'f2.in'], "f2.in\n")
94 test
.write(['work', 'f3.in'], "f3.in\n")
95 test
.write(['work', 'sub', 'f4.in'], "sub/f4.in\n")
96 test
.write(f5_txt
, "f5.txt\n")
97 test
.write(f6_txt
, "f6.txt\n")
99 test
.run(chdir
= 'work', arguments
= '.')
101 test
.must_match(f1_out
, "f1.in\n", mode
='r')
102 test
.must_match(f2_out
, "f2.in\n", mode
='r')
103 test
.must_match(f3_out
, "f3.in\n", mode
='r')
104 test
.must_match(f4_out
, "sub/f4.in\n", mode
='r')
105 test
.must_match(['work', 'f5.txt'], "f5.txt\n", mode
='r')
106 test
.must_match(['work', 'export', 'f5.txt'], "f5.txt\n", mode
='r')
107 test
.must_match(['work', 'f6.txt'], "f6.txt\n", mode
='r')
108 test
.must_match(['work', 'export', 'f6.txt'], "f6.txt\n", mode
='r')
110 test
.must_match(['work', 'my_install.out'], os
.path
.join('export', 'f3.out'), mode
='r')
111 test
.must_match(['work', 'export', 'f1.in'], "f1.in\n", mode
='r')
113 # make sure the programs didn't get rebuilt, because nothing changed:
114 oldtime1
= os
.path
.getmtime(f1_out
)
115 oldtime2
= os
.path
.getmtime(f2_out
)
117 test
.write(['work', 'f1.in'], "f1.in again\n")
119 time
.sleep(2) # introduce a small delay, to make the test valid
121 test
.run(chdir
= 'work', arguments
= '.')
123 test
.fail_test(oldtime1
== os
.path
.getmtime(f1_out
))
124 test
.fail_test(oldtime2
!= os
.path
.getmtime(f2_out
))
126 # Verify that we didn't link to the Installed file.
127 with
open(f2_out
, 'w') as f
:
129 test
.must_match(['work', 'f2.out'], "f2.in\n", mode
='r')
131 # Verify that scons prints an error message
132 # if a target can not be unlinked before building it:
133 test
.write(['work', 'f1.in'], "f1.in again again\n")
135 # This test is not designed to work if running as root
137 os
.chmod(test
.workpath('work', 'export'), 0o555)
138 with
open(f1_out
, 'rb'):
141 "The process cannot access the file because it is being used by another process",
142 "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird",
144 test
.run(chdir
='work', arguments
=f1_out
, stderr
=None, status
=2)
145 test
.must_contain_any_line(test
.stderr(), expect
)
151 # indent-tabs-mode:nil
153 # vim: set expandtab tabstop=4 shiftwidth=4: