Merge pull request #4674 from bdbaddog/fix_2281_Aliases_ignore_pre_post_add_actions
[scons.git] / test / Parallel / duplicate-target.py
blobe947edc5fbf31806136863c97bee89647baf483e
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, when a file is specified multiple times in a target
29 list, we still build all of the necessary targets.
31 This used to cause a target to "disappear" from the DAG when its reference
32 count dropped below 0, because we were subtracting the duplicated target
33 mutiple times even though we'd only visit it once. This was particularly
34 hard to track down because the DAG itself (when printed with --tree=prune,
35 for example) doesn't show the duplication in the *target* list.
36 """
38 import TestSCons
40 _python_ = TestSCons._python_
42 test = TestSCons.TestSCons()
44 test.subdir('work', ['work', 'sub'])
46 tar_output = test.workpath('work.tar')
48 test.write(['work', 'mycopy.py'], """\
49 import sys
50 import time
51 time.sleep(int(sys.argv[1]))
52 with open(sys.argv[2], 'wb') as ofp, open(sys.argv[3], 'rb') as ifp:
53 ofp.write(ifp.read())
54 """)
56 test.write(['work', 'mytar.py'], """\
57 import sys
58 import os.path
60 ofp = open(sys.argv[1], 'wb')
62 def visit(dirname):
63 names = os.listdir(dirname)
64 names.sort()
65 for n in names:
66 p = os.path.join(dirname, n)
67 if os.path.isdir(p):
68 visit(p)
69 elif os.path.isfile(p):
70 with open(p, 'rb') as ifp:
71 ofp.write(ifp.read())
73 for s in sys.argv[2:]:
74 visit(s)
75 ofp.close()
76 """)
78 test.write(['work', 'SConstruct'], """\
79 env = Environment()
80 out1 = File('sub/f1.out')
81 out2 = File('sub/f2.out')
82 env.Command([out1, out1], 'sub/f1.in',
83 r'%(_python_)s mycopy.py 3 $TARGET $SOURCE')
84 env.Command([out2, out2], 'sub/f2.in',
85 r'%(_python_)s mycopy.py 3 $TARGET $SOURCE')
87 env.Command(r'%(tar_output)s', Dir('sub'),
88 r'%(_python_)s mytar.py $TARGET $SOURCE')
89 """ % locals())
91 test.write(['work', 'sub', 'f1.in'], "work/sub/f1.in\n")
92 test.write(['work', 'sub', 'f2.in'], "work/sub/f2.in\n")
94 test.run(chdir = 'work', arguments = tar_output + ' -j2')
96 test.must_match(['work', 'sub', 'f1.out'], "work/sub/f1.in\n")
97 test.must_match(['work', 'sub', 'f2.out'], "work/sub/f2.in\n")
98 test.must_match(tar_output, """\
99 work/sub/f1.in
100 work/sub/f1.in
101 work/sub/f2.in
102 work/sub/f2.in
103 """)
105 test.pass_test()
107 # Local Variables:
108 # tab-width:4
109 # indent-tabs-mode:nil
110 # End:
111 # vim: set expandtab tabstop=4 shiftwidth=4: