@@ -7,7 +7,8 @@ extern crate sccache;
77extern crate serde_json;
88
99use crate :: harness:: {
10- get_stats, sccache_command, start_local_daemon, stop_local_daemon, write_json_cfg, write_source,
10+ cargo_command, get_stats, init_cargo, sccache_command, start_local_daemon, stop_local_daemon,
11+ write_json_cfg, write_source,
1112} ;
1213use assert_cmd:: prelude:: * ;
1314use sccache:: config:: HTTPUrl ;
@@ -17,6 +18,7 @@ use sccache::dist::{
1718} ;
1819use std:: ffi:: OsStr ;
1920use std:: path:: Path ;
21+ use std:: process:: Output ;
2022
2123use sccache:: errors:: * ;
2224
@@ -48,6 +50,48 @@ fn basic_compile(tmpdir: &Path, sccache_cfg_path: &Path, sccache_cached_cfg_path
4850 . success ( ) ;
4951}
5052
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+ ] ;
63+ let cargo_name = "sccache-dist-test" ;
64+ let cargo_path = init_cargo ( tmpdir, cargo_name) ;
65+
66+ let manifest_file = "Cargo.toml" ;
67+ let source_file = "src/main.rs" ;
68+
69+ write_source (
70+ & cargo_path,
71+ manifest_file,
72+ r#"[package]
73+ name = "sccache-dist-test"
74+ version = "0.1.0"
75+ edition = "2021"
76+ [dependencies]
77+ libc = "0.2.169""# ,
78+ ) ;
79+ write_source (
80+ & cargo_path,
81+ source_file,
82+ r#"fn main() {
83+ println!("Hello, world!");
84+ }"# ,
85+ ) ;
86+
87+ cargo_command ( )
88+ . current_dir ( cargo_path)
89+ . args ( [ "build" , "--release" ] )
90+ . envs ( envs)
91+ . output ( )
92+ . unwrap ( )
93+ }
94+
5195pub fn dist_test_sccache_client_cfg (
5296 tmpdir : & Path ,
5397 scheduler_url : HTTPUrl ,
@@ -224,3 +268,73 @@ fn test_dist_failingserver() {
224268 assert_eq ! ( 1 , info. stats. cache_misses. all( ) ) ;
225269 } ) ;
226270}
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 ( ) ;
281+
282+ let mut system = harness:: DistSystem :: new ( & sccache_dist, tmpdir) ;
283+ system. add_scheduler ( ) ;
284+ let _server_handle = system. add_server ( ) ;
285+
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" ) ;
290+
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 ! ( 8 , 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+ } ) ;
304+ }
305+
306+ #[ test]
307+ #[ cfg_attr( not( feature = "dist-tests" ) , ignore) ]
308+ fn test_dist_cargo_makeflags ( ) {
309+ let tmpdir = tempfile:: Builder :: new ( )
310+ . prefix ( "sccache_dist_test" )
311+ . tempdir ( )
312+ . unwrap ( ) ;
313+ let tmpdir = tmpdir. path ( ) ;
314+ let sccache_dist = harness:: sccache_dist_path ( ) ;
315+
316+ let mut system = harness:: DistSystem :: new ( & sccache_dist, tmpdir) ;
317+ system. add_scheduler ( ) ;
318+ let _server_handle = system. add_server ( ) ;
319+
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" ) ;
324+
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) ;
328+
329+ assert ! ( !String :: from_utf8_lossy( & compile_output. stderr)
330+ . contains( "warning: failed to connect to jobserver from environment variable" ) ) ;
331+
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 ! ( 8 , 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+ } ) ;
340+ }
0 commit comments