Skip to content

Commit a85b875

Browse files
committed
Merge branch 'despecialize'
2 parents 32102ce + ccac550 commit a85b875

16 files changed

+1944
-833
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ log = "0.3"
1212
rustc-serialize = "0.3"
1313
regex = "0.2"
1414
clap = "2"
15-
crates-index-diff = "3"
16-
git2 = "0.6"
15+
crates-index-diff = "4"
16+
git2 = "0.7"
1717
time = "0.1"
18-
reqwest = "0.5"
19-
semver = "0.6"
18+
reqwest = "0.9"
19+
semver = "0.9"
2020
slug = "=0.1.1"
2121
env_logger = "0.4"
2222
magic = "0.12"
@@ -25,10 +25,11 @@ r2d2_postgres = "0.12"
2525
url = "1.4"
2626
libc = "0.2"
2727
badge = { version = "0", path = "src/web/badge" }
28-
error-chain = "0.10"
28+
failure = "0.1"
2929
comrak = { version = "0.2.10", default-features = false }
3030
toml = "0.4"
3131
html5ever = "0.22"
32+
cargo = { git = "https://github.com/rust-lang/cargo.git" }
3233

3334
# iron dependencies
3435
iron = "0.5"
@@ -37,10 +38,6 @@ handlebars-iron = "0.22"
3738
params = "0.6"
3839
staticfile = { version = "0.4", features = [ "cache" ] }
3940

40-
[dependencies.cargo]
41-
git = "https://github.com/onur/cargo.git"
42-
branch = "docs.rs"
43-
4441
[dependencies.postgres]
4542
version = "0.14"
4643
features = [ "with-time", "with-rustc-serialize" ]
@@ -50,8 +47,11 @@ tempdir = "0.3"
5047

5148
[build-dependencies]
5249
time = "0.1"
53-
git2 = "0.6"
54-
sass-rs = "0.0.18"
50+
git2 = "0.7"
51+
sass-rs = "0.2"
52+
53+
[patch.crates-io]
54+
failure = { git = "https://github.com/rust-lang-nursery/failure.git" }
5555

5656
[[bin]]
5757
name = "cratesfyi"

build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ fn get_git_hash() -> Option<String> {
4040

4141

4242
fn compile_sass() {
43-
use sass_rs::sass_context::SassFileContext;
43+
use sass_rs::Context;
4444

45-
let mut file_context = SassFileContext::new(concat!(env!("CARGO_MANIFEST_DIR"),
46-
"/templates/style.scss"));
45+
let mut file_context = Context::new_file(concat!(env!("CARGO_MANIFEST_DIR"),
46+
"/templates/style.scss")).unwrap();
4747
let css = file_context.compile().unwrap();
4848
let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("style.css");
4949
let mut file = File::create(&dest_path).unwrap();

src/db/add_package.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ use cargo::core::{Package, TargetKind};
1313
use rustc_serialize::json::{Json, ToJson};
1414
use slug::slugify;
1515
use reqwest::Client;
16-
use reqwest::header::{Accept, qitem};
16+
use reqwest::header::ACCEPT;
1717
use semver;
1818
use postgres::Connection;
1919
use time;
2020
use error::Result;
21-
21+
use failure::err_msg;
2222

2323
/// Adds a package into database.
2424
///
@@ -197,11 +197,11 @@ pub fn add_build_into_database(conn: &Connection,
197197

198198
fn initialize_package_in_database(conn: &Connection, pkg: &Package) -> Result<i32> {
199199
let mut rows = try!(conn.query("SELECT id FROM crates WHERE name = $1",
200-
&[&pkg.manifest().name()]));
200+
&[&pkg.manifest().name().as_str()]));
201201
// insert crate into database if it is not exists
202202
if rows.len() == 0 {
203203
rows = try!(conn.query("INSERT INTO crates (name) VALUES ($1) RETURNING id",
204-
&[&pkg.manifest().name()]));
204+
&[&pkg.manifest().name().as_str()]));
205205
}
206206
Ok(rows.get(0).get(0))
207207
}
@@ -212,7 +212,7 @@ fn initialize_package_in_database(conn: &Connection, pkg: &Package) -> Result<i3
212212
fn convert_dependencies(pkg: &Package) -> Vec<(String, String)> {
213213
let mut dependencies: Vec<(String, String)> = Vec::new();
214214
for dependency in pkg.manifest().dependencies() {
215-
let name = dependency.name().to_string();
215+
let name = dependency.package_name().to_string();
216216
let version = format!("{}", dependency.version_req());
217217
dependencies.push((name, version));
218218
}
@@ -222,7 +222,7 @@ fn convert_dependencies(pkg: &Package) -> Vec<(String, String)> {
222222

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

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

238238

239239
fn get_rustdoc(pkg: &Package) -> Result<Option<String>> {
240-
if pkg.manifest().targets()[0].src_path().is_absolute() {
241-
read_rust_doc(pkg.manifest().targets()[0].src_path())
240+
if pkg.manifest().targets()[0].src_path().path().is_absolute() {
241+
read_rust_doc(pkg.manifest().targets()[0].src_path().path())
242242
} else {
243-
let mut path = PathBuf::from(try!(source_path(&pkg).ok_or("File not found")));
244-
path.push(pkg.manifest().targets()[0].src_path());
243+
let mut path = PathBuf::from(try!(source_path(&pkg).ok_or_else(|| err_msg("File not found"))));
244+
path.push(pkg.manifest().targets()[0].src_path().path());
245245
read_rust_doc(path.as_path())
246246
}
247247
}
@@ -279,41 +279,41 @@ fn get_release_time_yanked_downloads
279279
pkg.manifest().name());
280280
// FIXME: There is probably better way to do this
281281
// and so many unwraps...
282-
let client = try!(Client::new());
282+
let client = Client::new();
283283
let mut res = try!(client.get(&url[..])
284-
.header(Accept(vec![qitem("application/json".parse().unwrap())]))
284+
.header(ACCEPT, "application/json")
285285
.send());
286286
let mut body = String::new();
287287
res.read_to_string(&mut body).unwrap();
288288
let json = Json::from_str(&body[..]).unwrap();
289289
let versions = try!(json.as_object()
290290
.and_then(|o| o.get("versions"))
291291
.and_then(|v| v.as_array())
292-
.ok_or("Not a JSON object"));
292+
.ok_or_else(|| err_msg("Not a JSON object")));
293293

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

296296
for version in versions {
297-
let version = try!(version.as_object().ok_or("Not a JSON object"));
297+
let version = try!(version.as_object().ok_or_else(|| err_msg("Not a JSON object")));
298298
let version_num = try!(version.get("num")
299299
.and_then(|v| v.as_string())
300-
.ok_or("Not a JSON object"));
300+
.ok_or_else(|| err_msg("Not a JSON object")));
301301

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

310310
yanked = Some(try!(version.get("yanked")
311311
.and_then(|c| c.as_boolean())
312-
.ok_or("Not a JSON object")));
312+
.ok_or_else(|| err_msg("Not a JSON object"))));
313313

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

318318
break;
319319
}
@@ -387,9 +387,9 @@ fn add_owners_into_database(conn: &Connection, pkg: &Package, crate_id: &i32) ->
387387
// owners available in: https://crates.io/api/v1/crates/rand/owners
388388
let owners_url = format!("https://crates.io/api/v1/crates/{}/owners",
389389
&pkg.manifest().name());
390-
let client = try!(Client::new());
390+
let client = Client::new();
391391
let mut res = try!(client.get(&owners_url[..])
392-
.header(Accept(vec![qitem("application/json".parse().unwrap())]))
392+
.header(ACCEPT, "application/json")
393393
.send());
394394
// FIXME: There is probably better way to do this
395395
// and so many unwraps...

src/db/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_serialize::json::{Json, ToJson};
1111
use std::fs::File;
1212
use std::io::Read;
1313
use error::Result;
14-
14+
use failure::err_msg;
1515

1616

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

5151
if !path.exists() {
52-
return Err("File not found".into());
52+
return Err(err_msg("File not found"));
5353
} else if path.is_file() {
5454
path.file_name()
5555
.and_then(|name| name.to_str())

src/docbuilder/chroot_builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use utils::{get_package, source_path, copy_dir, copy_doc_dir,
55
update_sources, parse_rustc_version, command_result};
66
use db::{connect_db, add_package_into_database, add_build_into_database, add_path_into_database};
77
use cargo::core::Package;
8+
use cargo::util::CargoResultExt;
89
use std::process::Command;
910
use std::path::PathBuf;
1011
use std::fs::remove_dir_all;
1112
use postgres::Connection;
1213
use rustc_serialize::json::Json;
13-
use error::{Result, ResultExt};
14+
use error::Result;
1415

1516

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

116117
/// Builds documentation of a package with cratesfyi in chroot environment
117118
fn build_package_in_chroot(&self, package: &Package) -> ChrootBuilderResult {
118-
use std::error::Error as StdError;
119119
debug!("Building package in chroot");
120120
let (rustc_version, cratesfyi_version) = self.get_versions();
121121
let cmd = format!("cratesfyi doc {} ={}",
@@ -134,7 +134,7 @@ impl DocBuilder {
134134
}
135135
Err(e) => {
136136
ChrootBuilderResult {
137-
output: e.description().to_owned(),
137+
output: e.to_string(),
138138
build_success: false,
139139
have_doc: false,
140140
have_examples: self.have_examples(&package),
@@ -239,7 +239,7 @@ impl DocBuilder {
239239
debug!("Cleaning package");
240240
use std::fs::remove_dir_all;
241241
let documentation_path = PathBuf::from(&self.options.destination)
242-
.join(package.manifest().name());
242+
.join(package.manifest().name().as_str());
243243
let source_path = source_path(&package).unwrap();
244244
// Some crates don't have documentation, so we don't care if removing_dir_all fails
245245
let _ = self.remove_build_dir();
@@ -356,7 +356,7 @@ impl DocBuilder {
356356
let rustc_version = parse_rustc_version(&res.rustc_version)?;
357357

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

362362
info!("Copying essential files for: {}", res.rustc_version);

src/docbuilder/crates.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fs;
55
use std::path::PathBuf;
66
use rustc_serialize::json::Json;
77
use error::Result;
8-
8+
use failure::err_msg;
99

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

31-
let obj = try!(data.as_object().ok_or("Not a JSON object"));
31+
let obj = try!(data.as_object().ok_or_else(|| err_msg("Not a JSON object")));
3232
let crate_name = try!(obj.get("name")
3333
.and_then(|n| n.as_string())
34-
.ok_or("`name` not found in JSON object"));
34+
.ok_or_else(|| err_msg("`name` not found in JSON object")));
3535
let vers = try!(obj.get("vers")
3636
.and_then(|n| n.as_string())
37-
.ok_or("`vers` not found in JSON object"));
37+
.ok_or_else(|| err_msg("`vers` not found in JSON object")));
3838

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

6565
if !path.is_dir() {
66-
return Err("Not a directory".into());
66+
return Err(err_msg("Not a directory"));
6767
}
6868

6969
for file in try!(path.read_dir()) {

src/docbuilder/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::Path;
33
use cargo::core::Package;
44
use toml::Value;
55
use error::Result;
6-
6+
use failure::err_msg;
77

88
/// Metadata for custom builds
99
///
@@ -61,14 +61,14 @@ pub struct Metadata {
6161

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

7474
pub fn from_manifest<P: AsRef<Path>>(path: P) -> Metadata {

src/docbuilder/options.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::{env, fmt};
44
use std::path::PathBuf;
55
use error::Result;
6-
6+
use failure::err_msg;
77

88
#[derive(Clone)]
99
pub struct DocBuilderOptions {
@@ -94,16 +94,16 @@ impl DocBuilderOptions {
9494

9595
pub fn check_paths(&self) -> Result<()> {
9696
if !self.destination.exists() {
97-
return Err("Destination path not exists".into());
97+
return Err(err_msg("Destination path not exists"));
9898
}
9999
if !self.chroot_path.exists() {
100-
return Err("Chroot path not exists".into());
100+
return Err(err_msg("Chroot path not exists"));
101101
}
102102
if !self.crates_io_index_path.exists() {
103-
return Err("crates.io-index path not exists".into());
103+
return Err(err_msg("crates.io-index path not exists"));
104104
}
105105
if !self.crates_io_index_path.exists() {
106-
return Err("Logs path not exists".into());
106+
return Err(err_msg("Logs path not exists"));
107107
}
108108
Ok(())
109109
}

src/error.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
//! Errors used in cratesfyi
22
3-
use std::io;
4-
use rustc_serialize::json;
5-
use postgres;
6-
use cargo;
7-
use reqwest;
8-
use magic::MagicError;
9-
use git2;
10-
use regex;
3+
use std::result::Result as StdResult;
114

5+
pub use failure::{Error, ResultExt};
126

13-
error_chain! {
14-
foreign_links {
15-
IoError(io::Error);
16-
JsonBuilderError(json::BuilderError);
17-
PostgresConnectError(postgres::error::ConnectError);
18-
PostgresError(postgres::error::Error);
19-
ReqwestError(reqwest::Error);
20-
Git2Error(git2::Error);
21-
MagicError(MagicError);
22-
CargoError(Box<cargo::CargoError>);
23-
RegexError(regex::Error);
24-
}
25-
}
7+
pub type Result<T> = StdResult<T, Error>;

0 commit comments

Comments
 (0)