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

rustbuild --verbose switch is missing env var info #38686

Closed
pnkfelix opened this issue Dec 29, 2016 · 10 comments · Fixed by #39888 or #82403
Closed

rustbuild --verbose switch is missing env var info #38686

pnkfelix opened this issue Dec 29, 2016 · 10 comments · Fixed by #39888 or #82403
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@pnkfelix
Copy link
Member

When I run time python /Users/fklock/Dev/Mozilla/rust.git/x.py build --stage 1, in an error condition like error: Could not compile `core`, I see the subsequent suggestion: To learn more, run the command again with --verbose.

When I run with --verbose, I do see helpful output with the build commands it executes. In particular, I see rustc invocations that I would like to run myself, with RUST_BACKTRACE=1 turned on.

Unfortunately:

 /Users/fklock/Dev/Mozilla/rust.git/objdir-dbgopt/build/bootstrap/debug/rustc /Users/fklock/Dev/Mozilla/rust.git/src/libcore/lib.rs --crate-name core --crate-type lib -C opt-level=2 -C metadata=7824b4c14b4ca3e8 -C extra-filename=-7824b4c14b4ca3e8 --out-dir /Users/fklock/Dev/Mozilla/rust.git/objdir-dbgopt/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps --emit=dep-info,link --target x86_64-apple-darwin -L dependency=/Users/fklock/Dev/Mozilla/rust.git/objdir-dbgopt/build/x86_64-apple-darwin/stage1-std/x86_64-apple-darwin/release/deps
thread 'main' panicked at 'RUSTC_STAGE was not set: NotPresent', ../src/libcore/result.rs:837

i.e., the environment variable RUSTC_STAGE needs to be set. After I set that, I get:

thread 'main' panicked at 'RUSTC_SYSROOT was not set', ../src/libcore/option.rs:705

and I start to wonder: "How many of these environment variables are there? Am I going to have to deduce the values for all of them? Why doesn't the --verbose flag either include them in the command invocation output (to make it trivial to cut-and-paste the desired command), or at least include them somewhere in the output so that I can grep for them?"

@pnkfelix
Copy link
Member Author

(I suspect the naive fix for this, to print key="value" each time .env is invoked within the rustbuild, is not palatable because it looks like we invoke .env many times with the same arguments for every cargo invocation.)

@pnkfelix
Copy link
Member Author

cc @alexcrichton

@alexcrichton
Copy link
Member

Yeah I've often wondered if we should update the Debug for Command implementation to print out extra environment variables. Unfortunately short of vendoring our own Command we don't really have a way to implement this in rustbuild :(

@alexcrichton alexcrichton added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Dec 29, 2016
@est31
Copy link
Member

est31 commented Dec 29, 2016

Dupe of #38221

nagisa added a commit to nagisa/rust that referenced this issue Feb 16, 2017
This is a simple way to workaround the debugging issues caused by the rustc
wrapper used in the bootstrap process. Namely, it uses some obscure environment
variables and you can’t just copy the failed command and run it in the shell or
debugger to examine the failure more closely.

With `--on-fail` its possible to run an arbitrary command within exactly the
same environment under which rustc failed. Theres’s multiple ways to use this
new flag:

$ python x.py build --stage=1 --on-fail=env

    would print a list of environment variables and the failed command, so a
    few copy-pastes and you now can run the same rust in your shell outside the
    bootstrap system.

$ python x.py build --stage=1 --on-fail=bash

    Is a more useful variation of the command above in that it launches a whole
    shell with environment already in place! All that’s left to do is copy-paste
    the command just above the shell prompt!

Fixes rust-lang#38686
Fixes rust-lang#38221
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 17, 2017
…chton

[rustbuild] add a way to run command after failure

This is a simple way to workaround the debugging issues caused by the rustc
wrapper used in the bootstrap process. Namely, it uses some obscure environment
variables and you can’t just copy the failed command and run it in the shell or
debugger to examine the failure more closely.

With `--on-fail` its possible to run an arbitrary command within exactly the
same environment under which rustc failed. Theres’s multiple ways to use this
new flag:

$ python x.py build --stage=1 --on-fail=env

    would print a list of environment variables and the failed command, so a
    few copy-pastes and you now can run the same rust in your shell outside the
    bootstrap system.

$ python x.py build --stage=1 --on-fail=bash

    Is a more useful variation of the command above in that it launches a whole
    shell with environment already in place! All that’s left to do is copy-paste
    the command just above the shell prompt!

Fixes rust-lang#38686
Fixes rust-lang#38221
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 17, 2017
…chton

[rustbuild] add a way to run command after failure

This is a simple way to workaround the debugging issues caused by the rustc
wrapper used in the bootstrap process. Namely, it uses some obscure environment
variables and you can’t just copy the failed command and run it in the shell or
debugger to examine the failure more closely.

With `--on-fail` its possible to run an arbitrary command within exactly the
same environment under which rustc failed. Theres’s multiple ways to use this
new flag:

$ python x.py build --stage=1 --on-fail=env

    would print a list of environment variables and the failed command, so a
    few copy-pastes and you now can run the same rust in your shell outside the
    bootstrap system.

$ python x.py build --stage=1 --on-fail=bash

    Is a more useful variation of the command above in that it launches a whole
    shell with environment already in place! All that’s left to do is copy-paste
    the command just above the shell prompt!

Fixes rust-lang#38686
Fixes rust-lang#38221
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 23, 2017
…chton

[rustbuild] add a way to run command after failure

This is a simple way to workaround the debugging issues caused by the rustc
wrapper used in the bootstrap process. Namely, it uses some obscure environment
variables and you can't just copy the failed command and run it in the shell or
debugger to examine the failure more closely.

With `--on-fail` its possible to run an arbitrary command within exactly the
same environment under which rustc failed. Theres's multiple ways to use this
new flag:

$ python x.py build --stage=1 --on-fail=env

    would print a list of environment variables and the failed command, so a
    few copy-pastes and you now can run the same rust in your shell outside the
    bootstrap system.

$ python x.py build --stage=1 --on-fail=bash

    Is a more useful variation of the command above in that it launches a whole
    shell with environment already in place! All that's left to do is copy-paste
    the command just above the shell prompt!

Fixes rust-lang#38686
Fixes rust-lang#38221
eddyb added a commit to eddyb/rust that referenced this issue Feb 25, 2017
…chton

[rustbuild] add a way to run command after failure

This is a simple way to workaround the debugging issues caused by the rustc
wrapper used in the bootstrap process. Namely, it uses some obscure environment
variables and you can't just copy the failed command and run it in the shell or
debugger to examine the failure more closely.

With `--on-fail` its possible to run an arbitrary command within exactly the
same environment under which rustc failed. Theres's multiple ways to use this
new flag:

$ python x.py build --stage=1 --on-fail=env

    would print a list of environment variables and the failed command, so a
    few copy-pastes and you now can run the same rust in your shell outside the
    bootstrap system.

$ python x.py build --stage=1 --on-fail=bash

    Is a more useful variation of the command above in that it launches a whole
    shell with environment already in place! All that's left to do is copy-paste
    the command just above the shell prompt!

Fixes rust-lang#38686
Fixes rust-lang#38221
eddyb added a commit to eddyb/rust that referenced this issue Feb 25, 2017
…chton

[rustbuild] add a way to run command after failure

This is a simple way to workaround the debugging issues caused by the rustc
wrapper used in the bootstrap process. Namely, it uses some obscure environment
variables and you can't just copy the failed command and run it in the shell or
debugger to examine the failure more closely.

With `--on-fail` its possible to run an arbitrary command within exactly the
same environment under which rustc failed. Theres's multiple ways to use this
new flag:

$ python x.py build --stage=1 --on-fail=env

    would print a list of environment variables and the failed command, so a
    few copy-pastes and you now can run the same rust in your shell outside the
    bootstrap system.

$ python x.py build --stage=1 --on-fail=bash

    Is a more useful variation of the command above in that it launches a whole
    shell with environment already in place! All that's left to do is copy-paste
    the command just above the shell prompt!

Fixes rust-lang#38686
Fixes rust-lang#38221
@pnkfelix
Copy link
Member Author

I might claim that #39888 did not fix this in full generality.

Yes, the particular case where I filed this bug was one where the rustc invocation was failing, and thus --on-fail can be used to extract the state of the environment variables.

However, today I wanted to extract the rustc invocation in a case where that invocation was not failing, because I am investigating a code generation issue that I have only managed to replicate within the binary generated for rustc itself. The command I observe via --verbose does not work on its own, and I am currently assuming that this is once again due to my lack of knowledge about which environment variables to set (and to what values).

@pnkfelix
Copy link
Member Author

Here's a simple diff that solves my problem completely, and I suspect is sufficiently low impact (since I think it would only affect people using RUSTC_VERBOSE=1 ... and maybe those using -vv?) that I am tempted to put it up as a PR:

diff --git HEAD:/src/bootstrap/bin/rustc.rs INDEX:/src/bootstrap/bin/rustc.rs
index 37336a56d7..182fc0862c 100644
--- HEAD:/src/bootstrap/bin/rustc.rs
+++ INDEX:/src/bootstrap/bin/rustc.rs
@@ -279,6 +279,10 @@ fn main() {
     }
 
     if verbose > 1 {
+        for (i, (k, v)) in env::vars().enumerate() {
+            eprintln!("rustc env[{}]: {} = {}", i, k, v);
+        }
+        eprintln!("rustc directory: {}", env::current_dir().unwrap().display());
         eprintln!("rustc command: {:?}", cmd);
     }

@Mark-Simulacrum
Copy link
Member

I would be happy to review (and likely accept) such a PR.

@pnkfelix
Copy link
Member Author

pnkfelix commented Oct 7, 2019

Reopening based on reasoning given in my earlier comment

@pnkfelix pnkfelix reopened this Oct 7, 2019
@hdhoang hdhoang added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Nov 7, 2019
@mark-i-m
Copy link
Member

@pnkfelix I'm attempting to use your patch above, but I'm not sure I understand where/when those outputs would occur. I am running ./x.py build -vv. Do I need to rebuild rustc to see anything?

@pnkfelix
Copy link
Member Author

@mark-i-m I would have expected the patch to cause a change to the output you saw from ./x.py build -vv, though maybe I misremember whether x.py properly rebuilds itself when the rustbuild source changes?

@bors bors closed this as completed in 9720cd1 Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
6 participants