From c94e0028732005f37ee755283a821ecc9acc0175 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 20:59:09 -0500 Subject: [PATCH 01/17] remove copy_dir --- src/utils/copy.rs | 10 ---------- src/utils/mod.rs | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/utils/copy.rs b/src/utils/copy.rs index bc47c78f7..72942e7ca 100644 --- a/src/utils/copy.rs +++ b/src/utils/copy.rs @@ -8,16 +8,6 @@ use error::Result; use regex::Regex; - -/// Copies files from source directory to destination directory. -pub fn copy_dir>(source: P, destination: P) -> Result<()> { - copy_files_and_handle_html(source.as_ref().to_path_buf(), - destination.as_ref().to_path_buf(), - false, - "") -} - - /// Copies documentation from a crate's target directory to destination. /// /// Target directory must have doc directory. diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 06864b9bc..2d668b75f 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,7 +1,7 @@ //! Various utilities for cratesfyi -pub use self::copy::{copy_dir, copy_doc_dir}; +pub use self::copy::copy_doc_dir; pub use self::github_updater::github_updater; pub use self::release_activity_updater::update_release_activity; pub use self::daemon::start_daemon; From e49aa3945a77d0b285287d91076c82eddfdaee75 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:04:45 -0500 Subject: [PATCH 02/17] make utils pub(crate) where possible --- src/utils/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 2d668b75f..8f54a7511 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,12 +1,12 @@ //! Various utilities for cratesfyi -pub use self::copy::copy_doc_dir; +pub(crate) use self::copy::copy_doc_dir; pub use self::github_updater::github_updater; pub use self::release_activity_updater::update_release_activity; pub use self::daemon::start_daemon; -pub use self::rustc_version::{parse_rustc_version, get_current_versions, command_result}; -pub use self::html::extract_head_and_body; +pub(crate) use self::rustc_version::parse_rustc_version; +pub(crate) use self::html::extract_head_and_body; pub use self::queue::add_crate_to_queue; pub(crate) use self::cargo_metadata::{CargoMetadata, Package as MetadataPackage}; From 3b55d6566e1793029546a507a0dc7a1c730900a4 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:05:25 -0500 Subject: [PATCH 03/17] remove dead code in rustc version --- src/utils/rustc_version.rs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/utils/rustc_version.rs b/src/utils/rustc_version.rs index b7fea0a04..6aca1e8a6 100644 --- a/src/utils/rustc_version.rs +++ b/src/utils/rustc_version.rs @@ -1,5 +1,4 @@ -use std::process::{Command, Output}; use regex::Regex; use error::Result; use failure::err_msg; @@ -18,26 +17,6 @@ pub fn parse_rustc_version>(version: S) -> Result { captures.get(2).unwrap().as_str())) } - -/// Returns current version of rustc and cratesfyi -pub fn get_current_versions() -> Result<(String, String)> { - let rustc_version = command_result(Command::new("rustc").arg("--version").output()?)?; - let cratesfyi_version = command_result(Command::new("rustc").arg("--version").output()?)?; - - Ok((rustc_version, cratesfyi_version)) -} - - -pub fn command_result(output: Output) -> Result { - let mut command_out = String::from_utf8_lossy(&output.stdout).into_owned(); - command_out.push_str(&String::from_utf8_lossy(&output.stderr).into_owned()[..]); - match output.status.success() { - true => Ok(command_out), - false => Err(err_msg(command_out)), - } -} - - #[test] fn test_parse_rustc_version() { assert_eq!(parse_rustc_version("rustc 1.10.0-nightly (57ef01513 2016-05-23)").unwrap(), From 5444d63f1d7589aabeb272ead9d7c58fbad0afae Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:17:16 -0500 Subject: [PATCH 04/17] make more things pub(crate) --- src/bin/cratesfyi.rs | 2 +- src/db/mod.rs | 6 +++--- src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index 7c78bc97a..65124ee96 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -239,7 +239,7 @@ pub fn main() { let mut count = 1; let mut total = 0; while count != 0 { - count = db::file::move_to_s3(&conn, 5_000).expect("Failed to upload batch to S3"); + count = db::move_to_s3(&conn, 5_000).expect("Failed to upload batch to S3"); total += count; eprintln!( "moved {} rows to s3 in this batch, total moved so far: {}", diff --git a/src/db/mod.rs b/src/db/mod.rs index e486b0b15..a4ff498ba 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -3,8 +3,8 @@ pub(crate) use self::add_package::add_package_into_database; pub(crate) use self::add_package::add_build_into_database; pub(crate) use self::add_package::CratesIoData; -pub use self::file::add_path_into_database; -pub use self::migrate::{migrate, migrate_temporary}; +pub use self::file::{add_path_into_database, move_to_s3}; +pub use self::migrate::migrate; pub use self::delete_crate::delete_crate; use postgres::{Connection, TlsMode}; @@ -14,7 +14,7 @@ use r2d2; use r2d2_postgres; mod add_package; -pub mod file; +pub(crate) mod file; mod migrate; mod delete_crate; pub mod blacklist; diff --git a/src/lib.rs b/src/lib.rs index 6723147d2..53ac808f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ pub use self::docbuilder::options::DocBuilderOptions; pub use self::docbuilder::metadata::Metadata; pub use self::web::Server; -pub mod error; +pub(crate) mod error; pub mod db; pub mod utils; mod docbuilder; From 343c69a6debbd40b54c2a3fb8e03e5e62b5b7c75 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:26:03 -0500 Subject: [PATCH 05/17] only compile ApplyMode::Temporary in test mode --- src/db/migrate.rs | 3 +++ src/db/mod.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/db/migrate.rs b/src/db/migrate.rs index c4182b0f6..59e72dbda 100644 --- a/src/db/migrate.rs +++ b/src/db/migrate.rs @@ -10,6 +10,7 @@ use std::borrow::Cow; #[derive(Copy, Clone)] enum ApplyMode { Permanent, + #[cfg(test)] Temporary, } @@ -22,6 +23,7 @@ impl MigrationContext { fn format_query<'a>(&self, query: &'a str) -> Cow<'a, str> { match self.apply_mode { ApplyMode::Permanent => Cow::Borrowed(query), + #[cfg(test)] ApplyMode::Temporary => { Cow::Owned(query.replace("CREATE TABLE", "CREATE TEMPORARY TABLE")) } @@ -73,6 +75,7 @@ pub fn migrate(version: Option, conn: &Connection) -> CratesfyiResult<( migrate_inner(version, conn, ApplyMode::Permanent) } +#[cfg(test)] pub fn migrate_temporary(version: Option, conn: &Connection) -> CratesfyiResult<()> { migrate_inner(version, conn, ApplyMode::Temporary) } diff --git a/src/db/mod.rs b/src/db/mod.rs index a4ff498ba..a8c4e19fc 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -5,6 +5,8 @@ pub(crate) use self::add_package::add_build_into_database; pub(crate) use self::add_package::CratesIoData; pub use self::file::{add_path_into_database, move_to_s3}; pub use self::migrate::migrate; +#[cfg(test)] +pub(crate) use self::migrate::migrate_temporary; pub use self::delete_crate::delete_crate; use postgres::{Connection, TlsMode}; From e8eabd4baaa80660c3c1d7c600701bb815148e9b Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:26:35 -0500 Subject: [PATCH 06/17] remove unused argument --- src/docbuilder/rustwide_builder.rs | 3 +-- src/utils/copy.rs | 16 +++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index a22bb1a92..1d08b889c 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -522,8 +522,7 @@ impl RustwideBuilder { } info!("{} {}", source.display(), dest.display()); - copy_doc_dir(source, dest, self.rustc_version.trim())?; - Ok(()) + copy_doc_dir(source, dest) } fn upload_docs( diff --git a/src/utils/copy.rs b/src/utils/copy.rs index 72942e7ca..76df232ff 100644 --- a/src/utils/copy.rs +++ b/src/utils/copy.rs @@ -14,22 +14,17 @@ use regex::Regex; /// /// This function is designed to avoid file duplications. It is using rustc version string /// to rename common files (css files, jquery.js, playpen.js, main.js etc.) in a standard rustdoc. -pub fn copy_doc_dir>(target: P, - destination: P, - rustc_version: &str) - -> Result<()> { +pub fn copy_doc_dir>(target: P, destination: P) -> Result<()> { let source = PathBuf::from(target.as_ref()).join("doc"); copy_files_and_handle_html(source, destination.as_ref().to_path_buf(), - true, - rustc_version) + true) } fn copy_files_and_handle_html(source: PathBuf, destination: PathBuf, - handle_html: bool, - rustc_version: &str) + handle_html: bool) -> Result<()> { // FIXME: handle_html is useless since we started using --resource-suffix @@ -57,8 +52,7 @@ fn copy_files_and_handle_html(source: PathBuf, fs::create_dir_all(&destination_full_path)?; copy_files_and_handle_html(file.path(), destination_full_path, - handle_html, - &rustc_version)? + handle_html)? } else if handle_html && dup_regex.is_match(&file.file_name().into_string().unwrap()[..]) { continue; } else { @@ -84,7 +78,7 @@ mod test { let destination = tempdir::TempDir::new("cratesfyi").unwrap(); // lets try to copy a src directory to tempdir - let res = copy_dir(Path::new("src"), destination.path()); + let res = copy_doc_dir(Path::new("src"), destination.path()); // remove temp dir fs::remove_dir_all(destination.path()).unwrap(); From a21fbfe421f9b3017e8dc9980ce392b2d3e560db Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:29:46 -0500 Subject: [PATCH 07/17] remove unused `handle_html` argument --- src/utils/copy.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/utils/copy.rs b/src/utils/copy.rs index 76df232ff..7b2f30e66 100644 --- a/src/utils/copy.rs +++ b/src/utils/copy.rs @@ -16,16 +16,7 @@ use regex::Regex; /// to rename common files (css files, jquery.js, playpen.js, main.js etc.) in a standard rustdoc. pub fn copy_doc_dir>(target: P, destination: P) -> Result<()> { let source = PathBuf::from(target.as_ref()).join("doc"); - copy_files_and_handle_html(source, - destination.as_ref().to_path_buf(), - true) -} - - -fn copy_files_and_handle_html(source: PathBuf, - destination: PathBuf, - handle_html: bool) - -> Result<()> { + let destination = destination.as_ref().to_path_buf(); // FIXME: handle_html is useless since we started using --resource-suffix // argument with rustdoc @@ -50,10 +41,8 @@ fn copy_files_and_handle_html(source: PathBuf, if metadata.is_dir() { fs::create_dir_all(&destination_full_path)?; - copy_files_and_handle_html(file.path(), - destination_full_path, - handle_html)? - } else if handle_html && dup_regex.is_match(&file.file_name().into_string().unwrap()[..]) { + copy_doc_dir(file.path(), destination_full_path)? + } else if dup_regex.is_match(&file.file_name().into_string().unwrap()[..]) { continue; } else { fs::copy(&file.path(), &destination_full_path)?; From 087f7a1ae81a8d7857b727bb858b9ef31cef0ae0 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:34:59 -0500 Subject: [PATCH 08/17] don't export metadata --- src/docbuilder/mod.rs | 5 +++-- src/docbuilder/rustwide_builder.rs | 2 +- src/lib.rs | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/docbuilder/mod.rs b/src/docbuilder/mod.rs index c6e5e8b7c..21b03d0b1 100644 --- a/src/docbuilder/mod.rs +++ b/src/docbuilder/mod.rs @@ -1,6 +1,6 @@ -pub mod options; -pub mod metadata; +pub(crate) mod options; +mod metadata; mod limits; mod rustwide_builder; mod crates; @@ -9,6 +9,7 @@ mod queue; pub use self::rustwide_builder::RustwideBuilder; pub(crate) use self::rustwide_builder::BuildResult; pub(crate) use self::limits::Limits; +pub(self) use self::metadata::Metadata; use std::fs; diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index 1d08b889c..d82f6a25b 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -16,7 +16,7 @@ use std::borrow::Cow; use std::collections::HashSet; use std::path::Path; use utils::{copy_doc_dir, parse_rustc_version, CargoMetadata}; -use Metadata; +use super::Metadata; const USER_AGENT: &str = "docs.rs builder (https://github.com/rust-lang/docs.rs)"; const DEFAULT_RUSTWIDE_WORKSPACE: &str = ".rustwide"; diff --git a/src/lib.rs b/src/lib.rs index 53ac808f2..07625c86e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,6 @@ extern crate once_cell; pub use self::docbuilder::RustwideBuilder; pub use self::docbuilder::DocBuilder; pub use self::docbuilder::options::DocBuilderOptions; -pub use self::docbuilder::metadata::Metadata; pub use self::web::Server; pub(crate) mod error; From 569875b7e67e0f02e24d7771566d4c7331d790b9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 21:57:41 -0500 Subject: [PATCH 09/17] remove `pub` where possible --- src/db/file.rs | 2 +- src/docbuilder/metadata.rs | 4 ++-- src/utils/github_updater.rs | 10 +++++----- src/web/mod.rs | 26 +++++++++++++------------- src/web/releases.rs | 2 +- src/web/rustdoc.rs | 16 ++++++++-------- src/web/source.rs | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/db/file.rs b/src/db/file.rs index ad3609e46..0528822c3 100644 --- a/src/db/file.rs +++ b/src/db/file.rs @@ -42,7 +42,7 @@ fn get_file_list_from_dir>(path: P, } -pub fn get_file_list>(path: P) -> Result> { +fn get_file_list>(path: P) -> Result> { let path = path.as_ref(); let mut files = Vec::new(); diff --git a/src/docbuilder/metadata.rs b/src/docbuilder/metadata.rs index 5fdcd41b9..d916ca2c9 100644 --- a/src/docbuilder/metadata.rs +++ b/src/docbuilder/metadata.rs @@ -53,7 +53,7 @@ pub struct Metadata { /// System dependencies. /// /// Docs.rs is running on a Debian jessie. - pub dependencies: Option>, + dependencies: Option>, } @@ -69,7 +69,7 @@ impl Metadata { Err(err_msg("Manifest not found")) } - pub fn from_manifest>(path: P) -> Metadata { + fn from_manifest>(path: P) -> Metadata { use std::fs::File; use std::io::Read; let mut f = match File::open(path) { diff --git a/src/utils/github_updater.rs b/src/utils/github_updater.rs index f7a23ef91..a57206414 100644 --- a/src/utils/github_updater.rs +++ b/src/utils/github_updater.rs @@ -9,11 +9,11 @@ use failure::err_msg; /// Fields we need use in cratesfyi #[derive(Debug)] struct GitHubFields { - pub description: String, - pub stars: i64, - pub forks: i64, - pub issues: i64, - pub last_commit: time::Timespec, + description: String, + stars: i64, + forks: i64, + issues: i64, + last_commit: time::Timespec, } diff --git a/src/web/mod.rs b/src/web/mod.rs index cf35f8336..249170533 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -1,7 +1,7 @@ //! Web interface of cratesfyi -pub mod page; +pub(crate) mod page; /// ctry! (cratesfyitry) is extremely similar to try! and itry! /// except it returns an error page response instead of plain Err. @@ -45,7 +45,7 @@ mod builds; mod error; mod sitemap; mod routes; -pub mod metrics; +pub(crate) mod metrics; use std::{env, fmt}; use std::error::Error; @@ -105,7 +105,7 @@ impl CratesfyiHandler { chain } - pub fn new(pool_factory: PoolFactory) -> CratesfyiHandler { + fn new(pool_factory: PoolFactory) -> CratesfyiHandler { let routes = routes::build_routes(); let blacklisted_prefixes = routes.page_prefixes(); @@ -201,7 +201,7 @@ enum MatchVersion { impl MatchVersion { /// Convert this `MatchVersion` into an `Option`, discarding whether the matched version came /// from an exact version number or a semver requirement. - pub fn into_option(self) -> Option { + fn into_option(self) -> Option { match self { MatchVersion::Exact(v) | MatchVersion::Semver(v) => Some(v), MatchVersion::None => None, @@ -396,7 +396,7 @@ fn redirect(url: Url) -> Response { resp } -pub fn redirect_base(req: &Request) -> String { +fn redirect_base(req: &Request) -> String { // Try to get the scheme from CloudFront first, and then from iron let scheme = req.headers .get_raw("cloudfront-forwarded-proto") @@ -449,18 +449,18 @@ fn ico_handler(req: &mut Request) -> IronResult { /// MetaData used in header #[derive(Debug)] -pub struct MetaData { - pub name: String, - pub version: String, - pub description: Option, - pub target_name: Option, - pub rustdoc_status: bool, - pub default_target: String, +struct MetaData { + name: String, + version: String, + description: Option, + target_name: Option, + rustdoc_status: bool, + default_target: String, } impl MetaData { - pub fn from_crate(conn: &Connection, name: &str, version: &str) -> Option { + fn from_crate(conn: &Connection, name: &str, version: &str) -> Option { for row in &conn.query("SELECT crates.name, releases.version, releases.description, diff --git a/src/web/releases.rs b/src/web/releases.rs index bc5c454ee..20e1cc55a 100644 --- a/src/web/releases.rs +++ b/src/web/releases.rs @@ -330,7 +330,7 @@ pub fn releases_feed_handler(req: &mut Request) -> IronResult { } -pub fn releases_handler(packages: Vec, +fn releases_handler(packages: Vec, page_number: i64, release_type: &str, tab: &str, diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 07492fd62..1fe306ddd 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -23,14 +23,14 @@ use utils; #[derive(Debug)] struct RustdocPage { - pub head: String, - pub body: String, - pub body_class: String, - pub name: String, - pub full: String, - pub version: String, - pub description: Option, - pub crate_details: Option, + head: String, + body: String, + body_class: String, + name: String, + full: String, + version: String, + description: Option, + crate_details: Option, } diff --git a/src/web/source.rs b/src/web/source.rs index 8fa3b0255..44eaf13d2 100644 --- a/src/web/source.rs +++ b/src/web/source.rs @@ -82,7 +82,7 @@ impl FileList { /// This function is only returning FileList for requested directory. If is empty, /// it will return list of files (and dirs) for root directory. req_path must be a /// directory or empty for root directory. - pub fn from_path(conn: &Connection, + fn from_path(conn: &Connection, name: &str, version: &str, req_path: &str) From 5d565122b2d881023d9f547ece98ca343219d880 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 22:00:33 -0500 Subject: [PATCH 10/17] remove unused import --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 3f200eff0..075ae5ea1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,6 +2,6 @@ use std::result::Result as StdResult; -pub use failure::{Error, ResultExt}; +pub(crate) use failure::Error; pub type Result = StdResult; From 7cb0a07ebcebfbefad21d64b10a6fa96b2945042 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 22:13:04 -0500 Subject: [PATCH 11/17] make create_pool pub(crate) --- src/db/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/mod.rs b/src/db/mod.rs index a8c4e19fc..7ca8f36e8 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -31,7 +31,7 @@ pub fn connect_db() -> Result { } -pub fn create_pool() -> r2d2::Pool { +pub(crate) fn create_pool() -> r2d2::Pool { let db_url = env::var("CRATESFYI_DATABASE_URL") .expect("CRATESFYI_DATABASE_URL environment variable is not exists"); let manager = r2d2_postgres::PostgresConnectionManager::new(&db_url[..], From e34ebf286b0bd4871d31ccb402fec307a840aab9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 22 Jan 2020 21:01:51 -0500 Subject: [PATCH 12/17] fix bad merge --- src/web/crate_details.rs | 2 +- src/web/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/web/crate_details.rs b/src/web/crate_details.rs index 44c8333ce..b70a27b15 100644 --- a/src/web/crate_details.rs +++ b/src/web/crate_details.rs @@ -43,7 +43,7 @@ pub struct CrateDetails { github_stars: Option, github_forks: Option, github_issues: Option, - pub metadata: MetaData, + pub(crate) metadata: MetaData, is_library: bool, doc_targets: Option, license: Option, diff --git a/src/web/mod.rs b/src/web/mod.rs index 249170533..53f818a42 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -449,13 +449,13 @@ fn ico_handler(req: &mut Request) -> IronResult { /// MetaData used in header #[derive(Debug)] -struct MetaData { +pub(crate) struct MetaData { name: String, version: String, description: Option, target_name: Option, rustdoc_status: bool, - default_target: String, + pub default_target: String, } From ba4b5c0bce602ae35694c73e14a0af9c7dd593c6 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 4 Feb 2020 21:30:22 -0500 Subject: [PATCH 13/17] pub(crate) doesn't make sense in lib.rs Co-Authored-By: Koenraad Verheyden --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 07625c86e..438dad802 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ pub use self::docbuilder::DocBuilder; pub use self::docbuilder::options::DocBuilderOptions; pub use self::web::Server; -pub(crate) mod error; +mod error; pub mod db; pub mod utils; mod docbuilder; From af147c5120b9b4237d42559f2b553120d5bffe8e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 4 Feb 2020 21:38:45 -0500 Subject: [PATCH 14/17] address review comments re: copy test --- src/utils/copy.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/utils/copy.rs b/src/utils/copy.rs index 7b2f30e66..9a7023848 100644 --- a/src/utils/copy.rs +++ b/src/utils/copy.rs @@ -12,16 +12,12 @@ use regex::Regex; /// /// Target directory must have doc directory. /// -/// This function is designed to avoid file duplications. It is using rustc version string -/// to rename common files (css files, jquery.js, playpen.js, main.js etc.) in a standard rustdoc. +/// This function is designed to avoid file duplications. pub fn copy_doc_dir>(target: P, destination: P) -> Result<()> { let source = PathBuf::from(target.as_ref()).join("doc"); let destination = destination.as_ref().to_path_buf(); - // FIXME: handle_html is useless since we started using --resource-suffix - // argument with rustdoc - - // Make sure destination directory is exists + // Make sure destination directory exists if !destination.exists() { fs::create_dir_all(&destination)?; } @@ -62,8 +58,7 @@ mod test { use super::*; #[test] - #[ignore] - fn test_copy_dir() { + fn test_copy_doc_dir() { let destination = tempdir::TempDir::new("cratesfyi").unwrap(); // lets try to copy a src directory to tempdir From 695c5fa5bd985b962f3f6fa4d7eeb6081146092c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 4 Feb 2020 22:04:59 -0500 Subject: [PATCH 15/17] remote system dependencies from metadata this was causing confusion, see https://github.com/rust-lang/docs.rs/issues/164 --- src/docbuilder/metadata.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/docbuilder/metadata.rs b/src/docbuilder/metadata.rs index d916ca2c9..97f0ea963 100644 --- a/src/docbuilder/metadata.rs +++ b/src/docbuilder/metadata.rs @@ -22,7 +22,6 @@ use failure::err_msg; /// default-target = "x86_64-unknown-linux-gnu" /// rustc-args = [ "--example-rustc-arg" ] /// rustdoc-args = [ "--example-rustdoc-arg" ] -/// dependencies = [ "example-system-dependency" ] /// ``` /// /// You can define one or more fields in your `Cargo.toml`. @@ -49,11 +48,6 @@ pub struct Metadata { /// List of command line arguments for `rustdoc`. pub rustdoc_args: Option>, - - /// System dependencies. - /// - /// Docs.rs is running on a Debian jessie. - dependencies: Option>, } @@ -93,7 +87,6 @@ impl Metadata { default_target: None, rustc_args: None, rustdoc_args: None, - dependencies: None, } } @@ -122,8 +115,6 @@ impl Metadata { .and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect()); metadata.rustdoc_args = table.get("rustdoc-args").and_then(|f| f.as_array()) .and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect()); - metadata.dependencies = table.get("dependencies").and_then(|f| f.as_array()) - .and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect()); } metadata @@ -151,7 +142,6 @@ mod test { default-target = "x86_64-unknown-linux-gnu" rustc-args = [ "--example-rustc-arg" ] rustdoc-args = [ "--example-rustdoc-arg" ] - dependencies = [ "example-system-dependency" ] "#; let metadata = Metadata::from_str(manifest); @@ -176,9 +166,5 @@ mod test { let rustdoc_args = metadata.rustdoc_args.unwrap(); assert_eq!(rustdoc_args.len(), 1); assert_eq!(rustdoc_args[0], "--example-rustdoc-arg".to_owned()); - - let dependencies = metadata.dependencies.unwrap(); - assert_eq!(dependencies.len(), 1); - assert_eq!(dependencies[0], "example-system-dependency".to_owned()); } } From 57fcc45d84bb7d6e0c14f5b06600d8ca07b0aa73 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 4 Feb 2020 22:06:35 -0500 Subject: [PATCH 16/17] re-comment failing test --- src/utils/copy.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/copy.rs b/src/utils/copy.rs index 9a7023848..53d7d7e2b 100644 --- a/src/utils/copy.rs +++ b/src/utils/copy.rs @@ -58,6 +58,7 @@ mod test { use super::*; #[test] + #[ignore] fn test_copy_doc_dir() { let destination = tempdir::TempDir::new("cratesfyi").unwrap(); From d752ec289850eb0b7e4a5edc765e2df3aca97acb Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 4 Feb 2020 22:19:52 -0500 Subject: [PATCH 17/17] fix failing test --- src/utils/copy.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/utils/copy.rs b/src/utils/copy.rs index 53d7d7e2b..d92a277f4 100644 --- a/src/utils/copy.rs +++ b/src/utils/copy.rs @@ -54,19 +54,21 @@ pub fn copy_doc_dir>(target: P, destination: P) -> Result<()> { mod test { extern crate env_logger; use std::fs; - use std::path::Path; use super::*; #[test] - #[ignore] fn test_copy_doc_dir() { - let destination = tempdir::TempDir::new("cratesfyi").unwrap(); + let source = tempdir::TempDir::new("cratesfyi-src").unwrap(); + let destination = tempdir::TempDir::new("cratesfyi-dst").unwrap(); + let doc = source.path().join("doc"); + fs::create_dir(&doc).unwrap(); - // lets try to copy a src directory to tempdir - let res = copy_doc_dir(Path::new("src"), destination.path()); - // remove temp dir - fs::remove_dir_all(destination.path()).unwrap(); + fs::write(doc.join("index.html"), "spooky").unwrap(); + fs::write(doc.join("index.txt"), "spooky").unwrap(); - assert!(res.is_ok()); + // lets try to copy a src directory to tempdir + copy_doc_dir(source.path(), destination.path()).unwrap(); + assert!(destination.path().join("index.html").exists()); + assert!(!destination.path().join("index.txt").exists()); } }