Skip to content

Commit bb795ab

Browse files
authored
Merge pull request #3698 from bdbaddog/fix_broken_fixture_mylink
Fix fake mylink.py was broken on win32.
2 parents 1b28380 + 0944be4 commit bb795ab

File tree

4 files changed

+58
-23
lines changed

4 files changed

+58
-23
lines changed

SCons/Tool/gcc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def detect_version(env, cc):
7777
# GCC versions older than that, we should use --version and a
7878
# regular expression.
7979
# pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'],
80-
pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'],
80+
pipe=SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'],
8181
stdin='devnull',
8282
stderr='devnull',
8383
stdout=subprocess.PIPE)
@@ -94,6 +94,7 @@ def detect_version(env, cc):
9494
while SCons.Util.to_str(pipe.stdout.readline()):
9595
pass
9696

97+
9798
# -dumpversion variant:
9899
# if line:
99100
# version = line

test/CompilationDatabase/basic.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727
"""
2828

2929
import sys
30+
import os
31+
import os.path
3032
import TestSCons
3133

3234
test = TestSCons.TestSCons()
3335

34-
if sys.platform == 'win32':
35-
test.file_fixture('mylink_win32.py', 'mylink.py')
36-
else:
37-
test.file_fixture('mylink.py')
38-
36+
test.file_fixture('mylink.py')
3937
test.file_fixture('mygcc.py')
4038

4139
test.verbose_set(1)
@@ -67,23 +65,30 @@
6765
}
6866
]""" % (sys.executable, test.workdir)
6967

68+
if sys.platform == 'win32':
69+
example_rel_file = example_rel_file.replace('\\', '\\\\')
70+
7071
for f in rel_files:
7172
# print("Checking:%s" % f)
7273
test.must_exist(f)
73-
test.must_match(f, example_rel_file)
74+
test.must_match(f, example_rel_file, mode='r')
7475

7576
example_abs_file = """[
7677
{
7778
"command": "%s mygcc.py cc -o test_main.o -c test_main.c",
7879
"directory": "%s",
79-
"file": "%s/test_main.c",
80-
"output": "%s/test_main.o"
80+
"file": "%s",
81+
"output": "%s"
8182
}
82-
]""" % (sys.executable, test.workdir, test.workdir, test.workdir)
83+
]""" % (sys.executable, test.workdir, os.path.join(test.workdir, 'test_main.c'), os.path.join(test.workdir, 'test_main.o'))
84+
85+
if sys.platform == 'win32':
86+
example_abs_file = example_abs_file.replace('\\', '\\\\')
87+
8388

8489
for f in abs_files:
8590
test.must_exist(f)
86-
test.must_match(f, example_abs_file)
91+
test.must_match(f, example_abs_file, mode='r')
8792

8893

8994
test.pass_test()

test/CompilationDatabase/fixture/SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env = Environment(
77
LINKFLAGS=[],
88
CC='$PYTHON mygcc.py cc',
99
CXX='$PYTHON mygcc.py c++',
10+
tools=['gcc','g++','gnulink'],
1011
)
1112
env.Tool('compilation_db')
1213

test/fixture/mylink.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
1+
"""
2+
Dummy linker for use by tests"
3+
"""
14
import getopt
25
import sys
36

4-
opts, args = getopt.getopt(sys.argv[1:], 'o:s:')
5-
for opt, arg in opts:
6-
if opt == '-o':
7-
out = arg
8-
9-
with open(out, 'w') as ofp:
10-
for f in args:
11-
with open(f, 'r') as ifp:
12-
for line in ifp.readlines():
13-
if line[:5] != '#link':
14-
ofp.write(line)
15-
sys.exit(0)
7+
def fake_link():
8+
opts, args = getopt.getopt(sys.argv[1:], 'o:s:')
9+
for opt, arg in opts:
10+
if opt == '-o':
11+
out = arg
12+
13+
with open(out, 'w') as ofp:
14+
for f in args:
15+
with open(f, 'r') as ifp:
16+
for line in ifp.readlines():
17+
if line[:5] != '#link':
18+
ofp.write(line)
19+
sys.exit(0)
20+
21+
def fake_win32_link():
22+
args = sys.argv[1:]
23+
while args:
24+
a = args[0]
25+
if a == '-o':
26+
out = args[1]
27+
args = args[2:]
28+
continue
29+
if not a[0] in '/-':
30+
break
31+
args = args[1:]
32+
if a[:5].lower() == '/out:': out = a[5:]
33+
with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
34+
for line in ifp.readlines():
35+
if not line.startswith(b'#link'):
36+
ofp.write(line)
37+
sys.exit(0)
38+
39+
if __name__ == '__main__':
40+
if sys.platform == 'win32':
41+
fake_win32_link()
42+
else:
43+
fake_link()

0 commit comments

Comments
 (0)