Skip to content

Commit feedfe1

Browse files
schelltombh
authored andcommitted
sanitise the path for cargo tree invocation
1 parent 1bb88f9 commit feedfe1

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

crates/cargo-gpu/src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,17 @@ fn main() {
7878

7979
match cli.command {
8080
Command::Install(install) => {
81+
log::debug!("installing with arguments: {install:#?}");
8182
let (_, _) = install.run();
8283
}
83-
Command::Build(mut build) => build.run(),
84-
Command::Toml(toml) => toml.run(),
84+
Command::Build(mut build) => {
85+
log::debug!("building with arguments: {build:#?}");
86+
build.run()
87+
}
88+
Command::Toml(toml) => {
89+
log::debug!("building by toml file with arguments: {toml:#?}");
90+
toml.run()
91+
}
8592
Command::Show(show) => show.run(),
8693
Command::DumpUsage => dump_full_usage_for_readme(),
8794
}

crates/cargo-gpu/src/spirv_source.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,22 @@ impl SpirvSource {
172172

173173
/// Get the shader crate's `spirv_std = ...` definition in its `Cargo.toml`
174174
pub fn get_spirv_std_dep_definition(shader_crate_path: &std::path::PathBuf) -> Self {
175-
log::debug!("Running `cargo tree` on {}", shader_crate_path.display());
175+
let cwd = std::env::current_dir().expect("no cwd");
176+
let exec_path = if shader_crate_path.is_absolute() {
177+
shader_crate_path.clone()
178+
} else {
179+
cwd.join(shader_crate_path)
180+
}
181+
.canonicalize()
182+
.expect("could not get absolute path to shader crate");
183+
if !exec_path.is_dir() {
184+
log::error!("{exec_path:?} is not a directory, aborting");
185+
panic!("{exec_path:?} is not a directory");
186+
}
187+
188+
log::debug!("Running `cargo tree` on {}", exec_path.display());
176189
let output_cargo_tree = std::process::Command::new("cargo")
177-
.current_dir(shader_crate_path)
190+
.current_dir(&exec_path)
178191
.args(["tree", "--workspace", "--depth", "1", "--prefix", "none"])
179192
.output()
180193
.unwrap();
@@ -190,7 +203,7 @@ impl SpirvSource {
190203
log::trace!(" found {maybe_spirv_std_def:?}");
191204

192205
let Some(spirv_std_def) = maybe_spirv_std_def else {
193-
panic!("`spirv-std` not found in shader's `Cargo.toml` at {shader_crate_path:?}:\n{cargo_tree_string}");
206+
panic!("`spirv-std` not found in shader's `Cargo.toml` at {exec_path:?}:\n{cargo_tree_string}");
194207
};
195208

196209
Self::parse_spirv_std_source_and_version(spirv_std_def)
@@ -344,4 +357,10 @@ mod test {
344357
}
345358
);
346359
}
360+
361+
#[test_log::test]
362+
fn path_sanity() {
363+
let path = std::path::PathBuf::from("./");
364+
assert!(path.is_relative());
365+
}
347366
}

crates/cargo-gpu/src/toml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap::Parser;
55
use crate::{Cli, Command};
66

77
/// `cargo gpu toml`
8-
#[derive(Parser)]
8+
#[derive(Debug, Parser)]
99
pub struct Toml {
1010
/// Path to a workspace or package Cargo.toml file.
1111
///

0 commit comments

Comments
 (0)