Skip to content

Commit 3e6fed3

Browse files
committed
rustbuild: Add the error-index-generator
This adds a step and a rule for building the error index as part of rustbuild.
1 parent e9cb96a commit 3e6fed3

File tree

7 files changed

+61
-17
lines changed

7 files changed

+61
-17
lines changed

mk/crates.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
126126
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
127127
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
128128
TOOL_SOURCE_rustbook := $(S)src/tools/rustbook/main.rs
129-
TOOL_SOURCE_error_index_generator := $(S)src/error_index_generator/main.rs
129+
TOOL_SOURCE_error_index_generator := $(S)src/tools/error_index_generator/main.rs
130130

131131
ONLY_RLIB_core := 1
132132
ONLY_RLIB_libc := 1

src/bootstrap/build/doc.rs

+13
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,16 @@ pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) {
139139
build.run(&mut cargo);
140140
cp_r(&out_dir, out)
141141
}
142+
143+
pub fn error_index(build: &Build, stage: u32, host: &str, out: &Path) {
144+
println!("Documenting stage{} error index ({})", stage, host);
145+
let compiler = Compiler::new(stage, host);
146+
let mut index = Command::new(build.tool(&compiler, "error_index_generator"));
147+
index.arg("html");
148+
index.arg(out.join("error-index.html"));
149+
150+
// FIXME: shouldn't have to pass this env var
151+
index.env("CFG_BUILD", &build.config.build);
152+
153+
build.run(&mut index);
154+
}

src/bootstrap/build/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ impl Build {
178178
ToolRustbook { stage } => {
179179
compile::tool(self, stage, target.target, "rustbook");
180180
}
181+
ToolErrorIndex { stage } => {
182+
compile::tool(self, stage, target.target,
183+
"error_index_generator");
184+
}
181185
DocBook { stage } => {
182186
doc::rustbook(self, stage, target.target, "book", &doc_out);
183187
}
@@ -198,6 +202,9 @@ impl Build {
198202
DocRustc { stage } => {
199203
doc::rustc(self, stage, target.target, &doc_out);
200204
}
205+
DocErrorIndex { stage } => {
206+
doc::error_index(self, stage, target.target, &doc_out);
207+
}
201208

202209
CheckLinkcheck { stage } => {
203210
check::linkcheck(self, stage, target.target);

src/bootstrap/build/step.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ macro_rules! targets {
4848
// Various tools that we can build as part of the build.
4949
(tool_linkchecker, ToolLinkchecker { stage: u32 }),
5050
(tool_rustbook, ToolRustbook { stage: u32 }),
51+
(tool_error_index, ToolErrorIndex { stage: u32 }),
5152

5253
// Steps for long-running native builds. Ideally these wouldn't
5354
// actually exist and would be part of build scripts, but for now
@@ -68,6 +69,7 @@ macro_rules! targets {
6869
(doc_standalone, DocStandalone { stage: u32 }),
6970
(doc_std, DocStd { stage: u32 }),
7071
(doc_rustc, DocRustc { stage: u32 }),
72+
(doc_error_index, DocErrorIndex { stage: u32 }),
7173

7274
// Steps for running tests. The 'check' target is just a pseudo
7375
// target to depend on a bunch of others.
@@ -265,6 +267,9 @@ impl<'a> Step<'a> {
265267
Source::DocStyle { stage } => {
266268
vec![self.tool_rustbook(stage)]
267269
}
270+
Source::DocErrorIndex { stage } => {
271+
vec![self.tool_error_index(stage)]
272+
}
268273
Source::DocStandalone { stage } => {
269274
vec![self.rustc(stage)]
270275
}
@@ -274,7 +279,8 @@ impl<'a> Step<'a> {
274279
Source::Doc { stage } => {
275280
vec![self.doc_book(stage), self.doc_nomicon(stage),
276281
self.doc_style(stage), self.doc_standalone(stage),
277-
self.doc_std(stage)]
282+
self.doc_std(stage),
283+
self.doc_error_index(stage)]
278284
}
279285
Source::Check { stage, compiler: _ } => {
280286
vec![self.check_linkcheck(stage)]
@@ -286,6 +292,7 @@ impl<'a> Step<'a> {
286292
Source::ToolLinkchecker { stage } => {
287293
vec![self.libstd(stage, self.compiler(stage))]
288294
}
295+
Source::ToolErrorIndex { stage } |
289296
Source::ToolRustbook { stage } => {
290297
vec![self.librustc(stage, self.compiler(stage))]
291298
}

src/tools/error_index_generator/Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "error_index_generator"
4+
version = "0.0.0"
5+
6+
[[bin]]
7+
name = "error_index_generator"
8+
path = "main.rs"

src/error_index_generator/main.rs renamed to src/tools/error_index_generator/main.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ extern crate rustdoc;
1515
extern crate serialize as rustc_serialize;
1616

1717
use std::collections::BTreeMap;
18+
use std::env;
19+
use std::error::Error;
1820
use std::fs::{read_dir, File};
1921
use std::io::{Read, Write};
20-
use std::env;
2122
use std::path::Path;
22-
use std::error::Error;
23+
use std::path::PathBuf;
2324

2425
use syntax::diagnostics::metadata::{get_metadata_dir, ErrorMetadataMap, ErrorMetadata};
2526

@@ -173,31 +174,35 @@ fn render_error_page<T: Formatter>(err_map: &ErrorMetadataMap, output_path: &Pat
173174
formatter.footer(&mut output_file)
174175
}
175176

176-
fn main_with_result(format: OutputFormat) -> Result<(), Box<Error>> {
177+
fn main_with_result(format: OutputFormat, dst: &Path) -> Result<(), Box<Error>> {
177178
let build_arch = try!(env::var("CFG_BUILD"));
178179
let metadata_dir = get_metadata_dir(&build_arch);
179180
let err_map = try!(load_all_errors(&metadata_dir));
180181
match format {
181182
OutputFormat::Unknown(s) => panic!("Unknown output format: {}", s),
182-
OutputFormat::HTML(h) => try!(render_error_page(&err_map,
183-
Path::new("doc/error-index.html"),
184-
h)),
185-
OutputFormat::Markdown(m) => try!(render_error_page(&err_map,
186-
Path::new("doc/error-index.md"),
187-
m)),
183+
OutputFormat::HTML(h) => try!(render_error_page(&err_map, dst, h)),
184+
OutputFormat::Markdown(m) => try!(render_error_page(&err_map, dst, m)),
188185
}
189186
Ok(())
190187
}
191188

192-
fn parse_args() -> OutputFormat {
193-
for arg in env::args().skip(1) {
194-
return OutputFormat::from(&arg);
195-
}
196-
OutputFormat::from("html")
189+
fn parse_args() -> (OutputFormat, PathBuf) {
190+
let mut args = env::args().skip(1);
191+
let format = args.next().map(|a| OutputFormat::from(&a))
192+
.unwrap_or(OutputFormat::from("html"));
193+
let dst = args.next().map(PathBuf::from).unwrap_or_else(|| {
194+
match format {
195+
OutputFormat::HTML(..) => PathBuf::from("doc/error-index.html"),
196+
OutputFormat::Markdown(..) => PathBuf::from("doc/error-index.md"),
197+
OutputFormat::Unknown(..) => PathBuf::from("<nul>"),
198+
}
199+
});
200+
(format, dst)
197201
}
198202

199203
fn main() {
200-
if let Err(e) = main_with_result(parse_args()) {
204+
let (format, dst) = parse_args();
205+
if let Err(e) = main_with_result(format, &dst) {
201206
panic!("{}", e.description());
202207
}
203208
}

0 commit comments

Comments
 (0)