Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display environment variables when showing the command being run #5683

Closed
wants to merge 1 commit into from

Conversation

mikeyhew
Copy link
Contributor

@mikeyhew mikeyhew commented Jul 4, 2018

Even with #5666, when commands are shown in verbose output, there are still some cases where they can’t be run in the terminal. This is because the code is expecting certain environment variables that are provided by cargo. This PR updates the Display impl for ProcessBuilder to show the environment variables in front of the command (on unix), so that the command can be run. Example output:

screen shot 2018-07-04 at 4 14 34 pm

Note that for workspaces, you will still have to run the command from the workspace root.

I deliberately didn’t update any of the tests yet, because I want to see if this is desired. I also want to see if this can be done on windows, so hopefully someone with experience with that platform can comment.

Even with rust-lang#5666, when commands are shown in verbose output, there are
still some cases where they can’t be run in the terminal. This is
because the code is expecting certain environment variables that are
provided by cargo. This PR updates the `Display` impl for
`ProcessBuilder` to show the environment variables in front of the
command (on unix), so that the command can be run. Note that for
workspaces, you will still have to run the command from the workspace
root.

I deliberately didn’t update any of the tests yet, because I want to
see if this is desired, and figure out if there is a way to do this on
windows.
@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

Thanks for the PR!

It's true yeah that sometimes it's nice to have these baked in so they can be copy-pasted, but I think I'd prefer to solve a few issues first before merging if we merge:

  • This should have both a Unix and a Windows implementation
  • I think we may want to gate this on -vv instead of just -v

And I think that should be good enough?

@alexcrichton
Copy link
Member

ping @mikeyhew, have you had a chance to take another look at this?

@mikeyhew
Copy link
Contributor Author

Hey @alexcrichton that all sounds good, I'm just not familiar with windows, so not really sure what to do there. I was reading the answer to this question, and it looks like the cleanest way to pass environment variables to a subprocess is with a command (env) that you have to install.

One thing we could do is just output the environment variables on a separate line, so people can add them manually.

Any thoughts?

@alexcrichton
Copy link
Member

Hm so that answer does have at least a solution:

cmd /V /C "set EDITOR=vim&& echo !EDITOR!"

albeit not the greatest script :(

Another possible idea is to split this output onto multiple lines, but that has the unfortunate side effect of maybe getting mixed up with compiler diagnostic output (which Cargo doesn't synchronize with currently). I'm unfortunately also not sure what the best solution here would be...

@mikeyhew
Copy link
Contributor Author

@alexchrichton I take it stdin.lock() wouldn't help, because they are different processes.

@Marwes, you use windows — what would you do here?

@alexcrichton
Copy link
Member

Yeah unfortunately stdin.lock() wouldn't help the cross-process issue here

@Marwes
Copy link

Marwes commented Jul 22, 2018

@mikeyhew I use git bash for this reason and many others instead of cmd, so I am not any wiser of what's the best idea here (That SO link is the one I have used in the rare cases that I have needed it)

@alexcrichton
Copy link
Member

@mikeyhew hm do you have thoughts for how we might land this? Do you think it's important enough to land a unix-only implementation?

@mikeyhew
Copy link
Contributor Author

mikeyhew commented Aug 1, 2018

@alexcrichton ya, I think we should definitely support it at least on unix. For windows, I'm leaning toward the cmd option, because it can be pasted into the terminal and run:

cmd /c "set FOO=foo && BAR=bar && rustc --flag1 --flag2 file"

@alexcrichton
Copy link
Member

Ok makes sense to me, @rust-lang/cargo do y'all have thoughts on the feature here? It's pretty wonky (albeit not impossible) to implement this on Windows but wanted to check to see if anyone feels we should do something different here!

@joshtriplett
Copy link
Member

I absolutely want to see this land, to ensure that people can always re-run commands.

Regarding an implementation for Windows using cmd, I'd be deeply concerned about getting quoting correct to allow for copy-pasting.

@matklad
Copy link
Member

matklad commented Aug 7, 2018

Seems very useful! Does it make sense to show env only with -v -v, double verbose?

I also don’t think that we should go out of our way to make this copy-pastable on Windows. So, using VAR=foo binary syntax on windows seems fine by me: the user can adjust the command line themselthes depending on the shell being used.

@wycats
Copy link
Contributor

wycats commented Aug 8, 2018

I like gating it on -vv. I also think that if we think that the copy-pasting facility is useful on Linux and OSX, we should try to figure out how to make it work on Windows. I don't love that these micro-decisions often result in a noticeably worse user-experience on Windows in aggregate, and I don't think it would be too hard to figure out how to make this work properly.

@alexcrichton
Copy link
Member

Ok thanks for the input! @mikeyhew sounds like a "yes" to let's do the windows weird cmd syntax :)

(and then test it a bit for quoting and whatnot)

@alexcrichton
Copy link
Member

@mikeyhew ping on this, will you be able to implement the sytnax for windows?

@mikeyhew
Copy link
Contributor Author

@alexcrichton I've been busy lately, so that's why I haven't gotten to this yet. I don't have a windows machine, so I'd need to rely on CI to run tests for me, but I'll try that this coming week unless someone else wants to do the windows version.

@alexcrichton
Copy link
Member

Ok I'm going to close this for now as it's gone somewhat quite, but it can always be resubmitted!

@joshtriplett
Copy link
Member

joshtriplett commented Nov 16, 2018

I ran into another request for this from someone trying to debug builds, and I'd like to reopen it in the hopes that someone may wish to address it.

To avoid the perfect becoming the enemy of the good: I do think a UNIX implementation would be great to have. I'd also like to see this work on Windows, and I think it's important it work everywhere, but a solution that works on UNIX and makes things no worse on Windows would be an improvement.

@joshtriplett joshtriplett reopened this Nov 16, 2018
@bors
Copy link
Collaborator

bors commented Dec 11, 2018

☔ The latest upstream changes (presumably #6416) made this pull request unmergeable. Please resolve the merge conflicts.

@dwijnand
Copy link
Member

Along with a rebase, this is currently failing CI.

@mikeyhew
Copy link
Contributor Author

@dwijnand this never passed CI, since I didn't update the existing tests

bors added a commit that referenced this pull request Jan 3, 2019
Display environment variables for rustc commands

This picks up on the work done in PR #5683.

The extra output is only displayed with `-vv`.

The Windows output has the form `set FOO=foo && BAR=bar rustc ...` instead of
the form that suggested in #5683 to make escaping easier and since it's
simpler.
@dwijnand
Copy link
Member

dwijnand commented Jan 3, 2019

Superseded by #6492.

@dwijnand dwijnand closed this Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants