@@ -198,7 +198,8 @@ impl Profiler {
198
198
199
199
struct CargoProcess < ' a > {
200
200
compiler : Compiler < ' a > ,
201
- cwd : & ' a Path ,
201
+ src_dir : & ' a Path ,
202
+ target_directory : & ' a Path ,
202
203
build_kind : BuildKind ,
203
204
incremental : bool ,
204
205
processor_etc : Option < ( & ' a mut dyn Processor , RunKind , & ' a str , Option < & ' a Patch > ) > ,
@@ -227,7 +228,7 @@ impl<'a> CargoProcess<'a> {
227
228
self
228
229
}
229
230
230
- fn base_command ( & self , cwd : & Path , subcommand : & str ) -> Command {
231
+ fn base_command ( & self , subcommand : & str ) -> Command {
231
232
let mut cmd = Command :: new ( Path :: new ( self . compiler . cargo ) ) ;
232
233
cmd
233
234
// Not all cargo invocations (e.g. `cargo clean`) need all of these
@@ -239,7 +240,9 @@ impl<'a> CargoProcess<'a> {
239
240
// and any in-tree dependencies, and we don't want that; it wastes
240
241
// time.
241
242
. env ( "CARGO_INCREMENTAL" , "0" )
242
- . current_dir ( cwd)
243
+ . current_dir ( self . src_dir )
244
+ . arg ( "--target-dir" )
245
+ . arg ( self . target_directory )
243
246
. arg ( subcommand)
244
247
. arg ( "--manifest-path" )
245
248
. arg ( & self . manifest_path ) ;
@@ -250,10 +253,10 @@ impl<'a> CargoProcess<'a> {
250
253
cmd
251
254
}
252
255
253
- fn get_pkgid ( & self , cwd : & Path ) -> anyhow:: Result < String > {
254
- let mut pkgid_cmd = self . base_command ( cwd , "pkgid" ) ;
256
+ fn get_pkgid ( & self ) -> anyhow:: Result < String > {
257
+ let mut pkgid_cmd = self . base_command ( "pkgid" ) ;
255
258
let out = command_output ( & mut pkgid_cmd)
256
- . with_context ( || format ! ( "failed to obtain pkgid in '{:?}'" , cwd ) ) ?
259
+ . with_context ( || format ! ( "failed to obtain pkgid in '{:?}'" , self . src_dir ) ) ?
257
260
. stdout ;
258
261
let package_id = str:: from_utf8 ( & out) . unwrap ( ) ;
259
262
Ok ( package_id. trim ( ) . to_string ( ) )
@@ -305,8 +308,8 @@ impl<'a> CargoProcess<'a> {
305
308
}
306
309
} ;
307
310
308
- let mut cmd = self . base_command ( self . cwd , subcommand) ;
309
- cmd. arg ( "-p" ) . arg ( self . get_pkgid ( self . cwd ) ?) ;
311
+ let mut cmd = self . base_command ( subcommand) ;
312
+ cmd. arg ( "-p" ) . arg ( self . get_pkgid ( ) ?) ;
310
313
match self . build_kind {
311
314
BuildKind :: Check => {
312
315
cmd. arg ( "--profile" ) . arg ( "check" ) ;
@@ -353,10 +356,10 @@ impl<'a> CargoProcess<'a> {
353
356
// in-tree (e.g., in the case of the servo crates there are a lot of
354
357
// other components).
355
358
if let Some ( file) = & self . touch_file {
356
- touch ( & self . cwd , Path :: new ( & file) ) ?;
359
+ touch ( & self . src_dir , Path :: new ( & file) ) ?;
357
360
} else {
358
361
touch_all (
359
- & self . cwd . join (
362
+ & self . src_dir . join (
360
363
Path :: new ( & self . manifest_path )
361
364
. parent ( )
362
365
. expect ( "manifest has parent" ) ,
@@ -374,7 +377,7 @@ impl<'a> CargoProcess<'a> {
374
377
if self . incremental {
375
378
cmd. arg ( "-C" ) ;
376
379
let mut incr_arg = std:: ffi:: OsString :: from ( "incremental=" ) ;
377
- incr_arg. push ( self . cwd . join ( "incremental-state" ) ) ;
380
+ incr_arg. push ( self . target_directory . join ( "incremental-state" ) ) ;
378
381
cmd. arg ( incr_arg) ;
379
382
}
380
383
@@ -388,7 +391,7 @@ impl<'a> CargoProcess<'a> {
388
391
if let Some ( ( ref mut processor, run_kind, run_kind_str, patch) ) = self . processor_etc {
389
392
let data = ProcessOutputData {
390
393
name : self . processor_name . clone ( ) ,
391
- cwd : self . cwd ,
394
+ cwd : self . target_directory ,
392
395
build_kind : self . build_kind ,
393
396
run_kind,
394
397
run_kind_str,
@@ -952,7 +955,8 @@ impl Benchmark {
952
955
fn mk_cargo_process < ' a > (
953
956
& ' a self ,
954
957
compiler : Compiler < ' a > ,
955
- cwd : & ' a Path ,
958
+ target_directory : & ' a Path ,
959
+ src_dir : & ' a Path ,
956
960
build_kind : BuildKind ,
957
961
) -> CargoProcess < ' a > {
958
962
let mut cargo_args = self
@@ -973,7 +977,8 @@ impl Benchmark {
973
977
CargoProcess {
974
978
compiler,
975
979
processor_name : self . name . clone ( ) ,
976
- cwd,
980
+ target_directory,
981
+ src_dir,
977
982
build_kind,
978
983
incremental : false ,
979
984
processor_etc : None ,
@@ -1013,9 +1018,11 @@ impl Benchmark {
1013
1018
}
1014
1019
1015
1020
eprintln ! ( "Preparing {}" , self . name) ;
1021
+
1022
+ // These directories are *target* directories.
1016
1023
let build_kind_dirs = build_kinds
1017
1024
. iter ( )
1018
- . map ( |kind| Ok ( ( * kind, self . make_temp_dir ( & self . path ) ?) ) )
1025
+ . map ( |kind| Ok ( ( * kind, TempDir :: new ( ) ? , self . make_temp_dir ( & self . path ) ?) ) )
1019
1026
. collect :: < anyhow:: Result < Vec < _ > > > ( ) ?;
1020
1027
1021
1028
// In parallel (but with a limit to the number of CPUs), prepare all
@@ -1041,10 +1048,10 @@ impl Benchmark {
1041
1048
// target-directory global lock during compilation.
1042
1049
crossbeam_utils:: thread:: scope :: < _ , anyhow:: Result < ( ) > > ( |s| {
1043
1050
let server = jobserver:: Client :: new ( num_cpus:: get ( ) ) . context ( "jobserver::new" ) ?;
1044
- for ( build_kind, prep_dir ) in & build_kind_dirs {
1051
+ for ( build_kind, target_dir , src_dir ) in & build_kind_dirs {
1045
1052
let server = server. clone ( ) ;
1046
1053
s. spawn :: < _ , anyhow:: Result < ( ) > > ( move |_| {
1047
- self . mk_cargo_process ( compiler, prep_dir . path ( ) , * build_kind)
1054
+ self . mk_cargo_process ( compiler, target_dir . path ( ) , src_dir . path ( ) , * build_kind)
1048
1055
. jobserver ( server)
1049
1056
. run_rustc ( false ) ?;
1050
1057
Ok ( ( ) )
@@ -1054,7 +1061,7 @@ impl Benchmark {
1054
1061
} )
1055
1062
. unwrap ( ) ?;
1056
1063
1057
- for ( build_kind, prep_dir ) in build_kind_dirs {
1064
+ for ( build_kind, target_dir , src_dir ) in build_kind_dirs {
1058
1065
eprintln ! ( "Running {}: {:?} + {:?}" , self . name, build_kind, run_kinds) ;
1059
1066
1060
1067
// We want at least two runs for all benchmarks (since we run
@@ -1070,12 +1077,14 @@ impl Benchmark {
1070
1077
}
1071
1078
}
1072
1079
log:: debug!( "Benchmark iteration {}/{}" , i + 1 , iterations) ;
1073
- let timing_dir = self . make_temp_dir ( prep_dir. path ( ) ) ?;
1074
- let cwd = timing_dir. path ( ) ;
1080
+ let target_dir = self . make_temp_dir ( target_dir. path ( ) ) ?;
1081
+ let target_dir = target_dir. path ( ) ;
1082
+ let src_dir = self . make_temp_dir ( src_dir. path ( ) ) ?;
1083
+ let src_dir = src_dir. path ( ) ;
1075
1084
1076
1085
// A full non-incremental build.
1077
1086
if run_kinds. contains ( & RunKind :: Full ) {
1078
- self . mk_cargo_process ( compiler, cwd , build_kind)
1087
+ self . mk_cargo_process ( compiler, target_dir , src_dir , build_kind)
1079
1088
. processor ( processor, RunKind :: Full , "Full" , None )
1080
1089
. run_rustc ( true ) ?;
1081
1090
}
@@ -1088,15 +1097,15 @@ impl Benchmark {
1088
1097
|| run_kinds. contains ( & RunKind :: IncrUnchanged )
1089
1098
|| run_kinds. contains ( & RunKind :: IncrPatched )
1090
1099
{
1091
- self . mk_cargo_process ( compiler, cwd , build_kind)
1100
+ self . mk_cargo_process ( compiler, target_dir , src_dir , build_kind)
1092
1101
. incremental ( true )
1093
1102
. processor ( processor, RunKind :: IncrFull , "IncrFull" , None )
1094
1103
. run_rustc ( true ) ?;
1095
1104
}
1096
1105
1097
1106
// An incremental build with no changes (fastest incremental case).
1098
1107
if run_kinds. contains ( & RunKind :: IncrUnchanged ) {
1099
- self . mk_cargo_process ( compiler, cwd , build_kind)
1108
+ self . mk_cargo_process ( compiler, target_dir , src_dir , build_kind)
1100
1109
. incremental ( true )
1101
1110
. processor ( processor, RunKind :: IncrUnchanged , "IncrUnchanged" , None )
1102
1111
. run_rustc ( true ) ?;
@@ -1105,12 +1114,12 @@ impl Benchmark {
1105
1114
if run_kinds. contains ( & RunKind :: IncrPatched ) {
1106
1115
for ( i, patch) in self . patches . iter ( ) . enumerate ( ) {
1107
1116
log:: debug!( "applying patch {}" , patch. name) ;
1108
- patch. apply ( cwd ) . map_err ( |s| anyhow:: anyhow!( "{}" , s) ) ?;
1117
+ patch. apply ( src_dir ) . map_err ( |s| anyhow:: anyhow!( "{}" , s) ) ?;
1109
1118
1110
1119
// An incremental build with some changes (realistic
1111
1120
// incremental case).
1112
1121
let run_kind_str = format ! ( "IncrPatched{}" , i) ;
1113
- self . mk_cargo_process ( compiler, cwd , build_kind)
1122
+ self . mk_cargo_process ( compiler, target_dir , src_dir , build_kind)
1114
1123
. incremental ( true )
1115
1124
. processor (
1116
1125
processor,
0 commit comments