Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::sources::source::SourceMap;
use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;
use crate::util::{CanonicalUrl, GlobalContext};
use annotate_snippets::Level;
use anyhow::{Context as _, bail};
use tracing::{debug, trace};
use url::Url;
Expand Down Expand Up @@ -387,16 +388,19 @@ impl<'gctx> PackageRegistry<'gctx> {
unused_fields.push("`default-features`")
}
if !unused_fields.is_empty() {
let mut shell = self.source_config.gctx().shell();
shell.warn(format!(
"unused field in patch for `{}`: {}",
dep.package_name(),
unused_fields.join(", ")
))?;
shell.note(format!(
"configure {} in the `dependencies` entry",
unused_fields.join(", ")
))?;
self.source_config.gctx().shell().print_report(
&[Level::WARNING
.secondary_title(format!(
"unused field in patch for `{}`: {}",
dep.package_name(),
unused_fields.join(", ")
))
.element(Level::HELP.message(format!(
"configure {} in the `dependencies` entry",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slightly off-topic, but I wanted to attach a manifest/config location here. It's a bit tricky, though, because the dependency table was the result of a merge between configs and manifests. How would you feel about having Dependency (and potentially other things) keep track of their source location?

Copy link
Contributor

Choose a reason for hiding this comment

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

Really look forward to us adding more context like this though don't feel obligated to do so. This effort is more prep work for us to start doing these kinds of improvements. The most I expected to be done with this is wording changes to better fit the new style.

unused_fields.join(", ")
)))],
false,
)?;
}

// Go straight to the source for resolving `dep`. Load it as we
Expand Down
34 changes: 21 additions & 13 deletions src/cargo/ops/cargo_package/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::core::{Package, Workspace};
use crate::ops::PackageOpts;
use crate::sources::PathEntry;
use crate::{CargoResult, GlobalContext};
use annotate_snippets::Level;
use anyhow::Context;
use cargo_util::paths;
use gix::bstr::ByteSlice;
Expand Down Expand Up @@ -158,20 +159,27 @@ fn warn_symlink_checked_out_as_plain_text_file(
}

if src_files.iter().any(|f| f.maybe_plain_text_symlink()) {
let mut shell = gctx.shell();
shell.warn(format_args!(
"found symbolic links that may be checked out as regular files for git repo at `{}/`\n\
This might cause the `.crate` file to include incorrect or incomplete files",
repo.workdir().unwrap().display(),
))?;
let extra_note = if cfg!(windows) {
"\nAnd on Windows, enable the Developer Mode to support symlinks"
} else {
""
let msg = format!(
"found symbolic links that may be checked out as regular files for git repo at `{}/`",
repo.workdir().unwrap().display()
);
let mut notes = vec![
Level::NOTE.message(
"this might cause the `.crate` file to include incorrect or incomplete files",
),
Level::HELP.message("to avoid this, set the Git config `core.symlinks` to `true`"),
];
if cfg!(windows) {
notes.push(
Level::HELP.message("on Windows, enable the Developer Mode to support symlinks"),
);
};
shell.note(format_args!(
"to avoid this, set the Git config `core.symlinks` to `true`{extra_note}",
))?;
gctx.shell().print_report(
&[Level::WARNING
.secondary_title(msg)
.elements(notes.into_iter())],
false,
)?;
}

Ok(())
Expand Down
16 changes: 12 additions & 4 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::task::{Poll, ready};

use annotate_snippets::Level;
use anyhow::Context as _;
use cargo_util::paths::{self, exclude_from_backups_and_indexing};
use flate2::read::GzDecoder;
Expand Down Expand Up @@ -832,10 +833,17 @@ impl<'gctx> Source for RegistrySource<'gctx> {
.expect("--precise <yanked-version> in use");
if self.selected_precise_yanked.insert((name, version.clone())) {
let mut shell = self.gctx.shell();
shell.warn(format_args!(
"selected package `{name}@{version}` was yanked by the author"
))?;
shell.note("if possible, try a compatible non-yanked version")?;
shell.print_report(
&[Level::WARNING
.secondary_title(format!(
"selected package `{name}@{version}` was yanked by the author"
))
.element(
Level::HELP
.message("if possible, try a compatible non-yanked version"),
)],
false,
)?;
}
}
if called {
Expand Down
13 changes: 8 additions & 5 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ use crate::util::network::http::configure_http_handle;
use crate::util::network::http::http_handle;
use crate::util::{CanonicalUrl, closest_msg, internal};
use crate::util::{Filesystem, IntoUrl, IntoUrlWithBase, Rustc};
use annotate_snippets::Level;
use anyhow::{Context as _, anyhow, bail, format_err};
use cargo_credential::Secret;
use cargo_util::paths;
Expand Down Expand Up @@ -1582,13 +1583,15 @@ impl GlobalContext {
))?;
}
} else {
self.shell().warn(format!(
self.shell().print_report(&[
Level::WARNING.secondary_title(
format!(
"`{}` is deprecated in favor of `{filename_without_extension}.toml`",
possible.display(),
))?;
self.shell().note(
format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`"),
)?;
)).element(Level::HELP.message(
format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`")))

], false)?;
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ f1 = 1
let output = read_output(gctx);
let expected = str![[r#"
[WARNING] `[ROOT]/.cargo/config` is deprecated in favor of `config.toml`
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
|
= [HELP] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`

"#]];
assert_e2e().eq(&output, expected);
Expand All @@ -314,7 +315,8 @@ f1 = 1
p.cargo("-vV")
.with_stderr_data(str![[r#"
[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml`
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
|
= [HELP] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`

"#]])
.run();
Expand Down
5 changes: 3 additions & 2 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7450,8 +7450,9 @@ fn git_core_symlinks_false() {
p.cargo("package --allow-dirty")
.with_stderr_data(str![[r#"
[WARNING] found symbolic links that may be checked out as regular files for git repo at `[ROOT]/foo/`
This might cause the `.crate` file to include incorrect or incomplete files
[NOTE] to avoid this, set the Git config `core.symlinks` to `true`
|
= [NOTE] this might cause the `.crate` file to include incorrect or incomplete files
= [HELP] to avoid this, set the Git config `core.symlinks` to `true`
...
[PACKAGING] bar v0.0.0 ([ROOT]/foo)
[PACKAGED] 7 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
Expand Down
12 changes: 8 additions & 4 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ fn add_patch_with_features() {
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`
[NOTE] configure `features` in the `dependencies` entry
|
= [HELP] configure `features` in the `dependencies` entry
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
Expand All @@ -943,7 +944,8 @@ fn add_patch_with_features() {
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`
[NOTE] configure `features` in the `dependencies` entry
|
= [HELP] configure `features` in the `dependencies` entry
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
Expand Down Expand Up @@ -979,7 +981,8 @@ fn add_patch_with_setting_default_features() {
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`, `default-features`
[NOTE] configure `features`, `default-features` in the `dependencies` entry
|
= [HELP] configure `features`, `default-features` in the `dependencies` entry
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
Expand All @@ -991,7 +994,8 @@ fn add_patch_with_setting_default_features() {
p.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] unused field in patch for `bar`: `features`, `default-features`
[NOTE] configure `features`, `default-features` in the `dependencies` entry
|
= [HELP] configure `features`, `default-features` in the `dependencies` entry
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
Expand Down
6 changes: 4 additions & 2 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,8 @@ fn precise_yanked() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[WARNING] selected package `bar@0.1.1` was yanked by the author
[NOTE] if possible, try a compatible non-yanked version
|
= [HELP] if possible, try a compatible non-yanked version
[UPDATING] bar v0.1.0 -> v0.1.1

"#]])
Expand Down Expand Up @@ -1478,7 +1479,8 @@ fn precise_yanked_multiple_presence() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[WARNING] selected package `bar@0.1.1` was yanked by the author
[NOTE] if possible, try a compatible non-yanked version
|
= [HELP] if possible, try a compatible non-yanked version
[UPDATING] bar v0.1.0 -> v0.1.1

"#]])
Expand Down