@@ -61,21 +61,24 @@ impl SpirvCli {
61
61
Self :: ensure_workspace_rust_version_doesnt_conflict_with_shader (
62
62
shader_crate_path,
63
63
is_force_overwrite_lockfiles_v4_to_v3,
64
- ) ?;
64
+ )
65
+ . context ( "ensure_workspace_rust_version_doesnt_conflict_with_shader" ) ?;
65
66
66
67
if let Some ( shader_crate_lock) = maybe_shader_crate_lock {
67
68
cargo_lock_files_with_changed_manifest_versions. push ( shader_crate_lock) ;
68
69
}
69
70
70
71
let ( default_rust_gpu_source, rust_gpu_date, default_rust_gpu_channel) =
71
- SpirvSource :: get_rust_gpu_deps_from_shader ( shader_crate_path) ?;
72
+ SpirvSource :: get_rust_gpu_deps_from_shader ( shader_crate_path)
73
+ . context ( "get_rust_gpu_deps_from_shader" ) ?;
72
74
73
75
let maybe_workspace_crate_lock =
74
76
Self :: ensure_shader_rust_version_doesnt_conflict_with_any_cargo_locks (
75
77
shader_crate_path,
76
78
default_rust_gpu_channel. clone ( ) ,
77
79
is_force_overwrite_lockfiles_v4_to_v3,
78
- ) ?;
80
+ )
81
+ . context ( "ensure_shader_rust_version_doesnt_conflict_with_any_cargo_locks" ) ?;
79
82
80
83
if let Some ( workspace_crate_lock) = maybe_workspace_crate_lock {
81
84
cargo_lock_files_with_changed_manifest_versions. push ( workspace_crate_lock) ;
@@ -104,12 +107,13 @@ impl SpirvCli {
104
107
105
108
/// Create and/or return the cache directory
106
109
pub fn cached_checkout_path ( & self ) -> anyhow:: Result < std:: path:: PathBuf > {
107
- let checkout_dir = crate :: cache_dir ( ) ?
110
+ let checkout_dir = crate :: cache_dir ( )
111
+ . context ( "reading cache dir" ) ?
108
112
. join ( "spirv-builder-cli" )
109
113
. join ( crate :: to_dirname ( self . to_string ( ) . as_ref ( ) ) ) ;
110
- std:: fs:: create_dir_all ( & checkout_dir) . with_context ( || {
111
- format ! ( "could not create checkout dir '{}'" , checkout_dir. display( ) )
112
- } ) ?;
114
+ std:: fs:: create_dir_all ( & checkout_dir)
115
+ . with_context ( || format ! ( "could not create checkout dir '{}'" , checkout_dir. display( ) ) )
116
+ . context ( "crating directory in cahce dir" ) ?;
113
117
114
118
Ok ( checkout_dir)
115
119
}
@@ -124,7 +128,8 @@ impl SpirvCli {
124
128
// Check for the required toolchain
125
129
let output_toolchain_list = std:: process:: Command :: new ( "rustup" )
126
130
. args ( [ "toolchain" , "list" ] )
127
- . output ( ) ?;
131
+ . output ( )
132
+ . context ( "running rustup command" ) ?;
128
133
anyhow:: ensure!(
129
134
output_toolchain_list. status. success( ) ,
130
135
"could not list installed toolchains"
@@ -145,7 +150,8 @@ impl SpirvCli {
145
150
. arg ( & self . channel )
146
151
. stdout ( std:: process:: Stdio :: inherit ( ) )
147
152
. stderr ( std:: process:: Stdio :: inherit ( ) )
148
- . output ( ) ?;
153
+ . output ( )
154
+ . context ( "adding toolchain" ) ?;
149
155
anyhow:: ensure!(
150
156
output_toolchain_add. status. success( ) ,
151
157
"could not install required toolchain"
@@ -156,7 +162,8 @@ impl SpirvCli {
156
162
let output_component_list = std:: process:: Command :: new ( "rustup" )
157
163
. args ( [ "component" , "list" , "--toolchain" ] )
158
164
. arg ( & self . channel )
159
- . output ( ) ?;
165
+ . output ( )
166
+ . context ( "getting toolchain list" ) ?;
160
167
anyhow:: ensure!(
161
168
output_component_list. status. success( ) ,
162
169
"could not list installed components"
@@ -184,7 +191,8 @@ impl SpirvCli {
184
191
. args ( [ "rust-src" , "rustc-dev" , "llvm-tools" ] )
185
192
. stdout ( std:: process:: Stdio :: inherit ( ) )
186
193
. stderr ( std:: process:: Stdio :: inherit ( ) )
187
- . output ( ) ?;
194
+ . output ( )
195
+ . context ( "adding rustup component" ) ?;
188
196
anyhow:: ensure!(
189
197
output_component_add. status. success( ) ,
190
198
"could not install required components"
@@ -200,10 +208,10 @@ impl SpirvCli {
200
208
return Ok ( ( ) ) ;
201
209
}
202
210
log:: debug!( "asking for consent to install the required toolchain" ) ;
203
- crossterm:: terminal:: enable_raw_mode ( ) ?;
211
+ crossterm:: terminal:: enable_raw_mode ( ) . context ( "enabling raw mode" ) ?;
204
212
crate :: user_output!( "{prompt} [y/n]: " ) ;
205
- let input = crossterm:: event:: read ( ) ?;
206
- crossterm:: terminal:: disable_raw_mode ( ) ?;
213
+ let input = crossterm:: event:: read ( ) . context ( "reading crossterm event" ) ?;
214
+ crossterm:: terminal:: disable_raw_mode ( ) . context ( "disabling raw mode" ) ?;
207
215
208
216
if let crossterm:: event:: Event :: Key ( crossterm:: event:: KeyEvent {
209
217
code : crossterm:: event:: KeyCode :: Char ( 'y' ) ,
@@ -223,7 +231,8 @@ impl SpirvCli {
223
231
is_force_overwrite_lockfiles_v4_to_v3 : bool ,
224
232
) -> anyhow:: Result < Option < std:: path:: PathBuf > > {
225
233
log:: debug!( "Ensuring no v3/v4 `Cargo.lock` conflicts from workspace Rust..." ) ;
226
- let workspace_rust_version = Self :: get_rustc_version ( None ) ?;
234
+ let workspace_rust_version =
235
+ Self :: get_rustc_version ( None ) . context ( "reading rustc version" ) ?;
227
236
if version_check:: Version :: at_least (
228
237
& workspace_rust_version,
229
238
RUST_VERSION_THAT_USES_V4_CARGO_LOCKS ,
@@ -238,7 +247,8 @@ impl SpirvCli {
238
247
Self :: handle_conflicting_cargo_lock_v4 (
239
248
shader_crate_path,
240
249
is_force_overwrite_lockfiles_v4_to_v3,
241
- ) ?;
250
+ )
251
+ . context ( "handling v4/v3 conflict" ) ?;
242
252
243
253
if is_force_overwrite_lockfiles_v4_to_v3 {
244
254
Ok ( Some ( shader_crate_path. join ( "Cargo.lock" ) ) )
@@ -254,7 +264,8 @@ impl SpirvCli {
254
264
is_force_overwrite_lockfiles_v4_to_v3 : bool ,
255
265
) -> anyhow:: Result < Option < std:: path:: PathBuf > > {
256
266
log:: debug!( "Ensuring no v3/v4 `Cargo.lock` conflicts from shader's Rust..." ) ;
257
- let shader_rust_version = Self :: get_rustc_version ( Some ( channel) ) ?;
267
+ let shader_rust_version =
268
+ Self :: get_rustc_version ( Some ( channel) ) . context ( "getting rustc version" ) ?;
258
269
if version_check:: Version :: at_least (
259
270
& shader_rust_version,
260
271
RUST_VERSION_THAT_USES_V4_CARGO_LOCKS ,
@@ -279,14 +290,18 @@ impl SpirvCli {
279
290
Self :: handle_conflicting_cargo_lock_v4 (
280
291
shader_crate_path,
281
292
is_force_overwrite_lockfiles_v4_to_v3,
282
- ) ?;
293
+ )
294
+ . context ( "handling v4/v3 conflict" ) ?;
283
295
}
284
296
285
- if let Some ( workspace_root) = Self :: get_workspace_root ( shader_crate_path) ? {
297
+ if let Some ( workspace_root) =
298
+ Self :: get_workspace_root ( shader_crate_path) . context ( "reading workspace root" ) ?
299
+ {
286
300
Self :: handle_conflicting_cargo_lock_v4 (
287
301
workspace_root,
288
302
is_force_overwrite_lockfiles_v4_to_v3,
289
- ) ?;
303
+ )
304
+ . context ( "handling conflicting cargo v4" ) ?;
290
305
return Ok ( Some ( workspace_root. join ( "Cargo.lock" ) ) ) ;
291
306
}
292
307
@@ -299,7 +314,8 @@ impl SpirvCli {
299
314
fn get_workspace_root (
300
315
shader_crate_path : & std:: path:: Path ,
301
316
) -> anyhow:: Result < Option < & std:: path:: Path > > {
302
- let shader_cargo_toml = std:: fs:: read_to_string ( shader_crate_path. join ( "Cargo.toml" ) ) ?;
317
+ let shader_cargo_toml = std:: fs:: read_to_string ( shader_crate_path. join ( "Cargo.toml" ) )
318
+ . with_context ( || format ! ( "reading Cargo.toml at {}" , shader_crate_path. display( ) ) ) ?;
303
319
if !shader_cargo_toml. contains ( "workspace = true" ) {
304
320
return Ok ( None ) ;
305
321
}
@@ -327,13 +343,15 @@ impl SpirvCli {
327
343
is_force_overwrite_lockfiles_v4_to_v3 : bool ,
328
344
) -> anyhow:: Result < ( ) > {
329
345
let shader_cargo_lock_path = folder. join ( "Cargo.lock" ) ;
330
- let shader_cargo_lock = std:: fs:: read_to_string ( shader_cargo_lock_path. clone ( ) ) ?;
331
- let third_line = shader_cargo_lock. lines ( ) . nth ( 2 ) . context ( "" ) ?;
346
+ let shader_cargo_lock = std:: fs:: read_to_string ( shader_cargo_lock_path. clone ( ) )
347
+ . context ( "reading shader cargo lock" ) ?;
348
+ let third_line = shader_cargo_lock. lines ( ) . nth ( 2 ) . context ( "no third line" ) ?;
332
349
if third_line. contains ( "version = 4" ) {
333
350
Self :: handle_v3v4_conflict (
334
351
& shader_cargo_lock_path,
335
352
is_force_overwrite_lockfiles_v4_to_v3,
336
- ) ?;
353
+ )
354
+ . context ( "handling v4/v3 conflict" ) ?;
337
355
return Ok ( ( ) ) ;
338
356
}
339
357
if third_line. contains ( "version = 3" ) {
@@ -355,7 +373,8 @@ impl SpirvCli {
355
373
Self :: exit_with_v3v4_hack_suggestion ( ) ;
356
374
}
357
375
358
- Self :: replace_cargo_lock_manifest_version ( offending_cargo_lock, "4" , "3" ) ?;
376
+ Self :: replace_cargo_lock_manifest_version ( offending_cargo_lock, "4" , "3" )
377
+ . context ( "replacing version 4 -> 3" ) ?;
359
378
360
379
Ok ( ( ) )
361
380
}
@@ -365,7 +384,8 @@ impl SpirvCli {
365
384
pub fn revert_cargo_lock_manifest_versions ( & self ) -> anyhow:: Result < ( ) > {
366
385
for offending_cargo_lock in & self . cargo_lock_files_with_changed_manifest_versions {
367
386
log:: debug!( "Reverting: {}" , offending_cargo_lock. display( ) ) ;
368
- Self :: replace_cargo_lock_manifest_version ( offending_cargo_lock, "3" , "4" ) ?;
387
+ Self :: replace_cargo_lock_manifest_version ( offending_cargo_lock, "3" , "4" )
388
+ . context ( "replacing version 3 -> 4" ) ?;
369
389
}
370
390
371
391
Ok ( ( ) )
@@ -383,7 +403,8 @@ impl SpirvCli {
383
403
to_version,
384
404
offending_cargo_lock. display( )
385
405
) ;
386
- let old_contents = std:: fs:: read_to_string ( offending_cargo_lock) ?;
406
+ let old_contents = std:: fs:: read_to_string ( offending_cargo_lock)
407
+ . context ( "reading offending Cargo.lock" ) ?;
387
408
let new_contents = old_contents. replace (
388
409
& format ! ( "\n version = {from_version}\n " ) ,
389
410
& format ! ( "\n version = {to_version}\n " ) ,
@@ -392,7 +413,8 @@ impl SpirvCli {
392
413
let mut file = std:: fs:: OpenOptions :: new ( )
393
414
. write ( true )
394
415
. truncate ( true )
395
- . open ( offending_cargo_lock) ?;
416
+ . open ( offending_cargo_lock)
417
+ . context ( "opening offending Cargo.lock" ) ?;
396
418
file. write_all ( new_contents. as_bytes ( ) ) ?;
397
419
398
420
Ok ( ( ) )
0 commit comments