Commit e58bc754 authored by Silvan Mosberger's avatar Silvan Mosberger
Browse files

tests.nixpkgs-check-by-name: Remove Nixpkgs struct

Isn't necessary anymore with the refactoring
parent d65f3ddb
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -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 {
+3 −2
Original line number Diff line number Diff line
@@ -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)?;
        }
    }
+17 −30
Original line number Diff line number Diff line
@@ -13,15 +13,6 @@ 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

pub fn shard_for_package(package_name: &str) -> String {
@@ -33,18 +24,16 @@ impl Nixpkgs {
}

pub fn relative_dir_for_package(package_name: &str) -> PathBuf {
        Nixpkgs::relative_dir_for_shard(&Nixpkgs::shard_for_package(package_name))
            .join(package_name)
    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)
    }
    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<_>>()
    })
}