Skip to content

Commit

Permalink
remove build world subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Oct 12, 2023
1 parent 0fb8970 commit 318ab7b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 149 deletions.
26 changes: 3 additions & 23 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<RustwideBuilder> {
let mut builder = RustwideBuilder::init(&ctx)?;
builder.set_skip_build_if_exists(skip_if_exists);
Ok(builder)
};
let rustwide_builder = || -> Result<RustwideBuilder> { RustwideBuilder::init(&ctx) };

match self {
Self::World => {
rustwide_builder()?
.build_world()
.context("Failed to build world")?;
}

Self::Crate {
crate_name,
crate_version,
Expand Down
81 changes: 0 additions & 81 deletions src/docbuilder/crates.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/docbuilder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod crates;
mod limits;
mod rustwide_builder;

Expand Down
45 changes: 1 addition & 44 deletions src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -64,7 +64,6 @@ pub struct RustwideBuilder {
index: Arc<Index>,
rustc_version: String,
repository_stats_updater: Arc<RepositoryStatsUpdater>,
skip_build_if_exists: bool,
}

impl RustwideBuilder {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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<bool> {
self.update_toolchain()?;
let metadata = CargoMetadata::load_from_rustwide(&self.workspace, &self.toolchain, path)
Expand All @@ -348,10 +326,6 @@ impl RustwideBuilder {
) -> Result<bool> {
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);
Expand Down Expand Up @@ -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<bool> {
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<Option<i32>> {
self.repository_stats_updater
.load_repository(metadata)
Expand Down

0 comments on commit 318ab7b

Please sign in to comment.