From d35beb1974abdd2e5ae4f8fe777ebb7f5924d7fc Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 12 Dec 2019 13:16:00 -0500 Subject: [PATCH 1/3] docker: install nightly before checking what version it is --- src/docbuilder/rustwide_builder.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index 2a498da41..b773718a8 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -112,6 +112,7 @@ impl RustwideBuilder { fn detect_rustc_version(&self) -> Result { info!("detecting rustc's version..."); + self.toolchain.install(&self.workspace)?; let res = Command::new(&self.workspace, self.toolchain.rustc()) .args(&["--version"]) .log_output(false) From e58ee86f2deaf817e81cb429e89c0f47c191cfb7 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 12 Dec 2019 13:29:38 -0500 Subject: [PATCH 2/3] docker: fix the root cause instead of the proximate cause --- src/bin/cratesfyi.rs | 2 +- src/docbuilder/rustwide_builder.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index 1d100ba13..83f6f8613 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -182,7 +182,7 @@ pub fn main() { } let mut builder = RustwideBuilder::init().unwrap(); - builder.add_essential_files().expect("failed to add essential files"); + builder.update_toolchain().expect("failed to add essential files"); } else if let Some(_) = matches.subcommand_matches("lock") { docbuilder.lock().expect("Failed to lock"); } else if let Some(_) = matches.subcommand_matches("unlock") { diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index b773718a8..12abdc1ac 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -93,7 +93,7 @@ impl RustwideBuilder { }) } - fn update_toolchain(&mut self) -> Result<()> { + pub fn update_toolchain(&mut self) -> Result<()> { // Ignore errors if detection fails. let old_version = self.detect_rustc_version().ok(); @@ -112,7 +112,6 @@ impl RustwideBuilder { fn detect_rustc_version(&self) -> Result { info!("detecting rustc's version..."); - self.toolchain.install(&self.workspace)?; let res = Command::new(&self.workspace, self.toolchain.rustc()) .args(&["--version"]) .log_output(false) @@ -128,7 +127,7 @@ impl RustwideBuilder { } } - pub fn add_essential_files(&mut self) -> Result<()> { + fn add_essential_files(&mut self) -> Result<()> { self.rustc_version = self.detect_rustc_version()?; let rustc_version = parse_rustc_version(&self.rustc_version)?; From a7f515b8c6ee723359ab6dfcf4fe60fd6c2ec00a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 12 Dec 2019 14:46:18 -0500 Subject: [PATCH 3/3] docker: use update-toolchain in entrypoint using update-toolchain instead of add-essential files installs the toolchain first if it doesn't exist. This still keeps the `add-essential-files` command in case someone needs to update the essential files without updating the toolchain version. --- docker-entrypoint.sh | 2 +- src/bin/cratesfyi.rs | 18 +++++++++++------- src/docbuilder/rustwide_builder.rs | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 6a092391d..8ab8d0ff4 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -36,6 +36,6 @@ if ! [ -d "${CRATESFYI_PREFIX}/crates.io-index/.git" ]; then git --git-dir="$CRATESFYI_PREFIX/crates.io-index/.git" branch crates-index-diff_last-seen fi -cratesfyi build add-essential-files --only-first-time +cratesfyi build update-toolchain --only-first-time cratesfyi "$@" diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index 83f6f8613..2b06d0048 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -65,11 +65,13 @@ pub fn main() { .takes_value(true) .conflicts_with_all(&["CRATE_NAME", "CRATE_VERSION"]) .help("Build a crate at a specific path"))) - .subcommand(SubCommand::with_name("add-essential-files") - .about("Adds essential files for rustc") + .subcommand(SubCommand::with_name("update-toolchain") + .about("update the curretntly installed rustup toolchain") .arg(Arg::with_name("ONLY_FIRST_TIME") .long("only-first-time") - .help("add essential files only if no essential files are present"))) + .help("update toolchain only if no toolchain is currently installed"))) + .subcommand(SubCommand::with_name("add-essential-files") + .about("Adds essential files for the installed version of rustc")) .subcommand(SubCommand::with_name("lock").about("Locks cratesfyi daemon to stop \ building new crates")) .subcommand(SubCommand::with_name("unlock") @@ -171,18 +173,20 @@ pub fn main() { matches.value_of("CRATE_NAME").unwrap(), matches.value_of("CRATE_VERSION").unwrap(), None), }.expect("Building documentation failed"); docbuilder.save_cache().expect("Failed to save cache"); - } else if let Some(m) = matches.subcommand_matches("add-essential-files") { + } else if let Some(m) = matches.subcommand_matches("update-toolchain") { if m.is_present("ONLY_FIRST_TIME") { let conn = db::connect_db().unwrap(); let res = conn.query("SELECT * FROM config WHERE name = 'rustc_version';", &[]).unwrap(); if !res.is_empty() { - println!("add-essential files was already called in the past, exiting"); + println!("update-toolchain was already called in the past, exiting"); return; } } - let mut builder = RustwideBuilder::init().unwrap(); - builder.update_toolchain().expect("failed to add essential files"); + builder.update_toolchain().expect("failed to update toolchain"); + } else if matches.subcommand_matches("add-essential-files").is_some() { + let mut builder = RustwideBuilder::init().unwrap(); + builder.add_essential_files().expect("failed to add essential files"); } else if let Some(_) = matches.subcommand_matches("lock") { docbuilder.lock().expect("Failed to lock"); } else if let Some(_) = matches.subcommand_matches("unlock") { diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index 12abdc1ac..61a1099d7 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -127,7 +127,7 @@ impl RustwideBuilder { } } - fn add_essential_files(&mut self) -> Result<()> { + pub fn add_essential_files(&mut self) -> Result<()> { self.rustc_version = self.detect_rustc_version()?; let rustc_version = parse_rustc_version(&self.rustc_version)?;