diff --git a/cargo-dylint/src/main.rs b/cargo-dylint/src/main.rs index cf3e81ed6..5c75c4f89 100644 --- a/cargo-dylint/src/main.rs +++ b/cargo-dylint/src/main.rs @@ -23,8 +23,8 @@ enum CargoSubcommand { DYLINT_DRIVER_PATH (default: $HOME/.dylint_drivers) is the directory where Dylint stores rustc drivers. -DYLINT_LIBRARY_PATH (default: none) is a colon-separated list of directories where Dylint searches -for libraries. +DYLINT_LIBRARY_PATH (deprecated, default: none) is a colon-separated list of directories where +Dylint searches for libraries. Prefer workspace metadata (described below) for naming libraries. DYLINT_RUSTFLAGS (default: none) is a space-separated list of flags that Dylint passes to `rustc` when checking the packages in the workspace. diff --git a/dylint/src/name_toolchain_map/mod.rs b/dylint/src/name_toolchain_map/mod.rs index 7f88f76fa..35a13925e 100644 --- a/dylint/src/name_toolchain_map/mod.rs +++ b/dylint/src/name_toolchain_map/mod.rs @@ -1,3 +1,4 @@ +use crate::error::warn; use anyhow::{Context, Result, ensure}; use dylint_internal::{env, parse_path_filename}; use once_cell::sync::OnceCell; @@ -77,7 +78,7 @@ impl<'opts> Lazy<'opts> { // smoelius: If `--git` or `--path` was passed, then do not look for libraries by // other means. if !self.inner.opts.git_or_path() { - let dylint_library_paths = dylint_library_paths()?; + let dylint_library_paths = self.dylint_library_paths()?; for path in dylint_library_paths { for entry in dylint_libraries_in(&path)? { @@ -95,28 +96,33 @@ impl<'opts> Lazy<'opts> { Ok(name_toolchain_map) }) } -} -fn dylint_library_paths() -> Result> { - let mut paths = Vec::new(); + fn dylint_library_paths(&self) -> Result> { + let mut paths = Vec::new(); - if let Ok(val) = env::var(env::DYLINT_LIBRARY_PATH) { - for path in split_paths(&val) { - ensure!( - path.is_absolute(), - "DYLINT_LIBRARY_PATH contains `{}`, which is not absolute", - path.to_string_lossy() - ); - ensure!( - path.is_dir(), - "DYLINT_LIBRARY_PATH contains `{}`, which is not a directory", - path.to_string_lossy() + if let Ok(val) = env::var(env::DYLINT_LIBRARY_PATH) { + warn( + self.inner.opts, + "`DYLINT_LIBRARY_PATH` is deprecated; use workspace metadata to name libraries", ); - paths.push(path); + + for path in split_paths(&val) { + ensure!( + path.is_absolute(), + "DYLINT_LIBRARY_PATH contains `{}`, which is not absolute", + path.to_string_lossy() + ); + ensure!( + path.is_dir(), + "DYLINT_LIBRARY_PATH contains `{}`, which is not a directory", + path.to_string_lossy() + ); + paths.push(path); + } } - } - Ok(paths) + Ok(paths) + } } fn dylint_libraries_in( diff --git a/examples/general/crate_wide_allow/src/lib.rs b/examples/general/crate_wide_allow/src/lib.rs index caa3d8254..987464ed5 100644 --- a/examples/general/crate_wide_allow/src/lib.rs +++ b/examples/general/crate_wide_allow/src/lib.rs @@ -124,9 +124,7 @@ mod tests { let cargo_dylint = |example_rustflags: Option<&str>| { let mut command = Command::new(&*CARGO_DYLINT_PATH); - command - .env_remove(env::DYLINT_LIBRARY_PATH) - .args(["dylint", "--lib", "clippy"]); + command.args(["dylint", "--lib", "clippy"]); if let Some(rustflags) = example_rustflags { command.env( env::RUSTFLAGS, diff --git a/utils/testing/src/lib.rs b/utils/testing/src/lib.rs index 688dea742..78a972b74 100644 --- a/utils/testing/src/lib.rs +++ b/utils/testing/src/lib.rs @@ -166,16 +166,6 @@ fn initialize(name: &str) -> &Result { .build() .success()?; - // smoelius: `DYLINT_LIBRARY_PATH` must be set before `dylint_libs` is called. - // smoelius: This was true when `dylint_libs` called `name_toolchain_map`, but that is - // no longer the case. I am leaving the comment here for now in case removal - // of the `name_toolchain_map` call causes a regression. - let metadata = dylint_internal::cargo::current_metadata().unwrap(); - let dylint_library_path = metadata.target_directory.join("debug"); - unsafe { - set_var(env::DYLINT_LIBRARY_PATH, dylint_library_path); - } - let dylint_libs = dylint_libs(name)?; let driver = dylint::driver_builder::get( &dylint::opts::Dylint::default(),