@@ -148,8 +148,8 @@ impl SpirvSource {
148
148
let parse_git = || {
149
149
let link = & source. repr . get ( 4 ..) ?;
150
150
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 ( ) ;
153
153
let rev = link. get ( sharp_index + 1 ..) ?. to_owned ( ) ;
154
154
Some ( Self :: Git { url, rev } )
155
155
} ;
@@ -248,6 +248,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
248
248
#[ cfg( test) ]
249
249
mod test {
250
250
use super :: * ;
251
+ use cargo_metadata:: { PackageBuilder , PackageId , Source } ;
251
252
252
253
#[ test_log:: test]
253
254
fn parsing_spirv_std_dep_for_shader_template ( ) {
@@ -281,4 +282,50 @@ mod test {
281
282
. unwrap ( ) ;
282
283
assert_eq ! ( "https___github_com_Rust-GPU_rust-gpu+86fc4803" , & name) ;
283
284
}
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
+ }
284
331
}
0 commit comments