@@ -247,20 +247,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
247
247
let kind = unit. kind ;
248
248
let json_messages = bcx. build_config . json_messages ( ) ;
249
249
let extra_verbose = bcx. config . extra_verbose ( ) ;
250
-
251
- // TODO: no duplicate
252
- let prev_script_out_dir = paths:: read_bytes ( & root_output_file)
253
- . and_then ( |bytes| util:: bytes2path ( & bytes) )
254
- . unwrap_or_else ( |_| script_out_dir. clone ( ) ) ;
255
-
256
- // TODO: no duplicate
257
- let prev_output = BuildOutput :: parse_file (
258
- & output_file,
259
- & unit. pkg . to_string ( ) ,
260
- & prev_script_out_dir,
261
- & script_out_dir,
262
- )
263
- . ok ( ) ;
250
+ let ( prev_output, prev_script_out_dir) = prev_build_output ( cx, unit) ;
264
251
265
252
fs:: create_dir_all ( & script_dir) ?;
266
253
fs:: create_dir_all ( & script_out_dir) ?;
@@ -692,28 +679,45 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>, units: &[Unit<'b>]) -> Ca
692
679
}
693
680
}
694
681
695
- fn parse_previous_explicit_deps < ' a , ' cfg > ( cx : & mut Context < ' a , ' cfg > , unit : & Unit < ' a > ) -> CargoResult < ( ) > {
696
- let script_out_dir = cx. files ( ) . build_script_out_dir ( unit) ;
682
+ fn parse_previous_explicit_deps < ' a , ' cfg > (
683
+ cx : & mut Context < ' a , ' cfg > ,
684
+ unit : & Unit < ' a > ,
685
+ ) -> CargoResult < ( ) > {
697
686
let script_run_dir = cx. files ( ) . build_script_run_dir ( unit) ;
698
- let root_output_file = script_run_dir. join ( "root-output" ) ;
699
687
let output_file = script_run_dir. join ( "output" ) ;
688
+ let ( prev_output, _) = prev_build_output ( cx, unit) ;
689
+ let deps = BuildDeps :: new ( & output_file, prev_output. as_ref ( ) ) ;
690
+ cx. build_explicit_deps . insert ( * unit, deps) ;
691
+ Ok ( ( ) )
692
+ }
693
+ }
700
694
701
- // Check to see if the build script has already run, and if it has, keep
702
- // track of whether it has told us about some explicit dependencies.
703
- let prev_script_out_dir = paths:: read_bytes ( & root_output_file)
704
- . and_then ( |bytes| util:: bytes2path ( & bytes) )
705
- . unwrap_or_else ( |_| script_out_dir. clone ( ) ) ;
695
+ /// Returns the previous parsed `BuildOutput`, if any, from a previous
696
+ /// execution.
697
+ ///
698
+ /// Also returns the directory containing the output, typically used later in
699
+ /// processing.
700
+ fn prev_build_output < ' a , ' cfg > (
701
+ cx : & mut Context < ' a , ' cfg > ,
702
+ unit : & Unit < ' a > ,
703
+ ) -> ( Option < BuildOutput > , PathBuf ) {
704
+ let script_out_dir = cx. files ( ) . build_script_out_dir ( unit) ;
705
+ let script_run_dir = cx. files ( ) . build_script_run_dir ( unit) ;
706
+ let root_output_file = script_run_dir. join ( "root-output" ) ;
707
+ let output_file = script_run_dir. join ( "output" ) ;
706
708
707
- let prev_output = BuildOutput :: parse_file (
709
+ let prev_script_out_dir = paths:: read_bytes ( & root_output_file)
710
+ . and_then ( |bytes| util:: bytes2path ( & bytes) )
711
+ . unwrap_or_else ( |_| script_out_dir. clone ( ) ) ;
712
+
713
+ (
714
+ BuildOutput :: parse_file (
708
715
& output_file,
709
716
& unit. pkg . to_string ( ) ,
710
717
& prev_script_out_dir,
711
718
& script_out_dir,
712
719
)
713
- . ok ( ) ;
714
-
715
- let deps = BuildDeps :: new ( & output_file, prev_output. as_ref ( ) ) ;
716
- cx. build_explicit_deps . insert ( * unit, deps) ;
717
- Ok ( ( ) )
718
- }
720
+ . ok ( ) ,
721
+ prev_script_out_dir,
722
+ )
719
723
}
0 commit comments