Skip to content

Do not reuse tempfiles - #3140

Closed
simontegelid wants to merge 0 commit into
SCons:masterfrom
simontegelid:master
Closed

simontegelid wants to merge 0 commit into
SCons:masterfrom
simontegelid:master

Conversation

@simontegelid

@simontegelid simontegelid commented Jun 23, 2018 •

Copy link
Copy Markdown
Contributor

Actions lists where each action use TEMPFILE cannot use the same tempfiles. Therefore we cannot store the tempfile_cmdlist in neither the target nor the source attributes since those are common for all actions.

Reusing the same tempfile causes the same command to be invoked for all actions in the list. However, not reusing tempfiles will create unneeded tempfiles on strfunction invocation. This is better than producing incorrect results, but leaves the tempfile in a bad state.

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated master/src/CHANGES.txt directory (and read the README.txt in that directory)
  • I have updated the appropriate documentation

@bdbaddog

Copy link
Copy Markdown
Contributor

Did you mean ".. in either the target nor the source attributes since those are common for all actions."
and not "neither" ?

@bdbaddog

Copy link
Copy Markdown
Contributor

Can you provide an example SConstruct to demonstrate the problem?
Ideally discuss this in the users mailing list?

@simontegelid

simontegelid commented Jun 24, 2018 •

Copy link
Copy Markdown
Contributor Author

If the tempfile_cmdlist is stored as an attribute somwhere in the targets (or sources), all the subsequent actions in the same action list that is also using TEMPFILE will get the tempfile from the first TEMPFILE invocation. I provided a testcase in the pull request that exemplifies the problem, which is why I made a pull request and not opened a discussion in the users mailing list.

@bdbaddog

Copy link
Copy Markdown
Contributor

Bringing it to the users mailing list allows more eyes on the issue and potentially understanding why the code is as it is.
As you've removed some code added to fix some issues.
It wouldn't have been added arbitrarily.

Here's the email regarding the previous changes which you've altered.
https://pairlist2.pair.net/pipermail/scons-dev/2014-November/002041.html

Are those issues re-broken by your changes?

@simontegelid

Copy link
Copy Markdown
Contributor Author

Yes, as I mentioned "not reusing tempfiles will create unneeded tempfiles on strfunction invocation" but the current solution is producing incorrect results. I will bring it to the users mailing list for discussion.

@simontegelid

Copy link
Copy Markdown
Contributor Author

The users mailing list didn't get much attention. The solution for the duplicate tempfiles are not correct imo, since it gives incorrect builds for the test case I added. Any ideas how we can solve that in another way?

@bdbaddog

Copy link
Copy Markdown
Contributor

Would:

Actions lists with more than one action using ${TEMPFILE("TEMP FILE CONTENT")} should not use the
same tempfile for different "TEMP FILE CONTENT"

Be a better description than:

Actions lists where each action use TEMPFILE cannot use the
same tempfiles.

Also note as is the test fails against current master branch with missing xxx.py and yyy.py.

Also. I don't think the test captures checking that the tempfile for each action has a different name?

Seems like an optimal solution would have a single temp file for each item in an action list?
(And not a temp file per usage of each action?)

@bdbaddog

bdbaddog commented Aug 30, 2018 •

Copy link
Copy Markdown
Contributor

Here's an updated test which is still not going to catch if the tempfiles are named, but seems to run..

#!/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.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

"""
Verify that using $TEMPFILE in multiple actions in a
list invokes each command in the list.
"""

import os
import stat

import TestSCons

test = TestSCons.TestSCons(match = TestSCons.match_re)
_python_ = TestSCons._python_


test.write('echo.py', """\
#!/usr/bin/env python
from __future__ import print_function
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', """
env = Environment(BUILDCOM=['%(_python_)s echo.py ${TEMPFILE(" -otempfile $SOURCE")}',
                            '%(_python_)s echo.py second line ${TEMPFILE(" -o$TARGET tempfile")}'],
                  MAXLINELENGTH=1)
env.Command('file.output', 'file.input', '$BUILDCOM')
"""% locals())

test.write('file.input', "file.input\n")

test.run(arguments = '-n -Q .',
         stdout = """\
Using tempfile \\S+ for command line:
-otempfile file.input
%(_python_)s echo.py @\\S+
['echo.py', '-otempfile', @\\S+']
Using tempfile \\S+ for command line:
-ofile.output tempfile
%(_python_)s echo.py second line @\\S+
['echo.py', 'second', 'line', '-otempfile', '@\\S+']
"""%locals())

test.pass_test()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:

@bdbaddog bdbaddog closed this Feb 11, 2020
@bdbaddog bdbaddog reopened this Feb 11, 2020
@simontegelid

simontegelid commented Feb 12, 2020 •

Copy link
Copy Markdown
Contributor Author

Oh, sorry for leaving this behind for a long time. I just rebased it and took a look at the added test. I don't really get the details of how the tests are being run, I just used test/TEMPFILEPREFIX.py as a base for my test.

Running python3 ./runtest.py test/TEMPFILE-actionlist.py gives

1/1 (100.00%) /usr/bin/python3 test/TEMPFILE-actionlist.py
PASSED

What am I missing? Your proposed test seems more suitable, but I just fail to run it...

@simontegelid

simontegelid commented Feb 12, 2020 •

Copy link
Copy Markdown
Contributor Author

The PR was apparently closed when I force-pushed my rebase..? That wasn't my intention.

Edit: Pushed the wrong ref... Fixed now.

@simontegelid simontegelid mentioned this pull request Feb 12, 2020
3 tasks done
@mwichmann mwichmann added the TEMPFILE Long-command-line handling with TEMPFILE label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

TEMPFILE Long-command-line handling with TEMPFILE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants