Skip to content

Commit 038dc4b

Browse files
authored
Merge pull request #4693 from mwichmann/test/flagstests
Clean up CC and CXX FLAGS tests
2 parents 93033b3 + 680b984 commit 038dc4b

10 files changed

+373
-212
lines changed

CHANGES.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ NOTE: Since SCons 4.9.0, Python 3.7.0 or above is required.
1212

1313
RELEASE VERSION/DATE TO BE FILLED IN LATER
1414

15-
From John Doe:
16-
17-
- Whatever John Doe did.
15+
From John Doe:
16+
- Whatever John Doe did.
1817

1918
From Bill Prendergast:
2019
- Fixed SCons.Variables.PackageVariable to correctly test the default
@@ -23,6 +22,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
2322
when default setting is a boolean string.
2423

2524
From Mats Wichmann:
25+
- Clean up C and C++ FLAGS tests. Tests which use a real compiler
26+
are now more clearly distinguished (-live.py suffix and docstring).
2627
- runtest.py once again finds "external" tests, such as the tests for
2728
tools in scons-contrib. An earlier rework had broken this. Fixes #4699.
2829

RELEASE.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Past official release announcements appear at:
66

77
==================================================================
88

9-
A new SCons release, 4.9.0, is now available on the SCons download page:
9+
A new SCons release, X.Y.Z, is now available on the SCons download page:
1010

1111
https://scons.org/pages/download.html
1212

13+
Here is a summary of the changes since 4.9.1:
1314

14-
Here is a summary of the changes since 4.9.0:
1515

1616
NEW FUNCTIONALITY
1717
-----------------
@@ -66,4 +66,4 @@ Thanks to the following contributors listed below for their contributions to thi
6666
==========================================================================================
6767
.. code-block:: text
6868

69-
git shortlog --no-merges -ns 4.0.1..HEAD
69+
git shortlog --no-merges -ns 4.9.1..HEAD

test/CC/CCFLAGS.py test/CC/CCFLAGS-live.py

+32-29
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@
2323
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2424
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525

26+
"""
27+
Test behavior of CCFLAGS.
28+
29+
This is a live test, uses the detected C compiler.
30+
"""
31+
2632
import sys
33+
2734
import TestSCons
2835

29-
_obj = TestSCons._obj
36+
test = TestSCons.TestSCons()
3037

3138
if sys.platform == 'win32':
3239
import SCons.Tool.MSCommon as msc
@@ -41,19 +48,17 @@
4148
fooflags = '-DFOO'
4249
barflags = '-DBAR'
4350

44-
test = TestSCons.TestSCons()
45-
46-
test.write('SConstruct', """
51+
test.write('SConstruct', f"""\
4752
DefaultEnvironment(tools=[])
48-
foo = Environment(CCFLAGS = '%s')
49-
bar = Environment(CCFLAGS = '%s')
50-
foo.Object(target = 'foo%s', source = 'prog.c')
51-
bar.Object(target = 'bar%s', source = 'prog.c')
52-
foo.Program(target = 'foo', source = 'foo%s')
53-
bar.Program(target = 'bar', source = 'bar%s')
54-
foo.Program(target = 'prog', source = 'prog.c',
55-
CCFLAGS = '$CCFLAGS -DBAR $BAZ', BAZ = '-DBAZ')
56-
""" % (fooflags, barflags, _obj, _obj, _obj, _obj))
53+
foo = Environment(CCFLAGS='{fooflags}')
54+
bar = Environment(CCFLAGS='{barflags}')
55+
56+
foo_obj = foo.Object(target='foo', source='prog.c')
57+
bar_obj = bar.Object(target='bar', source='prog.c')
58+
foo.Program(target='foo', source=foo_obj)
59+
bar.Program(target='bar', source=bar_obj)
60+
foo.Program(target='prog', source='prog.c', CCFLAGS='$CCFLAGS -DBAR $BAZ', BAZ='-DBAZ')
61+
""")
5762

5863
test.write('prog.c', r"""
5964
#include <stdio.h>
@@ -76,30 +81,28 @@
7681
}
7782
""")
7883

79-
80-
test.run(arguments = '.')
81-
82-
test.run(program = test.workpath('foo'), stdout = "prog.c: FOO\n")
83-
test.run(program = test.workpath('bar'), stdout = "prog.c: BAR\n")
84-
test.run(program = test.workpath('prog'), stdout = """\
84+
test.run(arguments='.')
85+
test.run(program=test.workpath('foo'), stdout="prog.c: FOO\n")
86+
test.run(program=test.workpath('bar'), stdout="prog.c: BAR\n")
87+
test.run(program=test.workpath('prog'), stdout="""\
8588
prog.c: FOO
8689
prog.c: BAR
8790
prog.c: BAZ
8891
""")
8992

90-
test.write('SConstruct', """
93+
test.write('SConstruct', f"""\
9194
DefaultEnvironment(tools=[])
92-
bar = Environment(CCFLAGS = '%s')
93-
bar.Object(target = 'foo%s', source = 'prog.c')
94-
bar.Object(target = 'bar%s', source = 'prog.c')
95-
bar.Program(target = 'foo', source = 'foo%s')
96-
bar.Program(target = 'bar', source = 'bar%s')
97-
""" % (barflags, _obj, _obj, _obj, _obj))
95+
bar = Environment(CCFLAGS='{barflags}')
9896
99-
test.run(arguments = '.')
97+
foo_obj = bar.Object(target='foo', source='prog.c')
98+
bar_obj = bar.Object(target='bar', source='prog.c')
99+
bar.Program(target='foo', source=foo_obj)
100+
bar.Program(target='bar', source=bar_obj)
101+
""")
100102

101-
test.run(program = test.workpath('foo'), stdout = "prog.c: BAR\n")
102-
test.run(program = test.workpath('bar'), stdout = "prog.c: BAR\n")
103+
test.run(arguments='.')
104+
test.run(program=test.workpath('foo'), stdout="prog.c: BAR\n")
105+
test.run(program=test.workpath('bar'), stdout="prog.c: BAR\n")
103106

104107
test.pass_test()
105108

test/CC/CFLAGS.py test/CC/CFLAGS-live.py

+34-31
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@
2323
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2424
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525

26+
"""
27+
Test behavior of CFLAGS.
28+
29+
This is a live test, uses the detected C compiler.
30+
"""
31+
2632
import sys
33+
2734
import TestSCons
2835

2936
test = TestSCons.TestSCons()
3037

3138
# Make sure CFLAGS is not passed to CXX by just expanding CXXCOM
32-
test.write('SConstruct', """
39+
test.write('SConstruct', """\
3340
DefaultEnvironment(tools=[])
3441
env = Environment(CFLAGS='-xyz', CCFLAGS='-abc')
3542
print(env.subst('$CXXCOM'))
@@ -41,8 +48,6 @@
4148
test.must_not_contain_any_line(test.stdout(), ["-xyz"])
4249
test.must_contain_all_lines(test.stdout(), ["-abc"])
4350

44-
_obj = TestSCons._obj
45-
4651
# Test passing CFLAGS to C compiler by actually compiling programs
4752
if sys.platform == 'win32':
4853
import SCons.Tool.MSCommon as msc
@@ -57,17 +62,17 @@
5762
fooflags = '-DFOO'
5863
barflags = '-DBAR'
5964

60-
61-
test.write('SConstruct', """
62-
foo = Environment(CFLAGS = '%s')
63-
bar = Environment(CFLAGS = '%s')
64-
foo.Object(target = 'foo%s', source = 'prog.c')
65-
bar.Object(target = 'bar%s', source = 'prog.c')
66-
foo.Program(target = 'foo', source = 'foo%s')
67-
bar.Program(target = 'bar', source = 'bar%s')
68-
foo.Program(target = 'prog', source = 'prog.c',
69-
CFLAGS = '$CFLAGS -DBAR $BAZ', BAZ = '-DBAZ')
70-
""" % (fooflags, barflags, _obj, _obj, _obj, _obj))
65+
test.write('SConstruct', f"""\
66+
DefaultEnvironment(tools=[])
67+
foo = Environment(CFLAGS="{fooflags}")
68+
bar = Environment(CFLAGS="{barflags}")
69+
70+
foo_obj = foo.Object(target='foo', source='prog.c')
71+
bar_obj = bar.Object(target='bar', source='prog.c')
72+
foo.Program(target='foo', source=foo_obj)
73+
bar.Program(target='bar', source=bar_obj)
74+
foo.Program(target='prog', source='prog.c', CFLAGS='$CFLAGS -DBAR $BAZ', BAZ='-DBAZ')
75+
""")
7176

7277
test.write('prog.c', r"""
7378
#include <stdio.h>
@@ -90,30 +95,28 @@
9095
}
9196
""")
9297

93-
94-
95-
test.run(arguments = '.')
96-
97-
test.run(program = test.workpath('foo'), stdout = "prog.c: FOO\n")
98-
test.run(program = test.workpath('bar'), stdout = "prog.c: BAR\n")
99-
test.run(program = test.workpath('prog'), stdout = """\
98+
test.run(arguments='.')
99+
test.run(program=test.workpath('foo'), stdout="prog.c: FOO\n")
100+
test.run(program=test.workpath('bar'), stdout="prog.c: BAR\n")
101+
test.run(program=test.workpath('prog'), stdout="""\
100102
prog.c: FOO
101103
prog.c: BAR
102104
prog.c: BAZ
103105
""")
104106

105-
test.write('SConstruct', """
106-
bar = Environment(CFLAGS = '%s')
107-
bar.Object(target = 'foo%s', source = 'prog.c')
108-
bar.Object(target = 'bar%s', source = 'prog.c')
109-
bar.Program(target = 'foo', source = 'foo%s')
110-
bar.Program(target = 'bar', source = 'bar%s')
111-
""" % (barflags, _obj, _obj, _obj, _obj))
107+
test.write('SConstruct', f"""\
108+
DefaultEnvironment(tools=[])
109+
bar = Environment(CFLAGS='{barflags}')
112110
113-
test.run(arguments = '.')
111+
foo_obj = bar.Object(target='foo', source='prog.c')
112+
bar_obj = bar.Object(target='bar', source='prog.c')
113+
bar.Program(target='foo', source=foo_obj)
114+
bar.Program(target='bar', source=bar_obj)
115+
""")
114116

115-
test.run(program = test.workpath('foo'), stdout = "prog.c: BAR\n")
116-
test.run(program = test.workpath('bar'), stdout = "prog.c: BAR\n")
117+
test.run(arguments='.')
118+
test.run(program=test.workpath('foo'), stdout="prog.c: BAR\n")
119+
test.run(program=test.workpath('bar'), stdout="prog.c: BAR\n")
117120

118121
test.pass_test()
119122

test/CC/SHCCFLAGS.py test/CC/SHCCFLAGS-live.py

+32-26
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@
2323
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2424
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525

26+
"""
27+
Verify that $SHCCFLAGS settings are used to build shared object files.
28+
29+
This is a live test, uses the detected C compiler.
30+
"""
31+
32+
import os
2633
import sys
34+
2735
import TestSCons
28-
import os
29-
36+
3037
test = TestSCons.TestSCons()
3138

3239
e = test.Environment()
@@ -38,16 +45,16 @@
3845
if sys.platform.find('irix') > -1:
3946
os.environ['LD_LIBRARYN32_PATH'] = '.'
4047

41-
test.write('SConstruct', """
48+
test.write('SConstruct', f"""\
4249
DefaultEnvironment(tools=[])
43-
foo = Environment(SHCCFLAGS = '%s', WINDOWS_INSERT_DEF=1)
44-
bar = Environment(SHCCFLAGS = '%s', WINDOWS_INSERT_DEF=1)
50+
foo = Environment(SHCCFLAGS='{fooflags}', WINDOWS_INSERT_DEF=1)
51+
bar = Environment(SHCCFLAGS='{barflags}', WINDOWS_INSERT_DEF=1)
4552
46-
foo_obj = foo.SharedObject(target = 'foo', source = 'prog.c')
47-
foo.SharedLibrary(target = 'foo', source = foo_obj)
53+
foo_obj = foo.SharedObject(target='foo', source='prog.c')
54+
foo.SharedLibrary(target='foo', source=foo_obj)
4855
49-
bar_obj = bar.SharedObject(target = 'bar', source = 'prog.c')
50-
bar.SharedLibrary(target = 'bar', source = bar_obj)
56+
bar_obj = bar.SharedObject(target='bar', source='prog.c')
57+
bar.SharedLibrary(target='bar', source=bar_obj)
5158
5259
fooMain = foo.Clone(LIBS='foo', LIBPATH='.')
5360
foomain_obj = fooMain.Object(target='foomain', source='main.c')
@@ -56,7 +63,7 @@
5663
barMain = bar.Clone(LIBS='bar', LIBPATH='.')
5764
barmain_obj = barMain.Object(target='barmain', source='main.c')
5865
barMain.Program(target='barprog', source=barmain_obj)
59-
""" % (fooflags, barflags))
66+
""")
6067

6168
test.write('foo.def', r"""
6269
LIBRARY "foo"
@@ -89,7 +96,7 @@
8996
}
9097
""")
9198

92-
test.write('main.c', r"""
99+
test.write('main.c', """\
93100
94101
void doIt();
95102
@@ -101,31 +108,30 @@
101108
}
102109
""")
103110

104-
test.run(arguments = '.')
105-
106-
test.run(program = test.workpath('fooprog'), stdout = "prog.c: FOO\n")
107-
test.run(program = test.workpath('barprog'), stdout = "prog.c: BAR\n")
111+
test.run(arguments='.')
112+
test.run(program=test.workpath('fooprog'), stdout="prog.c: FOO\n")
113+
test.run(program=test.workpath('barprog'), stdout="prog.c: BAR\n")
108114

109-
test.write('SConstruct', """
110-
bar = Environment(SHCCFLAGS = '%s', WINDOWS_INSERT_DEF=1)
115+
test.write('SConstruct', f"""\
116+
DefaultEnvironment(tools=[])
117+
bar = Environment(SHCCFLAGS='{barflags}', WINDOWS_INSERT_DEF=1)
111118
112-
foo_obj = bar.SharedObject(target = 'foo', source = 'prog.c')
113-
bar.SharedLibrary(target = 'foo', source = foo_obj)
119+
foo_obj = bar.SharedObject(target='foo', source='prog.c')
120+
bar.SharedLibrary(target='foo', source=foo_obj)
114121
115-
bar_obj = bar.SharedObject(target = 'bar', source = 'prog.c')
116-
bar.SharedLibrary(target = 'bar', source = bar_obj)
122+
bar_obj = bar.SharedObject(target='bar', source='prog.c')
123+
bar.SharedLibrary(target='bar', source=bar_obj)
117124
118125
barMain = bar.Clone(LIBS='bar', LIBPATH='.')
119126
foomain_obj = barMain.Object(target='foomain', source='main.c')
120127
barmain_obj = barMain.Object(target='barmain', source='main.c')
121128
barMain.Program(target='barprog', source=foomain_obj)
122129
barMain.Program(target='fooprog', source=barmain_obj)
123-
""" % barflags)
124-
125-
test.run(arguments = '.')
130+
""")
126131

127-
test.run(program = test.workpath('fooprog'), stdout = "prog.c: BAR\n")
128-
test.run(program = test.workpath('barprog'), stdout = "prog.c: BAR\n")
132+
test.run(arguments='.')
133+
test.run(program=test.workpath('fooprog'), stdout="prog.c: BAR\n")
134+
test.run(program=test.workpath('barprog'), stdout="prog.c: BAR\n")
129135

130136
test.pass_test()
131137

0 commit comments

Comments
 (0)