@@ -19,7 +19,7 @@ mod client {
19
19
use dist:: pkg:: ToolchainPackager ;
20
20
use lru_disk_cache:: Error as LruError ;
21
21
use serde_json;
22
- use std:: collections:: HashMap ;
22
+ use std:: collections:: { HashMap , HashSet } ;
23
23
use std:: fs;
24
24
use std:: io:: Write ;
25
25
use std:: path:: { Path , PathBuf } ;
@@ -44,6 +44,8 @@ mod client {
44
44
custom_toolchains : Mutex < HashMap < Toolchain , CustomToolchain > > ,
45
45
// Lookup from local path -> toolchain details
46
46
custom_toolchain_paths : Mutex < HashMap < PathBuf , ( CustomToolchain , Option < Toolchain > ) > > ,
47
+ // Toolchains configured to not be distributed
48
+ disabled_toolchains : HashSet < PathBuf > ,
47
49
// Local machine mapping from 'weak' hashes to strong toolchain hashes
48
50
// - Weak hashes are what sccache uses to determine if a compiler has changed
49
51
// on the local machine - they're fast and 'good enough' (assuming we trust
@@ -57,7 +59,7 @@ mod client {
57
59
58
60
#[ cfg( feature = "dist-client" ) ]
59
61
impl ClientToolchains {
60
- pub fn new ( cache_dir : & Path , cache_size : u64 , config_custom_toolchains : & [ config:: DistCustomToolchain ] ) -> Self {
62
+ pub fn new ( cache_dir : & Path , cache_size : u64 , toolchain_configs : & [ config:: DistToolchainConfig ] ) -> Self {
61
63
let cache_dir = cache_dir. to_owned ( ) ;
62
64
fs:: create_dir_all ( & cache_dir) . unwrap ( ) ;
63
65
@@ -76,19 +78,34 @@ mod client {
76
78
let tc_cache_dir = cache_dir. join ( "tc" ) ;
77
79
let cache = Mutex :: new ( TcCache :: new ( & tc_cache_dir, cache_size) . unwrap ( ) ) ;
78
80
81
+ // Load in toolchain configuration
79
82
let mut custom_toolchain_paths = HashMap :: new ( ) ;
80
- for ct in config_custom_toolchains. into_iter ( ) {
81
- if custom_toolchain_paths. contains_key ( & ct. compiler_executable ) {
82
- panic ! ( "Multiple toolchains for {:?}" , ct. compiler_executable)
83
+ let mut disabled_toolchains = HashSet :: new ( ) ;
84
+ for ct in toolchain_configs. into_iter ( ) {
85
+ match ct {
86
+ config:: DistToolchainConfig :: PathOverride { compiler_executable, archive, archive_compiler_executable } => {
87
+ debug ! ( "Registering custom toolchain for {}" , compiler_executable. display( ) ) ;
88
+ let custom_tc = CustomToolchain {
89
+ archive : archive. clone ( ) ,
90
+ compiler_executable : archive_compiler_executable. clone ( ) ,
91
+ } ;
92
+ if custom_toolchain_paths. insert ( compiler_executable. clone ( ) , ( custom_tc, None ) ) . is_some ( ) {
93
+ panic ! ( "Multiple toolchains for {}" , compiler_executable. display( ) )
94
+ }
95
+ if disabled_toolchains. contains ( compiler_executable) {
96
+ panic ! ( "Override for toolchain {} conflicts with it being disabled" )
97
+ }
98
+ } ,
99
+ config:: DistToolchainConfig :: NoDist { compiler_executable } => {
100
+ debug ! ( "Disabling toolchain {}" , compiler_executable. display( ) ) ;
101
+ if !disabled_toolchains. insert ( compiler_executable. clone ( ) ) {
102
+ panic ! ( "Disabled toolchain {} multiple times" , compiler_executable. display( ) )
103
+ }
104
+ if custom_toolchain_paths. contains_key ( compiler_executable) {
105
+ panic ! ( "Override for toolchain {} conflicts with it being disabled" )
106
+ }
107
+ } ,
83
108
}
84
- let config:: DistCustomToolchain { compiler_executable, archive, archive_compiler_executable } = ct;
85
-
86
- debug ! ( "Registering custom toolchain for {:?}" , compiler_executable) ;
87
- let custom_tc = CustomToolchain {
88
- archive : archive. clone ( ) ,
89
- compiler_executable : archive_compiler_executable. clone ( ) ,
90
- } ;
91
- assert ! ( custom_toolchain_paths. insert( compiler_executable. clone( ) , ( custom_tc, None ) ) . is_none( ) ) ;
92
109
}
93
110
let custom_toolchain_paths = Mutex :: new ( custom_toolchain_paths) ;
94
111
@@ -97,6 +114,7 @@ mod client {
97
114
cache,
98
115
custom_toolchains : Mutex :: new ( HashMap :: new ( ) ) ,
99
116
custom_toolchain_paths,
117
+ disabled_toolchains,
100
118
// TODO: shouldn't clear on restart, but also should have some
101
119
// form of pruning
102
120
weak_map : Mutex :: new ( weak_map) ,
@@ -120,6 +138,9 @@ mod client {
120
138
}
121
139
// If the toolchain doesn't already exist, create it and insert into the cache
122
140
pub fn put_toolchain ( & self , compiler_path : & Path , weak_key : & str , toolchain_packager : Box < ToolchainPackager > ) -> Result < ( Toolchain , Option < String > ) > {
141
+ if self . disabled_toolchains . contains ( compiler_path) {
142
+ bail ! ( "Toolchain distribution for {} is disabled" , compiler_path. display( ) )
143
+ }
123
144
if let Some ( tc_and_compiler_path) = self . get_custom_toolchain ( compiler_path) {
124
145
debug ! ( "Using custom toolchain for {:?}" , compiler_path) ;
125
146
let ( tc, compiler_path) = tc_and_compiler_path. unwrap ( ) ;
0 commit comments