Skip to content

Commit 5085d57

Browse files
author
Joshua Nelson
committed
Revert "Support custom indexes"
This reverts commit 78f55cc.
1 parent 02d3cfd commit 5085d57

File tree

10 files changed

+35
-100
lines changed

10 files changed

+35
-100
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ log = "0.4"
2020
regex = "1"
2121
structopt = "0.3"
2222
crates-index = "0.15.1"
23-
crates-index-diff = "7.1"
23+
crates-index-diff = "7"
2424
reqwest = { version = "0.10.6", features = ["blocking", "json"] } # TODO: Remove blocking when async is ready
2525
semver = { version = "0.9", features = ["serde"] }
2626
slug = "=0.1.1"
@@ -40,7 +40,7 @@ schemamama = "0.3"
4040
schemamama_postgres = "0.3"
4141
systemstat = "0.1.4"
4242
prometheus = { version = "0.10.0", default-features = false }
43-
rustwide = { git = "https://github.com/rust-lang/rustwide.git" , rev = "bcf19b84128c983d02257a0ae9b91e5a6772122b"}
43+
rustwide = "0.10.0"
4444
mime_guess = "2"
4545
dotenv = "0.15"
4646
zstd = "0.5"

src/bin/cratesfyi.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::sync::Arc;
66
use docs_rs::db::{self, add_path_into_database, Pool, PoolClient};
77
use docs_rs::utils::{remove_crate_priority, set_crate_priority};
88
use docs_rs::{
9-
BuildQueue, Config, Context, DocBuilder, Index, Metrics, PackageKind, RustwideBuilder, Server,
10-
Storage,
9+
BuildQueue, Config, Context, DocBuilder, Index, Metrics, RustwideBuilder, Server, Storage,
1110
};
1211
use failure::{err_msg, Error, ResultExt};
1312
use once_cell::sync::OnceCell;
@@ -258,16 +257,8 @@ enum BuildSubcommand {
258257
#[structopt(name = "CRATE_VERSION")]
259258
crate_version: Option<String>,
260259

261-
/// Url for registry different from cratesio
262-
#[structopt(name = "CRATE_REGISTRY")]
263-
crate_registry: Option<String>,
264-
265260
/// Build a crate at a specific path
266-
#[structopt(
267-
short = "l",
268-
long = "local",
269-
conflicts_with_all(&["CRATE_NAME", "CRATE_VERSION", "CRATE_REGISTRY"])
270-
)]
261+
#[structopt(short = "l", long = "local", conflicts_with_all(&["CRATE_NAME", "CRATE_VERSION"]))]
271262
local: Option<PathBuf>,
272263
},
273264

@@ -308,7 +299,6 @@ impl BuildSubcommand {
308299
Self::Crate {
309300
crate_name,
310301
crate_version,
311-
crate_registry,
312302
local,
313303
} => {
314304
let mut builder = rustwide_builder()?;
@@ -323,10 +313,7 @@ impl BuildSubcommand {
323313
&crate_name.ok_or_else(|| err_msg("must specify name if not local"))?,
324314
&crate_version
325315
.ok_or_else(|| err_msg("must specify version if not local"))?,
326-
crate_registry
327-
.as_ref()
328-
.map(|s| PackageKind::Registry(s.as_str()))
329-
.unwrap_or(PackageKind::CratesIo),
316+
None,
330317
)
331318
.context("Building documentation failed")?;
332319
}
@@ -606,16 +593,7 @@ impl Context for BinContext {
606593
fn index(&self) -> Result<Arc<Index>, Error> {
607594
Ok(self
608595
.index
609-
.get_or_try_init::<_, Error>(|| {
610-
let config = self.config()?;
611-
Ok(Arc::new(
612-
if let Some(registry_url) = config.registry_url.clone() {
613-
Index::from_url(config.registry_index_path.clone(), registry_url)
614-
} else {
615-
Index::new(config.registry_index_path.clone())
616-
}?,
617-
))
618-
})?
596+
.get_or_try_init::<_, Error>(|| Ok(Arc::new(Index::new(&*self.config()?)?)))?
619597
.clone())
620598
}
621599
}

src/config.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub struct Config {
1212

1313
pub prefix: PathBuf,
1414
pub registry_index_path: PathBuf,
15-
pub registry_url: Option<String>,
1615

1716
// Database connection params
1817
pub(crate) database_url: String,
@@ -57,7 +56,6 @@ impl Config {
5756

5857
prefix: prefix.clone(),
5958
registry_index_path: env("REGISTRY_INDEX_PATH", prefix.join("crates.io-index"))?,
60-
registry_url: maybe_env("REGISTRY_URL")?,
6159

6260
database_url: require_env("CRATESFYI_DATABASE_URL")?,
6361
max_pool_size: env("DOCSRS_MAX_POOL_SIZE", 90)?,

src/docbuilder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ mod queue;
44
mod rustwide_builder;
55

66
pub(crate) use self::limits::Limits;
7+
pub use self::rustwide_builder::RustwideBuilder;
78
pub(crate) use self::rustwide_builder::{BuildResult, DocCoverage};
8-
pub use self::rustwide_builder::{PackageKind, RustwideBuilder};
99

1010
use crate::db::Pool;
1111
use crate::error::Result;

src/docbuilder/queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Updates registry index and builds new packages
22
3-
use super::{DocBuilder, PackageKind, RustwideBuilder};
3+
use super::{DocBuilder, RustwideBuilder};
44
use crate::error::Result;
55
use crate::utils::get_crate_priority;
66
use crate::Index;
@@ -79,7 +79,7 @@ impl DocBuilder {
7979
queue.process_next_crate(|krate| {
8080
processed = true;
8181

82-
builder.build_package(&krate.name, &krate.version, PackageKind::CratesIo)?;
82+
builder.build_package(&krate.name, &krate.version, None)?;
8383
Ok(())
8484
})?;
8585

src/docbuilder/rustwide_builder.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ const ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
5656
const DUMMY_CRATE_NAME: &str = "empty-library";
5757
const DUMMY_CRATE_VERSION: &str = "1.0.0";
5858

59-
pub enum PackageKind<'a> {
60-
Local(&'a Path),
61-
CratesIo,
62-
Registry(&'a str),
63-
}
64-
6559
pub struct RustwideBuilder {
6660
workspace: Workspace,
6761
toolchain: Toolchain,
@@ -265,12 +259,7 @@ impl RustwideBuilder {
265259
crates_from_path(
266260
&self.config.registry_index_path.clone(),
267261
&mut |name, version| {
268-
let registry_url = self.config.registry_url.clone();
269-
let package_kind = registry_url
270-
.as_ref()
271-
.map(|r| PackageKind::Registry(r.as_str()))
272-
.unwrap_or(PackageKind::CratesIo);
273-
if let Err(err) = self.build_package(name, version, package_kind) {
262+
if let Err(err) = self.build_package(name, version, None) {
274263
warn!("failed to build package {} {}: {}", name, version, err);
275264
}
276265
},
@@ -284,14 +273,14 @@ impl RustwideBuilder {
284273
err.context(format!("failed to load local package {}", path.display()))
285274
})?;
286275
let package = metadata.root();
287-
self.build_package(&package.name, &package.version, PackageKind::Local(path))
276+
self.build_package(&package.name, &package.version, Some(path))
288277
}
289278

290279
pub fn build_package(
291280
&mut self,
292281
name: &str,
293282
version: &str,
294-
kind: PackageKind<'_>,
283+
local: Option<&Path>,
295284
) -> Result<bool> {
296285
let mut conn = self.db.get()?;
297286

@@ -313,10 +302,10 @@ impl RustwideBuilder {
313302
let mut build_dir = self.workspace.build_dir(&format!("{}-{}", name, version));
314303
build_dir.purge()?;
315304

316-
let krate = match kind {
317-
PackageKind::Local(path) => Crate::local(path),
318-
PackageKind::CratesIo => Crate::crates_io(name, version),
319-
PackageKind::Registry(registry) => Crate::registry(registry, name, version),
305+
let krate = if let Some(path) = local {
306+
Crate::local(path)
307+
} else {
308+
Crate::crates_io(name, version)
320309
};
321310
krate.fetch(&self.workspace)?;
322311

src/index/mod.rs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{path::PathBuf, process::Command};
33
use url::Url;
44

55
use self::{api::Api, crates::Crates};
6-
use crate::error::Result;
6+
use crate::{error::Result, Config};
77
use failure::ResultExt;
88

99
pub(crate) mod api;
@@ -12,10 +12,9 @@ mod crates;
1212
pub struct Index {
1313
path: PathBuf,
1414
api: Api,
15-
repository_url: Option<String>,
1615
}
1716

18-
#[derive(Debug, serde::Deserialize, Clone)]
17+
#[derive(serde::Deserialize, Clone)]
1918
#[serde(rename_all = "kebab-case")]
2019
struct IndexConfig {
2120
dl: String,
@@ -41,44 +40,19 @@ fn load_config(repo: &git2::Repository) -> Result<IndexConfig> {
4140
}
4241

4342
impl Index {
44-
pub fn from_url(path: PathBuf, repository_url: String) -> Result<Self> {
45-
let url = repository_url.clone();
46-
let diff = crates_index_diff::Index::from_path_or_cloned_with_options(
47-
&path,
48-
crates_index_diff::CloneOptions { repository_url },
49-
)
50-
.context("initialising registry index repository")?;
51-
52-
let config = load_config(diff.repository()).context("loading registry config")?;
53-
let api = Api::new(config.api).context("initialising registry api client")?;
54-
Ok(Self {
55-
path,
56-
api,
57-
repository_url: Some(url),
58-
})
59-
}
60-
61-
pub fn new(path: PathBuf) -> Result<Self> {
43+
pub fn new(app_config: &Config) -> Result<Self> {
44+
let path = app_config.registry_index_path.clone();
6245
// This initializes the repository, then closes it afterwards to avoid leaking file descriptors.
6346
// See https://github.com/rust-lang/docs.rs/pull/847
6447
let diff = crates_index_diff::Index::from_path_or_cloned(&path)
6548
.context("initialising registry index repository")?;
6649
let config = load_config(diff.repository()).context("loading registry config")?;
6750
let api = Api::new(config.api).context("initialising registry api client")?;
68-
Ok(Self {
69-
path,
70-
api,
71-
repository_url: None,
72-
})
51+
Ok(Self { path, api })
7352
}
7453

7554
pub(crate) fn diff(&self) -> Result<crates_index_diff::Index> {
76-
let options = self
77-
.repository_url
78-
.clone()
79-
.map(|repository_url| crates_index_diff::CloneOptions { repository_url })
80-
.unwrap_or_default();
81-
let diff = crates_index_diff::Index::from_path_or_cloned_with_options(&self.path, options)
55+
let diff = crates_index_diff::Index::from_path_or_cloned(&self.path)
8256
.context("re-opening registry index for diff")?;
8357
Ok(diff)
8458
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub use self::build_queue::BuildQueue;
66
pub use self::config::Config;
77
pub use self::context::Context;
88
pub use self::docbuilder::DocBuilder;
9-
pub use self::docbuilder::PackageKind;
109
pub use self::docbuilder::RustwideBuilder;
1110
pub use self::index::Index;
1211
pub use self::metrics::Metrics;

src/test/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ impl TestEnvironment {
197197
pub(crate) fn index(&self) -> Arc<Index> {
198198
self.index
199199
.get_or_init(|| {
200-
Arc::new(
201-
Index::new(self.config().registry_index_path.clone())
202-
.expect("failed to initialize the index"),
203-
)
200+
Arc::new(Index::new(&*self.config()).expect("failed to initialize the index"))
204201
})
205202
.clone()
206203
}

0 commit comments

Comments
 (0)