From d65f3ddb890570dea21df41e386d0f6401c9ec3a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 20 Oct 2023 02:18:21 +0200 Subject: tests.nixpkgs-check-by-name: Make reference check part of structural check --- pkgs/test/nixpkgs-check-by-name/src/main.rs | 12 +++------ pkgs/test/nixpkgs-check-by-name/src/references.rs | 31 ++++++++++------------- pkgs/test/nixpkgs-check-by-name/src/structure.rs | 7 +++++ 3 files changed, 24 insertions(+), 26 deletions(-) (limited to 'pkgs') diff --git a/pkgs/test/nixpkgs-check-by-name/src/main.rs b/pkgs/test/nixpkgs-check-by-name/src/main.rs index 6138284d2900..ff223068697a 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( 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 b932b556f54f..91f898fe3bfd 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 24586c6b533c..09ec798e440e 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 { 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(), ) -- cgit 1.4.1