From f1bd5c6881fa739240d8ae8bd7a0d242b5c9500d Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 14 Jun 2020 15:47:55 -0700 Subject: Fix fake mylink.py was broken on win32. --- test/fixture/mylink.py | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index fe4af58..6c56427 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -1,15 +1,40 @@ import getopt import sys -opts, args = getopt.getopt(sys.argv[1:], 'o:s:') -for opt, arg in opts: - if opt == '-o': - out = arg - -with open(out, 'w') as ofp: - for f in args: - with open(f, 'r') as ifp: - for line in ifp.readlines(): - if line[:5] != '#link': - ofp.write(line) -sys.exit(0) +def fake_link(): + opts, args = getopt.getopt(sys.argv[1:], 'o:s:') + for opt, arg in opts: + if opt == '-o': + out = arg + + with open(out, 'w') as ofp: + for f in args: + with open(f, 'r') as ifp: + for line in ifp.readlines(): + if line[:5] != '#link': + ofp.write(line) + sys.exit(0) + +def fake_win32_link(): + args = sys.argv[1:] + while args: + a = args[0] + if a == '-o': + out = args[1] + args = args[2:] + continue + if not a[0] in '/-': + break + args = args[1:] + if a[:5].lower() == '/out:': out = a[5:] + with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: + for l in ifp.readlines(): + if not l.startswith(b'#link'): + ofp.write(l) + sys.exit(0) + +if __name__ == '__main__': + if sys.platform == 'win32': + fake_win32_link() + else: + fake_link() -- cgit v0.12 From 87526d678662e2ce64047a370e514efe33a922e9 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 14 Jun 2020 17:00:51 -0700 Subject: [appveyor skip][travis skip] fix sider warning --- test/fixture/mylink.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index 6c56427..0fa47a9 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -28,9 +28,9 @@ def fake_win32_link(): args = args[1:] if a[:5].lower() == '/out:': out = a[5:] with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: - for l in ifp.readlines(): - if not l.startswith(b'#link'): - ofp.write(l) + for line in ifp.readlines(): + if not line.startswith(b'#link'): + ofp.write(line) sys.exit(0) if __name__ == '__main__': -- cgit v0.12 From 5bdc4682ed0972f8fb9d3c7bc50ce8e0004faef2 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 14 Jun 2020 17:03:57 -0700 Subject: [appveyor skip][travis skip] fix sider warning --- test/fixture/mylink.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index 0fa47a9..19969f0 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -1,3 +1,6 @@ +""" +Dummy linker for use by tests" +""" import getopt import sys -- cgit v0.12 From 09925e59074a78b7b30af0be973e9abae11d2cde Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 15 Jun 2020 10:33:54 -0700 Subject: Fix test for compilation_db to work on windows and linux --- test/CompilationDatabase/basic.py | 25 +++++++++++++++---------- test/CompilationDatabase/fixture/SConstruct | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/test/CompilationDatabase/basic.py b/test/CompilationDatabase/basic.py index 21c883b..2f76752 100644 --- a/test/CompilationDatabase/basic.py +++ b/test/CompilationDatabase/basic.py @@ -27,15 +27,13 @@ and values of COMPILATIONDB_USE_ABSPATH """ import sys +import os +import os.path import TestSCons test = TestSCons.TestSCons() -if sys.platform == 'win32': - test.file_fixture('mylink_win32.py', 'mylink.py') -else: - test.file_fixture('mylink.py') - +test.file_fixture('mylink.py') test.file_fixture('mygcc.py') test.verbose_set(1) @@ -67,23 +65,30 @@ example_rel_file = """[ } ]""" % (sys.executable, test.workdir) +if sys.platform == 'win32': + example_rel_file = example_rel_file.replace('\\', '\\\\') + for f in rel_files: # print("Checking:%s" % f) test.must_exist(f) - test.must_match(f, example_rel_file) + test.must_match(f, example_rel_file, mode='r') example_abs_file = """[ { "command": "%s mygcc.py cc -o test_main.o -c test_main.c", "directory": "%s", - "file": "%s/test_main.c", - "output": "%s/test_main.o" + "file": "%s", + "output": "%s" } -]""" % (sys.executable, test.workdir, test.workdir, test.workdir) +]""" % (sys.executable, test.workdir, os.path.join(test.workdir, 'test_main.c'), os.path.join(test.workdir, 'test_main.o')) + +if sys.platform == 'win32': + example_abs_file = example_abs_file.replace('\\', '\\\\') + for f in abs_files: test.must_exist(f) - test.must_match(f, example_abs_file) + test.must_match(f, example_abs_file, mode='r') test.pass_test() diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct index 4043b5a..ea23bc3 100644 --- a/test/CompilationDatabase/fixture/SConstruct +++ b/test/CompilationDatabase/fixture/SConstruct @@ -7,6 +7,7 @@ env = Environment( LINKFLAGS=[], CC='$PYTHON mygcc.py cc', CXX='$PYTHON mygcc.py c++', + tools=['gcc','g++','gnulink'], ) env.Tool('compilation_db') -- cgit v0.12 From 8969b8496af2fbde0fc2bb63ce3db71edd8d7475 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 15 Jun 2020 10:51:55 -0700 Subject: Wrap SCons.Action._subproc() call with 'with' to prevent leaking popen object --- SCons/Tool/gcc.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/SCons/Tool/gcc.py b/SCons/Tool/gcc.py index 79b64f0..b530db2 100644 --- a/SCons/Tool/gcc.py +++ b/SCons/Tool/gcc.py @@ -77,22 +77,23 @@ def detect_version(env, cc): # GCC versions older than that, we should use --version and a # regular expression. # pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'], - pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], + with SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], stdin='devnull', stderr='devnull', - stdout=subprocess.PIPE) - if pipe.wait() != 0: - return version + stdout=subprocess.PIPE) as pipe: + if pipe.wait() != 0: + return version + + with pipe.stdout: + # -dumpversion variant: + # line = pipe.stdout.read().strip() + # --version variant: + line = SCons.Util.to_str(pipe.stdout.readline()) + # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: + # So continue with reading to let the child process actually terminate. + while SCons.Util.to_str(pipe.stdout.readline()): + pass - with pipe.stdout: - # -dumpversion variant: - # line = pipe.stdout.read().strip() - # --version variant: - line = SCons.Util.to_str(pipe.stdout.readline()) - # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: - # So continue with reading to let the child process actually terminate. - while SCons.Util.to_str(pipe.stdout.readline()): - pass # -dumpversion variant: # if line: -- cgit v0.12 From 0944be440ce687d828ff7838d5925c54ded2a48a Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 15 Jun 2020 12:10:36 -0700 Subject: remove context manager from Pipe() broke tests --- SCons/Tool/gcc.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/SCons/Tool/gcc.py b/SCons/Tool/gcc.py index b530db2..d56f6a0 100644 --- a/SCons/Tool/gcc.py +++ b/SCons/Tool/gcc.py @@ -77,22 +77,22 @@ def detect_version(env, cc): # GCC versions older than that, we should use --version and a # regular expression. # pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'], - with SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], + pipe=SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], stdin='devnull', stderr='devnull', - stdout=subprocess.PIPE) as pipe: - if pipe.wait() != 0: - return version - - with pipe.stdout: - # -dumpversion variant: - # line = pipe.stdout.read().strip() - # --version variant: - line = SCons.Util.to_str(pipe.stdout.readline()) - # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: - # So continue with reading to let the child process actually terminate. - while SCons.Util.to_str(pipe.stdout.readline()): - pass + stdout=subprocess.PIPE) + if pipe.wait() != 0: + return version + + with pipe.stdout: + # -dumpversion variant: + # line = pipe.stdout.read().strip() + # --version variant: + line = SCons.Util.to_str(pipe.stdout.readline()) + # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: + # So continue with reading to let the child process actually terminate. + while SCons.Util.to_str(pipe.stdout.readline()): + pass # -dumpversion variant: -- cgit v0.12