@@ -51,7 +51,7 @@ pub struct RustwideBuilder {
51
51
storage : Arc < Storage > ,
52
52
metrics : Arc < Metrics > ,
53
53
index : Arc < Index > ,
54
- artifact_cache : ArtifactCache ,
54
+ artifact_cache : Option < ArtifactCache > ,
55
55
rustc_version : String ,
56
56
repository_stats_updater : Arc < RepositoryStatsUpdater > ,
57
57
skip_build_if_exists : bool ,
@@ -72,11 +72,17 @@ impl RustwideBuilder {
72
72
builder = builder. sandbox_image ( image) ;
73
73
}
74
74
75
- let artifact_cache = ArtifactCache :: new ( config. prefix . join ( "artifact_cache" ) ) ?;
75
+ let artifact_cache = if config. use_build_artifact_cache {
76
+ Some ( ArtifactCache :: new ( config. prefix . join ( "artifact_cache" ) ) ?)
77
+ } else {
78
+ None
79
+ } ;
76
80
77
81
if cfg ! ( test) {
78
82
builder = builder. fast_init ( true ) ;
79
- artifact_cache. purge ( ) ?;
83
+ if let Some ( ref artifact_cache) = artifact_cache {
84
+ artifact_cache. purge ( ) ?;
85
+ }
80
86
}
81
87
82
88
let workspace = builder. init ( ) . map_err ( FailureError :: compat) ?;
@@ -209,7 +215,9 @@ impl RustwideBuilder {
209
215
210
216
let has_changed = old_version. as_deref ( ) != Some ( & self . rustc_version ) ;
211
217
if has_changed {
212
- self . artifact_cache . purge ( ) ?;
218
+ if let Some ( ref artifact_cache) = self . artifact_cache {
219
+ artifact_cache. purge ( ) ?;
220
+ }
213
221
self . add_essential_files ( ) ?;
214
222
}
215
223
Ok ( has_changed)
@@ -418,15 +426,16 @@ impl RustwideBuilder {
418
426
}
419
427
} ;
420
428
421
- if let Some ( ref published_by) = release_data. published_by {
429
+ if let ( Some ( ref artifact_cache) , Some ( ref published_by) ) =
430
+ ( & self . artifact_cache , release_data. published_by )
431
+ {
422
432
info ! (
423
433
host_target_dir=?build. host_target_dir( ) ,
424
434
published_by_id=published_by. id,
425
435
published_by_login=published_by. login,
426
436
"restoring artifact cache" ,
427
437
) ;
428
- if let Err ( err) = self
429
- . artifact_cache
438
+ if let Err ( err) = artifact_cache
430
439
. restore_to ( & published_by. id . to_string ( ) , build. host_target_dir ( ) )
431
440
{
432
441
warn ! ( ?err, "could not restore artifact cache" ) ;
@@ -587,15 +596,16 @@ impl RustwideBuilder {
587
596
}
588
597
}
589
598
590
- if let Some ( ref published_by) = release_data. published_by {
599
+ if let ( Some ( artifact_cache) , Some ( ref published_by) ) =
600
+ ( & self . artifact_cache , release_data. published_by )
601
+ {
591
602
info ! (
592
603
host_target_dir=?build. host_target_dir( ) ,
593
604
published_by_id=published_by. id,
594
605
published_by_login=published_by. login,
595
606
"saving artifact cache" ,
596
607
) ;
597
- if let Err ( err) = self
598
- . artifact_cache
608
+ if let Err ( err) = artifact_cache
599
609
. save ( & published_by. id . to_string ( ) , build. host_target_dir ( ) )
600
610
. context ( "error saving artifact cache" )
601
611
{
@@ -1147,21 +1157,27 @@ mod tests {
1147
1157
// first build creates the cache
1148
1158
assert ! ( !expected_cache_dir. exists( ) ) ;
1149
1159
assert ! ( builder. build_package( crate_, version, PackageKind :: CratesIo ) ?) ;
1160
+
1161
+ for chld in std:: fs:: read_dir ( expected_cache_dir. parent ( ) . unwrap ( ) ) ? {
1162
+ dbg ! ( & chld) ;
1163
+ }
1164
+
1150
1165
assert ! ( expected_cache_dir. exists( ) ) ;
1151
1166
1152
1167
// cache dir doesn't contain doc output
1153
1168
assert ! ( !expected_cache_dir. join( "doc" ) . exists( ) ) ;
1154
1169
1155
- // but seems to be a normal cargo target directory
1170
+ // but seems to be a normal cargo target directory,
1171
+ // which also means that `build_package` actually used the
1172
+ // target directory, and it was moved into the cache afterwards.
1156
1173
for expected_file in & [ "CACHEDIR.TAG" , "debug" ] {
1157
1174
assert ! ( expected_cache_dir. join( expected_file) . exists( ) ) ;
1158
1175
}
1159
1176
1160
- // do a second build
1177
+ // do a second build,
1178
+ // should not fail
1161
1179
assert ! ( builder. build_package( crate_, version, PackageKind :: CratesIo ) ?) ;
1162
1180
1163
- // FIXME: how would I know if the cache was used?
1164
-
1165
1181
Ok ( ( ) )
1166
1182
} ) ;
1167
1183
}
0 commit comments