1
+ use super :: caching:: ArtifactCache ;
1
2
use crate :: db:: file:: add_path_into_database;
2
3
use crate :: db:: {
3
4
add_build_into_database, add_doc_coverage, add_package_into_database,
@@ -27,12 +28,13 @@ use rustwide::{AlternativeRegistry, Build, Crate, Toolchain, Workspace, Workspac
27
28
use std:: collections:: { HashMap , HashSet } ;
28
29
use std:: path:: Path ;
29
30
use std:: sync:: Arc ;
30
- use tracing:: { debug, info, warn} ;
31
+ use tracing:: { debug, info, instrument , warn} ;
31
32
32
33
const USER_AGENT : & str = "docs.rs builder (https://github.com/rust-lang/docs.rs)" ;
33
34
const DUMMY_CRATE_NAME : & str = "empty-library" ;
34
35
const DUMMY_CRATE_VERSION : & str = "1.0.0" ;
35
36
37
+ #[ derive( Debug ) ]
36
38
pub enum PackageKind < ' a > {
37
39
Local ( & ' a Path ) ,
38
40
CratesIo ,
@@ -47,6 +49,7 @@ pub struct RustwideBuilder {
47
49
storage : Arc < Storage > ,
48
50
metrics : Arc < Metrics > ,
49
51
index : Arc < Index > ,
52
+ artifact_cache : ArtifactCache ,
50
53
rustc_version : String ,
51
54
repository_stats_updater : Arc < RepositoryStatsUpdater > ,
52
55
skip_build_if_exists : bool ,
@@ -89,6 +92,7 @@ impl RustwideBuilder {
89
92
Ok ( RustwideBuilder {
90
93
workspace,
91
94
toolchain,
95
+ artifact_cache : ArtifactCache :: new ( config. prefix . join ( "artifact_cache" ) ) ?,
92
96
config,
93
97
db : context. pool ( ) ?,
94
98
storage : context. storage ( ) ?,
@@ -197,6 +201,7 @@ impl RustwideBuilder {
197
201
198
202
let has_changed = old_version. as_deref ( ) != Some ( & self . rustc_version ) ;
199
203
if has_changed {
204
+ self . artifact_cache . purge ( ) ?;
200
205
self . add_essential_files ( ) ?;
201
206
}
202
207
Ok ( has_changed)
@@ -319,6 +324,7 @@ impl RustwideBuilder {
319
324
self . build_package ( & package. name , & package. version , PackageKind :: Local ( path) )
320
325
}
321
326
327
+ #[ instrument( skip( self ) ) ]
322
328
pub fn build_package (
323
329
& mut self ,
324
330
name : & str ,
@@ -383,6 +389,34 @@ impl RustwideBuilder {
383
389
( || -> Result < bool > {
384
390
use docsrs_metadata:: BuildTargets ;
385
391
392
+ let release_data = match self
393
+ . index
394
+ . api ( )
395
+ . get_release_data ( name, version)
396
+ . context ( "error fetching release data from crates.io" )
397
+ {
398
+ Ok ( data) => data,
399
+ Err ( err) => {
400
+ warn ! ( "{:#?}" , err) ;
401
+ ReleaseData :: default ( )
402
+ }
403
+ } ;
404
+
405
+ if let Some ( ref published_by) = release_data. published_by {
406
+ info ! (
407
+ host_target_dir=?build. host_target_dir( ) ,
408
+ published_by_id=published_by. id,
409
+ published_by_login=published_by. login,
410
+ "restoring artifact cache" ,
411
+ ) ;
412
+ if let Err ( err) = self
413
+ . artifact_cache
414
+ . restore_to ( & published_by. id . to_string ( ) , build. host_target_dir ( ) )
415
+ {
416
+ warn ! ( ?err, "could not restore artifact cache" ) ;
417
+ }
418
+ }
419
+
386
420
let mut has_docs = false ;
387
421
let mut successful_targets = Vec :: new ( ) ;
388
422
let metadata = Metadata :: from_crate_root ( build. host_source_dir ( ) ) ?;
@@ -534,6 +568,22 @@ impl RustwideBuilder {
534
568
Err ( err) => warn ! ( "{:#?}" , err) ,
535
569
}
536
570
571
+ if let Some ( ref published_by) = release_data. published_by {
572
+ info ! (
573
+ host_target_dir=?build. host_target_dir( ) ,
574
+ published_by_id=published_by. id,
575
+ published_by_login=published_by. login,
576
+ "saving artifact cache" ,
577
+ ) ;
578
+ if let Err ( err) = self
579
+ . artifact_cache
580
+ . save ( & published_by. id . to_string ( ) , build. host_target_dir ( ) )
581
+ . context ( "error giving back artifact cache" )
582
+ {
583
+ warn ! ( ?err, "could not give back artifact cache" ) ;
584
+ } ;
585
+ }
586
+
537
587
if res. result . successful {
538
588
// delete eventually existing files from pre-archive storage.
539
589
// we're doing this in the end so eventual problems in the build
0 commit comments