Skip to content
Open
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
4 changes: 2 additions & 2 deletions cargo-dylint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 24 additions & 18 deletions dylint/src/name_toolchain_map/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)? {
Expand All @@ -95,28 +96,33 @@ impl<'opts> Lazy<'opts> {
Ok(name_toolchain_map)
})
}
}

fn dylint_library_paths() -> Result<Vec<PathBuf>> {
let mut paths = Vec::new();
fn dylint_library_paths(&self) -> Result<Vec<PathBuf>> {
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(
Expand Down
4 changes: 1 addition & 3 deletions examples/general/crate_wide_allow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions utils/testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,6 @@ fn initialize(name: &str) -> &Result<PathBuf> {
.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(),
Expand Down