Skip to content

Commit 8995ab9

Browse files
committed
feat: add the deprecation warning
1 parent 7867550 commit 8995ab9

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::sources::source::QueryKind;
2121
use crate::sources::source::Source;
2222
use crate::util::GlobalContext;
2323
use crate::util::cache_lock::CacheLockMode;
24-
use crate::util::context::ConfigRelativePath;
24+
use crate::util::context::{ConfigRelativePath, Definition};
2525
use crate::util::errors::CargoResult;
2626
use crate::util::{FileLock, Filesystem};
2727

@@ -546,9 +546,29 @@ impl InstallInfo {
546546

547547
/// Determines the root directory where installation is done.
548548
pub fn resolve_root(flag: Option<&str>, gctx: &GlobalContext) -> CargoResult<Filesystem> {
549-
let config_root = gctx
550-
.get::<Option<ConfigRelativePath>>("install.root")?
551-
.map(|p| p.resolve_program(gctx));
549+
let config_root = match gctx.get::<Option<ConfigRelativePath>>("install.root")? {
550+
Some(p) => {
551+
let resolved = p.resolve_program(gctx);
552+
if resolved.is_relative() {
553+
let definition = p.value().definition.clone();
554+
if matches!(definition, Definition::Path(_)) {
555+
let suggested = format!("{}/", resolved.display());
556+
gctx.shell().warn(format!(
557+
"the `install.root` value `{}` defined in {} is deprecated; \
558+
a future version of Cargo will treat it as relative to the configuration \
559+
directory. Add a trailing slash (`{}`) to adopt the \
560+
correct behavior and silence this warning. See more at \
561+
https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths",
562+
resolved.display(),
563+
definition,
564+
suggested
565+
))?;
566+
}
567+
}
568+
Some(resolved)
569+
}
570+
None => None,
571+
};
552572

553573
Ok(flag
554574
.map(PathBuf::from)

tests/testsuite/install.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ fn relative_install_location_without_trailing_slash() {
522522
let mut cmd = cargo_process("install --path .");
523523
cmd.cwd(p.root());
524524
cmd.with_stderr_data(str![[r#"
525+
[WARNING] the `install.root` value `t1` defined in [ROOT]/.cargo/config.toml is deprecated; a future version of Cargo will treat it as relative to the configuration directory. Add a trailing slash (`t1/`) to adopt the correct behavior and silence this warning. See more at https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths
525526
[INSTALLING] foo v0.0.1 ([ROOT]/foo)
526527
[COMPILING] foo v0.0.1 ([ROOT]/foo)
527528
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s

0 commit comments

Comments
 (0)