From 18f07ee302fe21fe7762deae1afd9e9b9c088c7d Mon Sep 17 00:00:00 2001 From: J Robert Ray Date: Tue, 18 Jul 2023 19:44:51 -0700 Subject: [PATCH] Fix cyclic crate dependency #2 Relocate a tests file to avoid a cyclic dependency: spk_schema -> spk_schema_validators -> spk_schema (dev) Signed-off-by: J Robert Ray --- Cargo.lock | 1 - crates/spk-schema/crates/validators/Cargo.toml | 3 --- crates/spk-schema/crates/validators/src/validators.rs | 5 ++--- crates/spk-schema/src/v0/mod.rs | 4 ++++ .../{crates/validators/src => src/v0}/validators_test.rs | 5 ++--- 5 files changed, 8 insertions(+), 10 deletions(-) rename crates/spk-schema/{crates/validators/src => src/v0}/validators_test.rs (90%) diff --git a/Cargo.lock b/Cargo.lock index 3a30263999..6d72d6a05a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3879,7 +3879,6 @@ dependencies = [ "serde_json", "serde_yaml", "spfs", - "spk-schema", "spk-schema-foundation", "spk-schema-ident", "sys-info", diff --git a/crates/spk-schema/crates/validators/Cargo.toml b/crates/spk-schema/crates/validators/Cargo.toml index 37e01e490c..6e4c4b2f56 100644 --- a/crates/spk-schema/crates/validators/Cargo.toml +++ b/crates/spk-schema/crates/validators/Cargo.toml @@ -29,6 +29,3 @@ sys-info = "0.9.0" tempdir = "0.3.7" thiserror = { workspace = true } tracing = { workspace = true } - -[dev-dependencies] -spk-schema = { path = "../.." } diff --git a/crates/spk-schema/crates/validators/src/validators.rs b/crates/spk-schema/crates/validators/src/validators.rs index 13e94f380b..4fba90c72f 100644 --- a/crates/spk-schema/crates/validators/src/validators.rs +++ b/crates/spk-schema/crates/validators/src/validators.rs @@ -11,9 +11,8 @@ use spk_schema_ident::BuildIdent; use crate::{Error, Result}; -#[cfg(test)] -#[path = "./validators_test.rs"] -mod validators_test; +// Tests for this module are in spk-schema/src/v0/validators_test.rs to avoid +// a cyclic crate dependency (the tests need spk_schema::v0). /// Validates that all remaining build files are collected into at least one component pub fn must_collect_all_files<'a, Files>( diff --git a/crates/spk-schema/src/v0/mod.rs b/crates/spk-schema/src/v0/mod.rs index 1768289d46..cee7255ced 100644 --- a/crates/spk-schema/src/v0/mod.rs +++ b/crates/spk-schema/src/v0/mod.rs @@ -9,3 +9,7 @@ mod variant; pub use spec::Spec; pub use test_spec::TestSpec; pub use variant::Variant; + +#[cfg(test)] +#[path = "./validators_test.rs"] +mod validators_test; diff --git a/crates/spk-schema/crates/validators/src/validators_test.rs b/crates/spk-schema/src/v0/validators_test.rs similarity index 90% rename from crates/spk-schema/crates/validators/src/validators_test.rs rename to crates/spk-schema/src/v0/validators_test.rs index 5b95f3d8c8..d3357ac8e6 100644 --- a/crates/spk-schema/crates/validators/src/validators_test.rs +++ b/crates/spk-schema/src/v0/validators_test.rs @@ -2,10 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 // https://github.com/imageworks/spk -use spk_schema::v0; +use spk_schema_validators::{must_install_something, must_not_alter_existing_files}; -use super::{must_install_something, must_not_alter_existing_files}; -use crate::validators::must_collect_all_files; +use crate::{v0, validators::must_collect_all_files}; #[test] fn test_validate_build_changeset_nothing() {