@@ -466,6 +466,22 @@ impl RustwideBuilder {
466466 let successful = build_dir
467467 . build ( & self . toolchain , & krate, self . prepare_sandbox ( & limits) )
468468 . run ( |build| {
469+ let mut algs = HashSet :: new ( ) ;
470+
471+ debug ! ( "adding sources into database" ) ;
472+ let files_list = {
473+ let ( files_list, new_alg) = self
474+ . runtime
475+ . block_on ( add_path_into_remote_archive (
476+ & self . async_storage ,
477+ & source_archive_path ( name, version) ,
478+ build. host_source_dir ( ) ,
479+ false ,
480+ ) )
481+ . map_err ( |e| failure:: Error :: from_boxed_compat ( e. into ( ) ) ) ?;
482+ algs. insert ( new_alg) ;
483+ files_list
484+ } ;
469485 let metadata = Metadata :: from_crate_root ( build. host_source_dir ( ) ) ?;
470486 let BuildTargets {
471487 default_target,
@@ -528,7 +544,6 @@ impl RustwideBuilder {
528544 }
529545 }
530546
531- let mut algs = HashSet :: new ( ) ;
532547 let mut target_build_logs = HashMap :: new ( ) ;
533548 if has_docs {
534549 debug ! ( "adding documentation for the default target to the database" ) ;
@@ -564,20 +579,6 @@ impl RustwideBuilder {
564579 algs. insert ( new_alg) ;
565580 } ;
566581
567- // Store the sources even if the build fails
568- debug ! ( "adding sources into database" ) ;
569- let files_list = {
570- let ( files_list, new_alg) =
571- self . runtime . block_on ( add_path_into_remote_archive (
572- & self . async_storage ,
573- & source_archive_path ( name, version) ,
574- build. host_source_dir ( ) ,
575- false ,
576- ) ) ?;
577- algs. insert ( new_alg) ;
578- files_list
579- } ;
580-
581582 let has_examples = build. host_source_dir ( ) . join ( "examples" ) . is_dir ( ) ;
582583 if res. result . successful {
583584 self . metrics . successful_builds . inc ( ) ;
@@ -1369,6 +1370,34 @@ mod tests {
13691370 } ) ;
13701371 }
13711372
1373+ #[ test]
1374+ #[ ignore]
1375+ fn test_sources_are_added_even_for_build_failures_before_build ( ) {
1376+ wrapper ( |env| {
1377+ // https://github.com/rust-lang/docs.rs/issues/2523
1378+ // package with invalid cargo metadata.
1379+ // Will succeed in the crate fetch step, so sources are
1380+ // added. Will fail when we try to build.
1381+ let crate_ = "simconnect-sys" ;
1382+ let version = "0.23.1" ;
1383+ let mut builder = RustwideBuilder :: init ( env) . unwrap ( ) ;
1384+ builder. update_toolchain ( ) ?;
1385+
1386+ // `Result` is `Ok`, but the build-result is `false`
1387+ assert ! ( !builder. build_package( crate_, version, PackageKind :: CratesIo ) ?) ;
1388+
1389+ // source archice exists
1390+ let source_archive = source_archive_path ( crate_, version) ;
1391+ assert ! (
1392+ env. storage( ) . exists( & source_archive) ?,
1393+ "archive doesnt exist: {}" ,
1394+ source_archive
1395+ ) ;
1396+
1397+ Ok ( ( ) )
1398+ } ) ;
1399+ }
1400+
13721401 #[ test]
13731402 #[ ignore]
13741403 fn test_build_failures_before_build ( ) {
0 commit comments