-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Print environment variables for cargo run
in extra verbose mode
#12498
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Do you want to deal with cargo test
as well in this pull request, or a follow-up?
(Can also leave it there. I am fine with that 😁)
tests/testsuite/run.rs
Outdated
.file("src/main.rs", r#"fn main() {println!("run-a");}"#) | ||
.build(); | ||
|
||
p.cargo("run -vv").with_stderr("LD_LIBRARY_PATH").run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This contains two shortcomings:
- Different platforms have different library paths. This won't pass on Windows and macOS.
- This matches both
rustc
and the final binary invocations. We can't tell whether the env is from which.
What about this? [..]
for wildcard matches, and we match one env vars to verify the behavior.
p.cargo("run -vv").with_stderr("LD_LIBRARY_PATH").run(); | |
p.cargo("run -vv") | |
.with_stderr( | |
"\ | |
[COMPILING] a v0.0.1 ([CWD]) | |
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name a[..]` | |
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | |
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] target/debug/a[EXE]`", | |
) | |
.run(); |
Thanks for the hints. I added support for |
4807d25
to
f507281
Compare
f507281
to
2db59da
Compare
I believe changing to
would fix CI failures. BTW, is it possible to add a similar test for |
Thanks for the hint! I fixed the two failing tests and used |
2db59da
to
4eac5a1
Compare
Thanks! @bors r+ |
Print environment variables for `cargo run` in extra verbose mode
☀️ Test successful - checks-actions |
👀 Test was successful, but fast-forwarding failed: 422 Update is not a fast forward |
@bors retry |
☀️ Test successful - checks-actions |
Update cargo 15 commits in 7c3904d6c3ed54e8a413023519b55a536ad44d5b..80eca0e58fb2ff52c1e94fc191b55b37ed73e0e4 2023-08-14 20:11:43 +0000 to 2023-08-19 00:52:06 +0000 - chore: Downgrade serde below the binary blob (rust-lang/cargo#12528) - Improve error message for when no credential providers are available (rust-lang/cargo#12526) - Fix typo: "use" -> "used" (rust-lang/cargo#12522) - Document layout SemVer compatibility. (rust-lang/cargo#12169) - Make cargo-credential-gnome-secret built-in as cargo:libsecret (rust-lang/cargo#12521) - login: allow passing additional args to provider (rust-lang/cargo#12499) - cargo-credential-gnome-secret: dynamically load libsecret (rust-lang/cargo#12518) - credential-providers: make 1password no longer built-in (rust-lang/cargo#12507) - Print environment variables for `cargo run` in extra verbose mode (rust-lang/cargo#12498) - chore(cargo-util): bump version to 0.2.6 (rust-lang/cargo#12517) - credential: rename cargo:basic to cargo:token-from-stdout (rust-lang/cargo#12512) - fix(xtask-bump-check): query by package name to detect changes (rust-lang/cargo#12513) - ci: use pull request head commit whenever possible (rust-lang/cargo#12508) - Update hermit-abi (rust-lang/cargo#12504) - Crate checksum lookup query should match on semver build metadata (rust-lang/cargo#11447) r? ghost
Update cargo 15 commits in 7c3904d6c3ed54e8a413023519b55a536ad44d5b..80eca0e58fb2ff52c1e94fc191b55b37ed73e0e4 2023-08-14 20:11:43 +0000 to 2023-08-19 00:52:06 +0000 - chore: Downgrade serde below the binary blob (rust-lang/cargo#12528) - Improve error message for when no credential providers are available (rust-lang/cargo#12526) - Fix typo: "use" -> "used" (rust-lang/cargo#12522) - Document layout SemVer compatibility. (rust-lang/cargo#12169) - Make cargo-credential-gnome-secret built-in as cargo:libsecret (rust-lang/cargo#12521) - login: allow passing additional args to provider (rust-lang/cargo#12499) - cargo-credential-gnome-secret: dynamically load libsecret (rust-lang/cargo#12518) - credential-providers: make 1password no longer built-in (rust-lang/cargo#12507) - Print environment variables for `cargo run` in extra verbose mode (rust-lang/cargo#12498) - chore(cargo-util): bump version to 0.2.6 (rust-lang/cargo#12517) - credential: rename cargo:basic to cargo:token-from-stdout (rust-lang/cargo#12512) - fix(xtask-bump-check): query by package name to detect changes (rust-lang/cargo#12513) - ci: use pull request head commit whenever possible (rust-lang/cargo#12508) - Update hermit-abi (rust-lang/cargo#12504) - Crate checksum lookup query should match on semver build metadata (rust-lang/cargo#11447) r? ghost
What does this PR try to resolve?
This PR changes
cargo run
so that it prints the environment variables that it sets for the executed binary in extra verbose mode (cargo run -vv
). This is particularly useful when it setsLD_LIBRARY_PATH
which is needed to actually run the binary. Because if users want to run the binary withoutcargo
, they will need to know where should they point that variable. This is described in issue #4879.Fixes: #4879
How should we test and review this PR?
I tried to write a functional test, but I'm not sure how to check that
stderr
contains only a given substring, not a whole line.