Skip to content

Commit 2588627

Browse files
committed
added some more test and update ninja tool to handle commands
1 parent 1edf231 commit 2588627

File tree

4 files changed

+191
-3
lines changed

4 files changed

+191
-3
lines changed

src/engine/SCons/Tool/ninja.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def generate(self, ninja_file):
692692

693693
if "inputs" in build:
694694
build["inputs"].sort()
695-
695+
696696
ninja.build(**build)
697697

698698
template_builds = dict()
@@ -990,7 +990,7 @@ def get_command(env, node, action): # pylint: disable=too-many-branches
990990
comstr = get_comstr(sub_env, action, tlist, slist)
991991
if not comstr:
992992
return None
993-
993+
994994
provider = __NINJA_RULE_MAPPING.get(comstr, get_shell_command)
995995
rule, variables = provider(sub_env, node, action, tlist, slist, executor=executor)
996996

@@ -1478,6 +1478,17 @@ def ninja_file_depends_on_all(target, source, env):
14781478
except AttributeError:
14791479
pass
14801480

1481+
# We will subvert the normal Command to make sure all targets generated
1482+
# from commands will be linked to the ninja file
1483+
SconsCommand = SCons.Environment.Environment.Command
1484+
1485+
def NinjaCommand(self, target, source, action, **kw):
1486+
targets = SconsCommand(env, target, source, action, **kw)
1487+
env.Depends(ninja_file, targets)
1488+
return targets
1489+
1490+
SCons.Environment.Environment.Command = NinjaCommand
1491+
14811492
# Here we monkey patch the Task.execute method to not do a bunch of
14821493
# unnecessary work. If a build is a regular builder (i.e not a conftest and
14831494
# not our own Ninja builder) then we add it to the NINJA_STATE. Otherwise we

test/ninja/copy_function_command.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
import os
28+
import sys
29+
import TestSCons
30+
31+
_python_ = TestSCons._python_
32+
_exe = TestSCons._exe
33+
34+
test = TestSCons.TestSCons()
35+
36+
test.dir_fixture('ninja-fixture')
37+
38+
ninja = test.where_is('ninja', os.environ['PATH'])
39+
40+
if not ninja:
41+
test.skip_test("Could not find ninja in environment")
42+
43+
test.write('SConstruct', """
44+
env = Environment()
45+
env.Tool('ninja')
46+
env.Command('foo2.c', ['foo.c'], Copy('$TARGET','$SOURCE'))
47+
env.Program(target = 'foo', source = 'foo2.c')
48+
""")
49+
50+
# generate simple build
51+
test.run(stdout=None)
52+
test.must_contain_all_lines(test.stdout(),
53+
['Generating: build.ninja', 'Executing: build.ninja'])
54+
test.run(program = test.workpath('foo'), stdout="foo.c" + os.linesep)
55+
56+
# clean build and ninja files
57+
test.run(arguments='-c', stdout=None)
58+
test.must_contain_all_lines(test.stdout(), [
59+
'Removed foo2.o',
60+
'Removed foo2.c',
61+
'Removed foo',
62+
'Removed build.ninja'])
63+
64+
# only generate the ninja file
65+
test.run(arguments='--disable-auto-ninja', stdout=None)
66+
test.must_contain_all_lines(test.stdout(),
67+
['Generating: build.ninja'])
68+
test.must_not_contain_any_line(test.stdout(),
69+
['Executing: build.ninja'])
70+
71+
# run ninja independently
72+
test.run(program = ninja, stdout=None)
73+
test.run(program = test.workpath('foo'), stdout="foo.c" + os.linesep)
74+
75+
test.pass_test()
76+
77+
# Local Variables:
78+
# tab-width:4
79+
# indent-tabs-mode:nil
80+
# End:
81+
# vim: set expandtab tabstop=4 shiftwidth=4:

test/ninja/CC.py renamed to test/ninja/generate_and_build.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,41 @@
3535

3636
test.dir_fixture('ninja-fixture')
3737

38+
ninja = test.where_is('ninja', os.environ['PATH'])
39+
40+
if not ninja:
41+
test.skip_test("Could not find ninja in environment")
42+
3843
test.write('SConstruct', """
3944
env = Environment()
4045
env.Tool('ninja')
4146
env.Program(target = 'foo', source = 'foo.c')
42-
""" % locals())
47+
""")
4348

49+
# generate simple build
4450
test.run(stdout=None)
4551
test.must_contain_all_lines(test.stdout(),
4652
['Generating: build.ninja', 'Executing: build.ninja'])
4753
test.run(program = test.workpath('foo'), stdout="foo.c" + os.linesep)
4854

55+
# clean build and ninja files
4956
test.run(arguments='-c', stdout=None)
5057
test.must_contain_all_lines(test.stdout(), [
5158
'Removed foo.o',
5259
'Removed foo',
5360
'Removed build.ninja'])
61+
62+
# only generate the ninja file
5463
test.run(arguments='--disable-auto-ninja', stdout=None)
5564
test.must_contain_all_lines(test.stdout(),
5665
['Generating: build.ninja'])
5766
test.must_not_contain_any_line(test.stdout(),
5867
['Executing: build.ninja'])
5968

69+
# run ninja independently
70+
test.run(program = ninja, stdout=None)
71+
test.run(program = test.workpath('foo'), stdout="foo.c" + os.linesep)
72+
6073
test.pass_test()
6174

6275
# Local Variables:

test/ninja/shell_command.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
import os
28+
import sys
29+
import TestSCons
30+
31+
_python_ = TestSCons._python_
32+
_exe = TestSCons._exe
33+
34+
test = TestSCons.TestSCons()
35+
36+
test.dir_fixture('ninja-fixture')
37+
38+
ninja = test.where_is('ninja', os.environ['PATH'])
39+
40+
if not ninja:
41+
test.skip_test("Could not find ninja in environment")
42+
43+
test.write('SConstruct', """
44+
env = Environment()
45+
env.Tool('ninja')
46+
env.Program(target = 'foo', source = 'foo.c')
47+
env.Command('foo.out', ['foo'], './foo > foo.out')
48+
""")
49+
50+
# generate simple build
51+
test.run(stdout=None)
52+
test.must_contain_all_lines(test.stdout(),
53+
['Generating: build.ninja', 'Executing: build.ninja'])
54+
test.must_match('foo.out', 'foo.c' + os.linesep)
55+
56+
# clean build and ninja files
57+
test.run(arguments='-c', stdout=None)
58+
test.must_contain_all_lines(test.stdout(), [
59+
'Removed foo.o',
60+
'Removed foo',
61+
'Removed foo.out',
62+
'Removed build.ninja'])
63+
64+
# only generate the ninja file
65+
test.run(arguments='--disable-auto-ninja', stdout=None)
66+
test.must_contain_all_lines(test.stdout(),
67+
['Generating: build.ninja'])
68+
test.must_not_contain_any_line(test.stdout(),
69+
['Executing: build.ninja'])
70+
71+
# run ninja independently
72+
test.run(program = ninja, stdout=None)
73+
test.must_match('foo.out', 'foo.c' + os.linesep)
74+
75+
76+
77+
test.pass_test()
78+
79+
# Local Variables:
80+
# tab-width:4
81+
# indent-tabs-mode:nil
82+
# End:
83+
# vim: set expandtab tabstop=4 shiftwidth=4:

0 commit comments

Comments
 (0)