[naga xtask] Add and use ValidateSubcommand::all.

Add an `all` method to `ValidateSubcommand`, so that we can just use
matches elsewhere, and let the compile catch missing or duplicated
cases for us.
This commit is contained in:
Erich Gubler 2023-12-27 12:39:32 -08:00 committed by Jim Blandy
parent 71f18fd61a
commit e45a86fa7c
2 changed files with 34 additions and 18 deletions

View File

@ -127,6 +127,19 @@ impl ValidateSubcommand {
}
}
}
pub(crate) fn all() -> impl Iterator<Item = Self> {
[
Self::Spirv,
Self::Metal,
Self::Glsl,
Self::Dot,
Self::Wgsl,
Self::Hlsl(ValidateHlslCommand::Dxc),
Self::Hlsl(ValidateHlslCommand::Fxc),
]
.into_iter()
}
}
#[derive(Debug)]

View File

@ -144,24 +144,27 @@ fn collect_validation_jobs(jobs: &mut Vec<Job>, cmd: ValidateSubcommand) -> anyh
});
}
ValidateSubcommand::All => {
collect_validation_jobs(jobs, ValidateSubcommand::Wgsl)?;
collect_validation_jobs(jobs, ValidateSubcommand::Spirv)?;
collect_validation_jobs(jobs, ValidateSubcommand::Glsl)?;
collect_validation_jobs(jobs, ValidateSubcommand::Dot)?;
#[cfg(any(target_os = "macos", target_os = "ios"))]
collect_validation_jobs(jobs, ValidateSubcommand::Metal)?;
// The FXC compiler is only available on Windows.
//
// The DXC compiler can be built and run on any platform,
// but they don't make Linux releases and it's not clear
// what Git commit actually works on Linux, so restrict
// that to Windows as well.
#[cfg(windows)]
{
collect_validation_jobs(jobs, ValidateSubcommand::Hlsl(ValidateHlslCommand::Dxc))?;
collect_validation_jobs(jobs, ValidateSubcommand::Hlsl(ValidateHlslCommand::Fxc))?;
for subcmd in ValidateSubcommand::all() {
let should_validate = match &subcmd {
ValidateSubcommand::Wgsl
| ValidateSubcommand::Spirv
| ValidateSubcommand::Glsl
| ValidateSubcommand::Dot => true,
ValidateSubcommand::Metal => cfg!(any(target_os = "macos", target_os = "ios")),
// The FXC compiler is only available on Windows.
//
// The DXC compiler can be built and run on any platform,
// but they don't make Linux releases and it's not clear
// what Git commit actually works on Linux, so restrict
// that to Windows as well.
ValidateSubcommand::Hlsl(
ValidateHlslCommand::Dxc | ValidateHlslCommand::Fxc,
) => cfg!(os = "windows"),
ValidateSubcommand::All => continue,
};
if should_validate {
collect_validation_jobs(jobs, subcmd)?;
}
}
}
};