Skip to content

Commit b0a0861

Browse files
committed
load builder toolchain from database instead of environment
1 parent 5e249fc commit b0a0861

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/config.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub struct Config {
9999
pub(crate) rustwide_workspace: PathBuf,
100100
pub(crate) inside_docker: bool,
101101
pub(crate) docker_image: Option<String>,
102-
pub(crate) toolchain: String,
103102
pub(crate) build_cpu_limit: Option<u32>,
104103
pub(crate) build_default_memory_limit: Option<usize>,
105104
pub(crate) include_default_targets: bool,
@@ -113,7 +112,6 @@ impl Config {
113112
("CRATESFYI_DATABASE_URL", "DOCSRS_DATABASE_URL"),
114113
("CRATESFYI_GITHUB_ACCESSTOKEN", "DOCSRS_GITHUB_ACCESSTOKEN"),
115114
("CRATESFYI_RUSTWIDE_WORKSPACE", "DOCSRS_RUSTWIDE_WORKSPACE"),
116-
("CRATESFYI_TOOLCHAIN", "DOCSRS_TOOLCHAIN"),
117115
("DOCS_RS_DOCKER", "DOCSRS_DOCKER"),
118116
("DOCS_RS_LOCAL_DOCKER_IMAGE", "DOCSRS_DOCKER_IMAGE"),
119117
("DOCS_RS_BULID_CPU_LIMIT", "DOCSRS_BULID_CPU_LIMIT"),
@@ -202,7 +200,6 @@ impl Config {
202200
inside_docker: env("DOCSRS_DOCKER", false)?,
203201
docker_image: maybe_env("DOCSRS_LOCAL_DOCKER_IMAGE")?
204202
.or(maybe_env("DOCSRS_DOCKER_IMAGE")?),
205-
toolchain: env("DOCSRS_TOOLCHAIN", "nightly".to_string())?,
206203
build_cpu_limit: maybe_env("DOCSRS_BUILD_CPU_LIMIT")?,
207204
build_default_memory_limit: maybe_env("DOCSRS_BUILD_DEFAULT_MEMORY_LIMIT")?,
208205
include_default_targets: env("DOCSRS_INCLUDE_DEFAULT_TARGETS", true)?,

src/docbuilder/rustwide_builder.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::error::Result;
88
use crate::repositories::RepositoryStatsUpdater;
99
use crate::storage::{rustdoc_archive_path, source_archive_path};
1010
use crate::utils::{
11-
copy_dir_all, parse_rustc_version, queue_builder, report_error, set_config, CargoMetadata,
12-
ConfigName,
11+
copy_dir_all, get_config, parse_rustc_version, queue_builder, report_error, set_config,
12+
CargoMetadata, ConfigName,
1313
};
1414
use crate::RUSTDOC_STATIC_STORAGE_PREFIX;
1515
use crate::{db::blacklist::is_blacklisted, utils::MetadataPackage};
@@ -33,6 +33,21 @@ const COMPONENTS: &[&str] = &["llvm-tools-preview", "rustc-dev", "rustfmt"];
3333
const DUMMY_CRATE_NAME: &str = "empty-library";
3434
const DUMMY_CRATE_VERSION: &str = "1.0.0";
3535

36+
fn get_configured_toolchain(conn: &mut Client) -> Result<Toolchain> {
37+
let name: String = get_config(conn, ConfigName::Toolchain)?.unwrap_or_else(|| "nightly".into());
38+
39+
// If the toolchain is all hex, assume it references an artifact from
40+
// CI, for instance an `@bors try` build.
41+
let re = Regex::new(r"^[a-fA-F0-9]+$").unwrap();
42+
if re.is_match(&name) {
43+
debug!("using CI build {}", &name);
44+
Ok(Toolchain::ci(&name, false))
45+
} else {
46+
debug!("using toolchain {}", &name);
47+
Ok(Toolchain::dist(&name))
48+
}
49+
}
50+
3651
pub enum PackageKind<'a> {
3752
Local(&'a Path),
3853
CratesIo,
@@ -75,22 +90,13 @@ impl RustwideBuilder {
7590
.purge_all_build_dirs()
7691
.map_err(FailureError::compat)?;
7792

78-
// If the toolchain is all hex, assume it references an artifact from
79-
// CI, for instance an `@bors try` build.
80-
let re = Regex::new(r"^[a-fA-F0-9]+$").unwrap();
81-
let toolchain = if re.is_match(&config.toolchain) {
82-
debug!("using CI build {}", &config.toolchain);
83-
Toolchain::ci(&config.toolchain, false)
84-
} else {
85-
debug!("using toolchain {}", &config.toolchain);
86-
Toolchain::dist(&config.toolchain)
87-
};
93+
let pool = context.pool()?;
8894

8995
Ok(RustwideBuilder {
9096
workspace,
91-
toolchain,
97+
toolchain: get_configured_toolchain(&mut *pool.get()?)?,
9298
config,
93-
db: context.pool()?,
99+
db: pool,
94100
storage: context.storage()?,
95101
metrics: context.instance_metrics()?,
96102
index: context.index()?,
@@ -119,6 +125,8 @@ impl RustwideBuilder {
119125
}
120126

121127
pub fn update_toolchain(&mut self) -> Result<bool> {
128+
self.toolchain = get_configured_toolchain(&mut *self.db.get()?)?;
129+
122130
// For CI builds, a lot of the normal update_toolchain things don't apply.
123131
// CI builds are only for one platform (https://forge.rust-lang.org/infra/docs/rustc-ci.html#try-builds)
124132
// so we only try installing for the current platform. If that's not a match,

src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub enum ConfigName {
5656
RustcVersion,
5757
LastSeenIndexReference,
5858
QueueLocked,
59+
Toolchain,
5960
}
6061

6162
pub fn set_config(

0 commit comments

Comments
 (0)