Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop using custom rustc/cargo #243

Merged
merged 5 commits into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,473 changes: 1,768 additions & 705 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ log = "0.3"
rustc-serialize = "0.3"
regex = "0.2"
clap = "2"
crates-index-diff = "3"
git2 = "0.6"
crates-index-diff = "4"
git2 = "0.7"
time = "0.1"
reqwest = "0.5"
semver = "0.6"
reqwest = "0.9"
semver = "0.9"
slug = "=0.1.1"
env_logger = "0.4"
magic = "0.12"
Expand All @@ -25,10 +25,11 @@ r2d2_postgres = "0.12"
url = "1.4"
libc = "0.2"
badge = { version = "0", path = "src/web/badge" }
error-chain = "0.10"
failure = "0.1"
comrak = { version = "0.2.10", default-features = false }
toml = "0.4"
html5ever = "0.22"
cargo = { git = "https://github.com/rust-lang/cargo.git" }

# iron dependencies
iron = "0.5"
Expand All @@ -37,10 +38,6 @@ handlebars-iron = "0.22"
params = "0.6"
staticfile = { version = "0.4", features = [ "cache" ] }

[dependencies.cargo]
git = "https://github.com/onur/cargo.git"
branch = "docs.rs"

[dependencies.postgres]
version = "0.14"
features = [ "with-time", "with-rustc-serialize" ]
Expand All @@ -50,8 +47,11 @@ tempdir = "0.3"

[build-dependencies]
time = "0.1"
git2 = "0.6"
sass-rs = "0.0.18"
git2 = "0.7"
sass-rs = "0.2"

[patch.crates-io]
failure = { git = "https://github.com/rust-lang-nursery/failure.git" }

[[bin]]
name = "cratesfyi"
Expand Down
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ fn get_git_hash() -> Option<String> {


fn compile_sass() {
use sass_rs::sass_context::SassFileContext;
use sass_rs::Context;

let mut file_context = SassFileContext::new(concat!(env!("CARGO_MANIFEST_DIR"),
"/templates/style.scss"));
let mut file_context = Context::new_file(concat!(env!("CARGO_MANIFEST_DIR"),
"/templates/style.scss")).unwrap();
let css = file_context.compile().unwrap();
let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("style.css");
let mut file = File::create(&dest_path).unwrap();
Expand Down
40 changes: 20 additions & 20 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use cargo::core::{Package, TargetKind};
use rustc_serialize::json::{Json, ToJson};
use slug::slugify;
use reqwest::Client;
use reqwest::header::{Accept, qitem};
use reqwest::header::ACCEPT;
use semver;
use postgres::Connection;
use time;
use error::Result;

use failure::err_msg;

/// Adds a package into database.
///
Expand Down Expand Up @@ -197,11 +197,11 @@ pub fn add_build_into_database(conn: &Connection,

fn initialize_package_in_database(conn: &Connection, pkg: &Package) -> Result<i32> {
let mut rows = try!(conn.query("SELECT id FROM crates WHERE name = $1",
&[&pkg.manifest().name()]));
&[&pkg.manifest().name().as_str()]));
// insert crate into database if it is not exists
if rows.len() == 0 {
rows = try!(conn.query("INSERT INTO crates (name) VALUES ($1) RETURNING id",
&[&pkg.manifest().name()]));
&[&pkg.manifest().name().as_str()]));
}
Ok(rows.get(0).get(0))
}
Expand All @@ -212,7 +212,7 @@ fn initialize_package_in_database(conn: &Connection, pkg: &Package) -> Result<i3
fn convert_dependencies(pkg: &Package) -> Vec<(String, String)> {
let mut dependencies: Vec<(String, String)> = Vec::new();
for dependency in pkg.manifest().dependencies() {
let name = dependency.name().to_string();
let name = dependency.package_name().to_string();
let version = format!("{}", dependency.version_req());
dependencies.push((name, version));
}
Expand All @@ -222,7 +222,7 @@ fn convert_dependencies(pkg: &Package) -> Vec<(String, String)> {

/// Reads readme if there is any read defined in Cargo.toml of a Package
fn get_readme(pkg: &Package) -> Result<Option<String>> {
let readme_path = PathBuf::from(try!(source_path(&pkg).ok_or("File not found")))
let readme_path = PathBuf::from(try!(source_path(&pkg).ok_or_else(|| err_msg("File not found"))))
.join(pkg.manifest().metadata().readme.clone().unwrap_or("README.md".to_owned()));

if !readme_path.exists() {
Expand All @@ -237,11 +237,11 @@ fn get_readme(pkg: &Package) -> Result<Option<String>> {


fn get_rustdoc(pkg: &Package) -> Result<Option<String>> {
if pkg.manifest().targets()[0].src_path().is_absolute() {
read_rust_doc(pkg.manifest().targets()[0].src_path())
if pkg.manifest().targets()[0].src_path().path().is_absolute() {
read_rust_doc(pkg.manifest().targets()[0].src_path().path())
} else {
let mut path = PathBuf::from(try!(source_path(&pkg).ok_or("File not found")));
path.push(pkg.manifest().targets()[0].src_path());
let mut path = PathBuf::from(try!(source_path(&pkg).ok_or_else(|| err_msg("File not found"))));
path.push(pkg.manifest().targets()[0].src_path().path());
read_rust_doc(path.as_path())
}
}
Expand Down Expand Up @@ -279,41 +279,41 @@ fn get_release_time_yanked_downloads
pkg.manifest().name());
// FIXME: There is probably better way to do this
// and so many unwraps...
let client = try!(Client::new());
let client = Client::new();
let mut res = try!(client.get(&url[..])
.header(Accept(vec![qitem("application/json".parse().unwrap())]))
.header(ACCEPT, "application/json")
.send());
let mut body = String::new();
res.read_to_string(&mut body).unwrap();
let json = Json::from_str(&body[..]).unwrap();
let versions = try!(json.as_object()
.and_then(|o| o.get("versions"))
.and_then(|v| v.as_array())
.ok_or("Not a JSON object"));
.ok_or_else(|| err_msg("Not a JSON object")));

let (mut release_time, mut yanked, mut downloads) = (None, None, None);

for version in versions {
let version = try!(version.as_object().ok_or("Not a JSON object"));
let version = try!(version.as_object().ok_or_else(|| err_msg("Not a JSON object")));
let version_num = try!(version.get("num")
.and_then(|v| v.as_string())
.ok_or("Not a JSON object"));
.ok_or_else(|| err_msg("Not a JSON object")));

if &semver::Version::parse(version_num).unwrap() == pkg.manifest().version() {
let release_time_raw = try!(version.get("created_at")
.and_then(|c| c.as_string())
.ok_or("Not a JSON object"));
.ok_or_else(|| err_msg("Not a JSON object")));
release_time = Some(time::strptime(release_time_raw, "%Y-%m-%dT%H:%M:%S")
.unwrap()
.to_timespec());

yanked = Some(try!(version.get("yanked")
.and_then(|c| c.as_boolean())
.ok_or("Not a JSON object")));
.ok_or_else(|| err_msg("Not a JSON object"))));

downloads = Some(try!(version.get("downloads")
.and_then(|c| c.as_i64())
.ok_or("Not a JSON object")) as i32);
.ok_or_else(|| err_msg("Not a JSON object"))) as i32);

break;
}
Expand Down Expand Up @@ -387,9 +387,9 @@ fn add_owners_into_database(conn: &Connection, pkg: &Package, crate_id: &i32) ->
// owners available in: https://crates.io/api/v1/crates/rand/owners
let owners_url = format!("https://crates.io/api/v1/crates/{}/owners",
&pkg.manifest().name());
let client = try!(Client::new());
let client = Client::new();
let mut res = try!(client.get(&owners_url[..])
.header(Accept(vec![qitem("application/json".parse().unwrap())]))
.header(ACCEPT, "application/json")
.send());
// FIXME: There is probably better way to do this
// and so many unwraps...
Expand Down
4 changes: 2 additions & 2 deletions src/db/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_serialize::json::{Json, ToJson};
use std::fs::File;
use std::io::Read;
use error::Result;

use failure::err_msg;


fn file_path(prefix: &str, name: &str) -> String {
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn get_file_list<P: AsRef<Path>>(path: P) -> Result<Vec<String>> {
let mut files: Vec<String> = Vec::new();

if !path.exists() {
return Err("File not found".into());
return Err(err_msg("File not found"));
} else if path.is_file() {
path.file_name()
.and_then(|name| name.to_str())
Expand Down
10 changes: 5 additions & 5 deletions src/docbuilder/chroot_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use utils::{get_package, source_path, copy_dir, copy_doc_dir,
update_sources, parse_rustc_version, command_result};
use db::{connect_db, add_package_into_database, add_build_into_database, add_path_into_database};
use cargo::core::Package;
use cargo::util::CargoResultExt;
use std::process::Command;
use std::path::PathBuf;
use std::fs::remove_dir_all;
use postgres::Connection;
use rustc_serialize::json::Json;
use error::{Result, ResultExt};
use error::Result;


/// List of targets supported by docs.rs
Expand Down Expand Up @@ -115,7 +116,6 @@ impl DocBuilder {

/// Builds documentation of a package with cratesfyi in chroot environment
fn build_package_in_chroot(&self, package: &Package) -> ChrootBuilderResult {
use std::error::Error as StdError;
debug!("Building package in chroot");
let (rustc_version, cratesfyi_version) = self.get_versions();
let cmd = format!("cratesfyi doc {} ={}",
Expand All @@ -134,7 +134,7 @@ impl DocBuilder {
}
Err(e) => {
ChrootBuilderResult {
output: e.description().to_owned(),
output: e.to_string(),
build_success: false,
have_doc: false,
have_examples: self.have_examples(&package),
Expand Down Expand Up @@ -239,7 +239,7 @@ impl DocBuilder {
debug!("Cleaning package");
use std::fs::remove_dir_all;
let documentation_path = PathBuf::from(&self.options.destination)
.join(package.manifest().name());
.join(package.manifest().name().as_str());
let source_path = source_path(&package).unwrap();
// Some crates don't have documentation, so we don't care if removing_dir_all fails
let _ = self.remove_build_dir();
Expand Down Expand Up @@ -356,7 +356,7 @@ impl DocBuilder {
let rustc_version = parse_rustc_version(&res.rustc_version)?;

if !res.build_success {
return Err(format!("Failed to build empty crate for: {}", res.rustc_version).into());
return Err(format_err!("Failed to build empty crate for: {}", res.rustc_version));
}

info!("Copying essential files for: {}", res.rustc_version);
Expand Down
10 changes: 5 additions & 5 deletions src/docbuilder/crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs;
use std::path::PathBuf;
use rustc_serialize::json::Json;
use error::Result;

use failure::err_msg;

fn crates_from_file<F>(path: &PathBuf, func: &mut F) -> Result<()>
where F: FnMut(&str, &str) -> ()
Expand All @@ -28,13 +28,13 @@ fn crates_from_file<F>(path: &PathBuf, func: &mut F) -> Result<()>
Err(_) => continue,
};

let obj = try!(data.as_object().ok_or("Not a JSON object"));
let obj = try!(data.as_object().ok_or_else(|| err_msg("Not a JSON object")));
let crate_name = try!(obj.get("name")
.and_then(|n| n.as_string())
.ok_or("`name` not found in JSON object"));
.ok_or_else(|| err_msg("`name` not found in JSON object")));
let vers = try!(obj.get("vers")
.and_then(|n| n.as_string())
.ok_or("`vers` not found in JSON object"));
.ok_or_else(|| err_msg("`vers` not found in JSON object")));

// Skip yanked crates
if obj.get("yanked").and_then(|n| n.as_boolean()).unwrap_or(false) {
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn crates_from_path<F>(path: &PathBuf, func: &mut F) -> Result<()>
{

if !path.is_dir() {
return Err("Not a directory".into());
return Err(err_msg("Not a directory"));
}

for file in try!(path.read_dir()) {
Expand Down
6 changes: 3 additions & 3 deletions src/docbuilder/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use cargo::core::Package;
use toml::Value;
use error::Result;

use failure::err_msg;

/// Metadata for custom builds
///
Expand Down Expand Up @@ -61,14 +61,14 @@ pub struct Metadata {

impl Metadata {
pub fn from_package(pkg: &Package) -> Result<Metadata> {
let src_path = pkg.manifest_path().parent().ok_or("Source path not available")?;
let src_path = pkg.manifest_path().parent().ok_or_else(|| err_msg("Source path not available"))?;
for c in ["Cargo.toml.orig", "Cargo.toml"].iter() {
let manifest_path = src_path.clone().join(c);
if manifest_path.exists() {
return Ok(Metadata::from_manifest(manifest_path));
}
}
Err("Manifest not found".into())
Err(err_msg("Manifest not found"))
}

pub fn from_manifest<P: AsRef<Path>>(path: P) -> Metadata {
Expand Down
10 changes: 5 additions & 5 deletions src/docbuilder/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{env, fmt};
use std::path::PathBuf;
use error::Result;

use failure::err_msg;

#[derive(Clone)]
pub struct DocBuilderOptions {
Expand Down Expand Up @@ -94,16 +94,16 @@ impl DocBuilderOptions {

pub fn check_paths(&self) -> Result<()> {
if !self.destination.exists() {
return Err("Destination path not exists".into());
return Err(err_msg("Destination path not exists"));
}
if !self.chroot_path.exists() {
return Err("Chroot path not exists".into());
return Err(err_msg("Chroot path not exists"));
}
if !self.crates_io_index_path.exists() {
return Err("crates.io-index path not exists".into());
return Err(err_msg("crates.io-index path not exists"));
}
if !self.crates_io_index_path.exists() {
return Err("Logs path not exists".into());
return Err(err_msg("Logs path not exists"));
}
Ok(())
}
Expand Down
24 changes: 3 additions & 21 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
//! Errors used in cratesfyi

use std::io;
use rustc_serialize::json;
use postgres;
use cargo;
use reqwest;
use magic::MagicError;
use git2;
use regex;
use std::result::Result as StdResult;

pub use failure::{Error, ResultExt};

error_chain! {
foreign_links {
IoError(io::Error);
JsonBuilderError(json::BuilderError);
PostgresConnectError(postgres::error::ConnectError);
PostgresError(postgres::error::Error);
ReqwestError(reqwest::Error);
Git2Error(git2::Error);
MagicError(MagicError);
CargoError(Box<cargo::CargoError>);
RegexError(regex::Error);
}
}
pub type Result<T> = StdResult<T, Error>;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate error_chain;
extern crate failure;
extern crate cargo;
extern crate regex;
extern crate rustc_serialize;
Expand Down
Loading