]>
git.proxmox.com Git - rustc.git/blob - src/bootstrap/build/doc.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std
::fs
::{self, File}
;
12 use std
::io
::prelude
::*;
14 use std
::process
::Command
;
16 use build
::{Build, Compiler, Mode}
;
17 use build
::util
::{up_to_date, cp_r}
;
19 pub fn rustbook(build
: &Build
, stage
: u32, target
: &str, name
: &str, out
: &Path
) {
20 t
!(fs
::create_dir_all(out
));
22 let out
= out
.join(name
);
23 let compiler
= Compiler
::new(stage
, &build
.config
.build
);
24 let src
= build
.src
.join("src/doc").join(name
);
25 let index
= out
.join("index.html");
26 let rustbook
= build
.tool(&compiler
, "rustbook");
27 if up_to_date(&src
, &index
) && up_to_date(&rustbook
, &index
) {
30 println
!("Rustbook stage{} ({}) - {}", stage
, target
, name
);
31 let _
= fs
::remove_dir_all(&out
);
32 build
.run(build
.tool_cmd(&compiler
, "rustbook")
38 pub fn standalone(build
: &Build
, stage
: u32, target
: &str, out
: &Path
) {
39 println
!("Documenting stage{} standalone ({})", stage
, target
);
40 t
!(fs
::create_dir_all(out
));
42 let compiler
= Compiler
::new(stage
, &build
.config
.build
);
44 let favicon
= build
.src
.join("src/doc/favicon.inc");
45 let footer
= build
.src
.join("src/doc/footer.inc");
46 let full_toc
= build
.src
.join("src/doc/full-toc.inc");
47 t
!(fs
::copy(build
.src
.join("src/doc/rust.css"), out
.join("rust.css")));
49 let version_input
= build
.src
.join("src/doc/version_info.html.template");
50 let version_info
= out
.join("version_info.html");
52 if !up_to_date(&version_input
, &version_info
) {
53 let mut info
= String
::new();
54 t
!(t
!(File
::open(&version_input
)).read_to_string(&mut info
));
55 let blank
= String
::new();
56 let short
= build
.short_ver_hash
.as_ref().unwrap_or(&blank
);
57 let hash
= build
.ver_hash
.as_ref().unwrap_or(&blank
);
58 let info
= info
.replace("VERSION", &build
.release
)
59 .replace("SHORT_HASH", short
)
60 .replace("STAMP", hash
);
61 t
!(t
!(File
::create(&version_info
)).write_all(info
.as_bytes()));
64 for file
in t
!(fs
::read_dir(build
.src
.join("src/doc"))) {
66 let path
= file
.path();
67 let filename
= path
.file_name().unwrap().to_str().unwrap();
68 if !filename
.ends_with(".md") || filename
== "README.md" {
72 let html
= out
.join(filename
).with_extension("html");
73 let rustdoc
= build
.rustdoc(&compiler
);
74 if up_to_date(&path
, &html
) &&
75 up_to_date(&footer
, &html
) &&
76 up_to_date(&favicon
, &html
) &&
77 up_to_date(&full_toc
, &html
) &&
78 up_to_date(&version_info
, &html
) &&
79 up_to_date(&rustdoc
, &html
) {
83 let mut cmd
= Command
::new(&rustdoc
);
84 build
.add_rustc_lib_path(&compiler
, &mut cmd
);
85 cmd
.arg("--html-after-content").arg(&footer
)
86 .arg("--html-before-content").arg(&version_info
)
87 .arg("--html-in-header").arg(&favicon
)
88 .arg("--markdown-playground-url")
89 .arg("https://play.rust-lang.org/")
93 if filename
== "reference.md" {
94 cmd
.arg("--html-in-header").arg(&full_toc
);
97 if filename
== "not_found.md" {
98 cmd
.arg("--markdown-no-toc")
99 .arg("--markdown-css")
100 .arg("https://doc.rust-lang.org/rust.css");
102 cmd
.arg("--markdown-css").arg("rust.css");
108 pub fn std(build
: &Build
, stage
: u32, target
: &str, out
: &Path
) {
109 println
!("Documenting stage{} std ({})", stage
, target
);
110 t
!(fs
::create_dir_all(out
));
111 let compiler
= Compiler
::new(stage
, &build
.config
.build
);
112 let out_dir
= build
.stage_out(&compiler
, Mode
::Libstd
)
113 .join(target
).join("doc");
114 let rustdoc
= build
.rustdoc(&compiler
);
116 build
.clear_if_dirty(&out_dir
, &rustdoc
);
118 let mut cargo
= build
.cargo(&compiler
, Mode
::Libstd
, target
, "doc");
119 cargo
.arg("--manifest-path")
120 .arg(build
.src
.join("src/rustc/std_shim/Cargo.toml"))
121 .arg("--features").arg(build
.std_features());
122 build
.run(&mut cargo
);
126 pub fn test(build
: &Build
, stage
: u32, target
: &str, out
: &Path
) {
127 println
!("Documenting stage{} test ({})", stage
, target
);
128 let compiler
= Compiler
::new(stage
, &build
.config
.build
);
129 let out_dir
= build
.stage_out(&compiler
, Mode
::Libtest
)
130 .join(target
).join("doc");
131 let rustdoc
= build
.rustdoc(&compiler
);
133 build
.clear_if_dirty(&out_dir
, &rustdoc
);
135 let mut cargo
= build
.cargo(&compiler
, Mode
::Libtest
, target
, "doc");
136 cargo
.arg("--manifest-path")
137 .arg(build
.src
.join("src/rustc/test_shim/Cargo.toml"));
138 build
.run(&mut cargo
);
142 pub fn rustc(build
: &Build
, stage
: u32, target
: &str, out
: &Path
) {
143 println
!("Documenting stage{} compiler ({})", stage
, target
);
144 let compiler
= Compiler
::new(stage
, &build
.config
.build
);
145 let out_dir
= build
.stage_out(&compiler
, Mode
::Librustc
)
146 .join(target
).join("doc");
147 let rustdoc
= build
.rustdoc(&compiler
);
148 if !up_to_date(&rustdoc
, &out_dir
.join("rustc/index.html")) {
149 t
!(fs
::remove_dir_all(&out_dir
));
151 let mut cargo
= build
.cargo(&compiler
, Mode
::Librustc
, target
, "doc");
152 cargo
.arg("--manifest-path")
153 .arg(build
.src
.join("src/rustc/Cargo.toml"))
154 .arg("--features").arg(build
.rustc_features());
155 build
.run(&mut cargo
);
159 pub fn error_index(build
: &Build
, stage
: u32, target
: &str, out
: &Path
) {
160 println
!("Documenting stage{} error index ({})", stage
, target
);
161 t
!(fs
::create_dir_all(out
));
162 let compiler
= Compiler
::new(stage
, &build
.config
.build
);
163 let mut index
= build
.tool_cmd(&compiler
, "error_index_generator");
165 index
.arg(out
.join("error-index.html"));
167 // FIXME: shouldn't have to pass this env var
168 index
.env("CFG_BUILD", &build
.config
.build
);
170 build
.run(&mut index
);