Skip to content

Commit

Permalink
fix(naga-cli): allow output files with --stdin-file-path
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler authored and jimblandy committed Oct 31, 2024
1 parent 4e47ba4 commit 16f012b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions naga-cli/src/bin/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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(());
Expand Down

0 comments on commit 16f012b

Please sign in to comment.