Skip to content

Commit 8f319e7

Browse files
committed
fix git parsing with no ? in url
1 parent 6b01daa commit 8f319e7

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

Cargo.lock

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ semver.workspace = true
2727

2828
[dev-dependencies]
2929
test-log.workspace = true
30+
cargo_metadata = { workspace = true, features = ["builder"] }
3031

3132
[lints]
3233
workspace = true

crates/cargo-gpu/src/spirv_source.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ impl SpirvSource {
148148
let parse_git = || {
149149
let link = &source.repr.get(4..)?;
150150
let sharp_index = link.find('#')?;
151-
let question_mark_index = link.find('?')?;
152-
let url = link.get(..question_mark_index)?.to_owned();
151+
let url_end = link.find('?').unwrap_or(sharp_index);
152+
let url = link.get(..url_end)?.to_owned();
153153
let rev = link.get(sharp_index + 1..)?.to_owned();
154154
Some(Self::Git { url, rev })
155155
};
@@ -248,6 +248,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
248248
#[cfg(test)]
249249
mod test {
250250
use super::*;
251+
use cargo_metadata::{PackageBuilder, PackageId, Source};
251252

252253
#[test_log::test]
253254
fn parsing_spirv_std_dep_for_shader_template() {
@@ -281,4 +282,50 @@ mod test {
281282
.unwrap();
282283
assert_eq!("https___github_com_Rust-GPU_rust-gpu+86fc4803", &name);
283284
}
285+
286+
#[test_log::test]
287+
fn parse_git_with_rev() {
288+
let source = parse_git(
289+
"git+https://github.com/Rust-GPU/rust-gpu?rev=86fc48032c4cd4afb74f1d81ae859711d20386a1#86fc4803",
290+
);
291+
assert_eq!(
292+
source,
293+
SpirvSource::Git {
294+
url: "https://github.com/Rust-GPU/rust-gpu".to_owned(),
295+
rev: "86fc4803".to_owned(),
296+
}
297+
)
298+
}
299+
300+
#[test_log::test]
301+
fn parse_git_no_question_mark() {
302+
// taken directly from Graphite
303+
let source = parse_git(
304+
"git+https://github.com/Rust-GPU/rust-gpu.git#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421",
305+
);
306+
assert_eq!(
307+
source,
308+
SpirvSource::Git {
309+
url: "https://github.com/Rust-GPU/rust-gpu.git".to_owned(),
310+
rev: "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421".to_owned(),
311+
}
312+
)
313+
}
314+
315+
fn parse_git(source: &str) -> SpirvSource {
316+
let package = PackageBuilder::new(
317+
"spirv-std",
318+
Version::new(0, 9, 0),
319+
PackageId {
320+
repr: "".to_owned(),
321+
},
322+
"",
323+
)
324+
.source(Some(Source {
325+
repr: source.to_owned(),
326+
}))
327+
.build()
328+
.unwrap();
329+
SpirvSource::parse_spirv_std_source_and_version(&package).unwrap()
330+
}
284331
}

0 commit comments

Comments
 (0)