diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-20 02:18:21 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:18:13 +0200 |
commit | d65f3ddb890570dea21df41e386d0f6401c9ec3a (patch) | |
tree | 7659b4c020359c636ec0f43b4ae57ce4491cf3ac /pkgs/test | |
parent | 0475238ec08c5b903eac37a13efd1b6f4b9617a3 (diff) |
tests.nixpkgs-check-by-name: Make reference check part of structural check
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/main.rs | 12 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/references.rs | 31 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/structure.rs | 7 |
3 files changed, 24 insertions, 26 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/main.rs b/pkgs/test/nixpkgs-check-by-name/src/main.rs index 6138284d2900d..ff223068697ad 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/main.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/main.rs @@ -6,7 +6,7 @@ mod utils; use crate::structure::check_structure; use anyhow::Context; -use check_result::{flatten_check_results, write_check_result}; +use check_result::write_check_result; use clap::{Parser, ValueEnum}; use colored::Colorize; use std::io; @@ -91,14 +91,8 @@ pub fn check_nixpkgs<W: io::Write>( let check_result = check_structure(&nixpkgs_path); if let Some(nixpkgs) = write_check_result(&mut error_writer, check_result)? { - // Only if we could successfully parse the structure, we do the semantic checks - let check_result = flatten_check_results( - [ - eval::check_values(version, &nixpkgs, eval_accessible_paths), - references::check_references(&nixpkgs), - ], - |_| (), - ); + // Only if we could successfully parse the structure, we do the evaluation checks + let check_result = eval::check_values(version, &nixpkgs, eval_accessible_paths); write_check_result(&mut error_writer, check_result)?; } } diff --git a/pkgs/test/nixpkgs-check-by-name/src/references.rs b/pkgs/test/nixpkgs-check-by-name/src/references.rs index b932b556f54fe..91f898fe3bfd4 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/references.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/references.rs @@ -1,5 +1,4 @@ use crate::check_result::{flatten_check_results, pass, CheckError, CheckResult}; -use crate::structure::Nixpkgs; use crate::utils; use crate::utils::LineIndex; @@ -19,23 +18,21 @@ struct PackageContext<'a> { /// Check that every package directory in pkgs/by-name doesn't link to outside that directory. /// Both symlinks and Nix path expressions are checked. -pub fn check_references(nixpkgs: &Nixpkgs) -> CheckResult<()> { - // Check the directories for each package separately - let check_results = nixpkgs.package_names.iter().map(|package_name| { - let relative_package_dir = Nixpkgs::relative_dir_for_package(package_name); - let context = PackageContext { - relative_package_dir: &relative_package_dir, - absolute_package_dir: &nixpkgs.path.join(&relative_package_dir), - }; +pub fn check_references( + relative_package_dir: &Path, + absolute_package_dir: &Path, +) -> CheckResult<()> { + let context = PackageContext { + relative_package_dir: &relative_package_dir.to_path_buf(), + absolute_package_dir: &absolute_package_dir.to_path_buf(), + }; - // The empty argument here is the subpath under the package directory to check - // An empty one means the package directory itself - check_path(&context, Path::new("")).context(format!( - "While checking the references in package directory {}", - relative_package_dir.display() - )) - }); - flatten_check_results(check_results, |_| ()) + // The empty argument here is the subpath under the package directory to check + // An empty one means the package directory itself + check_path(&context, Path::new("")).context(format!( + "While checking the references in package directory {}", + relative_package_dir.display() + )) } /// Checks for a specific path to not have references outside diff --git a/pkgs/test/nixpkgs-check-by-name/src/structure.rs b/pkgs/test/nixpkgs-check-by-name/src/structure.rs index 24586c6b533cb..09ec798e440e7 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/structure.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/structure.rs @@ -1,6 +1,7 @@ use crate::check_result::{ flatten_check_results, pass, sequence_check_results, CheckError, CheckResult, }; +use crate::references; use crate::utils; use crate::utils::{BASE_SUBPATH, PACKAGE_NIX_FILENAME}; use lazy_static::lazy_static; @@ -154,11 +155,17 @@ pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> { pass(()) }; + let reference_check_result = references::check_references( + &relative_package_dir, + &path.join(&relative_package_dir), + ); + flatten_check_results( [ name_check_result, shard_check_result, package_nix_check_result, + reference_check_result, ], |_| package_name.clone(), ) |