@@ -6,7 +6,7 @@ use collector::command_output;
6
6
use database:: { PatchName , QueryLabel } ;
7
7
use futures:: stream:: FuturesUnordered ;
8
8
use futures:: stream:: StreamExt ;
9
- use std:: cmp;
9
+ use std:: { cmp, ffi :: OsStr , path :: Component } ;
10
10
use std:: collections:: HashMap ;
11
11
use std:: env;
12
12
use std:: fmt;
@@ -23,6 +23,20 @@ use tokio::runtime::Runtime;
23
23
24
24
mod rustc;
25
25
26
+ #[ cfg( windows) ]
27
+ fn rename < P : AsRef < Path > , Q : AsRef < Path > > ( from : P , to : Q ) -> anyhow:: Result < ( ) > {
28
+ let ( from, to) = ( from. as_ref ( ) , to. as_ref ( ) ) ;
29
+
30
+ let ctx = format ! ( "renaming file {:?} to {:?}" , from, to) ;
31
+
32
+ if fs:: metadata ( from) ?. is_file ( ) {
33
+ return Ok ( fs:: rename ( from, to) . with_context ( || ctx. clone ( ) ) ?) ;
34
+ }
35
+
36
+ collector:: robocopy ( from, to, & [ & "/move" ] ) . with_context ( || ctx. clone ( ) )
37
+ }
38
+
39
+ #[ cfg( unix) ]
26
40
fn rename < P : AsRef < Path > , Q : AsRef < Path > > ( from : P , to : Q ) -> anyhow:: Result < ( ) > {
27
41
let ( from, to) = ( from. as_ref ( ) , to. as_ref ( ) ) ;
28
42
if fs:: rename ( from, to) . is_err ( ) {
@@ -44,26 +58,48 @@ fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> anyhow::Result<()>
44
58
Ok ( ( ) )
45
59
}
46
60
47
- fn touch ( root : & Path , path : & Path ) -> anyhow:: Result < ( ) > {
48
- let mut cmd = Command :: new ( "touch" ) ;
49
- cmd. current_dir ( root) . arg ( path) ;
50
- command_output ( & mut cmd) . with_context ( || format ! ( "touching {:?} in {:?}" , path, root) ) ?;
61
+ fn touch ( path : & Path ) -> anyhow:: Result < ( ) > {
62
+ log:: trace!( "touching file {:?}" , path) ;
63
+
64
+ filetime:: set_file_mtime ( path, filetime:: FileTime :: now ( ) ) . with_context ( || format ! ( "touching file {:?}" , path) ) ?;
65
+
51
66
Ok ( ( ) )
52
67
}
53
68
54
69
fn touch_all ( path : & Path ) -> anyhow:: Result < ( ) > {
55
- let mut cmd = Command :: new ( "bash" ) ;
56
- // Don't touch files in `target/`, since they're likely generated by build scripts and might be from a dependency.
57
- // Don't touch build scripts, which confuses the wrapped rustc.
58
- cmd. current_dir ( path)
59
- . args ( & [ "-c" , "find . -path ./target -prune -false -o -name '*.rs' | grep -v '^./build.rs$' | xargs touch" ] ) ;
60
- command_output ( & mut cmd) . with_context ( || format ! ( "touching all .rs in {:?}" , path) ) ?;
61
- // We also delete the cmake caches to avoid errors when moving directories around.
62
- // This might be a bit slower but at least things build
63
- let mut cmd = Command :: new ( "bash" ) ;
64
- cmd. current_dir ( path)
65
- . args ( & [ "-c" , "find . -name 'CMakeCache.txt' -delete" ] ) ;
66
- command_output ( & mut cmd) . with_context ( || format ! ( "deleting cmake caches in {:?}" , path) ) ?;
70
+ fn is_valid ( path : & Path ) -> bool {
71
+ let target_dir = Component :: Normal ( OsStr :: new ( "target" ) ) ;
72
+
73
+ // Don't touch files in `target/`, since they're likely generated by build scripts and might be from a dependency.
74
+ if path. components ( ) . any ( |component| component == target_dir) {
75
+ return false ;
76
+ }
77
+
78
+ if let Some ( extn) = path. extension ( ) {
79
+ if extn. to_str ( ) == Some ( "rs" ) {
80
+ // Don't touch build scripts, which confuses the wrapped rustc.
81
+ return path. file_name ( ) != Some ( OsStr :: new ( "build.rs" ) ) ;
82
+ }
83
+ }
84
+
85
+ false
86
+ }
87
+
88
+ for entry in walkdir:: WalkDir :: new ( path) {
89
+ let entry = entry?;
90
+ let path = entry. path ( ) ;
91
+
92
+ // We also delete the cmake caches to avoid errors when moving directories around.
93
+ // This might be a bit slower but at least things build
94
+ if path. file_name ( ) == Some ( OsStr :: new ( "CMakeCache.txt" ) ) {
95
+ fs:: remove_file ( path) . with_context ( || format ! ( "deleting cmake caches in {:?}" , path) ) ?;
96
+ }
97
+
98
+ if is_valid ( path) {
99
+ touch ( path) ?;
100
+ }
101
+ }
102
+
67
103
Ok ( ( ) )
68
104
}
69
105
@@ -380,7 +416,7 @@ impl<'a> CargoProcess<'a> {
380
416
// in-tree (e.g., in the case of the servo crates there are a lot of
381
417
// other components).
382
418
if let Some ( file) = & self . touch_file {
383
- touch ( & self . cwd , Path :: new ( & file) ) ?;
419
+ touch ( & self . cwd . join ( Path :: new ( & file) ) ) ?;
384
420
} else {
385
421
touch_all (
386
422
& self . cwd . join (
@@ -880,11 +916,13 @@ impl<'a> Processor for ProfileProcessor<'a> {
880
916
rename ( path, filepath ( & zsp_dir, "Zsp.string_data" ) ) ?;
881
917
} else if filename_str. ends_with ( ".string_index" ) {
882
918
rename ( path, filepath ( & zsp_dir, "Zsp.string_index" ) ) ?;
919
+ } else if filename_str. ends_with ( ".mm_profdata" ) {
920
+ rename ( path, filepath ( & zsp_dir, "Zsp.mm_profdata" ) ) ?;
883
921
} else {
884
922
panic ! ( "unexpected file {:?}" , path) ;
885
923
}
886
924
}
887
- assert_eq ! ( num_files, 3 ) ;
925
+ assert ! ( num_files == 3 || num_files == 1 ) ;
888
926
889
927
// Run `summarize`.
890
928
let mut summarize_cmd = Command :: new ( "summarize" ) ;
@@ -1095,15 +1133,26 @@ impl Benchmark {
1095
1133
self . config . supports_stable
1096
1134
}
1097
1135
1136
+ #[ cfg( windows) ]
1137
+ fn copy ( from : & Path , to : & Path ) -> anyhow:: Result < ( ) > {
1138
+ collector:: robocopy ( from, to, & [ ] )
1139
+ }
1140
+
1141
+ #[ cfg( unix) ]
1142
+ fn copy ( from : & Path , to : & Path ) -> anyhow:: Result < ( ) > {
1143
+ let mut cmd = Command :: new ( "cp" ) ;
1144
+ cmd. arg ( "-pLR" ) . arg ( from) . arg ( to) ;
1145
+ command_output ( & mut cmd) ?;
1146
+ Ok ( ( ) )
1147
+ }
1148
+
1098
1149
fn make_temp_dir ( & self , base : & Path ) -> anyhow:: Result < TempDir > {
1099
1150
// Appending `.` means we copy just the contents of `base` into
1100
1151
// `tmp_dir`, rather than `base` itself.
1101
1152
let mut base_dot = base. to_path_buf ( ) ;
1102
1153
base_dot. push ( "." ) ;
1103
1154
let tmp_dir = TempDir :: new ( ) ?;
1104
- let mut cmd = Command :: new ( "cp" ) ;
1105
- cmd. arg ( "-pLR" ) . arg ( base_dot) . arg ( tmp_dir. path ( ) ) ;
1106
- command_output ( & mut cmd) . with_context ( || format ! ( "copying {} to tmp dir" , self . name) ) ?;
1155
+ Self :: copy ( & base_dot, tmp_dir. path ( ) ) . with_context ( || format ! ( "copying {} to tmp dir" , self . name) ) ?;
1107
1156
Ok ( tmp_dir)
1108
1157
}
1109
1158
@@ -1497,14 +1546,14 @@ impl Patch {
1497
1546
}
1498
1547
}
1499
1548
1500
- pub fn apply ( & self , dir : & Path ) -> Result < ( ) , String > {
1549
+ pub fn apply ( & self , dir : & Path ) -> anyhow :: Result < ( ) > {
1501
1550
log:: debug!( "applying {} to {:?}" , self . name, dir) ;
1502
- let mut cmd = Command :: new ( "patch" ) ;
1503
- cmd. current_dir ( dir ) . args ( & [ "-Np1" , "-i" ] ) . arg ( & * self . path ) ;
1504
- cmd. stdout ( Stdio :: null ( ) ) ;
1505
- if cmd . status ( ) . map ( |s| !s . success ( ) ) . unwrap_or ( false ) {
1506
- return Err ( format ! ( "could not execute {:?}." , cmd) ) ;
1507
- }
1551
+
1552
+ let mut cmd = Command :: new ( "git" ) ;
1553
+ cmd. current_dir ( dir ) . args ( & [ "apply" ] ) . args ( & [ "-Np1" ] ) . arg ( & * self . path ) ;
1554
+
1555
+ command_output ( & mut cmd) ? ;
1556
+
1508
1557
Ok ( ( ) )
1509
1558
}
1510
1559
}
0 commit comments