-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Warn when installing with a non-default toolchain #16131
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
base: master
Are you sure you want to change the base?
Conversation
r? @weihanglo rustbot has assigned @weihanglo. Use |
2157847
to
9006944
Compare
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.
EDIT: The force push was to make Clippy happy.
Feel free to force-push and re-organize your commits during the iterations.
src/cargo/ops/cargo_install.rs
Outdated
.unwrap_or_default(); | ||
self.gctx.shell().warn(format!( | ||
"\ | ||
using non-default toolchain{maybe_toolchain} overridden by {source} |
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.
we now prefer annotate-snippets style diagnostics. See the linked pull requests in #15944 for references.
(I guess the "use cargo +stable install …"
can be rendered under a help:
)
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.
Using warn
is fine if its a single message but yes, this should be two messages as written, a warn and help.
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.
Please tell me if I used the new API incorrectly.
|
||
/// Performs a `cargo install` with a non-default toolchain in a simulated | ||
/// rustup environment. The purpose is to verify the warning that is emitted. | ||
#[cargo_test] |
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.
We prefer tests for a behavior change on its own commit first, so that in the next fix impl commit we can see the behavior change through test assertion/snapshot diff.
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.
Note that with what was said, each commit should pass tests. As the last commit has no test changes, I'm assuming that instead you added all tests as if feature is implemented and put them in the test commit.
See https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request for more details
5f2fbb4
to
c64e01a
Compare
use cargo_test_support::install::{assert_has_installed_exe, assert_has_not_installed_exe, exe}; | ||
use cargo_test_support::paths; | ||
|
||
fn pkg(name: &str, vers: &str) { |
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.
For myself, I'm not too much of a fan of us reusing like this as it hides in the test what is happening and gets annoying when you just need a little customization. Just directly publish the needed package inside of your test.
[DOWNLOADING] crates ... | ||
[DOWNLOADED] foo v0.0.1 (registry `dummy-registry`) | ||
[INSTALLING] foo v0.0.1 | ||
[WARNING] using non-default toolchain `test-toolchain` overridden by env |
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.
When the new rustup is released, to avoid it causing annoyances in our tests, I suspect we want to update
cargo/crates/cargo-test-support/src/lib.rs
Line 1377 in 40076ea
fn test_env(mut self) -> Self { |
RUSTUP_*
and env_remove
them from the binary being executed
// The toolchain rustc needs to call the real rustc. In order to do that, | ||
// it needs to restore or clear the RUSTUP environment variables so that | ||
// if rustup is installed, it will call the correct rustc. | ||
let rustup_toolchain_source_setup = match std::env::var_os("RUSTUP_TOOLCHAIN_SOURCE") { |
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.
I don't think we should be doing anything based on the rustup we are running in
See also #16131 (comment)
/// Arguments | ||
/// | ||
/// - `proxy_calls_cargo`: if true, the cargo proxy calls the cargo under test; | ||
/// otherwise, the cargo proxy calls an executable that panics immediately | ||
/// - `env_setup`: environment variable setup the proxy should perform | ||
fn simulated_rustup_environment(proxy_calls_cargo: bool, env_setup: &str) -> RustupEnvironment { |
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.
These make the tests much harder to read and not thrilled about injecting code directly into things.
/// Performs a `cargo install` with a non-default toolchain in a simulated | ||
/// rustup environment. The purpose is to verify the warning that is emitted. | ||
#[cargo_test] | ||
fn cargo_install_with_non_default_toolchain() { |
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.
We should likely have cargo install
tests for
- Rustup that doesn't set
RUSTUP_TOOLCHAIN_SOURCE
- For each value of
RUSTUP_TOOLCHAIN_SOURCE
- For an unknown value of
RUSTUP_TOOLCHAIN_SOURCE
(handling future cases where new values are added)
&& !matches!( | ||
source, | ||
RustupToolchainSource::Default | RustupToolchainSource::CommandLine |
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.
Downside to matches!
is we can miss it if new values are added. For now, that is not likely to happen as this is all for one feature. That might not always be the case.
I would
- Move the
&str
->RustupToolchainSource
to a function onget_rustup_toolchain_source
(shouldn't touchgctx
) - Have a function on
RustupToolchainSource
that lts is ask the question we are asking here and uses amatch
with every case enumerated
.map(|toolchain| format!(" `{toolchain}`")) | ||
.unwrap_or_default(); | ||
let report = &[Level::WARNING | ||
.primary_title(format!( |
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.
Not too obvious but we are limiting ourselves to secondary_title
s for now
"using non-default toolchain{maybe_toolchain} overridden by {source}" | ||
)) | ||
.element(Level::HELP.message(format!( | ||
"Use `cargo +stable install` if you meant to use the stable toolchain." |
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.
Please change Use
to use
. Our messages should be lower case
I really wish we had [+default
](#t-rustup > Could we support `+default` toolchain? @ 💬) to suggest here.
If its purely for diagnostic purposes, we could run rustup show active-toolchain
, parse the output, and show that toolchain here. If we ever want to force its use, it needs to be a more strictly defined programmatic interface.
|
||
fn get_rustup_toolchain_source(&self) -> Option<RustupToolchainSource> { | ||
self.gctx | ||
.get_env("RUSTUP_TOOLCHAIN_SOURCE") |
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.
My gut reaction is we should make an exception and read from std::env
. That seems matched with
Lines 75 to 78 in 40076ea
// ALLOWED: `RUSTUP_HOME` should only be read from process env, otherwise | |
// other tools may point to executables from incompatible distributions. | |
#[allow(clippy::disallowed_methods)] | |
std::env::var_os("RUSTUP_HOME").is_some() |
but then we have this
Lines 362 to 363 in 40076ea
gctx.get_env("RUSTUP_HOME"), | |
gctx.get_env("RUSTUP_TOOLCHAIN"), |
This PR implements the cargo changes for #11036. The rustup changes were implemented in rust-lang/rustup#4518.
The PR is currently organized as four commits:
RUSTUP_TOOLCHAIN_SOURCE
. This change is not strictly necessary, but it improves the rustup tests' fidelity.pkg
function to a location where the next commit can use it.cargo install
is invoked with a non-default toolchain, as indicated byRUSTUP_TOOLCHAIN_SOURCE
.In the third commit, two significant changes were made to
simulated_rustup_environment
:RUSTUP_TOOLCHAIN_SOURCE
) before calling the proxied tool.The PR is currently marked as draft because rust-lang/rustup#4518 has not yet been released. Technically, this PR could be merged before then. But testing it with a fixed rustup would seem to make sense.
Nits are welcome.
cc: @epage