@@ -343,7 +343,6 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
343343 } else {
344344 build_runner. files ( ) . build_script_out_dir ( unit)
345345 } ;
346- let script_run_dir = build_runner. files ( ) . build_script_run_dir ( unit) ;
347346
348347 if let Some ( deps) = unit. pkg . manifest ( ) . metabuild ( ) {
349348 prepare_metabuild ( build_runner, build_script_unit, deps) ?;
@@ -490,16 +489,14 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
490489 let pkg_descr = unit. pkg . to_string ( ) ;
491490 let build_script_outputs = Arc :: clone ( & build_runner. build_script_outputs ) ;
492491 let id = unit. pkg . package_id ( ) ;
493- let output_file = script_run_dir. join ( "output" ) ;
494- let err_file = script_run_dir. join ( "stderr" ) ;
495- let root_output_file = script_run_dir. join ( "root-output" ) ;
492+ let run_files = BuildScriptRunFiles :: for_unit ( build_runner, unit) ;
496493 let host_target_root = build_runner. files ( ) . host_dest ( ) . map ( |v| v. to_path_buf ( ) ) ;
497494 let all = (
498495 id,
499496 library_name. clone ( ) ,
500497 pkg_descr. clone ( ) ,
501498 Arc :: clone ( & build_script_outputs) ,
502- output_file . clone ( ) ,
499+ run_files . stdout . clone ( ) ,
503500 script_out_dir. clone ( ) ,
504501 ) ;
505502 let build_scripts = build_runner. build_scripts . get ( unit) . cloned ( ) ;
@@ -510,7 +507,7 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
510507
511508 paths:: create_dir_all ( & script_dir) ?;
512509 paths:: create_dir_all ( & script_out_dir) ?;
513- paths:: create_dir_all ( & script_run_dir ) ?;
510+ paths:: create_dir_all ( & run_files . root ) ?;
514511
515512 let nightly_features_allowed = build_runner. bcx . gctx . nightly_features_allowed ;
516513 let targets: Vec < Target > = unit. pkg . targets ( ) . to_vec ( ) ;
@@ -584,7 +581,7 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
584581
585582 // And now finally, run the build command itself!
586583 state. running ( & cmd) ;
587- let timestamp = paths:: set_invocation_time ( & script_run_dir ) ?;
584+ let timestamp = paths:: set_invocation_time ( & run_files . root ) ?;
588585 let prefix = format ! ( "[{} {}] " , id. name( ) , id. version( ) ) ;
589586 let mut log_messages_in_case_of_panic = Vec :: new ( ) ;
590587 let span = tracing:: debug_span!( "build_script" , process = cmd. to_string( ) ) ;
@@ -669,12 +666,12 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
669666 // This is also the location where we provide feedback into the build
670667 // state informing what variables were discovered via our script as
671668 // well.
672- paths:: write ( & output_file , & output. stdout ) ?;
669+ paths:: write ( & run_files . stdout , & output. stdout ) ?;
673670 // This mtime shift allows Cargo to detect if a source file was
674671 // modified in the middle of the build.
675- paths:: set_file_time_no_err ( output_file , timestamp) ;
676- paths:: write ( & err_file , & output. stderr ) ?;
677- paths:: write ( & root_output_file , paths:: path2bytes ( & script_out_dir) ?) ?;
672+ paths:: set_file_time_no_err ( run_files . stdout , timestamp) ;
673+ paths:: write ( & run_files . stderr , & output. stderr ) ?;
674+ paths:: write ( & run_files . root_output , paths:: path2bytes ( & script_out_dir) ?) ?;
678675 let parsed_output = BuildOutput :: parse (
679676 & output. stdout ,
680677 library_name,
@@ -1355,10 +1352,9 @@ pub fn build_map(build_runner: &mut BuildRunner<'_, '_>) -> CargoResult<()> {
13551352
13561353 /// Load any dependency declarations from a previous build script run.
13571354 fn parse_previous_explicit_deps ( build_runner : & mut BuildRunner < ' _ , ' _ > , unit : & Unit ) {
1358- let script_run_dir = build_runner. files ( ) . build_script_run_dir ( unit) ;
1359- let output_file = script_run_dir. join ( "output" ) ;
1355+ let run_files = BuildScriptRunFiles :: for_unit ( build_runner, unit) ;
13601356 let ( prev_output, _) = prev_build_output ( build_runner, unit) ;
1361- let deps = BuildDeps :: new ( & output_file , prev_output. as_ref ( ) ) ;
1357+ let deps = BuildDeps :: new ( & run_files . stdout , prev_output. as_ref ( ) ) ;
13621358 build_runner. build_explicit_deps . insert ( unit. clone ( ) , deps) ;
13631359 }
13641360}
@@ -1377,17 +1373,15 @@ fn prev_build_output(
13771373 } else {
13781374 build_runner. files ( ) . build_script_out_dir ( unit)
13791375 } ;
1380- let script_run_dir = build_runner. files ( ) . build_script_run_dir ( unit) ;
1381- let root_output_file = script_run_dir. join ( "root-output" ) ;
1382- let output_file = script_run_dir. join ( "output" ) ;
1376+ let run_files = BuildScriptRunFiles :: for_unit ( build_runner, unit) ;
13831377
1384- let prev_script_out_dir = paths:: read_bytes ( & root_output_file )
1378+ let prev_script_out_dir = paths:: read_bytes ( & run_files . root_output )
13851379 . and_then ( |bytes| paths:: bytes2path ( & bytes) )
13861380 . unwrap_or_else ( |_| script_out_dir. clone ( ) ) ;
13871381
13881382 (
13891383 BuildOutput :: parse_file (
1390- & output_file ,
1384+ & run_files . stdout ,
13911385 unit. pkg . library ( ) . map ( |t| t. crate_name ( ) ) ,
13921386 & unit. pkg . to_string ( ) ,
13931387 & prev_script_out_dir,
@@ -1434,3 +1428,35 @@ impl BuildScriptOutputs {
14341428 self . outputs . iter ( )
14351429 }
14361430}
1431+
1432+ /// Files with information about a running build script.
1433+ struct BuildScriptRunFiles {
1434+ /// The directory containing files related to running a build script.
1435+ root : PathBuf ,
1436+ /// The stdout produced by the build script
1437+ stdout : PathBuf ,
1438+ /// The stderr produced by the build script
1439+ stderr : PathBuf ,
1440+ /// A file that contains the path of `root`.
1441+ /// This is used for detect if the directory was moved since the previous run.
1442+ root_output : PathBuf ,
1443+ }
1444+
1445+ impl BuildScriptRunFiles {
1446+ pub fn for_unit ( build_runner : & BuildRunner < ' _ , ' _ > , unit : & Unit ) -> Self {
1447+ let root = build_runner. files ( ) . build_script_run_dir ( unit) ;
1448+ let stdout = if build_runner. bcx . gctx . cli_unstable ( ) . build_dir_new_layout {
1449+ root. join ( "stdout" )
1450+ } else {
1451+ root. join ( "output" )
1452+ } ;
1453+ let stderr = root. join ( "stderr" ) ;
1454+ let root_output = root. join ( "root-output" ) ;
1455+ Self {
1456+ root,
1457+ stdout,
1458+ stderr,
1459+ root_output,
1460+ }
1461+ }
1462+ }
0 commit comments