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

Print environment variables for cargo run in extra verbose mode #12498

Merged
merged 3 commits into from
Aug 17, 2023

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Aug 14, 2023

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 sets LD_LIBRARY_PATH which is needed to actually run the binary. Because if users want to run the binary without cargo, 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.

@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2023

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added Command-run S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2023
Copy link
Member

@weihanglo weihanglo left a 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 😁)

.file("src/main.rs", r#"fn main() {println!("run-a");}"#)
.build();

p.cargo("run -vv").with_stderr("LD_LIBRARY_PATH").run();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contains two shortcomings:

What about this? [..] for wildcard matches, and we match one env vars to verify the behavior.

Suggested change
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();

tests/testsuite/run.rs Outdated Show resolved Hide resolved
@Kobzol
Copy link
Contributor Author

Kobzol commented Aug 15, 2023

Thanks for the hints. I added support for cargo test too. I have to say, it would be really nice if cargo had auto-blessable tests with placeholders 😆 Getting the text output right is not straightforward.

@weihanglo
Copy link
Member

weihanglo commented Aug 15, 2023

I believe changing to

[RUNNING] `[..] rustdoc [..]--test [..]`

would fix CI failures.

BTW, is it possible to add a similar test for cargo bench?

@Kobzol
Copy link
Contributor Author

Kobzol commented Aug 16, 2023

Thanks for the hint! I fixed the two failing tests and used [DOCTEST] foo in the test test, as I noticed it was used in the failing tests. I also added a test for bench.

@arlosi
Copy link
Contributor

arlosi commented Aug 16, 2023

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 16, 2023

📌 Commit 4eac5a1 has been approved by arlosi

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 16, 2023
bors added a commit that referenced this pull request Aug 16, 2023
Print environment variables for `cargo run` in extra verbose mode
@bors
Copy link
Collaborator

bors commented Aug 16, 2023

⌛ Testing commit 4eac5a1 with merge 522e9fc...

@bors
Copy link
Collaborator

bors commented Aug 16, 2023

☀️ Test successful - checks-actions
Approved by: arlosi
Pushing 522e9fc to master...

@bors
Copy link
Collaborator

bors commented Aug 16, 2023

👀 Test was successful, but fast-forwarding failed: 422 Update is not a fast forward

@arlosi
Copy link
Contributor

arlosi commented Aug 17, 2023

@bors retry

@bors
Copy link
Collaborator

bors commented Aug 17, 2023

⌛ Testing commit 4eac5a1 with merge 7b61184...

@bors
Copy link
Collaborator

bors commented Aug 17, 2023

☀️ Test successful - checks-actions
Approved by: arlosi
Pushing 7b61184 to master...

@bors bors merged commit 7b61184 into rust-lang:master Aug 17, 2023
19 checks passed
@Kobzol Kobzol deleted the run-verbose-print-env branch August 17, 2023 07:45
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 19, 2023
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2023
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
@ehuss ehuss added this to the 1.73.0 milestone Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-run Command-test S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo run -v should show setting of LD_LIBRARY_PATH
6 participants