@@ -7,34 +7,29 @@ extern crate sccache;
7
7
extern crate serde_json;
8
8
9
9
use crate :: harness:: {
10
- cargo_command, get_stats, init_cargo, sccache_command, start_local_daemon, stop_local_daemon,
11
- write_json_cfg, write_source,
10
+ client:: { sccache_client_cfg, SccacheClient } ,
11
+ dist:: { cargo_command, sccache_dist_path, DistSystem } ,
12
+ init_cargo, write_source,
12
13
} ;
13
14
use assert_cmd:: prelude:: * ;
14
15
use sccache:: config:: HTTPUrl ;
15
16
use sccache:: dist:: {
16
17
AssignJobResult , CompileCommand , InputsReader , JobId , JobState , RunJobResult , ServerIncoming ,
17
18
ServerOutgoing , SubmitToolchainResult , Toolchain , ToolchainReader ,
18
19
} ;
19
- use std:: ffi:: OsStr ;
20
20
use std:: path:: Path ;
21
21
use std:: process:: Output ;
22
22
23
23
use sccache:: errors:: * ;
24
24
25
25
mod harness;
26
26
27
- fn basic_compile ( tmpdir : & Path , sccache_cfg_path : & Path , sccache_cached_cfg_path : & Path ) {
28
- let envs: Vec < ( _ , & OsStr ) > = vec ! [
29
- ( "RUST_BACKTRACE" , "1" . as_ref( ) ) ,
30
- ( "SCCACHE_LOG" , "debug" . as_ref( ) ) ,
31
- ( "SCCACHE_CONF" , sccache_cfg_path. as_ref( ) ) ,
32
- ( "SCCACHE_CACHED_CONF" , sccache_cached_cfg_path. as_ref( ) ) ,
33
- ] ;
27
+ fn basic_compile ( client : & SccacheClient , tmpdir : & Path ) {
34
28
let source_file = "x.c" ;
35
29
let obj_file = "x.o" ;
36
30
write_source ( tmpdir, source_file, "#if !defined(SCCACHE_TEST_DEFINE)\n #error SCCACHE_TEST_DEFINE is not defined\n #endif\n int x() { return 5; }" ) ;
37
- sccache_command ( )
31
+ client
32
+ . cmd ( )
38
33
. args ( [
39
34
std:: env:: var ( "CC" )
40
35
. unwrap_or_else ( |_| "gcc" . to_string ( ) )
@@ -45,21 +40,13 @@ fn basic_compile(tmpdir: &Path, sccache_cfg_path: &Path, sccache_cached_cfg_path
45
40
. arg ( tmpdir. join ( source_file) )
46
41
. arg ( "-o" )
47
42
. arg ( tmpdir. join ( obj_file) )
48
- . envs ( envs)
43
+ . env ( "RUST_BACKTRACE" , "1" )
44
+ . env ( "SCCACHE_RECACHE" , "1" )
49
45
. assert ( )
50
46
. success ( ) ;
51
47
}
52
48
53
- fn rust_compile ( tmpdir : & Path , sccache_cfg_path : & Path , sccache_cached_cfg_path : & Path ) -> Output {
54
- let sccache_path = assert_cmd:: cargo:: cargo_bin ( "sccache" ) . into_os_string ( ) ;
55
- let envs: Vec < ( _ , & OsStr ) > = vec ! [
56
- ( "RUSTC_WRAPPER" , sccache_path. as_ref( ) ) ,
57
- ( "CARGO_TARGET_DIR" , "target" . as_ref( ) ) ,
58
- ( "RUST_BACKTRACE" , "1" . as_ref( ) ) ,
59
- ( "SCCACHE_LOG" , "debug" . as_ref( ) ) ,
60
- ( "SCCACHE_CONF" , sccache_cfg_path. as_ref( ) ) ,
61
- ( "SCCACHE_CACHED_CONF" , sccache_cached_cfg_path. as_ref( ) ) ,
62
- ] ;
49
+ fn rust_compile ( client : & SccacheClient , tmpdir : & Path ) -> Output {
63
50
let cargo_name = "sccache-dist-test" ;
64
51
let cargo_path = init_cargo ( tmpdir, cargo_name) ;
65
52
@@ -87,7 +74,16 @@ fn rust_compile(tmpdir: &Path, sccache_cfg_path: &Path, sccache_cached_cfg_path:
87
74
cargo_command ( )
88
75
. current_dir ( cargo_path)
89
76
. args ( [ "build" , "--release" ] )
90
- . envs ( envs)
77
+ . envs (
78
+ client
79
+ . cmd ( )
80
+ . get_envs ( )
81
+ . map ( |( k, v) | ( k, v. unwrap_or_default ( ) ) ) ,
82
+ )
83
+ . env ( "RUSTC_WRAPPER" , & client. path )
84
+ . env ( "CARGO_TARGET_DIR" , "target" )
85
+ . env ( "RUST_BACKTRACE" , "1" )
86
+ . env ( "SCCACHE_RECACHE" , "1" )
91
87
. output ( )
92
88
. unwrap ( )
93
89
}
@@ -96,7 +92,7 @@ pub fn dist_test_sccache_client_cfg(
96
92
tmpdir : & Path ,
97
93
scheduler_url : HTTPUrl ,
98
94
) -> sccache:: config:: FileConfig {
99
- let mut sccache_cfg = harness :: sccache_client_cfg ( tmpdir, false ) ;
95
+ let mut sccache_cfg = sccache_client_cfg ( tmpdir, false ) ;
100
96
sccache_cfg. cache . disk . as_mut ( ) . unwrap ( ) . size = 0 ;
101
97
sccache_cfg. dist . scheduler_url = Some ( scheduler_url) ;
102
98
sccache_cfg
@@ -110,29 +106,27 @@ fn test_dist_basic() {
110
106
. tempdir ( )
111
107
. unwrap ( ) ;
112
108
let tmpdir = tmpdir. path ( ) ;
113
- let sccache_dist = harness :: sccache_dist_path ( ) ;
109
+ let sccache_dist = sccache_dist_path ( ) ;
114
110
115
- let mut system = harness :: DistSystem :: new ( & sccache_dist, tmpdir) ;
111
+ let mut system = DistSystem :: new ( & sccache_dist, tmpdir) ;
116
112
system. add_scheduler ( ) ;
117
113
system. add_server ( ) ;
118
114
119
- let sccache_cfg = dist_test_sccache_client_cfg ( tmpdir, system. scheduler_url ( ) ) ;
120
- let sccache_cfg_path = tmpdir. join ( "sccache-cfg.json" ) ;
121
- write_json_cfg ( tmpdir, "sccache-cfg.json" , & sccache_cfg) ;
122
- let sccache_cached_cfg_path = tmpdir. join ( "sccache-cached-cfg" ) ;
123
-
124
- stop_local_daemon ( ) ;
125
- start_local_daemon ( & sccache_cfg_path, & sccache_cached_cfg_path) ;
126
- basic_compile ( tmpdir, & sccache_cfg_path, & sccache_cached_cfg_path) ;
127
-
128
- get_stats ( |info| {
129
- assert_eq ! ( 1 , info. stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
130
- assert_eq ! ( 0 , info. stats. dist_errors) ;
131
- assert_eq ! ( 1 , info. stats. compile_requests) ;
132
- assert_eq ! ( 1 , info. stats. requests_executed) ;
133
- assert_eq ! ( 0 , info. stats. cache_hits. all( ) ) ;
134
- assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
135
- } ) ;
115
+ let client = system. new_client ( & dist_test_sccache_client_cfg (
116
+ tmpdir,
117
+ system. scheduler_url ( ) ,
118
+ ) ) ;
119
+
120
+ basic_compile ( & client, tmpdir) ;
121
+
122
+ let stats = client. stats ( ) . unwrap ( ) ;
123
+
124
+ assert_eq ! ( 1 , stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
125
+ assert_eq ! ( 0 , stats. dist_errors) ;
126
+ assert_eq ! ( 1 , stats. compile_requests) ;
127
+ assert_eq ! ( 1 , stats. requests_executed) ;
128
+ assert_eq ! ( 0 , stats. cache_hits. all( ) ) ;
129
+ assert_eq ! ( 1 , stats. cache_misses. all( ) ) ;
136
130
}
137
131
138
132
#[ test]
@@ -143,32 +137,31 @@ fn test_dist_restartedserver() {
143
137
. tempdir ( )
144
138
. unwrap ( ) ;
145
139
let tmpdir = tmpdir. path ( ) ;
146
- let sccache_dist = harness :: sccache_dist_path ( ) ;
140
+ let sccache_dist = sccache_dist_path ( ) ;
147
141
148
- let mut system = harness :: DistSystem :: new ( & sccache_dist, tmpdir) ;
142
+ let mut system = DistSystem :: new ( & sccache_dist, tmpdir) ;
149
143
system. add_scheduler ( ) ;
150
144
let server_handle = system. add_server ( ) ;
151
145
152
- let sccache_cfg = dist_test_sccache_client_cfg ( tmpdir , system. scheduler_url ( ) ) ;
153
- let sccache_cfg_path = tmpdir. join ( "sccache-cfg.json" ) ;
154
- write_json_cfg ( tmpdir , "sccache-cfg.json" , & sccache_cfg ) ;
155
- let sccache_cached_cfg_path = tmpdir . join ( "sccache-cached-cfg" ) ;
146
+ let client = system. new_client ( & dist_test_sccache_client_cfg (
147
+ tmpdir,
148
+ system . scheduler_url ( ) ,
149
+ ) ) ;
156
150
157
- stop_local_daemon ( ) ;
158
- start_local_daemon ( & sccache_cfg_path, & sccache_cached_cfg_path) ;
159
- basic_compile ( tmpdir, & sccache_cfg_path, & sccache_cached_cfg_path) ;
151
+ basic_compile ( & client, tmpdir) ;
160
152
161
153
system. restart_server ( & server_handle) ;
162
- basic_compile ( tmpdir, & sccache_cfg_path, & sccache_cached_cfg_path) ;
163
-
164
- get_stats ( |info| {
165
- assert_eq ! ( 2 , info. stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
166
- assert_eq ! ( 0 , info. stats. dist_errors) ;
167
- assert_eq ! ( 2 , info. stats. compile_requests) ;
168
- assert_eq ! ( 2 , info. stats. requests_executed) ;
169
- assert_eq ! ( 0 , info. stats. cache_hits. all( ) ) ;
170
- assert_eq ! ( 2 , info. stats. cache_misses. all( ) ) ;
171
- } ) ;
154
+
155
+ basic_compile ( & client, tmpdir) ;
156
+
157
+ let stats = client. stats ( ) . unwrap ( ) ;
158
+
159
+ assert_eq ! ( 2 , stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
160
+ assert_eq ! ( 0 , stats. dist_errors) ;
161
+ assert_eq ! ( 2 , stats. compile_requests) ;
162
+ assert_eq ! ( 2 , stats. requests_executed) ;
163
+ assert_eq ! ( 0 , stats. cache_hits. all( ) ) ;
164
+ assert_eq ! ( 2 , stats. cache_misses. all( ) ) ;
172
165
}
173
166
174
167
#[ test]
@@ -179,28 +172,26 @@ fn test_dist_nobuilder() {
179
172
. tempdir ( )
180
173
. unwrap ( ) ;
181
174
let tmpdir = tmpdir. path ( ) ;
182
- let sccache_dist = harness :: sccache_dist_path ( ) ;
175
+ let sccache_dist = sccache_dist_path ( ) ;
183
176
184
- let mut system = harness :: DistSystem :: new ( & sccache_dist, tmpdir) ;
177
+ let mut system = DistSystem :: new ( & sccache_dist, tmpdir) ;
185
178
system. add_scheduler ( ) ;
186
179
187
- let sccache_cfg = dist_test_sccache_client_cfg ( tmpdir, system. scheduler_url ( ) ) ;
188
- let sccache_cfg_path = tmpdir. join ( "sccache-cfg.json" ) ;
189
- write_json_cfg ( tmpdir, "sccache-cfg.json" , & sccache_cfg) ;
190
- let sccache_cached_cfg_path = tmpdir. join ( "sccache-cached-cfg" ) ;
191
-
192
- stop_local_daemon ( ) ;
193
- start_local_daemon ( & sccache_cfg_path, & sccache_cached_cfg_path) ;
194
- basic_compile ( tmpdir, & sccache_cfg_path, & sccache_cached_cfg_path) ;
195
-
196
- get_stats ( |info| {
197
- assert_eq ! ( 0 , info. stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
198
- assert_eq ! ( 1 , info. stats. dist_errors) ;
199
- assert_eq ! ( 1 , info. stats. compile_requests) ;
200
- assert_eq ! ( 1 , info. stats. requests_executed) ;
201
- assert_eq ! ( 0 , info. stats. cache_hits. all( ) ) ;
202
- assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
203
- } ) ;
180
+ let client = system. new_client ( & dist_test_sccache_client_cfg (
181
+ tmpdir,
182
+ system. scheduler_url ( ) ,
183
+ ) ) ;
184
+
185
+ basic_compile ( & client, tmpdir) ;
186
+
187
+ let stats = client. stats ( ) . unwrap ( ) ;
188
+
189
+ assert_eq ! ( 0 , stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
190
+ assert_eq ! ( 1 , stats. dist_errors) ;
191
+ assert_eq ! ( 1 , stats. compile_requests) ;
192
+ assert_eq ! ( 1 , stats. requests_executed) ;
193
+ assert_eq ! ( 0 , stats. cache_hits. all( ) ) ;
194
+ assert_eq ! ( 1 , stats. cache_misses. all( ) ) ;
204
195
}
205
196
206
197
struct FailingServer ;
@@ -244,97 +235,64 @@ fn test_dist_failingserver() {
244
235
. tempdir ( )
245
236
. unwrap ( ) ;
246
237
let tmpdir = tmpdir. path ( ) ;
247
- let sccache_dist = harness :: sccache_dist_path ( ) ;
238
+ let sccache_dist = sccache_dist_path ( ) ;
248
239
249
- let mut system = harness :: DistSystem :: new ( & sccache_dist, tmpdir) ;
240
+ let mut system = DistSystem :: new ( & sccache_dist, tmpdir) ;
250
241
system. add_scheduler ( ) ;
251
242
system. add_custom_server ( FailingServer ) ;
252
243
253
- let sccache_cfg = dist_test_sccache_client_cfg ( tmpdir, system. scheduler_url ( ) ) ;
254
- let sccache_cfg_path = tmpdir. join ( "sccache-cfg.json" ) ;
255
- write_json_cfg ( tmpdir, "sccache-cfg.json" , & sccache_cfg) ;
256
- let sccache_cached_cfg_path = tmpdir. join ( "sccache-cached-cfg" ) ;
257
-
258
- stop_local_daemon ( ) ;
259
- start_local_daemon ( & sccache_cfg_path, & sccache_cached_cfg_path) ;
260
- basic_compile ( tmpdir, & sccache_cfg_path, & sccache_cached_cfg_path) ;
261
-
262
- get_stats ( |info| {
263
- assert_eq ! ( 0 , info. stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
264
- assert_eq ! ( 1 , info. stats. dist_errors) ;
265
- assert_eq ! ( 1 , info. stats. compile_requests) ;
266
- assert_eq ! ( 1 , info. stats. requests_executed) ;
267
- assert_eq ! ( 0 , info. stats. cache_hits. all( ) ) ;
268
- assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
269
- } ) ;
270
- }
271
-
272
- #[ test]
273
- #[ cfg_attr( not( feature = "dist-tests" ) , ignore) ]
274
- fn test_dist_cargo_build ( ) {
275
- let tmpdir = tempfile:: Builder :: new ( )
276
- . prefix ( "sccache_dist_test" )
277
- . tempdir ( )
278
- . unwrap ( ) ;
279
- let tmpdir = tmpdir. path ( ) ;
280
- let sccache_dist = harness:: sccache_dist_path ( ) ;
244
+ let client = system. new_client ( & dist_test_sccache_client_cfg (
245
+ tmpdir,
246
+ system. scheduler_url ( ) ,
247
+ ) ) ;
281
248
282
- let mut system = harness:: DistSystem :: new ( & sccache_dist, tmpdir) ;
283
- system. add_scheduler ( ) ;
284
- let _server_handle = system. add_server ( ) ;
249
+ basic_compile ( & client, tmpdir) ;
285
250
286
- let sccache_cfg = dist_test_sccache_client_cfg ( tmpdir, system. scheduler_url ( ) ) ;
287
- let sccache_cfg_path = tmpdir. join ( "sccache-cfg.json" ) ;
288
- write_json_cfg ( tmpdir, "sccache-cfg.json" , & sccache_cfg) ;
289
- let sccache_cached_cfg_path = tmpdir. join ( "sccache-cached-cfg" ) ;
251
+ let stats = client. stats ( ) . unwrap ( ) ;
290
252
291
- stop_local_daemon ( ) ;
292
- start_local_daemon ( & sccache_cfg_path, & sccache_cached_cfg_path) ;
293
- rust_compile ( tmpdir, & sccache_cfg_path, & sccache_cached_cfg_path)
294
- . assert ( )
295
- . success ( ) ;
296
- get_stats ( |info| {
297
- assert_eq ! ( 1 , info. stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
298
- assert_eq ! ( 0 , info. stats. dist_errors) ;
299
- assert_eq ! ( 5 , info. stats. compile_requests) ;
300
- assert_eq ! ( 1 , info. stats. requests_executed) ;
301
- assert_eq ! ( 0 , info. stats. cache_hits. all( ) ) ;
302
- assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
303
- } ) ;
253
+ assert_eq ! ( 0 , stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
254
+ assert_eq ! ( 1 , stats. dist_errors) ;
255
+ assert_eq ! ( 1 , stats. compile_requests) ;
256
+ assert_eq ! ( 1 , stats. requests_executed) ;
257
+ assert_eq ! ( 0 , stats. cache_hits. all( ) ) ;
258
+ assert_eq ! ( 1 , stats. cache_misses. all( ) ) ;
304
259
}
305
260
306
261
#[ test]
307
262
#[ cfg_attr( not( feature = "dist-tests" ) , ignore) ]
308
- fn test_dist_cargo_makeflags ( ) {
263
+ fn test_dist_cargo_build ( ) {
309
264
let tmpdir = tempfile:: Builder :: new ( )
310
265
. prefix ( "sccache_dist_test" )
311
266
. tempdir ( )
312
267
. unwrap ( ) ;
313
268
let tmpdir = tmpdir. path ( ) ;
314
- let sccache_dist = harness :: sccache_dist_path ( ) ;
269
+ let sccache_dist = sccache_dist_path ( ) ;
315
270
316
- let mut system = harness :: DistSystem :: new ( & sccache_dist, tmpdir) ;
271
+ let mut system = DistSystem :: new ( & sccache_dist, tmpdir) ;
317
272
system. add_scheduler ( ) ;
318
273
let _server_handle = system. add_server ( ) ;
319
274
320
- let sccache_cfg = dist_test_sccache_client_cfg ( tmpdir , system. scheduler_url ( ) ) ;
321
- let sccache_cfg_path = tmpdir. join ( "sccache-cfg.json" ) ;
322
- write_json_cfg ( tmpdir , "sccache-cfg.json" , & sccache_cfg ) ;
323
- let sccache_cached_cfg_path = tmpdir . join ( "sccache-cached-cfg" ) ;
275
+ let client = system. new_client ( & dist_test_sccache_client_cfg (
276
+ tmpdir,
277
+ system . scheduler_url ( ) ,
278
+ ) ) ;
324
279
325
- stop_local_daemon ( ) ;
326
- start_local_daemon ( & sccache_cfg_path, & sccache_cached_cfg_path) ;
327
- let compile_output = rust_compile ( tmpdir, & sccache_cfg_path, & sccache_cached_cfg_path) ;
280
+ let compile_output = rust_compile ( & client, tmpdir) ;
328
281
282
+ // Ensure sccache ignores inherited jobservers in CARGO_MAKEFLAGS
329
283
assert ! ( !String :: from_utf8_lossy( & compile_output. stderr)
330
284
. contains( "warning: failed to connect to jobserver from environment variable" ) ) ;
331
285
332
- get_stats ( |info| {
333
- assert_eq ! ( 1 , info. stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
334
- assert_eq ! ( 0 , info. stats. dist_errors) ;
335
- assert_eq ! ( 5 , info. stats. compile_requests) ;
336
- assert_eq ! ( 1 , info. stats. requests_executed) ;
337
- assert_eq ! ( 0 , info. stats. cache_hits. all( ) ) ;
338
- assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
339
- } ) ;
286
+ // Assert compilation succeeded
287
+ compile_output. assert ( ) . success ( ) ;
288
+
289
+ let stats = client. stats ( ) . unwrap ( ) ;
290
+
291
+ assert_eq ! ( 1 , stats. dist_compiles. values( ) . sum:: <usize >( ) ) ;
292
+ assert_eq ! ( 0 , stats. dist_errors) ;
293
+ // check >= 5 because cargo >=1.82 does additional requests with -vV
294
+ assert ! ( stats. compile_requests >= 5 ) ;
295
+ assert_eq ! ( 1 , stats. requests_executed) ;
296
+ assert_eq ! ( 0 , stats. cache_hits. all( ) ) ;
297
+ assert_eq ! ( 1 , stats. cache_misses. all( ) ) ;
340
298
}
0 commit comments