diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-20 02:22:42 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:18:13 +0200 |
commit | e58bc75444d5d722a995cf350b0d6c298aeb3808 (patch) | |
tree | 4b45a83a3243a0d1b9e85caf34b904bc961fe50b /pkgs/test | |
parent | d65f3ddb890570dea21df41e386d0f6401c9ec3a (diff) |
tests.nixpkgs-check-by-name: Remove Nixpkgs struct
Isn't necessary anymore with the refactoring
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/eval.rs | 15 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/main.rs | 5 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/structure.rs | 47 |
3 files changed, 28 insertions, 39 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/eval.rs b/pkgs/test/nixpkgs-check-by-name/src/eval.rs index eb90a295a5776..487ec7cab7300 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/eval.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/eval.rs @@ -41,7 +41,8 @@ const EXPR: &str = include_str!("eval.nix"); /// See the `eval.nix` file for how this is achieved on the Nix side pub fn check_values( version: Version, - nixpkgs: &structure::Nixpkgs, + nixpkgs_path: &Path, + package_names: Vec<String>, eval_accessible_paths: Vec<&Path>, ) -> CheckResult<()> { // Write the list of packages we need to check into a temporary JSON file. @@ -53,7 +54,7 @@ pub fn check_values( // entry is needed. let attrs_file_path = attrs_file.path().canonicalize()?; - serde_json::to_writer(&attrs_file, &nixpkgs.package_names).context(format!( + serde_json::to_writer(&attrs_file, &package_names).context(format!( "Failed to serialise the package names to the temporary path {}", attrs_file_path.display() ))?; @@ -85,9 +86,9 @@ pub fn check_values( .arg(&attrs_file_path) // Same for the nixpkgs to test .args(["--arg", "nixpkgsPath"]) - .arg(&nixpkgs.path) + .arg(nixpkgs_path) .arg("-I") - .arg(&nixpkgs.path); + .arg(nixpkgs_path); // Also add extra paths that need to be accessible for path in eval_accessible_paths { @@ -109,9 +110,9 @@ pub fn check_values( String::from_utf8_lossy(&result.stdout) ))?; - let check_results = nixpkgs.package_names.iter().map(|package_name| { - let relative_package_file = structure::Nixpkgs::relative_file_for_package(package_name); - let absolute_package_file = nixpkgs.path.join(&relative_package_file); + let check_results = package_names.iter().map(|package_name| { + let relative_package_file = structure::relative_file_for_package(package_name); + let absolute_package_file = nixpkgs_path.join(&relative_package_file); if let Some(attribute_info) = actual_files.get(package_name) { let valid = match &attribute_info.variant { diff --git a/pkgs/test/nixpkgs-check-by-name/src/main.rs b/pkgs/test/nixpkgs-check-by-name/src/main.rs index ff223068697ad..67f6055e73383 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/main.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/main.rs @@ -90,9 +90,10 @@ pub fn check_nixpkgs<W: io::Write>( } else { let check_result = check_structure(&nixpkgs_path); - if let Some(nixpkgs) = write_check_result(&mut error_writer, check_result)? { + if let Some(package_names) = write_check_result(&mut error_writer, check_result)? { // Only if we could successfully parse the structure, we do the evaluation checks - let check_result = eval::check_values(version, &nixpkgs, eval_accessible_paths); + let check_result = + eval::check_values(version, &nixpkgs_path, package_names, eval_accessible_paths); write_check_result(&mut error_writer, check_result)?; } } diff --git a/pkgs/test/nixpkgs-check-by-name/src/structure.rs b/pkgs/test/nixpkgs-check-by-name/src/structure.rs index 09ec798e440e7..c8fbc17fcb392 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/structure.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/structure.rs @@ -13,38 +13,27 @@ lazy_static! { static ref PACKAGE_NAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_-]+$").unwrap(); } -/// Contains information about the structure of the pkgs/by-name directory of a Nixpkgs -pub struct Nixpkgs { - /// The path to nixpkgs - pub path: PathBuf, - /// The names of all packages declared in pkgs/by-name - pub package_names: Vec<String>, -} - -impl Nixpkgs { - // Some utility functions for the basic structure +// Some utility functions for the basic structure - pub fn shard_for_package(package_name: &str) -> String { - package_name.to_lowercase().chars().take(2).collect() - } +pub fn shard_for_package(package_name: &str) -> String { + package_name.to_lowercase().chars().take(2).collect() +} - pub fn relative_dir_for_shard(shard_name: &str) -> PathBuf { - PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}")) - } +pub fn relative_dir_for_shard(shard_name: &str) -> PathBuf { + PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}")) +} - pub fn relative_dir_for_package(package_name: &str) -> PathBuf { - Nixpkgs::relative_dir_for_shard(&Nixpkgs::shard_for_package(package_name)) - .join(package_name) - } +pub fn relative_dir_for_package(package_name: &str) -> PathBuf { + relative_dir_for_shard(&shard_for_package(package_name)).join(package_name) +} - pub fn relative_file_for_package(package_name: &str) -> PathBuf { - Nixpkgs::relative_dir_for_package(package_name).join(PACKAGE_NIX_FILENAME) - } +pub fn relative_file_for_package(package_name: &str) -> PathBuf { + relative_dir_for_package(package_name).join(PACKAGE_NIX_FILENAME) } /// Read the structure of a Nixpkgs directory, displaying errors on the writer. /// May return early with I/O errors. -pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> { +pub fn check_structure(path: &Path) -> CheckResult<Vec<String>> { let base_dir = path.join(BASE_SUBPATH); let check_results = utils::read_dir_sorted(&base_dir)? @@ -52,7 +41,7 @@ pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> { .map(|shard_entry| { let shard_path = shard_entry.path(); let shard_name = shard_entry.file_name().to_string_lossy().into_owned(); - let relative_shard_path = Nixpkgs::relative_dir_for_shard(&shard_name); + let relative_shard_path = relative_dir_for_shard(&shard_name); if shard_name == "README.md" { // README.md is allowed to be a file and not checked @@ -120,8 +109,7 @@ pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> { pass(()) }; - let correct_relative_package_dir = - Nixpkgs::relative_dir_for_package(&package_name); + let correct_relative_package_dir = relative_dir_for_package(&package_name); let shard_check_result = if relative_package_dir != correct_relative_package_dir { // Only show this error if we have a valid shard and package name @@ -176,8 +164,7 @@ pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> { } }); - flatten_check_results(check_results, |x| Nixpkgs { - path: path.to_owned(), - package_names: x.into_iter().flatten().collect::<Vec<_>>(), + flatten_check_results(check_results, |x| { + x.into_iter().flatten().collect::<Vec<_>>() }) } |