diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index ea3dca362..329814165 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -97,10 +97,6 @@ enum Toggle { )] enum CommandLine { Build { - /// Skips building documentation if documentation exists - #[arg(name = "SKIP_IF_EXISTS", short = 's', long = "skip")] - skip_if_exists: bool, - #[command(subcommand)] subcommand: BuildSubcommand, }, @@ -155,10 +151,7 @@ impl CommandLine { let ctx = BinContext::new(); match self { - Self::Build { - skip_if_exists, - subcommand, - } => subcommand.handle_args(ctx, skip_if_exists)?, + Self::Build { subcommand } => subcommand.handle_args(ctx)?, Self::StartRegistryWatcher { metric_server_socket_addr, repository_stats_updater, @@ -355,9 +348,6 @@ impl PrioritySubcommand { #[derive(Debug, Clone, PartialEq, Eq, Subcommand)] enum BuildSubcommand { - /// Builds documentation of every crate - World, - /// Builds documentation for a crate Crate { /// Crate name @@ -395,22 +385,12 @@ enum BuildSubcommand { } impl BuildSubcommand { - fn handle_args(self, ctx: BinContext, skip_if_exists: bool) -> Result<()> { + fn handle_args(self, ctx: BinContext) -> Result<()> { let build_queue = ctx.build_queue()?; - let rustwide_builder = || -> Result { - let mut builder = RustwideBuilder::init(&ctx)?; - builder.set_skip_build_if_exists(skip_if_exists); - Ok(builder) - }; + let rustwide_builder = || -> Result { RustwideBuilder::init(&ctx) }; match self { - Self::World => { - rustwide_builder()? - .build_world() - .context("Failed to build world")?; - } - Self::Crate { crate_name, crate_version, diff --git a/src/docbuilder/crates.rs b/src/docbuilder/crates.rs deleted file mode 100644 index b250262ee..000000000 --- a/src/docbuilder/crates.rs +++ /dev/null @@ -1,81 +0,0 @@ -use crate::error::Result; -use anyhow::Context; -use serde_json::Value; -use std::io::prelude::*; -use std::io::BufReader; -use std::{fs, path::Path, str::FromStr}; - -fn crates_from_file(path: &Path, func: &mut F) -> Result<()> -where - F: FnMut(&str, &str), -{ - let reader = fs::File::open(path).map(BufReader::new)?; - - let mut name = String::new(); - let mut versions = Vec::new(); - - for line in reader.lines() { - // some crates have invalid UTF-8 (nanny-sys-0.0.7) - // skip them - let line = if let Ok(line) = line { - line - } else { - continue; - }; - - let data = if let Ok(data) = Value::from_str(line.trim()) { - data - } else { - continue; - }; - - let obj = data.as_object().context("Not a JSON object")?; - let crate_name = obj - .get("name") - .and_then(|n| n.as_str()) - .context("`name` not found in JSON object")?; - let vers = obj - .get("vers") - .and_then(|n| n.as_str()) - .context("`vers` not found in JSON object")?; - - // Skip yanked crates - if obj.get("yanked").and_then(|n| n.as_bool()).unwrap_or(false) { - continue; - } - - name.clear(); - name.push_str(crate_name); - versions.push(vers.to_string()); - } - - if !name.is_empty() { - for version in versions { - func(&name, &version); - } - } - - Ok(()) -} - -pub fn crates_from_path(path: &Path, func: &mut F) -> Result<()> -where - F: FnMut(&str, &str), -{ - for file in path.read_dir()? { - let file = file?; - let path = file.path(); - // skip files under .git and config.json - if path.to_str().unwrap().contains(".git") || path.file_name().unwrap() == "config.json" { - continue; - } - - if path.is_dir() { - crates_from_path(&path, func)?; - } else { - crates_from_file(&path, func)?; - } - } - - Ok(()) -} diff --git a/src/docbuilder/mod.rs b/src/docbuilder/mod.rs index 6eadd9295..2378b3c36 100644 --- a/src/docbuilder/mod.rs +++ b/src/docbuilder/mod.rs @@ -1,4 +1,3 @@ -mod crates; mod limits; mod rustwide_builder; diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index 8ddba1110..f073f9c32 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -3,7 +3,7 @@ use crate::db::{ add_build_into_database, add_doc_coverage, add_package_into_database, add_path_into_remote_archive, update_crate_data_in_database, Pool, }; -use crate::docbuilder::{crates::crates_from_path, Limits}; +use crate::docbuilder::Limits; use crate::error::Result; use crate::repositories::RepositoryStatsUpdater; use crate::storage::{rustdoc_archive_path, source_archive_path}; @@ -64,7 +64,6 @@ pub struct RustwideBuilder { index: Arc, rustc_version: String, repository_stats_updater: Arc, - skip_build_if_exists: bool, } impl RustwideBuilder { @@ -102,14 +101,9 @@ impl RustwideBuilder { index: context.index()?, rustc_version: String::new(), repository_stats_updater: context.repository_stats_updater()?, - skip_build_if_exists: false, }) } - pub fn set_skip_build_if_exists(&mut self, should: bool) { - self.skip_build_if_exists = should; - } - fn prepare_sandbox(&self, limits: &Limits) -> SandboxBuilder { SandboxBuilder::new() .cpu_limit(self.config.build_cpu_limit.map(|limit| limit as f32)) @@ -314,22 +308,6 @@ impl RustwideBuilder { Ok(()) } - pub fn build_world(&mut self) -> Result<()> { - crates_from_path( - &self.config.registry_index_path.clone(), - &mut |name, version| { - let registry_url = self.config.registry_url.clone(); - let package_kind = registry_url - .as_ref() - .map(|r| PackageKind::Registry(r.as_str())) - .unwrap_or(PackageKind::CratesIo); - if let Err(err) = self.build_package(name, version, package_kind) { - warn!("failed to build package {} {}: {}", name, version, err); - } - }, - ) - } - pub fn build_local_package(&mut self, path: &Path) -> Result { self.update_toolchain()?; let metadata = CargoMetadata::load_from_rustwide(&self.workspace, &self.toolchain, path) @@ -348,10 +326,6 @@ impl RustwideBuilder { ) -> Result { let mut conn = self.db.get()?; - if !self.should_build(&mut conn, name, version)? { - return Ok(false); - } - self.update_toolchain()?; info!("building package {} {}", name, version); @@ -859,23 +833,6 @@ impl RustwideBuilder { copy_dir_all(source, dest).map_err(Into::into) } - fn should_build(&self, conn: &mut Client, name: &str, version: &str) -> Result { - if self.skip_build_if_exists { - // Check whether no successful builds are present in the database. - Ok(conn - .query( - "SELECT 1 FROM crates, releases, builds - WHERE crates.id = releases.crate_id AND releases.id = builds.rid - AND crates.name = $1 AND releases.version = $2 - AND builds.build_status = TRUE;", - &[&name, &version], - )? - .is_empty()) - } else { - Ok(true) - } - } - fn get_repo(&self, metadata: &MetadataPackage) -> Result> { self.repository_stats_updater .load_repository(metadata)