From 1c4f9fab0372e93381af232c4e62db311c0881c6 Mon Sep 17 00:00:00 2001 From: Ram Kaniyur Date: Thu, 8 Feb 2018 15:07:40 +1100 Subject: [PATCH 1/2] Get initial target from metadata or something. --- Cargo.lock | 70 ++++++++++++++++---------------- src/docbuilder/chroot_builder.rs | 18 ++++++-- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 526b68816..e95481dc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,38 +1,3 @@ -[root] -name = "cratesfyi" -version = "0.4.2" -dependencies = [ - "badge 0.1.1", - "cargo 0.20.0 (git+https://github.com/onur/cargo.git?branch=docs.rs)", - "clap 2.23.3 (registry+https://github.com/rust-lang/crates.io-index)", - "comrak 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crates-index-diff 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "handlebars-iron 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "magic 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "params 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "postgres 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "r2d2 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "r2d2_postgres 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "router 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", - "sass-rs 0.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slug 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "staticfile 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "advapi32-sys" version = "0.2.0" @@ -290,6 +255,41 @@ dependencies = [ "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cratesfyi" +version = "0.4.2" +dependencies = [ + "badge 0.1.1", + "cargo 0.20.0 (git+https://github.com/onur/cargo.git?branch=docs.rs)", + "clap 2.23.3 (registry+https://github.com/rust-lang/crates.io-index)", + "comrak 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crates-index-diff 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "handlebars-iron 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", + "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "magic 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "params 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "postgres 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2_postgres 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "router 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", + "sass-rs 0.0.18 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slug 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "staticfile 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam" version = "0.2.10" diff --git a/src/docbuilder/chroot_builder.rs b/src/docbuilder/chroot_builder.rs index fba903769..aeff9ab1b 100644 --- a/src/docbuilder/chroot_builder.rs +++ b/src/docbuilder/chroot_builder.rs @@ -1,6 +1,7 @@ use super::DocBuilder; use super::crates::crates_from_path; +use super::metadata::Metadata; use utils::{get_package, source_path, copy_dir, copy_doc_dir, update_sources}; use db::{connect_db, add_package_into_database, add_build_into_database, add_path_into_database}; use cargo::core::Package; @@ -118,9 +119,20 @@ impl DocBuilder { use std::error::Error as StdError; debug!("Building package in chroot"); let (rustc_version, cratesfyi_version) = self.get_versions(); - let cmd = format!("cratesfyi doc {} ={}", - package.manifest().name(), - package.manifest().version()); + + let meta = Metadata::from_package(package).ok(); + let target = meta.as_ref().and_then(|meta| meta.default_target.as_ref()); + let cmd = if let Some(target) = target { + format!("cratesfyi doc {} ={} {}", + package.manifest().name(), + package.manifest().version(), + target) + } else { + format!("cratesfyi doc {} ={}", + package.manifest().name(), + package.manifest().version()) + }; + match self.chroot_command(cmd) { Ok(o) => { ChrootBuilderResult { From 7f5759953a1ff13c2b666482af2286c92619e463 Mon Sep 17 00:00:00 2001 From: Ram Kaniyur Date: Thu, 8 Feb 2018 15:19:52 +1100 Subject: [PATCH 2/2] Checks that target is supported first. --- src/docbuilder/chroot_builder.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/docbuilder/chroot_builder.rs b/src/docbuilder/chroot_builder.rs index aeff9ab1b..31b2f999b 100644 --- a/src/docbuilder/chroot_builder.rs +++ b/src/docbuilder/chroot_builder.rs @@ -122,15 +122,18 @@ impl DocBuilder { let meta = Metadata::from_package(package).ok(); let target = meta.as_ref().and_then(|meta| meta.default_target.as_ref()); - let cmd = if let Some(target) = target { - format!("cratesfyi doc {} ={} {}", - package.manifest().name(), - package.manifest().version(), - target) - } else { - format!("cratesfyi doc {} ={}", - package.manifest().name(), - package.manifest().version()) + let cmd = match target { + Some(target) if TARGETS.contains(&target.as_str()) => { + format!("cratesfyi doc {} ={} {}", + package.manifest().name(), + package.manifest().version(), + target) + } + _ => { + format!("cratesfyi doc {} ={}", + package.manifest().name(), + package.manifest().version()) + } }; match self.chroot_command(cmd) {