summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2020-07-14 13:36:34 -0700
committerGitHub <noreply@github.com>2020-07-14 13:36:34 -0700
commitc3efa33c412b7fdb2f836358d8d8c6a0954f4bc5 (patch)
tree9d1cf2c6bcfe76c6157d01cf642d2fc86b342ea1
parent2560cd7a5dab48f2e55d053b1532c415c9eb6ea7 (diff)
parentdeb6e40f0ffa92140e0ac016407c9a53e1b7c1ea (diff)
downloadscons-git-c3efa33c412b7fdb2f836358d8d8c6a0954f4bc5.tar.gz
Merge pull request #3741 from bdbaddog/add_configurable_dir_to_tempfilemunge
Add configurable dir to tempfilemunge vi TEMPFILEDIR
-rwxr-xr-xCHANGES.txt12
-rw-r--r--SCons/Platform/__init__.py8
-rw-r--r--SCons/Platform/__init__.xml8
-rw-r--r--test/TempFileMunge/TEMPFILEDIR.py74
-rw-r--r--test/TempFileMunge/TEMPFILEPREFIX.py (renamed from test/TEMPFILEPREFIX.py)14
-rw-r--r--test/TempFileMunge/TEMPFILESUFFIX.py (renamed from test/TEMPFILESUFFIX.py)14
-rw-r--r--test/TempFileMunge/fixture/SConstruct.tempfiledir17
-rwxr-xr-xtest/fixture/echo.py2
8 files changed, 114 insertions, 35 deletions
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.
</summary>
</cvar>
-
+<cvar name="TEMPFILEDIR">
+<summary>
+<para>
+The directory to create the tempfile in.
+</para>
+</summary>
+</cvar>
</sconsdoc>
diff --git a/test/TempFileMunge/TEMPFILEDIR.py b/test/TempFileMunge/TEMPFILEDIR.py
new file mode 100644
index 000000000..b528be3b7
--- /dev/null
+++ b/test/TempFileMunge/TEMPFILEDIR.py
@@ -0,0 +1,74 @@
+#!/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)
+"""
+from re import escape
+import tempfile
+import TestSCons
+from TestCmd import IS_WINDOWS
+
+test = TestSCons.TestSCons(match=TestSCons.match_re)
+
+test.file_fixture('fixture/SConstruct.tempfiledir', 'SConstruct')
+
+expected_output = r"""Using tempfile __WORKDIR__/my_temp_files/\S+ for command line:
+xxx.py foo.out foo.in
+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+
+"""
+
+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)
+expected_output = expected_output.replace("__TEMPDIR__", td_escaped)
+
+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:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/TEMPFILEPREFIX.py b/test/TempFileMunge/TEMPFILEPREFIX.py
index 4ccfd7d09..ac2ae4660 100644
--- a/test/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
@@ -36,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/TEMPFILESUFFIX.py b/test/TempFileMunge/TEMPFILESUFFIX.py
index df546ac5e..a19317db9 100644
--- a/test/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
@@ -36,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..ea26c2762
--- /dev/null
+++ b/test/TempFileMunge/fixture/SConstruct.tempfiledir
@@ -0,0 +1,17 @@
+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')
+
+plain_env = Environment(
+ BUILDCOM='${TEMPFILE("xxx.py $TARGET $SOURCES")}',
+ MAXLINELENGTH=16,
+)
+plain_env.Command('global_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)