This is an archive of the discontinued LLVM Phabricator instance.

[test] Capture stderr from 'tar --version' call as well
ClosedPublic

Authored by mgorny on Dec 7 2018, 9:20 AM.

Details

Summary

Capture the stderr from 'tar --version' call as otherwise error messages
spill onto user's terminal unnecessarily (e.g. on NetBSD where tar does
not support long options). While at it, refactor the code to use
communicate() instead of reinventing the wheel.

Diff Detail

Repository
rL LLVM

Event Timeline

mgorny created this revision.Dec 7 2018, 9:20 AM
MaskRay added inline comments.Dec 7 2018, 9:52 AM
test/lit.cfg.py
99 ↗(On Diff #177238)

If you don't need stderr, remove stderr=subprocess.PIPE,

subprocess.Popen followed by communicate() can be replaced by check_output

if 'GNU tar' in sout: does not in Python 3 as sout would have type bytes, not str

mgorny updated this revision to Diff 177250.Dec 7 2018, 10:51 AM
mgorny marked 2 inline comments as done.
ruiu added a subscriber: ruiu.Dec 7 2018, 11:00 AM
ruiu added inline comments.
test/lit.cfg.py
99 ↗(On Diff #177238)

I think as Fangrui suggested

subprocess.check_output(["/tmp/foo"], stderr=subprocess.STDOUT)

is better than subprocess.Popen followed by communicate() and wait().

Sorry, it seems that my reply didn't go through.

test/lit.cfg.py
99 ↗(On Diff #177238)

I need to silence stderr. Given that /dev/null is not portable, and subprocess.DEVNULL requires py3.3+, capturing it is the simplest solution.

check_output() will throw when tar doesn't support version, i.e. it would break NetBSD completely instead of silencing the error.

I'll fix the type mismatch.

ruiu added inline comments.Dec 7 2018, 11:08 AM
test/lit.cfg.py
99 ↗(On Diff #177238)

Oh sorry I didn't know that check_output throws if a subprocess exits with non-zero exit code.

MaskRay added inline comments.Dec 7 2018, 11:19 AM
test/lit.cfg.py
101 ↗(On Diff #177250)

LG, but serr can be replaced by _ if it is not used.

mgorny updated this revision to Diff 177265.Dec 7 2018, 11:38 AM
mgorny marked 2 inline comments as done.
mgorny marked 2 inline comments as done.
ruiu added inline comments.Dec 7 2018, 12:43 PM
test/lit.cfg.py
100 ↗(On Diff #177265)

Maybe a silly question, but is this OK to remove this line?

mgorny marked an inline comment as done.Dec 7 2018, 1:00 PM
mgorny added inline comments.
test/lit.cfg.py
100 ↗(On Diff #177265)

Yes. communicate() waits on the process.

krytarowski resigned from this revision.Dec 7 2018, 3:39 PM

I don't feel enough comfortable with this Python code.

ruiu accepted this revision.Dec 14 2018, 2:38 PM

LGTM

This revision is now accepted and ready to land.Dec 14 2018, 2:38 PM
This revision was automatically updated to reflect the committed changes.