This is an archive of the discontinued LLVM Phabricator instance.

Added 'cd -' built in to lit
AbandonedPublic

Authored by jmittert on Nov 9 2018, 9:25 AM.

Details

Summary

Pass '-' to cd return to the previous directory. I had encountered some (non
llvm) lit tests which use (cd %t && ... ) to run commands and this seemed
like a more portable way to do that.

Diff Detail

Event Timeline

jmittert created this revision.Nov 9 2018, 9:25 AM
rnk added a comment.Nov 9 2018, 1:19 PM

Can you add a quick test to the lit test suite for this? Shouldn't be too hard, make some dirs, cd into and out, pwd, filecheck the output.

jmittert updated this revision to Diff 173450.Nov 9 2018, 2:55 PM

Added a test for cd -

rnk accepted this revision.Nov 9 2018, 5:52 PM

lgtm

This revision is now accepted and ready to land.Nov 9 2018, 5:52 PM

I don't have commit access, can you commit this for me please?

joerg requested changes to this revision.Nov 11 2018, 2:06 PM
joerg added a subscriber: joerg.

I'm quite against this. "cd -" is a non-portable extension to shell and should never be used in first place.

This revision now requires changes to proceed.Nov 11 2018, 2:06 PM
jmittert added a comment.EditedNov 12 2018, 9:57 AM

Hmm, would pushd/popd be a more reasonable alternative then? I didn't want to have to maintain the extra state.

Edit: Actually, can you clarify what you mean by non-portable? This is being interpreted by lit.py so the underlying system/shell shouldn't matter. In addition, I though cd - is part of the posix standard. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html

joerg added a comment.Nov 12 2018, 5:53 PM

Personally, I would strongly prefer if the test cases are as explicit as possible. That makes debugging based on the llvm-lit output a lot easier. Ignoring anything else, this feature would make it a lot more tricky to figure out what exactly is going on.

So then assuming I want to run a single command in a given directory, what's the recommended way of doing that if not pushd/cd -? (cd %t && ...) currently doesn't work on Windows which is what I was trying to work around.

rnk added a comment.Nov 13 2018, 1:34 PM

I'm quite against this. "cd -" is a non-portable extension to shell and should never be used in first place.

Can you elaborate? In what way is cd - non-portable? Is it a bash-ism? If it is, why should lit care? Lit looks for "bash" by name on every platform, so far as I know.

joerg added a comment.Nov 13 2018, 2:24 PM

As I said: because it makes it harder to rerun parts of the test interactively. Which is a good enough reason to forbid cd - as well as any directory stack operations, IMO.

rnk added a comment.Nov 13 2018, 2:50 PM

As I said: because it makes it harder to rerun parts of the test interactively. Which is a good enough reason to forbid cd - as well as any directory stack operations, IMO.

Is your objection that you would prefer that tests remain written as (cd dir && dosomething), and not use cd -? If so, I think it would be better to comment on the reviews that migrate the tests from one pattern to another. cd - is a generally available bash feature that any test author could use anywhere. It's really up to the individuals owners writing and maintaining tests as to whether they care more about using subshells vs. having their test run on Windows.

My understanding is that implementing the full set of features offered by subshells is pretty out of scope for lit. To be faithful, we'd really need to start launching a shell process that updates its real CWD, environment, stdout, stdin, etc. The goal of the python lit shell is to be fast on Windows, and launching those extra processes works against that goal. I would be in favor of adding a limited amount of subshell handling, but just adding cd - seems like a reasonable shortcut to me.

joerg added a comment.Nov 13 2018, 3:36 PM

I would actually rule out subshells as well. I see no reason why a test case should have to use them, i.e. compared to just change the working directory back afterwards. As I said, I want to be able to repeat a problematic command manually and interactively as easy as possible. Using non-portable shell features is a problem for that. Depending on state between commands is also annoying. Let's really try to keep it minimal and where necessary, adjust test case guidelines and test cases to simplify things.

jmittert abandoned this revision.Jan 15 2019, 3:43 PM

I can work around not having this.