From d6ecc399de10455c765c47c7f1d008fae55a29eb Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Jul 2020 16:02:20 -0700 Subject: move tempfilemung tests to their own directory --- test/TEMPFILEPREFIX.py | 124 ----------------------------------- test/TEMPFILESUFFIX.py | 124 ----------------------------------- test/TempFileMunge/TEMPFILEPREFIX.py | 124 +++++++++++++++++++++++++++++++++++ test/TempFileMunge/TEMPFILESUFFIX.py | 124 +++++++++++++++++++++++++++++++++++ 4 files changed, 248 insertions(+), 248 deletions(-) delete mode 100644 test/TEMPFILEPREFIX.py delete mode 100644 test/TEMPFILESUFFIX.py create mode 100644 test/TempFileMunge/TEMPFILEPREFIX.py create mode 100644 test/TempFileMunge/TEMPFILESUFFIX.py diff --git a/test/TEMPFILEPREFIX.py b/test/TEMPFILEPREFIX.py deleted file mode 100644 index 4ccfd7d09..000000000 --- a/test/TEMPFILEPREFIX.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -""" -Verify that setting the $TEMPFILEPREFIX variable will cause -it to appear at the front of name of the generated tempfile -used for long command lines. -""" - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import os -import stat - -import TestSCons - -test = TestSCons.TestSCons(match = TestSCons.match_re) - -test.write('echo.py', """\ -import sys -print(sys.argv) -""") - -echo_py = test.workpath('echo.py') - -st = os.stat(echo_py) -os.chmod(echo_py, st[stat.ST_MODE]|0o111) - -test.write('SConstruct', """ -import os -env = Environment( - BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', - MAXLINELENGTH = 16, - TEMPFILEPREFIX = '-via', -) -env.AppendENVPath('PATH', os.curdir) -env.Command('foo.out', 'foo.in', '$BUILDCOM') -""") - -test.write('foo.in', "foo.in\n") - -test.run(arguments = '-n -Q .', - stdout = """\ -Using tempfile \\S+ for command line: -xxx.py foo.out foo.in -xxx.py -via\\S+ -""") - -test.write('SConstruct', """ -import os - -def print_cmd_line(s, targets, sources, env): - pass - -env = Environment( - BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', - MAXLINELENGTH = 16, - TEMPFILEPREFIX = '-via', - PRINT_CMD_LINE_FUNC=print_cmd_line -) -env.AppendENVPath('PATH', os.curdir) -env.Command('foo.out', 'foo.in', '$BUILDCOM') -""") - -test.run(arguments = '-n -Q .', - stdout = """""") - -test.write('SConstruct', """ -import os -from SCons.Platform import TempFileMunge - -class TestTempFileMunge(TempFileMunge): - - def __init__(self, cmd, cmdstr = None): - super(TestTempFileMunge, self).__init__(cmd, cmdstr) - - def _print_cmd_str(self, target, source, env, cmdstr): - super(TestTempFileMunge, self)._print_cmd_str(target, source, None, cmdstr) - -env = Environment( - TEMPFILE = TestTempFileMunge, - BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', - MAXLINELENGTH = 16, - TEMPFILEPREFIX = '-via', - -) -env.AppendENVPath('PATH', os.curdir) -env.Command('foo.out', 'foo.in', '$BUILDCOM') -""") - -test.run(arguments = '-n -Q .', - stdout = """\ -Using tempfile \\S+ for command line: -xxx.py foo.out foo.in -xxx.py -via\\S+ -""") - -test.pass_test() - -# Local Variables: -# tab-width:4 -# indent-tabs-mode:nil -# End: -# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/TEMPFILESUFFIX.py b/test/TEMPFILESUFFIX.py deleted file mode 100644 index df546ac5e..000000000 --- a/test/TEMPFILESUFFIX.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -# __COPYRIGHT__ -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY -# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -""" -Verify that setting the $TEMPFILESUFFIX variable will cause -it to appear at the end of name of the generated tempfile -used for long command lines. -""" - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -import os -import stat - -import TestSCons - -test = TestSCons.TestSCons(match=TestSCons.match_re) - -test.write('echo.py', """\ -import sys -print(sys.argv) -""") - -echo_py = test.workpath('echo.py') - -st = os.stat(echo_py) -os.chmod(echo_py, st[stat.ST_MODE] | 0o111) - -test.write('SConstruct', """ -import os -env = Environment( - BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', - MAXLINELENGTH = 16, - TEMPFILESUFFIX = '.foo', -) -env.AppendENVPath('PATH', os.curdir) -env.Command('foo.out', 'foo.in', '$BUILDCOM') -""") - -test.write('foo.in', "foo.in\n") - -test.run(arguments = '-n -Q .', - stdout = """\ -Using tempfile \\S+ for command line: -xxx.py foo.out foo.in -xxx.py \\S+ -""") - -test.write('SConstruct', """ -import os - -def print_cmd_line(s, targets, sources, env): - pass - -env = Environment( - BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', - MAXLINELENGTH = 16, - TEMPFILESUFFIX = '.foo', - PRINT_CMD_LINE_FUNC=print_cmd_line -) -env.AppendENVPath('PATH', os.curdir) -env.Command('foo.out', 'foo.in', '$BUILDCOM') -""") - -test.run(arguments = '-n -Q .', - stdout = """""") - -test.write('SConstruct', """ -import os -from SCons.Platform import TempFileMunge - -class TestTempFileMunge(TempFileMunge): - - def __init__(self, cmd, cmdstr = None): - super(TestTempFileMunge, self).__init__(cmd, cmdstr) - - def _print_cmd_str(self, target, source, env, cmdstr): - super(TestTempFileMunge, self)._print_cmd_str(target, source, None, cmdstr) - -env = Environment( - TEMPFILE = TestTempFileMunge, - BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', - MAXLINELENGTH = 16, - TEMPFILESUFFIX = '.foo', - -) -env.AppendENVPath('PATH', os.curdir) -env.Command('foo.out', 'foo.in', '$BUILDCOM') -""") - -test.run(arguments = '-n -Q .', - stdout = """\ -Using tempfile \\S+ for command line: -xxx.py foo.out foo.in -xxx.py \\S+ -""") - -test.pass_test() - -# Local Variables: -# tab-width:4 -# indent-tabs-mode:nil -# End: -# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/TempFileMunge/TEMPFILEPREFIX.py b/test/TempFileMunge/TEMPFILEPREFIX.py new file mode 100644 index 000000000..4ccfd7d09 --- /dev/null +++ b/test/TempFileMunge/TEMPFILEPREFIX.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +Verify that setting the $TEMPFILEPREFIX variable will cause +it to appear at the front of name of the generated tempfile +used for long command lines. +""" + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import stat + +import TestSCons + +test = TestSCons.TestSCons(match = TestSCons.match_re) + +test.write('echo.py', """\ +import sys +print(sys.argv) +""") + +echo_py = test.workpath('echo.py') + +st = os.stat(echo_py) +os.chmod(echo_py, st[stat.ST_MODE]|0o111) + +test.write('SConstruct', """ +import os +env = Environment( + BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH = 16, + TEMPFILEPREFIX = '-via', +) +env.AppendENVPath('PATH', os.curdir) +env.Command('foo.out', 'foo.in', '$BUILDCOM') +""") + +test.write('foo.in', "foo.in\n") + +test.run(arguments = '-n -Q .', + stdout = """\ +Using tempfile \\S+ for command line: +xxx.py foo.out foo.in +xxx.py -via\\S+ +""") + +test.write('SConstruct', """ +import os + +def print_cmd_line(s, targets, sources, env): + pass + +env = Environment( + BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH = 16, + TEMPFILEPREFIX = '-via', + PRINT_CMD_LINE_FUNC=print_cmd_line +) +env.AppendENVPath('PATH', os.curdir) +env.Command('foo.out', 'foo.in', '$BUILDCOM') +""") + +test.run(arguments = '-n -Q .', + stdout = """""") + +test.write('SConstruct', """ +import os +from SCons.Platform import TempFileMunge + +class TestTempFileMunge(TempFileMunge): + + def __init__(self, cmd, cmdstr = None): + super(TestTempFileMunge, self).__init__(cmd, cmdstr) + + def _print_cmd_str(self, target, source, env, cmdstr): + super(TestTempFileMunge, self)._print_cmd_str(target, source, None, cmdstr) + +env = Environment( + TEMPFILE = TestTempFileMunge, + BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH = 16, + TEMPFILEPREFIX = '-via', + +) +env.AppendENVPath('PATH', os.curdir) +env.Command('foo.out', 'foo.in', '$BUILDCOM') +""") + +test.run(arguments = '-n -Q .', + stdout = """\ +Using tempfile \\S+ for command line: +xxx.py foo.out foo.in +xxx.py -via\\S+ +""") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/TempFileMunge/TEMPFILESUFFIX.py b/test/TempFileMunge/TEMPFILESUFFIX.py new file mode 100644 index 000000000..df546ac5e --- /dev/null +++ b/test/TempFileMunge/TEMPFILESUFFIX.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +Verify that setting the $TEMPFILESUFFIX variable will cause +it to appear at the end of name of the generated tempfile +used for long command lines. +""" + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import stat + +import TestSCons + +test = TestSCons.TestSCons(match=TestSCons.match_re) + +test.write('echo.py', """\ +import sys +print(sys.argv) +""") + +echo_py = test.workpath('echo.py') + +st = os.stat(echo_py) +os.chmod(echo_py, st[stat.ST_MODE] | 0o111) + +test.write('SConstruct', """ +import os +env = Environment( + BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH = 16, + TEMPFILESUFFIX = '.foo', +) +env.AppendENVPath('PATH', os.curdir) +env.Command('foo.out', 'foo.in', '$BUILDCOM') +""") + +test.write('foo.in', "foo.in\n") + +test.run(arguments = '-n -Q .', + stdout = """\ +Using tempfile \\S+ for command line: +xxx.py foo.out foo.in +xxx.py \\S+ +""") + +test.write('SConstruct', """ +import os + +def print_cmd_line(s, targets, sources, env): + pass + +env = Environment( + BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH = 16, + TEMPFILESUFFIX = '.foo', + PRINT_CMD_LINE_FUNC=print_cmd_line +) +env.AppendENVPath('PATH', os.curdir) +env.Command('foo.out', 'foo.in', '$BUILDCOM') +""") + +test.run(arguments = '-n -Q .', + stdout = """""") + +test.write('SConstruct', """ +import os +from SCons.Platform import TempFileMunge + +class TestTempFileMunge(TempFileMunge): + + def __init__(self, cmd, cmdstr = None): + super(TestTempFileMunge, self).__init__(cmd, cmdstr) + + def _print_cmd_str(self, target, source, env, cmdstr): + super(TestTempFileMunge, self)._print_cmd_str(target, source, None, cmdstr) + +env = Environment( + TEMPFILE = TestTempFileMunge, + BUILDCOM = '${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH = 16, + TEMPFILESUFFIX = '.foo', + +) +env.AppendENVPath('PATH', os.curdir) +env.Command('foo.out', 'foo.in', '$BUILDCOM') +""") + +test.run(arguments = '-n -Q .', + stdout = """\ +Using tempfile \\S+ for command line: +xxx.py foo.out foo.in +xxx.py \\S+ +""") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: -- cgit v1.2.1 From 6b15020834c8a1a64ee31ebb1f36132d1bb0177b Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Jul 2020 16:07:53 -0700 Subject: remove unneeded __REVISION__ and __copyright__ --- test/TempFileMunge/TEMPFILEPREFIX.py | 4 ---- test/TempFileMunge/TEMPFILESUFFIX.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/test/TempFileMunge/TEMPFILEPREFIX.py b/test/TempFileMunge/TEMPFILEPREFIX.py index 4ccfd7d09..9e2f752d6 100644 --- a/test/TempFileMunge/TEMPFILEPREFIX.py +++ b/test/TempFileMunge/TEMPFILEPREFIX.py @@ -1,7 +1,5 @@ #!/usr/bin/env python # -# __COPYRIGHT__ -# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -27,8 +25,6 @@ it to appear at the front of name of the generated tempfile used for long command lines. """ -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - import os import stat diff --git a/test/TempFileMunge/TEMPFILESUFFIX.py b/test/TempFileMunge/TEMPFILESUFFIX.py index df546ac5e..151338c9c 100644 --- a/test/TempFileMunge/TEMPFILESUFFIX.py +++ b/test/TempFileMunge/TEMPFILESUFFIX.py @@ -1,7 +1,5 @@ #!/usr/bin/env python # -# __COPYRIGHT__ -# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -27,8 +25,6 @@ it to appear at the end of name of the generated tempfile used for long command lines. """ -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - import os import stat -- cgit v1.2.1 From 3c23953ee555ab9552a2a22cd16e25f0f5dfc408 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 10 Jul 2020 18:29:27 -0700 Subject: Added TEMPFILEDIR to allow configuring where TEMPFILEMUNGE create's it's temporary files --- CHANGES.txt | 12 +++-- SCons/Platform/__init__.py | 8 +++- SCons/Platform/__init__.xml | 8 +++- test/TempFileMunge/TEMPFILEDIR.py | 56 +++++++++++++++++++++++ test/TempFileMunge/TEMPFILEPREFIX.py | 10 ---- test/TempFileMunge/TEMPFILESUFFIX.py | 10 ---- test/TempFileMunge/fixture/SConstruct.tempfiledir | 11 +++++ test/fixture/echo.py | 2 + 8 files changed, 90 insertions(+), 27 deletions(-) create mode 100644 test/TempFileMunge/TEMPFILEDIR.py create mode 100644 test/TempFileMunge/fixture/SConstruct.tempfiledir create mode 100755 test/fixture/echo.py diff --git a/CHANGES.txt b/CHANGES.txt index 9277f74a0..354fccd9e 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,15 +8,17 @@ NOTE: The 4.0.0 Release of SCons will drops Python 2.7 Support RELEASE 4.1.0.devyyyymmdd - Mon, 04 Jul 2020 16:06:40 -0700 - From John Doe: - - - Whatever John Doe did. - From Rob Boehne: - Fix subprocess execution of 'lslpp' on AIX to produce text standard i/o. - Re-do the fix for suncxx tool (Oracle Studio compiler) now that only Python 3 is supported, to avoid decoding errors. - + + From William Deegan: + - Added Environment() variable TEMPFILEDIR which allows setting the directory which temp + files createdby TEMPFILEMUNGE are created in. + + + RELEASE 4.0.0 - Sat, 04 Jul 2020 12:00:27 +0000 From Dirk Baechle: diff --git a/SCons/Platform/__init__.py b/SCons/Platform/__init__.py index 4c912d430..5d3541b39 100644 --- a/SCons/Platform/__init__.py +++ b/SCons/Platform/__init__.py @@ -205,7 +205,13 @@ class TempFileMunge: else: suffix = '.lnk' - fd, tmp = tempfile.mkstemp(suffix, text=True) + if 'TEMPFILEDIR' in env: + tempfile_dir = env.subst('$TEMPFILEDIR') + os.makedirs(tempfile_dir, exist_ok=True) + else: + tempfile_dir = None + + fd, tmp = tempfile.mkstemp(suffix, dir=tempfile_dir, text=True) native_tmp = SCons.Util.get_native_path(tmp) if env.get('SHELL', None) == 'sh': diff --git a/SCons/Platform/__init__.xml b/SCons/Platform/__init__.xml index e877b1e0f..6582590d1 100644 --- a/SCons/Platform/__init__.xml +++ b/SCons/Platform/__init__.xml @@ -267,5 +267,11 @@ Note this value is used literally and not expanded by the subst logic. - + + + +The directory to create the tempfile in. + + + diff --git a/test/TempFileMunge/TEMPFILEDIR.py b/test/TempFileMunge/TEMPFILEDIR.py new file mode 100644 index 000000000..c1ed6f917 --- /dev/null +++ b/test/TempFileMunge/TEMPFILEDIR.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +Verify that setting the $TEMPFILEDIR variable will cause +the generated tempfile used for long command lines to be created in specified directory. +And if not specified in one of TMPDIR, TEMP or TMP (based on os' normal usage of such) +""" +import os.path +import TestSCons + +test = TestSCons.TestSCons(match=TestSCons.match_re) + +test.file_fixture('fixture/SConstruct.tempfiledir', 'SConstruct') + +test.write('foo.in', "foo.in\n") + +test.run(arguments='-n -Q .', + stdout="""\ +Using tempfile \\S+ for command line: +xxx.py foo.out foo.in +xxx.py \\S+ +""") + +try: + tempfile = test.stdout().splitlines()[0].split()[2] +except IndexError: + test.fail_test("Unexpected output couldn't find tempfile") + +dirname = os.path.basename(os.path.dirname(tempfile)) +test.fail_test('my_temp_files' != dirname, message="Temp file not created in \"my_temp_files\" directory") +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/TempFileMunge/TEMPFILEPREFIX.py b/test/TempFileMunge/TEMPFILEPREFIX.py index 9e2f752d6..ac2ae4660 100644 --- a/test/TempFileMunge/TEMPFILEPREFIX.py +++ b/test/TempFileMunge/TEMPFILEPREFIX.py @@ -32,16 +32,6 @@ import TestSCons test = TestSCons.TestSCons(match = TestSCons.match_re) -test.write('echo.py', """\ -import sys -print(sys.argv) -""") - -echo_py = test.workpath('echo.py') - -st = os.stat(echo_py) -os.chmod(echo_py, st[stat.ST_MODE]|0o111) - test.write('SConstruct', """ import os env = Environment( diff --git a/test/TempFileMunge/TEMPFILESUFFIX.py b/test/TempFileMunge/TEMPFILESUFFIX.py index 151338c9c..a19317db9 100644 --- a/test/TempFileMunge/TEMPFILESUFFIX.py +++ b/test/TempFileMunge/TEMPFILESUFFIX.py @@ -32,16 +32,6 @@ import TestSCons test = TestSCons.TestSCons(match=TestSCons.match_re) -test.write('echo.py', """\ -import sys -print(sys.argv) -""") - -echo_py = test.workpath('echo.py') - -st = os.stat(echo_py) -os.chmod(echo_py, st[stat.ST_MODE] | 0o111) - test.write('SConstruct', """ import os env = Environment( diff --git a/test/TempFileMunge/fixture/SConstruct.tempfiledir b/test/TempFileMunge/fixture/SConstruct.tempfiledir new file mode 100644 index 000000000..6b7300d64 --- /dev/null +++ b/test/TempFileMunge/fixture/SConstruct.tempfiledir @@ -0,0 +1,11 @@ +import os + +my_temp_dir = os.path.join(os.getcwd(), 'my_temp_files') + +env = Environment( + BUILDCOM='${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH=16, + TEMPFILEDIR=my_temp_dir, +) +env.AppendENVPath('PATH', os.curdir) +env.Command('foo.out', 'foo.in', '$BUILDCOM') diff --git a/test/fixture/echo.py b/test/fixture/echo.py new file mode 100755 index 000000000..a13f2cad2 --- /dev/null +++ b/test/fixture/echo.py @@ -0,0 +1,2 @@ +import sys +print(sys.argv) -- cgit v1.2.1 From af6b2afffaa25d0630807b16add9d614f6d85454 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 14 Jul 2020 12:17:49 -0700 Subject: Add test for defaulted TEMPFILEDIR behavior as well --- test/TempFileMunge/TEMPFILEDIR.py | 43 +++++++++++++++-------- test/TempFileMunge/fixture/SConstruct.tempfiledir | 6 ++++ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/test/TempFileMunge/TEMPFILEDIR.py b/test/TempFileMunge/TEMPFILEDIR.py index c1ed6f917..ced2fe935 100644 --- a/test/TempFileMunge/TEMPFILEDIR.py +++ b/test/TempFileMunge/TEMPFILEDIR.py @@ -24,29 +24,44 @@ Verify that setting the $TEMPFILEDIR variable will cause the generated tempfile used for long command lines to be created in specified directory. And if not specified in one of TMPDIR, TEMP or TMP (based on os' normal usage of such) """ -import os.path +from re import escape +import tempfile import TestSCons test = TestSCons.TestSCons(match=TestSCons.match_re) test.file_fixture('fixture/SConstruct.tempfiledir', 'SConstruct') -test.write('foo.in', "foo.in\n") - -test.run(arguments='-n -Q .', - stdout="""\ -Using tempfile \\S+ for command line: +expected_output = r"""Using tempfile __WORKDIR__/my_temp_files/\S+ for command line: xxx.py foo.out foo.in -xxx.py \\S+ -""") +xxx.py @__WORKDIR__/my_temp_files/\S+ +Using tempfile __TEMPDIR__/\S+ for command line: +xxx.py global_foo.out foo.in +xxx.py @__TEMPDIR__/\S+ +""" -try: - tempfile = test.stdout().splitlines()[0].split()[2] -except IndexError: - test.fail_test("Unexpected output couldn't find tempfile") +wd_escaped = escape(test.workdir) +td_escaped = escape(tempfile.gettempdir()) +expected_output =expected_output.replace("__WORKDIR__", wd_escaped) +expected_output = expected_output.replace("__TEMPDIR__", td_escaped) -dirname = os.path.basename(os.path.dirname(tempfile)) -test.fail_test('my_temp_files' != dirname, message="Temp file not created in \"my_temp_files\" directory") +test.write('foo.in', "foo.in\n") + +test.run(arguments='-n -Q .', + stdout=expected_output) +# """\ +# Using tempfile \\S+ for command line: +# xxx.py foo.out foo.in +# xxx.py \\S+ +# """) +# +# try: +# tempfile = test.stdout().splitlines()[0].split()[2] +# except IndexError: +# test.fail_test("Unexpected output couldn't find tempfile") +# +# dirname = os.path.basename(os.path.dirname(tempfile)) +# test.fail_test('my_temp_files' != dirname, message="Temp file not created in \"my_temp_files\" directory") test.pass_test() # Local Variables: diff --git a/test/TempFileMunge/fixture/SConstruct.tempfiledir b/test/TempFileMunge/fixture/SConstruct.tempfiledir index 6b7300d64..ea26c2762 100644 --- a/test/TempFileMunge/fixture/SConstruct.tempfiledir +++ b/test/TempFileMunge/fixture/SConstruct.tempfiledir @@ -9,3 +9,9 @@ env = Environment( ) env.AppendENVPath('PATH', os.curdir) env.Command('foo.out', 'foo.in', '$BUILDCOM') + +plain_env = Environment( + BUILDCOM='${TEMPFILE("xxx.py $TARGET $SOURCES")}', + MAXLINELENGTH=16, +) +plain_env.Command('global_foo.out', 'foo.in', '$BUILDCOM') -- cgit v1.2.1 From deb6e40f0ffa92140e0ac016407c9a53e1b7c1ea Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 14 Jul 2020 12:37:27 -0700 Subject: swap / to \ for win32 and regex escape that --- test/TempFileMunge/TEMPFILEDIR.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/TempFileMunge/TEMPFILEDIR.py b/test/TempFileMunge/TEMPFILEDIR.py index ced2fe935..b528be3b7 100644 --- a/test/TempFileMunge/TEMPFILEDIR.py +++ b/test/TempFileMunge/TEMPFILEDIR.py @@ -27,6 +27,7 @@ And if not specified in one of TMPDIR, TEMP or TMP (based on os' normal usage of from re import escape import tempfile import TestSCons +from TestCmd import IS_WINDOWS test = TestSCons.TestSCons(match=TestSCons.match_re) @@ -40,6 +41,8 @@ xxx.py global_foo.out foo.in xxx.py @__TEMPDIR__/\S+ """ +if IS_WINDOWS: + expected_output = expected_output.replace('/','\\\\') wd_escaped = escape(test.workdir) td_escaped = escape(tempfile.gettempdir()) expected_output =expected_output.replace("__WORKDIR__", wd_escaped) -- cgit v1.2.1