Skip to content

Commit 16f012b

Browse files
ErichDonGublerjimblandy
authored andcommitted
fix(naga-cli): allow output files with --stdin-file-path
1 parent 4e47ba4 commit 16f012b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ Bottom level categories:
4040

4141
## Unreleased
4242

43-
## New Features
43+
### New Features
4444

45-
### Naga
45+
#### Naga
4646

4747
- Parse `diagnostic(…)` directives, but don't implement any triggering rules yet. By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456).
48+
- 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).
4849

4950
### Changes
5051

naga-cli/src/bin/naga.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,15 @@ fn run() -> anyhow::Result<()> {
451451
return bulk_validate(args, &params);
452452
}
453453

454-
let (input_path, input) = if let Some(path) = args.files.first() {
455-
let path = Path::new(path);
456-
(path, fs::read(path)?)
457-
} else if let Some(path) = &args.stdin_file_path {
454+
let mut files = args.files.iter();
455+
456+
let (input_path, input) = if let Some(path) = args.stdin_file_path.as_ref() {
458457
let mut input = vec![];
459458
std::io::stdin().lock().read_to_end(&mut input)?;
460459
(Path::new(path), input)
460+
} else if let Some(path) = files.next() {
461+
let path = Path::new(path);
462+
(path, fs::read(path)?)
461463
} else {
462464
return Err(CliError("Input file path is not specified").into());
463465
};
@@ -492,12 +494,12 @@ fn run() -> anyhow::Result<()> {
492494
}
493495
}
494496

495-
let output_paths = args.files.get(1..).unwrap_or(&[]);
497+
let output_paths = files;
496498

497499
// Decide which capabilities our output formats can support.
498500
let validation_caps =
499501
output_paths
500-
.iter()
502+
.clone()
501503
.fold(naga::valid::Capabilities::all(), |caps, path| {
502504
use naga::valid::Capabilities as C;
503505
let missing = match Path::new(path).extension().and_then(|ex| ex.to_str()) {
@@ -567,7 +569,7 @@ fn run() -> anyhow::Result<()> {
567569
//
568570
// If the user asked for output, don't stop: some output formats (".txt",
569571
// ".dot", ".bin") can be generated even without a `ModuleInfo`.
570-
if output_paths.is_empty() {
572+
if output_paths.clone().next().is_none() {
571573
if info.is_some() {
572574
println!("Validation successful");
573575
return Ok(());

0 commit comments

Comments
 (0)