13
13
use std:: collections:: HashMap ;
14
14
use std:: env;
15
15
use std:: fs:: File ;
16
- use std:: io:: { BufRead , BufReader } ;
16
+ use std:: io:: { self , BufRead , BufReader } ;
17
17
use std:: path:: { Path , PathBuf } ;
18
18
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
19
19
use std:: sync:: { Arc , Mutex } ;
@@ -26,9 +26,7 @@ use lazy_static::lazy_static;
26
26
use rls_analysis:: { AnalysisHost , Target } ;
27
27
use rls_vfs:: Vfs ;
28
28
use serde_json;
29
-
30
- #[ path = "../../tests/support/project_builder.rs" ]
31
- mod project_builder;
29
+ use walkdir:: WalkDir ;
32
30
33
31
lazy_static ! {
34
32
static ref COUNTER : AtomicUsize = AtomicUsize :: new( 0 ) ;
@@ -50,9 +48,8 @@ impl Environment {
50
48
}
51
49
52
50
let fixture_dir = FIXTURES_DIR . join ( fixture_dir. as_ref ( ) ) ;
53
- let project = project_builder:: ProjectBuilder :: try_from_fixture ( fixture_dir)
54
- . unwrap ( )
55
- . build ( ) ;
51
+ let scratchpad_dir = build_scratchpad_from_fixture ( fixture_dir)
52
+ . expect ( "Can't copy fixture files to scratchpad" ) ;
56
53
57
54
let target_dir = env:: var ( "CARGO_TARGET_DIR" )
58
55
. map ( |s| Path :: new ( & s) . to_owned ( ) )
@@ -66,7 +63,7 @@ impl Environment {
66
63
config. target_dir = Inferrable :: Specified ( Some ( working_dir. clone ( ) ) ) ;
67
64
config. unstable_features = true ;
68
65
69
- let cache = Cache :: new ( project . root ( ) . to_owned ( ) ) ;
66
+ let cache = Cache :: new ( scratchpad_dir ) ;
70
67
71
68
Self {
72
69
config : Some ( config) ,
@@ -114,6 +111,32 @@ impl Drop for Environment {
114
111
}
115
112
}
116
113
114
+ pub fn build_scratchpad_from_fixture ( fixture_dir : impl AsRef < Path > ) -> io:: Result < PathBuf > {
115
+ let fixture_dir = fixture_dir. as_ref ( ) ;
116
+
117
+ let dirname = fixture_dir. file_name ( )
118
+ . ok_or_else ( || io:: Error :: new ( io:: ErrorKind :: NotFound , "No filename" ) ) ?;
119
+
120
+ // FIXME: For now persist the path; ideally we should clean up after every test
121
+ let genroot = tempfile:: tempdir ( ) ?. into_path ( ) . join ( dirname) ;
122
+ // Recursively copy read-only fixture files to freshly generated scratchpad
123
+ for entry in WalkDir :: new ( fixture_dir) . into_iter ( ) {
124
+ let entry = entry?;
125
+ let src = entry. path ( ) ;
126
+
127
+ let relative = src. strip_prefix ( fixture_dir) . unwrap ( ) ;
128
+ let dst = genroot. join ( relative) ;
129
+
130
+ if std:: fs:: metadata ( src) ?. is_dir ( ) {
131
+ std:: fs:: create_dir ( dst) ?;
132
+ } else {
133
+ std:: fs:: copy ( src, dst) ?;
134
+ }
135
+ }
136
+
137
+ Ok ( genroot)
138
+ }
139
+
117
140
struct MockMsgReader {
118
141
messages : Vec < String > ,
119
142
cur : AtomicUsize ,
0 commit comments