tests.nixpkgs-check-by-name: Minor improvements from review

This commit is contained in:
Silvan Mosberger 2023-12-15 01:02:02 +01:00
parent 53b43ce0e3
commit 413dd9c03e
4 changed files with 24 additions and 19 deletions

View file

@ -41,7 +41,7 @@ enum AttributeVariant {
pub fn check_values(
nixpkgs_path: &Path,
package_names: Vec<String>,
eval_accessible_paths: &Vec<&Path>,
eval_accessible_paths: &[&Path],
) -> validation::Result<version::Nixpkgs> {
// Write the list of packages we need to check into a temporary JSON file.
// This can then get read by the Nix evaluation.
@ -110,11 +110,11 @@ pub fn check_values(
))?;
Ok(
validation::sequence(package_names.iter().map(|package_name| {
let relative_package_file = structure::relative_file_for_package(package_name);
validation::sequence(package_names.into_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) {
if let Some(attribute_info) = actual_files.get(&package_name) {
let check_result = if !attribute_info.is_derivation {
NixpkgsProblem::NonDerivation {
relative_package_file: relative_package_file.clone(),

View file

@ -31,12 +31,7 @@ pub struct Args {
fn main() -> ExitCode {
let args = Args::parse();
match process(
args.base.as_deref(),
&args.nixpkgs,
&vec![],
&mut io::stderr(),
) {
match process(args.base.as_deref(), &args.nixpkgs, &[], &mut io::stderr()) {
Ok(true) => {
eprintln!("{}", "Validated successfully".green());
ExitCode::SUCCESS
@ -69,10 +64,10 @@ fn main() -> ExitCode {
pub fn process<W: io::Write>(
base_nixpkgs: Option<&Path>,
main_nixpkgs: &Path,
eval_accessible_paths: &Vec<&Path>,
eval_accessible_paths: &[&Path],
error_writer: &mut W,
) -> anyhow::Result<bool> {
let main_result = check_nixpkgs(main_nixpkgs, eval_accessible_paths)?;
let main_result = check_nixpkgs(main_nixpkgs, eval_accessible_paths, error_writer)?;
let check_result = main_result.result_map(|nixpkgs_version| {
if let Some(base) = base_nixpkgs {
check_nixpkgs(base, eval_accessible_paths, error_writer)?.result_map(
@ -99,11 +94,17 @@ pub fn process<W: io::Write>(
}
}
/// Checks whether the pkgs/by-name structure in Nixpkgs is valid,
/// and returns to which degree it's valid for checks with increased strictness.
pub fn check_nixpkgs(
/// Checks whether the pkgs/by-name structure in Nixpkgs is valid.
///
/// This does not include checks that depend on the base version of Nixpkgs to compare against,
/// which is used for checks that were only introduced later and increased strictness.
///
/// Instead a `version::Nixpkgs` is returned, whose `compare` method allows comparing the
/// result of this function for the base Nixpkgs against the one for the main Nixpkgs.
pub fn check_nixpkgs<W: io::Write>(
nixpkgs_path: &Path,
eval_accessible_paths: &Vec<&Path>,
eval_accessible_paths: &[&Path],
error_writer: &mut W,
) -> validation::Result<version::Nixpkgs> {
Ok({
let nixpkgs_path = nixpkgs_path.canonicalize().context(format!(
@ -112,10 +113,11 @@ pub fn check_nixpkgs(
))?;
if !nixpkgs_path.join(utils::BASE_SUBPATH).exists() {
eprintln!(
writeln!(
error_writer,
"Given Nixpkgs path does not contain a {} subdirectory, no check necessary.",
utils::BASE_SUBPATH
);
)?;
Success(version::Nixpkgs::default())
} else {
check_structure(&nixpkgs_path)?.result_map(|package_names|
@ -224,7 +226,7 @@ mod tests {
// We don't want coloring to mess up the tests
let writer = temp_env::with_var("NO_COLOR", Some("1"), || -> anyhow::Result<_> {
let mut writer = vec![];
process(base_nixpkgs, &path, &vec![&extra_nix_path], &mut writer)
process(base_nixpkgs, &path, &[&extra_nix_path], &mut writer)
.context(format!("Failed test case {name}"))?;
Ok(writer)
})?;

View file

@ -16,6 +16,8 @@ impl Nixpkgs {
/// Compares two Nixpkgs versions against each other, returning validation errors only if the
/// `from` version satisfied the stricter checks, while the `to` version doesn't satisfy them
/// anymore.
/// This enables a gradual transition from weaker to stricter checks, by only allowing PRs to
/// increase strictness.
pub fn compare(optional_from: Option<Self>, to: Self) -> Validation<()> {
validation::sequence_(
// We only loop over the current attributes,

View file

@ -0,0 +1 @@
Given Nixpkgs path does not contain a pkgs/by-name subdirectory, no check necessary.