@@ -28,6 +28,8 @@ pub struct BuildOutput {
28
28
pub metadata : Vec < ( String , String ) > ,
29
29
/// Paths to trigger a rerun of this build script.
30
30
pub rerun_if_changed : Vec < String > ,
31
+ /// Environment variables which, when changed, will cause a rebuild.
32
+ pub rerun_if_env_changed : Vec < String > ,
31
33
/// Warnings generated by this build,
32
34
pub warnings : Vec < String > ,
33
35
}
@@ -59,6 +61,12 @@ pub struct BuildScripts {
59
61
pub plugins : BTreeSet < PackageId > ,
60
62
}
61
63
64
+ pub struct BuildDeps {
65
+ pub build_script_output : PathBuf ,
66
+ pub rerun_if_changed : Vec < String > ,
67
+ pub rerun_if_env_changed : Vec < String > ,
68
+ }
69
+
62
70
/// Prepares a `Work` that executes the target as a custom build script.
63
71
///
64
72
/// The `req` given is the requirement which this run of the build script will
@@ -181,11 +189,8 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
181
189
// Check to see if the build script has already run, and if it has keep
182
190
// track of whether it has told us about some explicit dependencies
183
191
let prev_output = BuildOutput :: parse_file ( & output_file, & pkg_name) . ok ( ) ;
184
- let rerun_if_changed = match prev_output {
185
- Some ( ref prev) => prev. rerun_if_changed . clone ( ) ,
186
- None => Vec :: new ( ) ,
187
- } ;
188
- cx. build_explicit_deps . insert ( * unit, ( output_file. clone ( ) , rerun_if_changed) ) ;
192
+ let deps = BuildDeps :: new ( & output_file, prev_output. as_ref ( ) ) ;
193
+ cx. build_explicit_deps . insert ( * unit, deps) ;
189
194
190
195
fs:: create_dir_all ( & script_output) ?;
191
196
fs:: create_dir_all ( & build_output) ?;
@@ -246,8 +251,6 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
246
251
247
252
} ) ?;
248
253
249
- paths:: write ( & output_file, & output. stdout ) ?;
250
- paths:: write ( & err_file, & output. stderr ) ?;
251
254
252
255
// After the build command has finished running, we need to be sure to
253
256
// remember all of its output so we can later discover precisely what it
@@ -256,6 +259,8 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
256
259
// This is also the location where we provide feedback into the build
257
260
// state informing what variables were discovered via our script as
258
261
// well.
262
+ paths:: write ( & output_file, & output. stdout ) ?;
263
+ paths:: write ( & err_file, & output. stderr ) ?;
259
264
let parsed_output = BuildOutput :: parse ( & output. stdout , & pkg_name) ?;
260
265
261
266
if json_messages {
@@ -337,6 +342,7 @@ impl BuildOutput {
337
342
let mut env = Vec :: new ( ) ;
338
343
let mut metadata = Vec :: new ( ) ;
339
344
let mut rerun_if_changed = Vec :: new ( ) ;
345
+ let mut rerun_if_env_changed = Vec :: new ( ) ;
340
346
let mut warnings = Vec :: new ( ) ;
341
347
let whence = format ! ( "build script of `{}`" , pkg_name) ;
342
348
@@ -378,6 +384,7 @@ impl BuildOutput {
378
384
"rustc-env" => env. push ( BuildOutput :: parse_rustc_env ( value, & whence) ?) ,
379
385
"warning" => warnings. push ( value. to_string ( ) ) ,
380
386
"rerun-if-changed" => rerun_if_changed. push ( value. to_string ( ) ) ,
387
+ "rerun-if-env-changed" => rerun_if_env_changed. push ( value. to_string ( ) ) ,
381
388
_ => metadata. push ( ( key. to_string ( ) , value. to_string ( ) ) ) ,
382
389
}
383
390
}
@@ -389,6 +396,7 @@ impl BuildOutput {
389
396
env : env,
390
397
metadata : metadata,
391
398
rerun_if_changed : rerun_if_changed,
399
+ rerun_if_env_changed : rerun_if_env_changed,
392
400
warnings : warnings,
393
401
} )
394
402
}
@@ -436,6 +444,20 @@ impl BuildOutput {
436
444
}
437
445
}
438
446
447
+ impl BuildDeps {
448
+ pub fn new ( output_file : & Path , output : Option < & BuildOutput > ) -> BuildDeps {
449
+ BuildDeps {
450
+ build_script_output : output_file. to_path_buf ( ) ,
451
+ rerun_if_changed : output. map ( |p| & p. rerun_if_changed )
452
+ . cloned ( )
453
+ . unwrap_or_default ( ) ,
454
+ rerun_if_env_changed : output. map ( |p| & p. rerun_if_env_changed )
455
+ . cloned ( )
456
+ . unwrap_or_default ( ) ,
457
+ }
458
+ }
459
+ }
460
+
439
461
/// Compute the `build_scripts` map in the `Context` which tracks what build
440
462
/// scripts each package depends on.
441
463
///
0 commit comments