tests.nixpkgs-check-by-name: Remove Nixpkgs struct
Isn't necessary anymore with the refactoring
This commit is contained in:
parent
d65f3ddb89
commit
e58bc75444
3 changed files with 28 additions and 39 deletions
|
@ -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
|
/// See the `eval.nix` file for how this is achieved on the Nix side
|
||||||
pub fn check_values(
|
pub fn check_values(
|
||||||
version: Version,
|
version: Version,
|
||||||
nixpkgs: &structure::Nixpkgs,
|
nixpkgs_path: &Path,
|
||||||
|
package_names: Vec<String>,
|
||||||
eval_accessible_paths: Vec<&Path>,
|
eval_accessible_paths: Vec<&Path>,
|
||||||
) -> CheckResult<()> {
|
) -> CheckResult<()> {
|
||||||
// Write the list of packages we need to check into a temporary JSON file.
|
// 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.
|
// entry is needed.
|
||||||
let attrs_file_path = attrs_file.path().canonicalize()?;
|
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 {}",
|
"Failed to serialise the package names to the temporary path {}",
|
||||||
attrs_file_path.display()
|
attrs_file_path.display()
|
||||||
))?;
|
))?;
|
||||||
|
@ -85,9 +86,9 @@ pub fn check_values(
|
||||||
.arg(&attrs_file_path)
|
.arg(&attrs_file_path)
|
||||||
// Same for the nixpkgs to test
|
// Same for the nixpkgs to test
|
||||||
.args(["--arg", "nixpkgsPath"])
|
.args(["--arg", "nixpkgsPath"])
|
||||||
.arg(&nixpkgs.path)
|
.arg(nixpkgs_path)
|
||||||
.arg("-I")
|
.arg("-I")
|
||||||
.arg(&nixpkgs.path);
|
.arg(nixpkgs_path);
|
||||||
|
|
||||||
// Also add extra paths that need to be accessible
|
// Also add extra paths that need to be accessible
|
||||||
for path in eval_accessible_paths {
|
for path in eval_accessible_paths {
|
||||||
|
@ -109,9 +110,9 @@ pub fn check_values(
|
||||||
String::from_utf8_lossy(&result.stdout)
|
String::from_utf8_lossy(&result.stdout)
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
let check_results = nixpkgs.package_names.iter().map(|package_name| {
|
let check_results = package_names.iter().map(|package_name| {
|
||||||
let relative_package_file = structure::Nixpkgs::relative_file_for_package(package_name);
|
let relative_package_file = structure::relative_file_for_package(package_name);
|
||||||
let absolute_package_file = nixpkgs.path.join(&relative_package_file);
|
let absolute_package_file = nixpkgs_path.join(&relative_package_file);
|
||||||
|
|
||||||
if let Some(attribute_info) = actual_files.get(package_name) {
|
if let Some(attribute_info) = actual_files.get(package_name) {
|
||||||
let valid = match &attribute_info.variant {
|
let valid = match &attribute_info.variant {
|
||||||
|
|
|
@ -90,9 +90,10 @@ pub fn check_nixpkgs<W: io::Write>(
|
||||||
} else {
|
} else {
|
||||||
let check_result = check_structure(&nixpkgs_path);
|
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
|
// 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)?;
|
write_check_result(&mut error_writer, check_result)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,38 +13,27 @@ lazy_static! {
|
||||||
static ref PACKAGE_NAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_-]+$").unwrap();
|
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
|
// Some utility functions for the basic structure
|
||||||
pub struct Nixpkgs {
|
|
||||||
/// The path to nixpkgs
|
pub fn shard_for_package(package_name: &str) -> String {
|
||||||
pub path: PathBuf,
|
package_name.to_lowercase().chars().take(2).collect()
|
||||||
/// The names of all packages declared in pkgs/by-name
|
|
||||||
pub package_names: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Nixpkgs {
|
pub fn relative_dir_for_shard(shard_name: &str) -> PathBuf {
|
||||||
// Some utility functions for the basic structure
|
PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}"))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn shard_for_package(package_name: &str) -> String {
|
pub fn relative_dir_for_package(package_name: &str) -> PathBuf {
|
||||||
package_name.to_lowercase().chars().take(2).collect()
|
relative_dir_for_shard(&shard_for_package(package_name)).join(package_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn relative_dir_for_shard(shard_name: &str) -> PathBuf {
|
pub fn relative_file_for_package(package_name: &str) -> PathBuf {
|
||||||
PathBuf::from(format!("{BASE_SUBPATH}/{shard_name}"))
|
relative_dir_for_package(package_name).join(PACKAGE_NIX_FILENAME)
|
||||||
}
|
|
||||||
|
|
||||||
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_file_for_package(package_name: &str) -> PathBuf {
|
|
||||||
Nixpkgs::relative_dir_for_package(package_name).join(PACKAGE_NIX_FILENAME)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the structure of a Nixpkgs directory, displaying errors on the writer.
|
/// Read the structure of a Nixpkgs directory, displaying errors on the writer.
|
||||||
/// May return early with I/O errors.
|
/// 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 base_dir = path.join(BASE_SUBPATH);
|
||||||
|
|
||||||
let check_results = utils::read_dir_sorted(&base_dir)?
|
let check_results = utils::read_dir_sorted(&base_dir)?
|
||||||
|
@ -52,7 +41,7 @@ pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> {
|
||||||
.map(|shard_entry| {
|
.map(|shard_entry| {
|
||||||
let shard_path = shard_entry.path();
|
let shard_path = shard_entry.path();
|
||||||
let shard_name = shard_entry.file_name().to_string_lossy().into_owned();
|
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" {
|
if shard_name == "README.md" {
|
||||||
// README.md is allowed to be a file and not checked
|
// README.md is allowed to be a file and not checked
|
||||||
|
@ -120,8 +109,7 @@ pub fn check_structure(path: &Path) -> CheckResult<Nixpkgs> {
|
||||||
pass(())
|
pass(())
|
||||||
};
|
};
|
||||||
|
|
||||||
let correct_relative_package_dir =
|
let correct_relative_package_dir = relative_dir_for_package(&package_name);
|
||||||
Nixpkgs::relative_dir_for_package(&package_name);
|
|
||||||
let shard_check_result =
|
let shard_check_result =
|
||||||
if relative_package_dir != correct_relative_package_dir {
|
if relative_package_dir != correct_relative_package_dir {
|
||||||
// Only show this error if we have a valid shard and package name
|
// 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 {
|
flatten_check_results(check_results, |x| {
|
||||||
path: path.to_owned(),
|
x.into_iter().flatten().collect::<Vec<_>>()
|
||||||
package_names: x.into_iter().flatten().collect::<Vec<_>>(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue