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