fix(naga-cli): allow output files with --stdin-file-path

This commit is contained in:
Erich Gubler 2024-10-30 15:34:54 -07:00 committed by Jim Blandy
parent 4e47ba4ac0
commit 16f012bc93
2 changed files with 12 additions and 9 deletions

View File

@ -40,11 +40,12 @@ Bottom level categories:
## Unreleased
## New Features
### New Features
### Naga
#### Naga
- Parse `diagnostic(…)` directives, but don't implement any triggering rules yet. By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456).
- Fix an issue where `naga` CLI would incorrectly skip the first positional argument when `--stdin-file-path` was specified. By @ErichDonGubler in [#6480](https://github.com/gfx-rs/wgpu/pull/6480).
### Changes

View File

@ -451,13 +451,15 @@ fn run() -> anyhow::Result<()> {
return bulk_validate(args, &params);
}
let (input_path, input) = if let Some(path) = args.files.first() {
let path = Path::new(path);
(path, fs::read(path)?)
} else if let Some(path) = &args.stdin_file_path {
let mut files = args.files.iter();
let (input_path, input) = if let Some(path) = args.stdin_file_path.as_ref() {
let mut input = vec![];
std::io::stdin().lock().read_to_end(&mut input)?;
(Path::new(path), input)
} else if let Some(path) = files.next() {
let path = Path::new(path);
(path, fs::read(path)?)
} else {
return Err(CliError("Input file path is not specified").into());
};
@ -492,12 +494,12 @@ fn run() -> anyhow::Result<()> {
}
}
let output_paths = args.files.get(1..).unwrap_or(&[]);
let output_paths = files;
// Decide which capabilities our output formats can support.
let validation_caps =
output_paths
.iter()
.clone()
.fold(naga::valid::Capabilities::all(), |caps, path| {
use naga::valid::Capabilities as C;
let missing = match Path::new(path).extension().and_then(|ex| ex.to_str()) {
@ -567,7 +569,7 @@ fn run() -> anyhow::Result<()> {
//
// If the user asked for output, don't stop: some output formats (".txt",
// ".dot", ".bin") can be generated even without a `ModuleInfo`.
if output_paths.is_empty() {
if output_paths.clone().next().is_none() {
if info.is_some() {
println!("Validation successful");
return Ok(());