diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9be5460fc..82c75fc56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,8 +71,7 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ ~/.cargo/git/checkouts/ - ~/.dylint_drivers/ - target/dylint/libraries/ + ~/.dylint/cache/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Rustup diff --git a/CHANGELOG.md b/CHANGELOG.md index 984c9a9cc..0d40f6b73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ This file records user-facing changes to packages `cargo_dylint`, `dylint`, `dylint_driver`, `dylint-link`, `dylint_linting`, and `dylint_testing`. If a change to one of those packages is missing, please [open an issue](https://github.com/trailofbits/dylint/issues). +## Unreleased + +- FEATURE: Share compiler drivers and lint libraries across projects under `~/.dylint/cache`, with a `DYLINT_CACHE_DIR` override, compatible driver isolation, and automatic legacy cache migration without removing or overwriting existing data ([#2184](https://github.com/trailofbits/dylint/pull/2184), [#2142](https://github.com/trailofbits/dylint/issues/2142)) - [@dblock](https://github.com/dblock). +- Deprecate the driver-only `DYLINT_DRIVER_PATH` override in favor of `DYLINT_CACHE_DIR`, retaining its existing layout and precedence for drivers. + ## 6.4.0 - FEATURE: Provide prebuilt binaries for Windows (x86-64) ([a551885](https://github.com/trailofbits/dylint/commit/a551885129c49a1d410125b212b8ea1fa7586326)) diff --git a/README.md b/README.md index 5a0c3670b..9b9b752b8 100644 --- a/README.md +++ b/README.md @@ -216,11 +216,11 @@ In addition, we recommend caching these directories: ```yaml ~/.cargo/git/checkouts/ -~/.dylint_drivers/ +~/.dylint/cache/ ~/.rustup/toolchains/ ``` -Also, if you do not cache `target/`, we recommend at least caching `target/dylint/libraries/`. +Dylint shares compiler drivers and lint libraries across projects in `~/.dylint/cache/`. Override it with an absolute `DYLINT_CACHE_DIR` and cache that directory in CI. Legacy caches are preserved during automatic migration. Lint libraries share one cache per toolchain; `--no-build` does not validate their source. ## Utilities diff --git a/cargo-dylint/README.md b/cargo-dylint/README.md index c1a711a76..7557cfd07 100644 --- a/cargo-dylint/README.md +++ b/cargo-dylint/README.md @@ -216,11 +216,11 @@ In addition, we recommend caching these directories: ```yaml ~/.cargo/git/checkouts/ -~/.dylint_drivers/ +~/.dylint/cache/ ~/.rustup/toolchains/ ``` -Also, if you do not cache `target/`, we recommend at least caching `target/dylint/libraries/`. +Dylint shares compiler drivers and lint libraries across projects in `~/.dylint/cache/`. Override it with an absolute `DYLINT_CACHE_DIR` and cache that directory in CI. Legacy caches are preserved during automatic migration. Lint libraries share one cache per toolchain; `--no-build` does not validate their source. ## Utilities diff --git a/cargo-dylint/src/main.rs b/cargo-dylint/src/main.rs index f5c01256a..81d8dc04c 100644 --- a/cargo-dylint/src/main.rs +++ b/cargo-dylint/src/main.rs @@ -20,10 +20,14 @@ enum CargoSubcommand { args_conflicts_with_subcommands = true, after_help = r#"ENVIRONMENT VARIABLES: +DYLINT_CACHE_DIR (default: $HOME/.dylint/cache) is an absolute directory for all cached compiler +drivers and lint libraries. It is created as needed; libraries use libraries//release/. + DYLINT_CLIPPY_REPO (default: none) is a path to a Dylint-exclusive clone of the Clippy repository. -DYLINT_DRIVER_PATH (default: $HOME/.dylint_drivers) is the directory where Dylint stores rustc -drivers. +DYLINT_DRIVER_PATH (deprecated, default: none) overrides only the compiler driver directory, with +one subdirectory per toolchain. It takes precedence over DYLINT_CACHE_DIR for drivers only. +Prefer DYLINT_CACHE_DIR to relocate all cached artifacts. 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. diff --git a/cargo-dylint/tests/integration/dylint_driver_path.rs b/cargo-dylint/tests/integration/dylint_driver_path.rs index 6bcd0773a..ee5863200 100644 --- a/cargo-dylint/tests/integration/dylint_driver_path.rs +++ b/cargo-dylint/tests/integration/dylint_driver_path.rs @@ -1,11 +1,18 @@ +use super::dylint_with_home; +use assert_cmd::cargo::cargo_bin_cmd; use dylint_internal::{ CommandExt, cargo, driver as dylint_driver, env, - rustup::{SanitizeEnvironment, toolchain_path}, - testing::new_template, + rustup::{SanitizeEnvironment, active_toolchain, toolchain_path}, + testing::{copy_dir, new_template}, }; -use std::fs::create_dir_all; -use tempfile::tempdir_in; +use predicates::prelude::*; +use std::{ + fs::{create_dir_all, read_dir, rename}, + path::Path, +}; +use tempfile::{tempdir, tempdir_in}; +#[allow(deprecated)] #[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))] #[test] fn dylint_driver_path() { @@ -36,3 +43,75 @@ fn dylint_driver_path() { .unwrap(); command.success().unwrap(); } + +#[test] +#[allow(deprecated)] +#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))] +fn cache_dir_relocates_artifacts() { + let home = tempdir().unwrap(); + let fixture = tempdir_in("../fixtures").unwrap(); + copy_dir( + Path::new("../fixtures/library_packages_in_dylint_toml"), + fixture.path(), + ) + .unwrap(); + let root = tempdir().unwrap(); + let cache = root.path().join("custom cache"); + let command = |cache: &Path| { + let mut command = dylint_with_home(home.path()); + command + .current_dir(&fixture) + .env(env::DYLINT_CACHE_DIR, cache) + .env_remove(env::DYLINT_DRIVER_PATH) + .env(env::CARGO_TARGET_DIR, fixture.path().join("target")) + .env_remove(env::CARGO_BUILD_BUILD_DIR) + .args(["dylint", "--all"]); + command + }; + + command(&cache) + .assert() + .success() + .stderr(predicate::str::contains("DYLINT_DRIVER_PATH").not()); + assert!(!home.path().join(".dylint").exists()); + let drivers = read_dir(cache.join("dylint-driver")) + .unwrap() + .map(|entry| entry.unwrap().path()) + .find(|path| path.is_dir()) + .unwrap(); + let toolchain = + active_toolchain(Path::new("../examples/restriction/collapsible_unwrap")).unwrap(); + assert!(drivers.join(toolchain).join("dylint-driver").is_file()); + assert!(cache.join("libraries").is_dir()); + + let other_cache = root.path().join("another cache"); + create_dir_all(&other_cache).unwrap(); + rename(cache.join("libraries"), other_cache.join("libraries")).unwrap(); + command(&other_cache) + .env(env::DYLINT_DRIVER_PATH, &drivers) + .arg("--no-build") + .assert() + .success() + .stderr(predicate::str::contains( + "`DYLINT_DRIVER_PATH` is deprecated", + )); + assert!(!other_cache.join("dylint-driver").exists()); + assert!(!home.path().join(".dylint").exists()); +} + +#[test] +#[allow(deprecated)] +fn cache_dir_requires_absolute_path() { + for path in ["", "relative-cache"] { + cargo_bin_cmd!("cargo-dylint") + .current_dir("../fixtures/library_packages_in_dylint_toml") + .env(env::DYLINT_CACHE_DIR, path) + .env_remove(env::DYLINT_DRIVER_PATH) + .args(["dylint", "list", "--all", "--no-build"]) + .assert() + .failure() + .stderr(predicate::str::contains( + "`DYLINT_CACHE_DIR` must be an absolute path", + )); + } +} diff --git a/cargo-dylint/tests/integration/library_packages.rs b/cargo-dylint/tests/integration/library_packages.rs index fe3556725..d32402963 100644 --- a/cargo-dylint/tests/integration/library_packages.rs +++ b/cargo-dylint/tests/integration/library_packages.rs @@ -1,7 +1,15 @@ +use super::{dylint_with_home, installed_driver_directory}; use assert_cmd::cargo::cargo_bin_cmd; -use dylint_internal::{CommandExt, cargo, env, packaging::isolate, testing::copy_dir}; +use dylint_internal::{ + CommandExt, cargo, env, library_filename_with_toolchain, packaging::isolate, + rustup::active_toolchain, testing::copy_dir, +}; use predicates::prelude::*; -use std::{fs::OpenOptions, io::Write, path::Path}; +use std::{ + fs::{OpenOptions, create_dir_all, read_to_string, rename, write}, + io::Write, + path::Path, +}; use tempfile::{tempdir, tempdir_in}; // smoelius: "Separate lints into categories" commit @@ -152,6 +160,188 @@ fn library_packages_with_configured_build_directory_and_dylint_link() { )); } +#[test] +fn libraries_dir_shared_across_workspaces() { + libraries_dir_shared_across_workspaces_inner(false); +} + +#[test] +fn libraries_dir_with_configured_build_directory_and_dylint_link() { + libraries_dir_shared_across_workspaces_inner(true); +} + +fn libraries_dir_shared_across_workspaces_inner(copy_with_dylint_link: bool) { + let cache = tempdir().unwrap(); + let home = cache.path().join("shared home"); + let libraries_directory = home.join(".dylint/cache/libraries"); + let build_directory = tempdir().unwrap(); + let toolchain = + active_toolchain(Path::new("../examples/restriction/collapsible_unwrap")).unwrap(); + for first_build in [true, false] { + let temp_fixture = tempdir_in("../fixtures").unwrap(); + copy_dir( + Path::new("../fixtures/library_packages_in_dylint_toml"), + temp_fixture.path(), + ) + .unwrap(); + let target_directory = temp_fixture.path().join("target"); + + let command = || { + let mut command = dylint_with_home(&home); + command + .current_dir(&temp_fixture) + .env(env::CARGO_TARGET_DIR, &target_directory) + .env( + env::DYLINT_LINK_ENABLE_COPY_LIBRARY, + if copy_with_dylint_link { "1" } else { "0" }, + ) + .env_remove(env::CARGO_BUILD_BUILD_DIR); + if copy_with_dylint_link { + command.env(env::CARGO_BUILD_BUILD_DIR, build_directory.path()); + } + command + }; + let assert = command() + .args(["dylint", "--all"]) + .assert() + .success() + .stderr(predicate::str::contains( + "\nwarning: `unwrap`s that could be combined\n", + )); + if first_build { + assert.stderr(predicate::str::contains("Compiling collapsible_unwrap")); + } else { + assert.stderr(predicate::str::contains("Compiling collapsible_unwrap").not()); + } + assert!(!target_directory.join("dylint/libraries").exists()); + assert!( + libraries_directory + .join(&toolchain) + .join("release") + .join(library_filename_with_toolchain( + "collapsible_unwrap", + &toolchain + ),) + .is_file() + ); + + command() + .args(["dylint", "list", "--all", "--no-build"]) + .assert() + .success() + .stdout(predicate::str::contains("collapsible_unwrap")); + } +} + +#[test] +#[allow(deprecated)] +#[cfg_attr( + dylint_lib = "general", + allow( + non_thread_safe_call_in_test, + reason = "All writes use private temporary directories" + ) +)] +fn default_cache_migration_and_reuse() { + let home = tempdir_in("../fixtures").unwrap(); + let fixtures = [ + tempdir_in("../fixtures").unwrap(), + tempdir_in("../fixtures").unwrap(), + ]; + for fixture in &fixtures { + copy_dir( + Path::new("../fixtures/library_packages_in_dylint_toml"), + fixture.path(), + ) + .unwrap(); + } + let legacy_drivers = home.path().join(".dylint_drivers"); + let legacy_libraries = fixtures[0].path().join("target/dylint/libraries"); + let toolchain = + active_toolchain(Path::new("../examples/restriction/collapsible_unwrap")).unwrap(); + + let installed_drivers = installed_driver_directory(); + let command = |fixture: &Path| { + let mut command = dylint_with_home(home.path()); + command + .current_dir(fixture) + .env(env::CARGO_TARGET_DIR, fixture.join("target")) + .env(env::DYLINT_LINK_ENABLE_COPY_LIBRARY, "0") + .env_remove(env::CARGO_BUILD_BUILD_DIR) + .env_remove(env::DYLINT_DRIVER_PATH) + .args(["dylint", "--all"]); + command + }; + command(fixtures[0].path()) + .env(env::DYLINT_DRIVER_PATH, &installed_drivers) + .assert() + .success(); + let legacy_driver = legacy_drivers.join(&toolchain); + create_dir_all(&legacy_driver).unwrap(); + copy_dir(&installed_drivers.join(&toolchain), &legacy_driver).unwrap(); + assert!(!home.path().join(".dylint/cache/dylint-driver").exists()); + let other_driver = home + .path() + .join(".dylint/cache/dylint-driver/0.0.0") + .join(&toolchain); + create_dir_all(&other_driver).unwrap(); + write(other_driver.join("dylint-driver"), "another installation").unwrap(); + + let legacy_toolchain = legacy_libraries.join(&toolchain); + let partition = home.path().join(".dylint/cache/libraries").join(&toolchain); + create_dir_all(&legacy_libraries).unwrap(); + rename(&partition, &legacy_toolchain).unwrap(); + + command(fixtures[0].path()) + .arg("--no-build") + .assert() + .success(); + for (index, fixture) in fixtures.iter().enumerate() { + let assert = command(fixture.path()).assert().success().stderr( + predicate::str::contains("\nwarning: `unwrap`s that could be combined\n") + .and(predicate::str::contains("Building driver").not()), + ); + if index == 0 { + assert.stderr(predicate::str::contains("Compiling clippy_utils").not()); + } else { + assert.stderr(predicate::str::contains("Compiling").not()); + } + } + let driver = Path::new(&toolchain).join("dylint-driver"); + assert!(legacy_drivers.join(&driver).is_file()); + let identity = read_to_string(legacy_driver.join("dylint-build-id")).unwrap(); + assert!( + home.path() + .join(".dylint/cache/dylint-driver") + .join(identity) + .join(driver) + .is_file() + ); + assert_eq!( + "another installation", + read_to_string(other_driver.join("dylint-driver")).unwrap() + ); + let library = Path::new(&toolchain) + .join("release") + .join(library_filename_with_toolchain( + "collapsible_unwrap", + &toolchain, + )); + assert!(legacy_libraries.join(&library).is_file()); + assert!( + home.path() + .join(".dylint/cache/libraries") + .join(&toolchain) + .join("release") + .join(library_filename_with_toolchain( + "collapsible_unwrap", + &toolchain, + )) + .is_file() + ); + assert!(!fixtures[1].path().join("target/dylint/libraries").exists()); +} + #[test] fn library_packages_with_rust_toolchain() { let tempdir = tempdir().unwrap(); @@ -202,7 +392,7 @@ pattern = "examples/general/crate_wide_allow" ) .unwrap(); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(tempdir.path()) .current_dir(&tempdir) .args(["dylint", "list"]) .assert() @@ -246,14 +436,14 @@ fn metadata_change() { ) .unwrap(); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(tempdir.path()) .current_dir(&tempdir) .args(["dylint", "--all"]) .assert() .success() .stderr(predicate::str::contains("Checking metadata_change_test")); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(tempdir.path()) .current_dir(&tempdir) .args(["dylint", "--all"]) .assert() @@ -277,7 +467,7 @@ fn metadata_change() { ) .unwrap(); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(tempdir.path()) .current_dir(&tempdir) .args(["dylint", "--all"]) .assert() @@ -475,14 +665,14 @@ path = {path_spec} ) .unwrap(); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(tempdir.path()) .current_dir(&tempdir) .args(["dylint", "--all"]) .assert() .success() .stderr(predicate::str::contains("Compiling")); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(tempdir.path()) .current_dir(&tempdir) .env(env::RUSTFLAGS, "--verbose") .args(["dylint", "--all"]) diff --git a/cargo-dylint/tests/integration/list.rs b/cargo-dylint/tests/integration/list.rs index bafee5326..831ba7912 100644 --- a/cargo-dylint/tests/integration/list.rs +++ b/cargo-dylint/tests/integration/list.rs @@ -2,6 +2,7 @@ // safe to run these tests under `cargo-llvm-cov`. // #![cfg(not(coverage))] +use super::dylint_with_home; use anyhow::{Context, Result}; use assert_cmd::{ assert::OutputAssertExt, @@ -20,7 +21,7 @@ use predicates::prelude::*; use std::{ ffi::OsStr, fmt::Write as _, - fs::{OpenOptions, create_dir_all}, + fs::OpenOptions, io::Write, path::{Path, PathBuf}, }; @@ -51,19 +52,18 @@ fn metadata_and_lib_path_are_deduplicated() { // where symlink creation can require additional privileges. The Windows case checks // deduplication without exercising alias resolution. #[cfg(unix)] - std::os::unix::fs::symlink(&target_dir, manifest_dir.path().join("target")).unwrap(); + std::os::unix::fs::symlink(&target_dir, manifest_dir.path().join(".dylint")).unwrap(); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(manifest_dir.path()) .current_dir(&manifest_dir) .args(["dylint", "list", "--all"]) .assert() .success(); - let library_path = target_libraries_directory(manifest_dir.path(), &toolchain) - .unwrap() + let library_path = cached_libraries_directory(manifest_dir.path(), &toolchain) .join(library_filename_with_toolchain("fill_me_in", &toolchain)); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(manifest_dir.path()) .current_dir(&manifest_dir) .args(["dylint", "list", "--all", "--no-build", "--lib-path"]) .arg(&library_path) @@ -232,7 +232,7 @@ fn output_path_collision() { append_workspace_metadata(manifest_dir.path(), [tempdirs.0.path(), tempdirs.1.path()]).unwrap(); - cargo_bin_cmd!("cargo-dylint") + dylint_with_home(manifest_dir.path()) .current_dir(&manifest_dir) .args(["dylint", "list", "--all"]) .assert() @@ -282,29 +282,25 @@ fn relative_path() { ) .unwrap(); - let libraries_dir = target_libraries_directory(tempdirs.2.path(), &toolchain).unwrap(); - - // smoelius: `libraries_dir` might not exist yet. - create_dir_all(&libraries_dir).unwrap(); - - let canonical_path = libraries_dir.canonicalize().unwrap(); - - // smoelius: On Windows, `tempdir.path()` must be canonicalized to ensure it has a path - // prefix. Otherwise, the call to `strip_prefix` could fail. - let relative_path = canonical_path - .strip_prefix(tempdirs.2.path().canonicalize().unwrap()) - .unwrap(); - - cargo_bin_cmd!("cargo-dylint") + let assert = dylint_with_home(tempdirs.2.path()) .current_dir(&tempdirs.2) .args(["dylint", "list", "--all"]) .assert() - .success() - .stdout( - predicate::str::contains(format!("fill_me_in ({})", relative_path.display())).and( - predicate::str::contains(format!("{lib_name} ({})", relative_path.display())), - ), - ); + .success(); + + let canonical_path = cached_libraries_directory(tempdirs.2.path(), &toolchain) + .canonicalize() + .unwrap(); + // dblock: Canonicalize both paths to preserve Windows path prefixes. + let relative_path = canonical_path + .strip_prefix(tempdirs.2.path().canonicalize().unwrap()) + .unwrap() + .to_path_buf(); + assert.stdout( + predicate::str::contains(format!("fill_me_in ({})", relative_path.display())).and( + predicate::str::contains(format!("{lib_name} ({})", relative_path.display())), + ), + ); } fn append_workspace_metadata<'a>( @@ -377,12 +373,10 @@ fn target_debug(dir: &Path) -> Result { // smoelius: Hack. This function duplicates logic from, e.g., // `dylint::library_packages::Package::library_path_with_toolchain`. -fn target_libraries_directory(dir: &Path, toolchain: &str) -> Result { - let target_directory = target_directory(dir)?; - Ok(target_directory - .join("dylint/libraries") +fn cached_libraries_directory(home: &Path, toolchain: &str) -> PathBuf { + home.join(".dylint/cache/libraries") .join(toolchain) - .join("release")) + .join("release") } fn target_directory(dir: &Path) -> Result { diff --git a/cargo-dylint/tests/integration/main.rs b/cargo-dylint/tests/integration/main.rs index c1fe21285..84504ca32 100644 --- a/cargo-dylint/tests/integration/main.rs +++ b/cargo-dylint/tests/integration/main.rs @@ -1,13 +1,53 @@ #![cfg_attr(dylint_lib = "general", allow(crate_wide_allow))] #![cfg_attr(dylint_lib = "supplementary", allow(nonexistent_path_in_comment))] +use assert_cmd::{Command, cargo::cargo_bin_cmd}; +use dylint_internal::{env, home::cargo_home, rustup::active_toolchain}; +use std::{ + path::{Path, PathBuf}, + sync::LazyLock, +}; + #[ctor::ctor(unsafe)] fn initialize() { unsafe { - std::env::remove_var(dylint_internal::env::CARGO_TERM_COLOR); + std::env::remove_var(env::CARGO_TERM_COLOR); } } +#[allow(deprecated)] +fn dylint_with_home(home: &Path) -> Command { + let original_home = std::env::home_dir().unwrap(); + let rustup_home = std::env::var_os(env::RUSTUP_HOME) + .map_or_else(|| original_home.join(".rustup"), Into::into); + // dblock: Isolate libraries without rebuilding installed drivers for every test. + let drivers = installed_driver_directory(); + let mut command = cargo_bin_cmd!("cargo-dylint"); + command + .env("HOME", home) + .env("USERPROFILE", home) + .env(env::CARGO_HOME, cargo_home().unwrap()) + .env(env::RUSTUP_HOME, rustup_home) + .env_remove(env::DYLINT_CACHE_DIR) + .env(env::DYLINT_DRIVER_PATH, drivers); + command +} + +fn installed_driver_directory() -> PathBuf { + static DIRECTORY: LazyLock = LazyLock::new(|| { + let toolchain = + active_toolchain(Path::new("../examples/restriction/collapsible_unwrap")).unwrap(); + let driver = + dylint::driver_builder::get(&dylint::opts::Dylint::default(), &toolchain).unwrap(); + driver + .parent() + .and_then(Path::parent) + .unwrap() + .to_path_buf() + }); + DIRECTORY.clone() +} + mod depinfo; mod dylint_driver_path; mod fix; diff --git a/dylint/Cargo.toml b/dylint/Cargo.toml index 487102dd8..a8736d06b 100644 --- a/dylint/Cargo.toml +++ b/dylint/Cargo.toml @@ -17,7 +17,7 @@ cargo-util-schemas = { workspace = true, optional = true } cargo_metadata = { workspace = true } chrono = { workspace = true, optional = true } dunce = { workspace = true } -fs_extra = { workspace = true, optional = true } +fs_extra = { workspace = true } glob = { workspace = true, optional = true } heck = { workspace = true, optional = true } hex = { workspace = true, optional = true } @@ -84,7 +84,6 @@ __cargo_cli = [ "cargo-util", "cargo-util-schemas", "dylint_internal/home", - "fs_extra", "glob", "hex", "rustc-stable-hash", diff --git a/dylint/README.md b/dylint/README.md index c1a711a76..7557cfd07 100644 --- a/dylint/README.md +++ b/dylint/README.md @@ -216,11 +216,11 @@ In addition, we recommend caching these directories: ```yaml ~/.cargo/git/checkouts/ -~/.dylint_drivers/ +~/.dylint/cache/ ~/.rustup/toolchains/ ``` -Also, if you do not cache `target/`, we recommend at least caching `target/dylint/libraries/`. +Dylint shares compiler drivers and lint libraries across projects in `~/.dylint/cache/`. Override it with an absolute `DYLINT_CACHE_DIR` and cache that directory in CI. Legacy caches are preserved during automatic migration. Lint libraries share one cache per toolchain; `--no-build` does not validate their source. ## Utilities diff --git a/dylint/build.rs b/dylint/build.rs index 6f73e2ba8..2b89cee1c 100644 --- a/dylint/build.rs +++ b/dylint/build.rs @@ -1,5 +1,10 @@ use dylint_internal::{cargo::cargo_home, env}; -use std::{fs::OpenOptions, io::Write, path::Path}; +use std::{ + fs::{OpenOptions, read, read_dir}, + hash::{DefaultHasher, Hash, Hasher}, + io::Write, + path::Path, +}; fn main() { write_dylint_driver_manifest_dir(); @@ -17,15 +22,13 @@ fn write_dylint_driver_manifest_dir() { #[cfg_attr(dylint_lib = "general", allow(abs_home_path))] let dylint_manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); - let dylint_driver_manifest_dir = if cfg!(feature = "__driver_from_crates_io") + let local_driver = !(cfg!(feature = "__driver_from_crates_io") || dylint_manifest_dir.starts_with(cargo_home) || dylint_manifest_dir .parent() .is_some_and(|path| path.ends_with("target/package")) - || env::var(env::DOCS_RS).is_ok() - { - "None".to_owned() - } else { + || env::var(env::DOCS_RS).is_ok()); + let dylint_driver_manifest_dir = if local_driver { let path_buf = dylint_manifest_dir.join("../driver"); // smoelius: Ensure the path exists at build time. @@ -36,6 +39,8 @@ fn write_dylint_driver_manifest_dir() { ); format!("Some({:?})", path_buf.to_string_lossy()) + } else { + "None".to_owned() }; let mut file = OpenOptions::new() @@ -50,4 +55,46 @@ fn write_dylint_driver_manifest_dir() { const DYLINT_DRIVER_MANIFEST_DIR: Option<&str> = {dylint_driver_manifest_dir};"# ) .unwrap(); + let version = env!("CARGO_PKG_VERSION"); + let key = if local_driver { + let mut hasher = DefaultHasher::new(); + let root = dylint_manifest_dir.parent().unwrap(); + root.canonicalize().unwrap().hash(&mut hasher); + for path in [ + "Cargo.toml", + "Cargo.lock", + "dylint/build.rs", + "dylint/src/driver_builder", + "driver/Cargo.toml", + "driver/Cargo.lock", + "driver/src", + "driver/build", + "internal/Cargo.toml", + "internal/build.rs", + "internal/src", + ] { + hash_driver_source(&root.join(path), &mut hasher); + } + format!("{version}-dev-{:016x}", hasher.finish()) + } else { + version.to_owned() + }; + writeln!(file, "const DYLINT_DRIVER_CACHE_KEY: &str = {key:?};").unwrap(); +} + +fn hash_driver_source(path: &Path, hasher: &mut DefaultHasher) { + println!("cargo:rerun-if-changed={}", path.display()); + path.hash(hasher); + if path.is_dir() { + let mut paths = read_dir(path) + .unwrap() + .map(|entry| entry.unwrap().path()) + .collect::>(); + paths.sort(); + for path in paths { + hash_driver_source(&path, hasher); + } + } else { + read(path).unwrap().hash(hasher); + } } diff --git a/dylint/src/cache.rs b/dylint/src/cache.rs new file mode 100644 index 000000000..561630ef8 --- /dev/null +++ b/dylint/src/cache.rs @@ -0,0 +1,272 @@ +use crate::flock; +use anyhow::{Context, Result, anyhow, ensure}; +use dylint_internal::env; +use std::{ + env::{home_dir, var_os}, + fs::{File, create_dir_all, read_dir, rename}, + path::{Path, PathBuf}, +}; +use tempfile::tempdir_in; + +pub const DRIVER_PACKAGE: &str = "dylint-driver"; + +pub fn directory(name: &str) -> Result { + let root = if let Some(directory) = var_os(env::DYLINT_CACHE_DIR) { + let directory = PathBuf::from(directory); + ensure!( + directory.is_absolute(), + "`DYLINT_CACHE_DIR` must be an absolute path, got `{}`", + directory.display() + ); + directory + } else { + let home = home_dir().ok_or_else(|| anyhow!("Could not find HOME directory"))?; + home.join(".dylint/cache") + }; + Ok(root.join(name)) +} + +#[cfg(any(feature = "__cargo_cli", test))] +pub(crate) fn migrate(source: &Path, destination: &Path) -> Result<()> { + migrate_with(source, destination, |_| Ok(true)) +} + +pub(crate) fn migrate_with( + source: &Path, + destination: &Path, + prepare: impl FnOnce(&Path) -> Result, +) -> Result<()> { + if destination + .try_exists() + .with_context(|| format!("Could not inspect cache `{}`", destination.display()))? + || !source.is_dir() + { + return Ok(()); + } + + let parent = destination + .parent() + .ok_or_else(|| anyhow!("Could not find cache parent directory"))?; + create_dir_all(parent) + .with_context(|| format!("Could not create cache directory `{}`", parent.display()))?; + let _destination_lock = flock::lock_path(parent) + .with_context(|| format!("Could not lock cache directory `{}`", parent.display()))?; + if destination + .try_exists() + .with_context(|| format!("Could not inspect cache `{}`", destination.display()))? + { + return Ok(()); + } + + // dblock: Coordinate with legacy Cargo builds or driver installation while copying. + let cargo_lock = source.join("release/.cargo-lock"); + let _source_lock = if cargo_lock.is_file() { + flock::lock_file(&cargo_lock) + .with_context(|| format!("Could not lock legacy cache `{}`", cargo_lock.display()))? + } else { + flock::lock_path(source) + .with_context(|| format!("Could not lock legacy cache `{}`", source.display()))? + }; + let staging = tempdir_in(parent).with_context(|| { + format!( + "Could not create staging directory in `{}`", + parent.display() + ) + })?; + let mut options = fs_extra::dir::CopyOptions::new(); + options.content_only = true; + fs_extra::dir::copy(source, &staging, &options).with_context(|| { + format!( + "Could not migrate cache from `{}` to `{}`", + source.display(), + destination.display() + ) + })?; + preserve_modified_times(source, staging.path())?; + if !prepare(staging.path())? { + return Ok(()); + } + if let Err(error) = rename(&staging, destination) + && !destination.is_dir() + { + return Err(error) + .with_context(|| format!("Could not install cache at `{}`", destination.display())); + } + Ok(()) +} + +fn preserve_modified_times(source: &Path, destination: &Path) -> Result<()> { + let entries = read_dir(source) + .with_context(|| format!("Could not read legacy cache `{}`", source.display()))?; + for entry in entries { + let entry = + entry.with_context(|| format!("Could not read legacy cache `{}`", source.display()))?; + let source = entry.path(); + let destination = destination.join(entry.file_name()); + let metadata = entry + .metadata() + .with_context(|| format!("Could not inspect legacy cache `{}`", source.display()))?; + if metadata.is_dir() { + preserve_modified_times(&source, &destination)?; + } else { + let modified = metadata.modified().with_context(|| { + format!("Could not read cache timestamp `{}`", source.display()) + })?; + let mut options = File::options(); + options.read(true); + #[cfg(windows)] + { + use std::os::windows::fs::OpenOptionsExt; + use windows_sys::Win32::Storage::FileSystem::FILE_WRITE_ATTRIBUTES; + + options.access_mode(FILE_WRITE_ATTRIBUTES); + } + let file = options.open(&destination).with_context(|| { + format!("Could not open cache file `{}`", destination.display()) + })?; + file.set_modified(modified).with_context(|| { + format!( + "Could not preserve cache timestamp `{}`", + destination.display() + ) + })?; + } + } + Ok(()) +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +#[cfg_attr( + dylint_lib = "general", + allow( + non_thread_safe_call_in_test, + reason = "All writes use private temporary directories" + ) +)] +mod tests { + use super::*; + use dylint_internal::{library_filename_with_toolchain, library_plain_filename}; + use std::{ + fs::{read, write}, + thread, + time::UNIX_EPOCH, + }; + use tempfile::tempdir; + + #[test] + fn migration_preserves_legacy_cache_and_existing_destination() { + let root = tempdir().unwrap(); + let source = root.path().join("legacy/toolchain"); + let destination = root.path().join("new/toolchain"); + create_dir_all(source.join("release")).unwrap(); + write(source.join("release/library"), "legacy").unwrap(); + File::options() + .write(true) + .open(source.join("release/library")) + .and_then(|file| file.set_modified(UNIX_EPOCH)) + .unwrap(); + + migrate(&source, &destination).unwrap(); + assert_eq!( + UNIX_EPOCH, + destination + .join("release/library") + .metadata() + .and_then(|metadata| metadata.modified()) + .unwrap() + ); + assert_eq!( + b"legacy", + read(destination.join("release/library")) + .unwrap() + .as_slice() + ); + assert_eq!( + b"legacy", + read(source.join("release/library")).unwrap().as_slice() + ); + + write(source.join("release/library"), "changed legacy").unwrap(); + write(destination.join("release/library"), "new").unwrap(); + migrate(&source, &destination).unwrap(); + assert_eq!( + b"new", + read(destination.join("release/library")) + .unwrap() + .as_slice() + ); + } + + #[test] + fn concurrent_migrations_publish_one_complete_cache() { + let root = tempdir().unwrap(); + let source = root.path().join("legacy/toolchain"); + let destination = root.path().join("new/toolchain"); + create_dir_all(source.join("release")).unwrap(); + write(source.join("release/.cargo-lock"), "").unwrap(); + write(source.join("release/library"), "library").unwrap(); + + thread::scope(|scope| { + for _ in 0..2 { + scope.spawn(|| migrate(&source, &destination).unwrap()); + } + }); + assert_eq!( + b"library", + read(destination.join("release/library")) + .unwrap() + .as_slice() + ); + } + + #[test] + fn missing_legacy_cache_does_not_create_destination() { + let root = tempdir().unwrap(); + let destination = root.path().join("new/toolchain"); + migrate(&root.path().join("missing"), &destination).unwrap(); + assert!(!destination.exists()); + } + + #[test] + fn rejected_legacy_cache_is_not_published() { + let root = tempdir().unwrap(); + let source = root.path().join("legacy/toolchain"); + let destination = root.path().join("new/version/toolchain"); + create_dir_all(&source).unwrap(); + write(source.join("dylint-driver"), "incompatible driver").unwrap(); + + migrate_with(&source, &destination, |_| Ok(false)).unwrap(); + assert!(!destination.exists()); + assert!(source.join("dylint-driver").is_file()); + + migrate_with(&source, &destination, |_| Ok(true)).unwrap(); + assert!(destination.join("dylint-driver").is_file()); + } + + #[test] + fn migration_preserves_library_outputs_and_dependencies() { + let root = tempdir().unwrap(); + let source = root.path().join("legacy/toolchain"); + let destination = root.path().join("new/libraries/toolchain"); + let plain = Path::new("release").join(library_plain_filename("library")); + let tagged = + Path::new("release").join(library_filename_with_toolchain("library", "toolchain")); + create_dir_all(source.join("release/deps")).unwrap(); + write(source.join(&plain), "library").unwrap(); + write(source.join(&tagged), "library").unwrap(); + write(source.join("release/deps/dependency"), "dependency").unwrap(); + migrate(&source, &destination).unwrap(); + assert_eq!( + b"library", + read(destination.join(&plain)).unwrap().as_slice() + ); + assert_eq!( + b"library", + read(destination.join(&tagged)).unwrap().as_slice() + ); + assert!(destination.join("release/deps/dependency").is_file()); + assert!(source.join(plain).is_file()); + assert!(source.join(tagged).is_file()); + } +} diff --git a/dylint/src/driver_builder/mod.rs b/dylint/src/driver_builder/mod.rs index e44aafa50..2791a7628 100644 --- a/dylint/src/driver_builder/mod.rs +++ b/dylint/src/driver_builder/mod.rs @@ -1,4 +1,4 @@ -use crate::{error::warn, opts}; +use crate::{cache, error::warn, flock, opts}; use anyhow::{Context, Result, anyhow, ensure}; use dylint_internal::{ CommandExt, cargo, driver as dylint_driver, env, @@ -7,13 +7,11 @@ use dylint_internal::{ use semver::Version; use std::{ env::{consts, home_dir}, - fs::{copy, create_dir_all, rename, write}, + fs::{copy, create_dir_all, read_to_string, rename, write}, path::{Path, PathBuf}, }; use tempfile::{NamedTempFile, tempdir}; -mod flock; - include!(concat!(env!("OUT_DIR"), "/dylint_driver_manifest_dir.rs")); const README_TXT: &str = " @@ -46,7 +44,7 @@ pub fn main() -> Result<()> { allow(question_mark_in_expression) )] pub fn get(opts: &opts::Dylint, toolchain: &str) -> Result { - let dylint_drivers = dylint_drivers()?; + let dylint_drivers = dylint_drivers(opts, toolchain)?; let driver_dir = dylint_drivers.join(toolchain); if !driver_dir.is_dir() { @@ -66,26 +64,39 @@ pub fn get(opts: &opts::Dylint, toolchain: &str) -> Result { Ok(driver) } -fn dylint_drivers() -> Result { +fn dylint_drivers(opts: &opts::Dylint, toolchain: &str) -> Result { + #[allow(deprecated)] if let Ok(dylint_driver_path) = env::var(env::DYLINT_DRIVER_PATH) { + warn( + opts, + "`DYLINT_DRIVER_PATH` is deprecated; use `DYLINT_CACHE_DIR` to relocate all cached artifacts", + ); let dylint_drivers = Path::new(&dylint_driver_path); ensure!(dylint_drivers.is_dir()); Ok(dylint_drivers.to_path_buf()) } else { - let home = home_dir().ok_or_else(|| anyhow!("Could not find HOME directory"))?; - let dylint_drivers = Path::new(&home).join(".dylint_drivers"); - if !dylint_drivers.is_dir() { - create_dir_all(&dylint_drivers).with_context(|| { - format!( - "`create_dir_all` failed for `{}`", - dylint_drivers.to_string_lossy() - ) + let root = cache::directory(cache::DRIVER_PACKAGE)?; + if !root.is_dir() { + create_dir_all(&root).with_context(|| { + format!("`create_dir_all` failed for `{}`", root.to_string_lossy()) })?; - let readme_txt = dylint_drivers.join("README.txt"); + let readme_txt = root.join("README.txt"); write(&readme_txt, README_TXT).with_context(|| { format!("`write` failed for `{}`", readme_txt.to_string_lossy()) })?; } + let dylint_drivers = root.join(DYLINT_DRIVER_CACHE_KEY); + if let Some(home) = home_dir() { + cache::migrate_with( + &home.join(".dylint_drivers").join(toolchain), + &dylint_drivers.join(toolchain), + |staging| { + let driver = staging.join("dylint-driver"); + let outdated = is_outdated(opts, toolchain, &driver)?; + Ok(!outdated) + }, + )?; + } Ok(dylint_drivers) } } @@ -94,6 +105,7 @@ fn is_outdated(opts: &opts::Dylint, toolchain: &str, driver: &Path) -> Result Result { let mut command = dylint_driver(toolchain, driver)?; let output = command.args(["-V"]).logged_output(true)?; + ensure!(output.status.success(), "Could not run cached driver"); let stdout = std::str::from_utf8(&output.stdout)?; let theirs = stdout .trim_end() @@ -105,8 +117,13 @@ fn is_outdated(opts: &opts::Dylint, toolchain: &str, driver: &Path) -> Result Result) -> bool { + ours == theirs && identity.map_or_else(|| key == ours.to_string(), |identity| identity == key) +} + #[cfg_attr(dylint_lib = "supplementary", allow(commented_out_code))] fn build(opts: &opts::Dylint, toolchain: &str, driver_dir: &Path) -> Result<()> { let tempdir = tempdir().with_context(|| "`tempdir` failed")?; @@ -180,6 +201,9 @@ fn build(opts: &opts::Dylint, toolchain: &str, driver_dir: &Path) -> Result<()> // smoelius: Close the writable handle (via `into_temp_path`) before renaming the file and // dropping the lock. If another process tries to execute the file while this one still holds a // writable handle, that other process will get "Text file busy". + let identity = driver_dir.join("dylint-build-id"); + write(&identity, DYLINT_DRIVER_CACHE_KEY) + .with_context(|| format!("Could not write driver identity `{}`", identity.display()))?; named_temp_file.into_temp_path().persist(&driver)?; drop(lock); @@ -249,6 +273,34 @@ components = ["llvm-tools-preview", "rustc-dev"] mod tests { use super::*; + #[test] + fn driver_versions_and_development_identities_must_match() { + let version = Version::new(6, 4, 0); + assert!(driver_matches(&version, &version, "6.4.0", None)); + for other in [Version::new(6, 3, 0), Version::new(6, 5, 0)] { + assert!(!driver_matches(&version, &other, "6.4.0", None)); + } + assert!(!driver_matches(&version, &version, "6.4.0-dev-a", None)); + assert!(!driver_matches( + &version, + &version, + "6.4.0-dev-a", + Some("6.4.0-dev-b") + )); + assert!(!driver_matches( + &version, + &version, + "6.4.0", + Some("6.4.0-dev-a") + )); + assert!(driver_matches( + &version, + &version, + "6.4.0-dev-a", + Some("6.4.0-dev-a") + )); + } + // smoelius: `tempdir` is a temporary directory. So there should be no race here. #[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))] #[cfg(not(feature = "__driver_from_crates_io"))] diff --git a/dylint/src/driver_builder/flock.rs b/dylint/src/flock.rs similarity index 93% rename from dylint/src/driver_builder/flock.rs rename to dylint/src/flock.rs index e065c1be8..ff56bcbe4 100644 --- a/dylint/src/driver_builder/flock.rs +++ b/dylint/src/flock.rs @@ -12,6 +12,12 @@ pub fn lock_path(path: &Path) -> Result { Ok(file) } +pub fn lock_file(path: &Path) -> Result { + let file = OpenOptions::new().read(true).write(true).open(path)?; + sys::lock_exclusive(&file)?; + Ok(file) +} + pub fn try_lock_path(path: &Path) -> Result { let file = open_lockable_file(path)?; sys::try_lock_exclusive(&file)?; diff --git a/dylint/src/lib.rs b/dylint/src/lib.rs index 5e1c265b8..69479505a 100644 --- a/dylint/src/lib.rs +++ b/dylint/src/lib.rs @@ -30,6 +30,9 @@ use error::warn; pub use error::warn as __warn; pub use error::{ColorizedError, ColorizedResult}; +mod cache; +mod flock; + mod name_toolchain_map; pub use name_toolchain_map::{Lazy as NameToolchainMap, ToolchainMap}; use name_toolchain_map::{LazyToolchainMap, MaybeLibrary}; diff --git a/dylint/src/library_packages/mod.rs b/dylint/src/library_packages/mod.rs index 8fd725a3c..aa8d9eef7 100644 --- a/dylint/src/library_packages/mod.rs +++ b/dylint/src/library_packages/mod.rs @@ -1,4 +1,4 @@ -use crate::{error::warn, opts}; +use crate::{cache, error::warn, opts}; use anyhow::{Context, Result, anyhow, bail, ensure}; use cargo_metadata::{ Error, Metadata, MetadataCommand, Package as MetadataPackage, TargetKind, camino::Utf8PathBuf, @@ -24,11 +24,8 @@ type Object = serde_json::Map; #[derive(Clone, Debug)] pub struct Package { - /// [`Metadata`] of the workspace being linted - /// - /// Caching a reference to the [`Metadata`] here ensures that it existed when the package was - /// created. - metadata: &'static Metadata, + /// Directory where the package's libraries are built, including the toolchain subdirectory + target_directory: PathBuf, /// Path to the package's directory pub root: PathBuf, /// The package's [`PackageId`], which includes the package's name, version, and source id @@ -37,7 +34,7 @@ pub struct Package { pub lib_name: String, /// Toolchain the package uses pub toolchain: String, - /// Cargo's build directory when `dylint-link` performs the copy; otherwise `None` + /// Cargo's build directory when needed for shared builds or linker copies build_directory: Option, } @@ -69,11 +66,7 @@ impl PartialOrd for Package { impl Package { pub fn target_directory(&self) -> PathBuf { - self.metadata - .target_directory - .join("dylint/libraries") - .join(&self.toolchain) - .into_std_path_buf() + self.target_directory.clone() } pub fn library_plain_path(&self) -> PathBuf { @@ -83,13 +76,7 @@ impl Package { } pub fn library_path_with_toolchain(&self) -> PathBuf { - // When Dylint copies the library, it does so after Cargo finishes and places the copy in - // `target_directory`. But when `dylint-link` performs the copy, it does so during linking - // and places the copy relative to the linker output, which can be under `build_directory`. - // This is especially relevant when the user changes the build directory location. - self.build_directory - .clone() - .unwrap_or_else(|| self.target_directory()) + self.target_directory() .join("release") .join(library_filename_with_toolchain( &self.lib_name, @@ -408,18 +395,10 @@ fn library_package( let package_id = package_id(&package, source_id.clone()); let lib_name = package_library_name(&package)?; let toolchain = active_toolchain(&path)?; - let build_directory = if env::enabled(env::DYLINT_LINK_ENABLE_COPY_LIBRARY) { - let target_directory = metadata - .target_directory - .join("dylint/libraries") - .join(&toolchain); - let metadata = cargo::metadata_with_target_dir(&path, target_directory)?; - metadata.build_directory.map(Utf8PathBuf::into_std_path_buf) - } else { - None - }; + let target_directory = target_directory(metadata, &toolchain)?; + let build_directory = build_directory(&path, &target_directory, &toolchain)?; packages.push(Package { - metadata, + target_directory, root: path, id: package_id, lib_name, @@ -498,6 +477,45 @@ pub fn package_library_name(package: &MetadataPackage) -> Result { }) } +fn target_directory(metadata: &Metadata, toolchain: &str) -> Result { + let root = cache::directory("libraries")?; + let target = root.join(toolchain); + let legacy = metadata + .target_directory + .join("dylint/libraries") + .join(toolchain); + cache::migrate(legacy.as_std_path(), &target)?; + Ok(target) +} + +fn build_directory( + package_root: &Path, + target_directory: &Path, + toolchain: &str, +) -> Result> { + let metadata = MetadataCommand::new() + .cargo_path("cargo") + .sanitize_environment() + .current_dir(package_root) + .no_deps() + .env(env::CARGO_TARGET_DIR, target_directory) + .exec()?; + let directory = metadata.build_directory.map(Utf8PathBuf::into_std_path_buf); + match directory { + Some(directory) if !directory.starts_with(target_directory) => Ok(Some(directory)), + // dblock: MSVC's linker cannot open the deeply nested default intermediate paths. + _ if cfg!(windows) => { + use std::hash::{DefaultHasher, Hash, Hasher}; + + let mut hasher = DefaultHasher::new(); + toolchain.hash(&mut hasher); + let root = cache::directory(".build")?; + Ok(Some(root.join(format!("{:016x}", hasher.finish())))) + } + directory => Ok(directory), + } +} + pub fn build_library(opts: &opts::Dylint, package: &Package) -> Result { let target_dir = package.target_directory(); @@ -506,24 +524,27 @@ pub fn build_library(opts: &opts::Dylint, package: &Package) -> Result if !opts.library_selection().no_build { // smoelius: Clear `RUSTFLAGS` so that changes to it do not cause workspace metadata entries // to be rebuilt. - cargo::build(&format!("workspace metadata entry `{}`", package.id.name())) - .quiet(opts.quiet) - .build() + let mut command = + cargo::build(&format!("workspace metadata entry `{}`", package.id.name())) + .quiet(opts.quiet) + .build(); + command .sanitize_environment() .env_remove(env::RUSTFLAGS) .current_dir(&package.root) - .args(["--release", "--target-dir", &target_dir.to_string_lossy()]) - .success()?; + .args(["--release", "--target-dir", &target_dir.to_string_lossy()]); + if let Some(directory) = &package.build_directory { + command.env(env::CARGO_BUILD_BUILD_DIR, directory); + } + command.success()?; - if !env::enabled(env::DYLINT_LINK_ENABLE_COPY_LIBRARY) { - let path_with_toolchain = copy_library( - &package.library_plain_path(), - &package.lib_name, - &package.toolchain, - )?; + let path_with_toolchain = copy_library( + &package.library_plain_path(), + &package.lib_name, + &package.toolchain, + )?; - assert_eq!(path, path_with_toolchain); - } + assert_eq!(path, path_with_toolchain); let exists = path .try_exists() diff --git a/examples/experimental/derive_opportunity/Cargo.lock b/examples/experimental/derive_opportunity/Cargo.lock index c77e925e1..f193842ea 100644 --- a/examples/experimental/derive_opportunity/Cargo.lock +++ b/examples/experimental/derive_opportunity/Cargo.lock @@ -224,6 +224,7 @@ dependencies = [ "cargo_metadata", "dunce", "dylint_internal", + "fs_extra", "libc", "log", "once_cell", @@ -353,6 +354,12 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "getopts" version = "0.2.24" diff --git a/examples/experimental/missing_doc_comment_llm/Cargo.lock b/examples/experimental/missing_doc_comment_llm/Cargo.lock index 6793f3a5b..042957fa3 100644 --- a/examples/experimental/missing_doc_comment_llm/Cargo.lock +++ b/examples/experimental/missing_doc_comment_llm/Cargo.lock @@ -557,6 +557,7 @@ dependencies = [ "cargo_metadata", "dunce", "dylint_internal", + "fs_extra", "libc", "log", "once_cell", diff --git a/examples/general/Cargo.lock b/examples/general/Cargo.lock index 70eb4f673..b1eba4241 100644 --- a/examples/general/Cargo.lock +++ b/examples/general/Cargo.lock @@ -312,6 +312,7 @@ dependencies = [ "cargo_metadata", "dunce", "dylint_internal", + "fs_extra", "libc", "log", "once_cell", @@ -452,6 +453,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "general" version = "6.4.0" diff --git a/examples/restriction/Cargo.lock b/examples/restriction/Cargo.lock index 7a181e5ca..f7eec32f5 100644 --- a/examples/restriction/Cargo.lock +++ b/examples/restriction/Cargo.lock @@ -345,6 +345,7 @@ dependencies = [ "cargo_metadata", "dunce", "dylint_internal", + "fs_extra", "libc", "log", "once_cell", @@ -502,6 +503,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "getopts" version = "0.2.24" diff --git a/examples/supplementary/Cargo.lock b/examples/supplementary/Cargo.lock index fd19d4030..b7df97f3a 100644 --- a/examples/supplementary/Cargo.lock +++ b/examples/supplementary/Cargo.lock @@ -369,6 +369,7 @@ dependencies = [ "cargo_metadata", "dunce", "dylint_internal", + "fs_extra", "libc", "log", "once_cell", @@ -511,6 +512,12 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "getopts" version = "0.2.24" diff --git a/examples/testing/clippy/Cargo.lock b/examples/testing/clippy/Cargo.lock index 4071f259c..0ab3fbd2a 100644 --- a/examples/testing/clippy/Cargo.lock +++ b/examples/testing/clippy/Cargo.lock @@ -279,6 +279,7 @@ dependencies = [ "cargo_metadata", "dunce", "dylint_internal", + "fs_extra", "libc", "log", "once_cell", @@ -417,6 +418,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "getopts" version = "0.2.24" diff --git a/examples/testing/straggler/Cargo.lock b/examples/testing/straggler/Cargo.lock index 3b89464f1..86e9afb40 100644 --- a/examples/testing/straggler/Cargo.lock +++ b/examples/testing/straggler/Cargo.lock @@ -211,6 +211,7 @@ dependencies = [ "cargo_metadata", "dunce", "dylint_internal", + "fs_extra", "libc", "log", "once_cell", @@ -340,6 +341,12 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "getopts" version = "0.2.24" diff --git a/internal/src/env.rs b/internal/src/env.rs index c47bc95ad..ae5106795 100644 --- a/internal/src/env.rs +++ b/internal/src/env.rs @@ -24,8 +24,9 @@ declare_const!(CI); declare_const!(CLIPPY_DISABLE_DOCS_LINKS); declare_const!(CLIPPY_DRIVER_PATH); declare_const!(DOCS_RS); +declare_const!(DYLINT_CACHE_DIR); declare_const!(DYLINT_CLIPPY_REPO); -declare_const!(DYLINT_DRIVER_PATH); +declare_const!(DYLINT_DRIVER_PATH, deprecated); declare_const!(DYLINT_LIBRARY_PATH, deprecated); declare_const!(DYLINT_LIBS); declare_const!(DYLINT_LINK_ENABLE_COPY_LIBRARY);