Skip to content

Next #131

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

Merged
merged 22 commits into from
Jun 7, 2017
Merged

Next #131

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
25 changes: 18 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cratesfyi"
version = "0.3.4"
version = "0.4.0"
authors = ["Onur Aslan <[email protected]>"]
readme = "README.md"
license = "MIT"
Expand All @@ -27,6 +27,7 @@ libc = "0.2"
badge = { version = "0", path = "src/web/badge" }
error-chain = "0.10"
comrak = { version = "0.1", default-features = false }
toml = "0.4"

# iron dependencies
iron = "0.5"
Expand All @@ -36,8 +37,8 @@ params = "0.6"
staticfile = { version = "0.4", features = [ "cache" ] }

[dependencies.cargo]
git = "https://github.com/rust-lang/cargo.git"
rev = "9fe7f07579d6d2672dd7e95c70adaea65d8e9a2e"
git = "https://github.com/onur/cargo.git"
branch = "docs.rs"

[dependencies.postgres]
version = "0.14"
Expand Down
16 changes: 14 additions & 2 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ pub fn main() {
.takes_value(true))
.arg(Arg::with_name("CHROOT_PATH")
.short("c")
.long("chroot")
.long("chroot-path")
.help("Sets chroot path")
.takes_value(true))
.arg(Arg::with_name("CHROOT_USER")
.short("u")
.long("chroot-user")
.help("Sets chroot user name")
.takes_value(true))
.arg(Arg::with_name("CONTAINER_NAME")
.short("n")
.long("container-name")
.help("Sets name of the container")
.takes_value(true))
.arg(Arg::with_name("CRATES_IO_INDEX_PATH")
.long("crates-io-index-path")
.help("Sets crates.io-index path")
Expand Down Expand Up @@ -93,7 +98,8 @@ pub fn main() {
building new crates"))
.subcommand(SubCommand::with_name("unlock")
.about("Unlocks cratesfyi daemon to continue \
building new crates")))
building new crates"))
.subcommand(SubCommand::with_name("print-options")))
.subcommand(SubCommand::with_name("start-web-server")
.about("Starts web server")
.arg(Arg::with_name("SOCKET_ADDR")
Expand Down Expand Up @@ -158,6 +164,10 @@ pub fn main() {
docbuilder_opts.chroot_user = chroot_user.to_string();
}

if let Some(container_name) = matches.value_of("CONTAINER_NAME") {
docbuilder_opts.container_name = container_name.to_string();
}

if let Some(crates_io_index_path) = matches.value_of("CRATES_IO_INDEX_PATH") {
docbuilder_opts.crates_io_index_path = PathBuf::from(crates_io_index_path);
}
Expand Down Expand Up @@ -189,6 +199,8 @@ pub fn main() {
docbuilder.lock().expect("Failed to lock");
} else if let Some(_) = matches.subcommand_matches("unlock") {
docbuilder.unlock().expect("Failed to unlock");
} else if let Some(_) = matches.subcommand_matches("print-options") {
println!("{:?}", docbuilder.options());
}

} else if let Some(matches) = matches.subcommand_matches("database") {
Expand Down
15 changes: 10 additions & 5 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

use ChrootBuilderResult;
use Metadata;
use utils::source_path;
use regex::Regex;

Expand Down Expand Up @@ -38,6 +39,7 @@ pub fn add_package_into_database(conn: &Connection,
&TargetKind::Lib(_) => true,
_ => false,
};
let metadata = Metadata::from_package(pkg);

let release_id: i32 = {
let rows = try!(conn.query("SELECT id FROM releases WHERE crate_id = $1 AND version = $2",
Expand All @@ -51,11 +53,11 @@ pub fn add_package_into_database(conn: &Connection,
homepage_url, description, description_long, readme,
authors, keywords, have_examples, downloads, files,
doc_targets, is_library, doc_rustc_version,
documentation_url
documentation_url, default_target
)
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10,
$11, $12, $13, $14, $15, $16, $17, $18, $19,
$20, $21, $22, $23, $24
$20, $21, $22, $23, $24, $25
)
RETURNING id",
&[&crate_id,
Expand All @@ -81,7 +83,8 @@ pub fn add_package_into_database(conn: &Connection,
&doc_targets.to_json(),
&is_library,
&res.rustc_version,
&pkg.manifest().metadata().documentation]));
&pkg.manifest().metadata().documentation,
&metadata.default_target]));
// return id
rows.get(0).get(0)

Expand All @@ -108,7 +111,8 @@ pub fn add_package_into_database(conn: &Connection,
doc_targets = $21,
is_library = $22,
doc_rustc_version = $23,
documentation_url = $24
documentation_url = $24,
default_target = $25
WHERE crate_id = $1 AND version = $2",
&[&crate_id,
&format!("{}", pkg.manifest().version()),
Expand All @@ -133,7 +137,8 @@ pub fn add_package_into_database(conn: &Connection,
&doc_targets.to_json(),
&is_library,
&res.rustc_version,
&pkg.manifest().metadata().documentation]));
&pkg.manifest().metadata().documentation,
&metadata.default_target]));
rows.get(0).get(0)
}
};
Expand Down
1 change: 1 addition & 0 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn create_tables(conn: &Connection) -> Result<(), Error> {
files JSON,
doc_targets JSON DEFAULT '[]',
doc_rustc_version VARCHAR(100) NOT NULL,
default_target VARCHAR(100),
UNIQUE (crate_id, version)
)",
"CREATE TABLE authors (
Expand Down
84 changes: 39 additions & 45 deletions src/docbuilder/chroot_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ use db::{connect_db, add_package_into_database, add_build_into_database, add_pat
use cargo::core::Package;
use std::process::{Command, Output};
use std::path::PathBuf;
use std::fs::remove_dir_all;
use postgres::Connection;
use rustc_serialize::json::Json;
use error::Result;
use regex::Regex;


/// List of targets supported by docs.rs
const TARGETS: [&'static str; 8] = [
"i686-apple-darwin",
"i686-pc-windows-gnu",
"i686-pc-windows-msvc",
"i686-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu"
];



#[derive(Debug)]
pub struct ChrootBuilderResult {
pub output: String,
Expand Down Expand Up @@ -57,6 +72,8 @@ impl DocBuilder {

info!("Building package {}-{}", name, version);

// Start with clean documentation directory
try!(self.remove_build_dir());

// Database connection
let conn = try!(connect_db());
Expand Down Expand Up @@ -132,46 +149,9 @@ impl DocBuilder {

/// Builds documentation of crate for every target and returns Vec of successfully targets
fn build_package_for_all_targets(&self, package: &Package) -> Vec<String> {
// Temporary skip tier 2 and tier 3 platforms
let targets = [// "aarch64-apple-ios",
// "aarch64-linux-android",
// "aarch64-unknown-linux-gnu",
// "arm-linux-androideabi",
// "arm-unknown-linux-gnueabi",
// "arm-unknown-linux-gnueabihf",
// "armv7-apple-ios",
// "armv7-linux-androideabi",
// "armv7-unknown-linux-gnueabihf",
// "armv7s-apple-ios",
// "i386-apple-ios",
// "i586-pc-windows-msvc",
// "i586-unknown-linux-gnu",
"i686-apple-darwin",
// "i686-linux-android",
"i686-pc-windows-gnu",
"i686-pc-windows-msvc",
// "i686-unknown-freebsd",
"i686-unknown-linux-gnu",
// "i686-unknown-linux-musl",
// "mips-unknown-linux-gnu",
// "mips-unknown-linux-musl",
// "mipsel-unknown-linux-gnu",
// "mipsel-unknown-linux-musl",
// "powerpc-unknown-linux-gnu",
// "powerpc64-unknown-linux-gnu",
// "powerpc64le-unknown-linux-gnu",
"x86_64-apple-darwin",
// "x86_64-apple-ios",
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
// "x86_64-rumprun-netbsd",
// "x86_64-unknown-freebsd",
"x86_64-unknown-linux-gnu" /* "x86_64-unknown-linux-musl",
* "x86_64-unknown-netbsd", */];

let mut successfuly_targets = Vec::new();

for target in targets.iter() {
for target in TARGETS.iter() {
debug!("Building {} for {}", canonical_name(&package), target);
let cmd = format!("cratesfyi doc {} ={} {}",
package.manifest().name(),
Expand All @@ -185,7 +165,7 @@ impl DocBuilder {
let target_doc_path = PathBuf::from(&self.options.chroot_path)
.join("home")
.join(&self.options.chroot_user)
.join(canonical_name(&package))
.join("cratesfyi")
.join(&target)
.join("doc");
if target_doc_path.exists() {
Expand Down Expand Up @@ -219,7 +199,7 @@ impl DocBuilder {
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
.join("home")
.join(&self.options.chroot_user)
.join(canonical_name(&package))
.join("cratesfyi")
.join(target.unwrap_or(""));
let destination = PathBuf::from(&self.options.destination)
.join(format!("{}/{}",
Expand All @@ -234,8 +214,22 @@ impl DocBuilder {


/// Removes build directory of a package in chroot
fn remove_build_dir(&self, package: &Package) -> Result<()> {
let _ = self.chroot_command(format!("rm -rf {}", canonical_name(&package)));
fn remove_build_dir(&self) -> Result<()> {
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
.join("home")
.join(&self.options.chroot_user)
.join("cratesfyi")
.join("doc");
let _ = remove_dir_all(crate_doc_path);
for target in TARGETS.iter() {
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
.join("home")
.join(&self.options.chroot_user)
.join("cratesfyi")
.join(target)
.join("doc");
let _ = remove_dir_all(crate_doc_path);
}
Ok(())
}

Expand All @@ -248,7 +242,7 @@ impl DocBuilder {
.join(package.manifest().name());
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(&package);
let _ = self.remove_build_dir();
let _ = remove_dir_all(documentation_path);
let _ = remove_dir_all(source_path);
Ok(())
Expand Down Expand Up @@ -280,7 +274,7 @@ impl DocBuilder {
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
.join("home")
.join(&self.options.chroot_user)
.join(canonical_name(&package))
.join("cratesfyi")
.join("doc")
.join(package.targets()[0].name().replace("-", "_").to_string());
crate_doc_path.exists()
Expand Down Expand Up @@ -381,7 +375,7 @@ impl DocBuilder {
let source = PathBuf::from(&self.options.chroot_path)
.join("home")
.join(&self.options.chroot_user)
.join(canonical_name(&pkg))
.join("cratesfyi")
.join("doc");

// use copy_documentation destination directory so self.clean can remove it when
Expand Down
Loading