Skip to content

Commit 9826ca0

Browse files
committed
Merge branch 'master' into web-merge
2 parents a4e2973 + 0b6b46c commit 9826ca0

File tree

4 files changed

+116
-8
lines changed

4 files changed

+116
-8
lines changed

README.md

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

2-
# cratesfyi
2+
# docs.rs
33

4-
[![Build Status](https://secure.travis-ci.org/onur/cratesfyi.svg?branch=master)](https://travis-ci.org/onur/cratesfyi)
5-
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/onur/cratesfyi/master/LICENSE)
4+
[![Build Status](https://secure.travis-ci.org/onur/docs.rs.svg?branch=master)](https://travis-ci.org/onur/docs.rs)
5+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/onur/docs.rs/master/LICENSE)
66

7-
Centralized crate documentation builder and explorer for the Rust programming
8-
language.
7+
Documentation host for the Rust Programming Language crates.
98

109

1110
## Installation
@@ -111,7 +110,7 @@ yourusername ALL=(ALL) NOPASSWD: /usr/sbin/chroot
111110
```
112111

113112

114-
### Seting up database
113+
### Setting up database
115114

116115
cratesfyi is using postgresql database to store crate and build
117116
information. You need to set up database before using chroot builder. To do

src/bin/cratesfyi.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ pub fn main() {
8989
.arg(Arg::with_name("CRATE_VERSION")
9090
.index(2)
9191
.required(true)
92-
.help("Version of crate"))))
92+
.help("Version of crate")))
93+
.subcommand(SubCommand::with_name("add-essential-files")
94+
.about("Adds essential files for rustc")))
9395
.subcommand(SubCommand::with_name("start-web-server")
9496
.about("Starts web server")
9597
.arg(Arg::with_name("SOCKET_ADDR")
@@ -175,6 +177,8 @@ pub fn main() {
175177
docbuilder.build_package(matches.value_of("CRATE_NAME").unwrap(),
176178
matches.value_of("CRATE_VERSION").unwrap())
177179
.expect("Building documentation failed");
180+
} else if let Some(_) = matches.subcommand_matches("add-essential-files") {
181+
docbuilder.add_essential_files().expect("Failed to add essential files");
178182
}
179183

180184
docbuilder.save_cache().expect("Failed to save cache");

src/db/add_package.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn add_package_into_database(conn: &Connection,
8888
$8, test_status = $9, license = $10, repository_url = $11, \
8989
homepage_url = $12, description = $13, description_long = $14, \
9090
readme = $15, authors = $16, keywords = $17, have_examples = $18, \
91-
downloads = $19, files = $20, doc_targets = $21, is_library = $22 \
91+
downloads = $19, files = $20, doc_targets = $21, is_library = $22, \
9292
doc_rustc_version = $23 \
9393
WHERE crate_id = $1 AND version = $2",
9494
&[&crate_id,
@@ -112,6 +112,7 @@ pub fn add_package_into_database(conn: &Connection,
112112
&downloads,
113113
&files,
114114
&doc_targets.to_json(),
115+
&is_library,
115116
&res.rustc_version]));
116117
rows.get(0).get(0)
117118
}

src/docbuilder/chroot_builder.rs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,100 @@ impl DocBuilder {
331331
package.manifest().version()));
332332
add_path_into_database(conn, &prefix, crate_doc_path)
333333
}
334+
335+
336+
/// This function will build an empty crate and will add essential documentation files.
337+
///
338+
/// It is required to run after every rustc update. cratesfyi is not keeping this files
339+
/// for every crate to avoid duplications.
340+
///
341+
/// List of the files:
342+
///
343+
/// * rustdoc.css (with rustc version)
344+
/// * main.css (with rustc version)
345+
/// * main.js (with rustc version)
346+
/// * jquery.js (with rustc version)
347+
/// * playpen.js (with rustc version)
348+
/// * normalize.css
349+
/// * FiraSans-Medium.woff
350+
/// * FiraSans-Regular.woff
351+
/// * Heuristica-Italic.woff
352+
/// * SourceCodePro-Regular.woff
353+
/// * SourceCodePro-Semibold.woff
354+
/// * SourceSerifPro-Bold.woff
355+
/// * SourceSerifPro-Regular.woff
356+
pub fn add_essential_files(&self) -> Result<(), DocBuilderError> {
357+
use std::fs::{copy, create_dir_all};
358+
359+
// acme-client-0.0.0 is an empty library crate and it will always build
360+
let pkg = try!(get_package("acme-client", Some("=0.0.0")));
361+
let res = self.build_package_in_chroot(&pkg);
362+
let rustc_version = parse_rustc_version(&res.rustc_version);
363+
364+
if !res.build_success {
365+
return Err(DocBuilderError::GenericError(format!("Failed to build empty crate for: {}",
366+
res.rustc_version)));
367+
}
368+
369+
info!("Copying essential files for: {}", res.rustc_version);
370+
371+
let files = (
372+
// files require rustc version subfix
373+
["rustdoc.css",
374+
"main.css",
375+
"main.js",
376+
"jquery.js",
377+
"playpen.js"],
378+
// files doesn't require rustc version subfix
379+
["normalize.css",
380+
"FiraSans-Medium.woff",
381+
"normalize.css",
382+
"FiraSans-Medium.woff",
383+
"FiraSans-Regular.woff",
384+
"Heuristica-Italic.woff",
385+
"SourceCodePro-Regular.woff",
386+
"SourceCodePro-Semibold.woff",
387+
"SourceSerifPro-Bold.woff",
388+
"SourceSerifPro-Regular.woff",
389+
],
390+
);
391+
392+
let source = PathBuf::from(&self.options.chroot_path)
393+
.join("home")
394+
.join(&self.options.chroot_user)
395+
.join(canonical_name(&pkg))
396+
.join("doc");
397+
398+
// use copy_documentation destination directory so self.clean can remove it when
399+
// we are done
400+
let destination = PathBuf::from(&self.options.destination)
401+
.join(format!("{}/{}",
402+
pkg.manifest().name(),
403+
pkg.manifest().version()));
404+
try!(create_dir_all(&destination));
405+
406+
for file in files.0.iter() {
407+
let source_path = source.join(file);
408+
let destination_path = {
409+
let spl: Vec<&str> = file.split('.').collect();
410+
destination.join(format!("{}-{}.{}", spl[0], rustc_version, spl[1]))
411+
};
412+
try!(copy(source_path, destination_path));
413+
}
414+
415+
for file in files.1.iter() {
416+
let source_path = source.join(file);
417+
let destination_path = destination.join(file);
418+
try!(copy(source_path, destination_path));
419+
}
420+
421+
let conn = try!(connect_db());
422+
try!(add_path_into_database(&conn, "", destination));
423+
424+
try!(self.clean(&pkg));
425+
426+
Ok(())
427+
}
334428
}
335429

336430

@@ -416,4 +510,14 @@ mod test {
416510
assert_eq!(parse_rustc_version("cratesfyi 0.2.0 (ba9ae23 2016-05-26)"),
417511
"20160526-0.2.0-ba9ae23");
418512
}
513+
514+
#[test]
515+
#[ignore]
516+
fn test_add_essential_files() {
517+
let _ = env_logger::init();
518+
let options = DocBuilderOptions::from_prefix(PathBuf::from("../cratesfyi-prefix"));
519+
let docbuilder = DocBuilder::new(options);
520+
521+
docbuilder.add_essential_files().unwrap();
522+
}
419523
}

0 commit comments

Comments
 (0)