Skip to content

Commit 88dd7aa

Browse files
aidanhsluser
authored andcommitted
Permit disabling toolchains
1 parent 3dec142 commit 88dd7aa

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

src/config.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,18 @@ impl CacheConfigs {
187187

188188
#[derive(Debug, PartialEq, Eq)]
189189
#[derive(Serialize, Deserialize)]
190-
pub struct DistCustomToolchain {
191-
pub compiler_executable: PathBuf,
192-
pub archive: PathBuf,
193-
pub archive_compiler_executable: String,
190+
#[serde(tag = "type")]
191+
pub enum DistToolchainConfig {
192+
#[serde(rename = "no_dist")]
193+
NoDist {
194+
compiler_executable: PathBuf,
195+
},
196+
#[serde(rename = "path_override")]
197+
PathOverride {
198+
compiler_executable: PathBuf,
199+
archive: PathBuf,
200+
archive_compiler_executable: String,
201+
},
194202
}
195203

196204
#[derive(Debug, PartialEq, Eq)]
@@ -215,7 +223,7 @@ pub struct DistConfig {
215223
pub auth: DistAuth,
216224
pub scheduler_addr: Option<IpAddr>,
217225
pub cache_dir: PathBuf,
218-
pub custom_toolchains: Vec<DistCustomToolchain>,
226+
pub toolchains: Vec<DistToolchainConfig>,
219227
pub toolchain_cache_size: u64,
220228
}
221229

@@ -225,7 +233,7 @@ impl Default for DistConfig {
225233
auth: Default::default(),
226234
scheduler_addr: Default::default(),
227235
cache_dir: default_dist_cache_dir(),
228-
custom_toolchains: Default::default(),
236+
toolchains: Default::default(),
229237
toolchain_cache_size: default_toolchain_cache_size(),
230238
}
231239
}

src/dist/cache.rs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod client {
1919
use dist::pkg::ToolchainPackager;
2020
use lru_disk_cache::Error as LruError;
2121
use serde_json;
22-
use std::collections::HashMap;
22+
use std::collections::{HashMap, HashSet};
2323
use std::fs;
2424
use std::io::Write;
2525
use std::path::{Path, PathBuf};
@@ -44,6 +44,8 @@ mod client {
4444
custom_toolchains: Mutex<HashMap<Toolchain, CustomToolchain>>,
4545
// Lookup from local path -> toolchain details
4646
custom_toolchain_paths: Mutex<HashMap<PathBuf, (CustomToolchain, Option<Toolchain>)>>,
47+
// Toolchains configured to not be distributed
48+
disabled_toolchains: HashSet<PathBuf>,
4749
// Local machine mapping from 'weak' hashes to strong toolchain hashes
4850
// - Weak hashes are what sccache uses to determine if a compiler has changed
4951
// on the local machine - they're fast and 'good enough' (assuming we trust
@@ -57,7 +59,7 @@ mod client {
5759

5860
#[cfg(feature = "dist-client")]
5961
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 {
6163
let cache_dir = cache_dir.to_owned();
6264
fs::create_dir_all(&cache_dir).unwrap();
6365

@@ -76,19 +78,34 @@ mod client {
7678
let tc_cache_dir = cache_dir.join("tc");
7779
let cache = Mutex::new(TcCache::new(&tc_cache_dir, cache_size).unwrap());
7880

81+
// Load in toolchain configuration
7982
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+
},
83108
}
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());
92109
}
93110
let custom_toolchain_paths = Mutex::new(custom_toolchain_paths);
94111

@@ -97,6 +114,7 @@ mod client {
97114
cache,
98115
custom_toolchains: Mutex::new(HashMap::new()),
99116
custom_toolchain_paths,
117+
disabled_toolchains,
100118
// TODO: shouldn't clear on restart, but also should have some
101119
// form of pruning
102120
weak_map: Mutex::new(weak_map),
@@ -120,6 +138,9 @@ mod client {
120138
}
121139
// If the toolchain doesn't already exist, create it and insert into the cache
122140
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+
}
123144
if let Some(tc_and_compiler_path) = self.get_custom_toolchain(compiler_path) {
124145
debug!("Using custom toolchain for {:?}", compiler_path);
125146
let (tc, compiler_path) = tc_and_compiler_path.unwrap();

src/dist/http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ mod client {
610610
}
611611

612612
impl Client {
613-
pub fn new(handle: &tokio_core::reactor::Handle, pool: &CpuPool, scheduler_addr: IpAddr, cache_dir: &Path, cache_size: u64, custom_toolchains: &[config::DistCustomToolchain], auth: &'static config::DistAuth) -> Self {
613+
pub fn new(handle: &tokio_core::reactor::Handle, pool: &CpuPool, scheduler_addr: IpAddr, cache_dir: &Path, cache_size: u64, toolchain_configs: &[config::DistToolchainConfig], auth: &'static config::DistAuth) -> Self {
614614
let timeout = Duration::new(REQUEST_TIMEOUT_SECS, 0);
615615
let client = reqwest::ClientBuilder::new().timeout(timeout).build().unwrap();
616616
let client_async = reqwest::unstable::async::ClientBuilder::new().timeout(timeout).build(handle).unwrap();
@@ -620,7 +620,7 @@ mod client {
620620
client,
621621
client_async,
622622
pool: pool.clone(),
623-
tc_cache: cache::ClientToolchains::new(cache_dir, cache_size, custom_toolchains),
623+
tc_cache: cache::ClientToolchains::new(cache_dir, cache_size, toolchain_configs),
624624
}
625625
}
626626
}

src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn start_server(port: u16) -> Result<()> {
146146
addr,
147147
&CONFIG.dist.cache_dir.join("client"),
148148
CONFIG.dist.toolchain_cache_size,
149-
&CONFIG.dist.custom_toolchains,
149+
&CONFIG.dist.toolchains,
150150
&CONFIG.dist.auth,
151151
))
152152
},

0 commit comments

Comments
 (0)