Skip to content

Commit e9c8b69

Browse files
pietroalbinionur
andauthored
Merge pull request #407 from rust-lang/rustwide
Switch to rustwide for sandboxing Co-authored-by: Onur Aslan <[email protected]>
2 parents 5f7cf5b + 5027343 commit e9c8b69

24 files changed

+1035
-1072
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ target
33
*.css.map
44
.sass-cache
55
.vagrant
6+
.rustwide

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ tokio = "0.1"
3939
systemstat = "0.1.4"
4040
prometheus = { version = "0.7.0", default-features = false }
4141
lazy_static = "1.0.0"
42+
rustwide = "0.3.0"
43+
tempdir = "0.3"
4244

4345
# iron dependencies
4446
iron = "0.5"
@@ -51,9 +53,6 @@ staticfile = { version = "0.4", features = [ "cache" ] }
5153
version = "0.15"
5254
features = [ "with-time", "with-rustc-serialize" ]
5355

54-
[dev-dependencies]
55-
tempdir = "0.3"
56-
5756
[build-dependencies]
5857
time = "0.1"
5958
git2 = "0.9"

src/bin/cratesfyi.rs

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ extern crate clap;
55
extern crate log;
66
extern crate env_logger;
77
extern crate time;
8+
extern crate rustwide;
89

910

1011
use std::env;
1112
use std::path::PathBuf;
1213

1314
use clap::{Arg, App, SubCommand};
14-
use cratesfyi::{DocBuilder, DocBuilderOptions, db};
15-
use cratesfyi::utils::{build_doc, add_crate_to_queue};
15+
use cratesfyi::{DocBuilder, RustwideBuilder, DocBuilderOptions, db};
16+
use cratesfyi::utils::add_crate_to_queue;
1617
use cratesfyi::start_web_server;
1718
use cratesfyi::db::{add_path_into_database, connect_db};
1819

@@ -23,20 +24,6 @@ pub fn main() {
2324
let matches = App::new("cratesfyi")
2425
.version(cratesfyi::BUILD_VERSION)
2526
.about(env!("CARGO_PKG_DESCRIPTION"))
26-
.subcommand(SubCommand::with_name("doc")
27-
.about("Builds documentation of a crate")
28-
.arg(Arg::with_name("CRATE_NAME")
29-
.index(1)
30-
.required(true)
31-
.help("Crate name"))
32-
.arg(Arg::with_name("CRATE_VERSION")
33-
.index(2)
34-
.required(false)
35-
.help("Crate version"))
36-
.arg(Arg::with_name("TARGET")
37-
.index(3)
38-
.required(false)
39-
.help("The target platform to compile for")))
4027
.subcommand(SubCommand::with_name("build")
4128
.about("Builds documentation in a chroot environment")
4229
.arg(Arg::with_name("PREFIX")
@@ -48,21 +35,6 @@ pub fn main() {
4835
.long("destination")
4936
.help("Sets destination path")
5037
.takes_value(true))
51-
.arg(Arg::with_name("CHROOT_PATH")
52-
.short("c")
53-
.long("chroot-path")
54-
.help("Sets chroot path")
55-
.takes_value(true))
56-
.arg(Arg::with_name("CHROOT_USER")
57-
.short("u")
58-
.long("chroot-user")
59-
.help("Sets chroot user name")
60-
.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))
6638
.arg(Arg::with_name("CRATES_IO_INDEX_PATH")
6739
.long("crates-io-index-path")
6840
.help("Sets crates.io-index path")
@@ -152,15 +124,7 @@ pub fn main() {
152124

153125

154126

155-
// doc subcommand
156-
if let Some(matches) = matches.subcommand_matches("doc") {
157-
let name = matches.value_of("CRATE_NAME").unwrap();
158-
let version = matches.value_of("CRATE_VERSION");
159-
let target = matches.value_of("TARGET");
160-
if let Err(e) = build_doc(name, version, target) {
161-
panic!("{:#?}", e);
162-
}
163-
} else if let Some(matches) = matches.subcommand_matches("build") {
127+
if let Some(matches) = matches.subcommand_matches("build") {
164128
let docbuilder_opts = {
165129
let mut docbuilder_opts = if let Some(prefix) = matches.value_of("PREFIX") {
166130
DocBuilderOptions::from_prefix(PathBuf::from(prefix))
@@ -175,18 +139,6 @@ pub fn main() {
175139
docbuilder_opts.destination = PathBuf::from(destination);
176140
}
177141

178-
if let Some(chroot_path) = matches.value_of("CHROOT_PATH") {
179-
docbuilder_opts.chroot_path = PathBuf::from(chroot_path);
180-
}
181-
182-
if let Some(chroot_user) = matches.value_of("CHROOT_USER") {
183-
docbuilder_opts.chroot_user = chroot_user.to_string();
184-
}
185-
186-
if let Some(container_name) = matches.value_of("CONTAINER_NAME") {
187-
docbuilder_opts.container_name = container_name.to_string();
188-
}
189-
190142
if let Some(crates_io_index_path) = matches.value_of("CRATES_IO_INDEX_PATH") {
191143
docbuilder_opts.crates_io_index_path = PathBuf::from(crates_io_index_path);
192144
}
@@ -204,16 +156,19 @@ pub fn main() {
204156

205157
if let Some(_) = matches.subcommand_matches("world") {
206158
docbuilder.load_cache().expect("Failed to load cache");
207-
docbuilder.build_world().expect("Failed to build world");
159+
let mut builder = RustwideBuilder::init().unwrap();
160+
builder.build_world(&mut docbuilder).expect("Failed to build world");
208161
docbuilder.save_cache().expect("Failed to save cache");
209162
} else if let Some(matches) = matches.subcommand_matches("crate") {
210163
docbuilder.load_cache().expect("Failed to load cache");
211-
docbuilder.build_package(matches.value_of("CRATE_NAME").unwrap(),
212-
matches.value_of("CRATE_VERSION").unwrap())
164+
let mut builder = RustwideBuilder::init().unwrap();
165+
builder.build_package(&mut docbuilder, matches.value_of("CRATE_NAME").unwrap(),
166+
matches.value_of("CRATE_VERSION").unwrap())
213167
.expect("Building documentation failed");
214168
docbuilder.save_cache().expect("Failed to save cache");
215169
} else if let Some(_) = matches.subcommand_matches("add-essential-files") {
216-
docbuilder.add_essential_files().expect("Failed to add essential files");
170+
let builder = RustwideBuilder::init().unwrap();
171+
builder.add_essential_files().expect("failed to add essential files");
217172
} else if let Some(_) = matches.subcommand_matches("lock") {
218173
docbuilder.lock().expect("Failed to lock");
219174
} else if let Some(_) = matches.subcommand_matches("unlock") {
@@ -287,5 +242,6 @@ fn logger_init() {
287242
record.args())
288243
});
289244
builder.parse(&env::var("RUST_LOG").unwrap_or("cratesfyi=info".to_owned()));
290-
builder.init();
245+
246+
rustwide::logging::init_with(builder.build());
291247
}

0 commit comments

Comments
 (0)