Skip to content

Commit 19f5839

Browse files
authored
Merge pull request #131 from onur/next
Next
2 parents fd0821f + 71bda02 commit 19f5839

19 files changed

+421
-131
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cratesfyi"
3-
version = "0.3.4"
3+
version = "0.4.0"
44
authors = ["Onur Aslan <[email protected]>"]
55
readme = "README.md"
66
license = "MIT"
@@ -27,6 +27,7 @@ libc = "0.2"
2727
badge = { version = "0", path = "src/web/badge" }
2828
error-chain = "0.10"
2929
comrak = { version = "0.1", default-features = false }
30+
toml = "0.4"
3031

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

3839
[dependencies.cargo]
39-
git = "https://github.com/rust-lang/cargo.git"
40-
rev = "9fe7f07579d6d2672dd7e95c70adaea65d8e9a2e"
40+
git = "https://github.com/onur/cargo.git"
41+
branch = "docs.rs"
4142

4243
[dependencies.postgres]
4344
version = "0.14"

src/bin/cratesfyi.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ pub fn main() {
5050
.takes_value(true))
5151
.arg(Arg::with_name("CHROOT_PATH")
5252
.short("c")
53-
.long("chroot")
53+
.long("chroot-path")
5454
.help("Sets chroot path")
5555
.takes_value(true))
5656
.arg(Arg::with_name("CHROOT_USER")
5757
.short("u")
5858
.long("chroot-user")
5959
.help("Sets chroot user name")
6060
.takes_value(true))
61+
.arg(Arg::with_name("CONTAINER_NAME")
62+
.short("n")
63+
.long("container-name")
64+
.help("Sets name of the container")
65+
.takes_value(true))
6166
.arg(Arg::with_name("CRATES_IO_INDEX_PATH")
6267
.long("crates-io-index-path")
6368
.help("Sets crates.io-index path")
@@ -93,7 +98,8 @@ pub fn main() {
9398
building new crates"))
9499
.subcommand(SubCommand::with_name("unlock")
95100
.about("Unlocks cratesfyi daemon to continue \
96-
building new crates")))
101+
building new crates"))
102+
.subcommand(SubCommand::with_name("print-options")))
97103
.subcommand(SubCommand::with_name("start-web-server")
98104
.about("Starts web server")
99105
.arg(Arg::with_name("SOCKET_ADDR")
@@ -158,6 +164,10 @@ pub fn main() {
158164
docbuilder_opts.chroot_user = chroot_user.to_string();
159165
}
160166

167+
if let Some(container_name) = matches.value_of("CONTAINER_NAME") {
168+
docbuilder_opts.container_name = container_name.to_string();
169+
}
170+
161171
if let Some(crates_io_index_path) = matches.value_of("CRATES_IO_INDEX_PATH") {
162172
docbuilder_opts.crates_io_index_path = PathBuf::from(crates_io_index_path);
163173
}
@@ -189,6 +199,8 @@ pub fn main() {
189199
docbuilder.lock().expect("Failed to lock");
190200
} else if let Some(_) = matches.subcommand_matches("unlock") {
191201
docbuilder.unlock().expect("Failed to unlock");
202+
} else if let Some(_) = matches.subcommand_matches("print-options") {
203+
println!("{:?}", docbuilder.options());
192204
}
193205

194206
} else if let Some(matches) = matches.subcommand_matches("database") {

src/db/add_package.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
use ChrootBuilderResult;
3+
use Metadata;
34
use utils::source_path;
45
use regex::Regex;
56

@@ -38,6 +39,7 @@ pub fn add_package_into_database(conn: &Connection,
3839
&TargetKind::Lib(_) => true,
3940
_ => false,
4041
};
42+
let metadata = Metadata::from_package(pkg);
4143

4244
let release_id: i32 = {
4345
let rows = try!(conn.query("SELECT id FROM releases WHERE crate_id = $1 AND version = $2",
@@ -51,11 +53,11 @@ pub fn add_package_into_database(conn: &Connection,
5153
homepage_url, description, description_long, readme,
5254
authors, keywords, have_examples, downloads, files,
5355
doc_targets, is_library, doc_rustc_version,
54-
documentation_url
56+
documentation_url, default_target
5557
)
5658
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10,
5759
$11, $12, $13, $14, $15, $16, $17, $18, $19,
58-
$20, $21, $22, $23, $24
60+
$20, $21, $22, $23, $24, $25
5961
)
6062
RETURNING id",
6163
&[&crate_id,
@@ -81,7 +83,8 @@ pub fn add_package_into_database(conn: &Connection,
8183
&doc_targets.to_json(),
8284
&is_library,
8385
&res.rustc_version,
84-
&pkg.manifest().metadata().documentation]));
86+
&pkg.manifest().metadata().documentation,
87+
&metadata.default_target]));
8588
// return id
8689
rows.get(0).get(0)
8790

@@ -108,7 +111,8 @@ pub fn add_package_into_database(conn: &Connection,
108111
doc_targets = $21,
109112
is_library = $22,
110113
doc_rustc_version = $23,
111-
documentation_url = $24
114+
documentation_url = $24,
115+
default_target = $25
112116
WHERE crate_id = $1 AND version = $2",
113117
&[&crate_id,
114118
&format!("{}", pkg.manifest().version()),
@@ -133,7 +137,8 @@ pub fn add_package_into_database(conn: &Connection,
133137
&doc_targets.to_json(),
134138
&is_library,
135139
&res.rustc_version,
136-
&pkg.manifest().metadata().documentation]));
140+
&pkg.manifest().metadata().documentation,
141+
&metadata.default_target]));
137142
rows.get(0).get(0)
138143
}
139144
};

src/db/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn create_tables(conn: &Connection) -> Result<(), Error> {
112112
files JSON,
113113
doc_targets JSON DEFAULT '[]',
114114
doc_rustc_version VARCHAR(100) NOT NULL,
115+
default_target VARCHAR(100),
115116
UNIQUE (crate_id, version)
116117
)",
117118
"CREATE TABLE authors (

src/docbuilder/chroot_builder.rs

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,27 @@ use db::{connect_db, add_package_into_database, add_build_into_database, add_pat
66
use cargo::core::Package;
77
use std::process::{Command, Output};
88
use std::path::PathBuf;
9+
use std::fs::remove_dir_all;
910
use postgres::Connection;
1011
use rustc_serialize::json::Json;
1112
use error::Result;
1213
use regex::Regex;
1314

1415

16+
/// List of targets supported by docs.rs
17+
const TARGETS: [&'static str; 8] = [
18+
"i686-apple-darwin",
19+
"i686-pc-windows-gnu",
20+
"i686-pc-windows-msvc",
21+
"i686-unknown-linux-gnu",
22+
"x86_64-apple-darwin",
23+
"x86_64-pc-windows-gnu",
24+
"x86_64-pc-windows-msvc",
25+
"x86_64-unknown-linux-gnu"
26+
];
27+
28+
29+
1530
#[derive(Debug)]
1631
pub struct ChrootBuilderResult {
1732
pub output: String,
@@ -57,6 +72,8 @@ impl DocBuilder {
5772

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

75+
// Start with clean documentation directory
76+
try!(self.remove_build_dir());
6077

6178
// Database connection
6279
let conn = try!(connect_db());
@@ -132,46 +149,9 @@ impl DocBuilder {
132149

133150
/// Builds documentation of crate for every target and returns Vec of successfully targets
134151
fn build_package_for_all_targets(&self, package: &Package) -> Vec<String> {
135-
// Temporary skip tier 2 and tier 3 platforms
136-
let targets = [// "aarch64-apple-ios",
137-
// "aarch64-linux-android",
138-
// "aarch64-unknown-linux-gnu",
139-
// "arm-linux-androideabi",
140-
// "arm-unknown-linux-gnueabi",
141-
// "arm-unknown-linux-gnueabihf",
142-
// "armv7-apple-ios",
143-
// "armv7-linux-androideabi",
144-
// "armv7-unknown-linux-gnueabihf",
145-
// "armv7s-apple-ios",
146-
// "i386-apple-ios",
147-
// "i586-pc-windows-msvc",
148-
// "i586-unknown-linux-gnu",
149-
"i686-apple-darwin",
150-
// "i686-linux-android",
151-
"i686-pc-windows-gnu",
152-
"i686-pc-windows-msvc",
153-
// "i686-unknown-freebsd",
154-
"i686-unknown-linux-gnu",
155-
// "i686-unknown-linux-musl",
156-
// "mips-unknown-linux-gnu",
157-
// "mips-unknown-linux-musl",
158-
// "mipsel-unknown-linux-gnu",
159-
// "mipsel-unknown-linux-musl",
160-
// "powerpc-unknown-linux-gnu",
161-
// "powerpc64-unknown-linux-gnu",
162-
// "powerpc64le-unknown-linux-gnu",
163-
"x86_64-apple-darwin",
164-
// "x86_64-apple-ios",
165-
"x86_64-pc-windows-gnu",
166-
"x86_64-pc-windows-msvc",
167-
// "x86_64-rumprun-netbsd",
168-
// "x86_64-unknown-freebsd",
169-
"x86_64-unknown-linux-gnu" /* "x86_64-unknown-linux-musl",
170-
* "x86_64-unknown-netbsd", */];
171-
172152
let mut successfuly_targets = Vec::new();
173153

174-
for target in targets.iter() {
154+
for target in TARGETS.iter() {
175155
debug!("Building {} for {}", canonical_name(&package), target);
176156
let cmd = format!("cratesfyi doc {} ={} {}",
177157
package.manifest().name(),
@@ -185,7 +165,7 @@ impl DocBuilder {
185165
let target_doc_path = PathBuf::from(&self.options.chroot_path)
186166
.join("home")
187167
.join(&self.options.chroot_user)
188-
.join(canonical_name(&package))
168+
.join("cratesfyi")
189169
.join(&target)
190170
.join("doc");
191171
if target_doc_path.exists() {
@@ -219,7 +199,7 @@ impl DocBuilder {
219199
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
220200
.join("home")
221201
.join(&self.options.chroot_user)
222-
.join(canonical_name(&package))
202+
.join("cratesfyi")
223203
.join(target.unwrap_or(""));
224204
let destination = PathBuf::from(&self.options.destination)
225205
.join(format!("{}/{}",
@@ -234,8 +214,22 @@ impl DocBuilder {
234214

235215

236216
/// Removes build directory of a package in chroot
237-
fn remove_build_dir(&self, package: &Package) -> Result<()> {
238-
let _ = self.chroot_command(format!("rm -rf {}", canonical_name(&package)));
217+
fn remove_build_dir(&self) -> Result<()> {
218+
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
219+
.join("home")
220+
.join(&self.options.chroot_user)
221+
.join("cratesfyi")
222+
.join("doc");
223+
let _ = remove_dir_all(crate_doc_path);
224+
for target in TARGETS.iter() {
225+
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
226+
.join("home")
227+
.join(&self.options.chroot_user)
228+
.join("cratesfyi")
229+
.join(target)
230+
.join("doc");
231+
let _ = remove_dir_all(crate_doc_path);
232+
}
239233
Ok(())
240234
}
241235

@@ -248,7 +242,7 @@ impl DocBuilder {
248242
.join(package.manifest().name());
249243
let source_path = source_path(&package).unwrap();
250244
// Some crates don't have documentation, so we don't care if removing_dir_all fails
251-
let _ = self.remove_build_dir(&package);
245+
let _ = self.remove_build_dir();
252246
let _ = remove_dir_all(documentation_path);
253247
let _ = remove_dir_all(source_path);
254248
Ok(())
@@ -280,7 +274,7 @@ impl DocBuilder {
280274
let crate_doc_path = PathBuf::from(&self.options.chroot_path)
281275
.join("home")
282276
.join(&self.options.chroot_user)
283-
.join(canonical_name(&package))
277+
.join("cratesfyi")
284278
.join("doc")
285279
.join(package.targets()[0].name().replace("-", "_").to_string());
286280
crate_doc_path.exists()
@@ -381,7 +375,7 @@ impl DocBuilder {
381375
let source = PathBuf::from(&self.options.chroot_path)
382376
.join("home")
383377
.join(&self.options.chroot_user)
384-
.join(canonical_name(&pkg))
378+
.join("cratesfyi")
385379
.join("doc");
386380

387381
// use copy_documentation destination directory so self.clean can remove it when

0 commit comments

Comments
 (0)