Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a link validator to rustbuild #32133

Merged
merged 12 commits into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ TOOL_DEPS_error_index_generator := rustdoc syntax serialize
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
TOOL_SOURCE_rustbook := $(S)src/rustbook/main.rs
TOOL_SOURCE_error_index_generator := $(S)src/error_index_generator/main.rs
TOOL_SOURCE_rustbook := $(S)src/tools/rustbook/main.rs
TOOL_SOURCE_error_index_generator := $(S)src/tools/error_index_generator/main.rs

ONLY_RLIB_core := 1
ONLY_RLIB_libc := 1
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ path = "main.rs"
name = "rustc"
path = "rustc.rs"

[[bin]]
name = "rustdoc"
path = "rustdoc.rs"

[dependencies]
build_helper = { path = "../build_helper" }
cmake = "0.1.10"
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def download_rust_nightly(self):

if self.rustc().startswith(self.bin_root()) and \
(not os.path.exists(self.rustc()) or self.rustc_out_of_date()):
shutil.rmtree(self.bin_root())
if os.path.exists(self.bin_root()):
shutil.rmtree(self.bin_root())
filename = "rust-std-nightly-" + self.build + ".tar.gz"
url = "https://static.rust-lang.org/dist/" + self.snap_rustc_date()
tarball = os.path.join(rustc_cache, filename)
Expand Down
21 changes: 21 additions & 0 deletions src/bootstrap/build/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::process::Command;

use build::{Build, Compiler};

pub fn linkcheck(build: &Build, stage: u32, host: &str) {
println!("Linkcheck stage{} ({})", stage, host);
let compiler = Compiler::new(stage, host);
let linkchecker = build.tool(&compiler, "linkchecker");
build.run(Command::new(&linkchecker)
.arg(build.out.join(host).join("doc")));
}
52 changes: 37 additions & 15 deletions src/bootstrap/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::process::Command;
use build_helper::output;

use build::util::{exe, staticlib, libdir, mtime, is_dylib};
use build::{Build, Compiler};
use build::{Build, Compiler, Mode};

/// Build the standard library.
///
Expand All @@ -39,9 +39,10 @@ pub fn std<'a>(build: &'a Build, stage: u32, target: &str,

build_startup_objects(build, target, &libdir);

let out_dir = build.cargo_out(stage, &host, true, target);
let out_dir = build.cargo_out(stage, &host, Mode::Libstd, target);
build.clear_if_dirty(&out_dir, &build.compiler_path(compiler));
let mut cargo = build.cargo(stage, compiler, true, target, "build");
let mut cargo = build.cargo(stage, compiler, Mode::Libstd, Some(target),
"build");
cargo.arg("--features").arg(build.std_features())
.arg("--manifest-path")
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"));
Expand Down Expand Up @@ -71,7 +72,7 @@ pub fn std_link(build: &Build,
compiler: &Compiler,
host: &str) {
let libdir = build.sysroot_libdir(stage, host, target);
let out_dir = build.cargo_out(stage, compiler.host, true, target);
let out_dir = build.cargo_out(stage, compiler.host, Mode::Libstd, target);

// If we're linking one compiler host's output into another, then we weren't
// called from the `std` method above. In that case we clean out what's
Expand Down Expand Up @@ -135,19 +136,15 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
println!("Building stage{} compiler artifacts ({} -> {})", stage,
host, target);

let out_dir = build.cargo_out(stage, &host, false, target);
let out_dir = build.cargo_out(stage, &host, Mode::Librustc, target);
build.clear_if_dirty(&out_dir, &libstd_shim(build, stage, &host, target));

let mut cargo = build.cargo(stage, compiler, false, target, "build");
cargo.arg("--features").arg(build.rustc_features(stage))
let mut cargo = build.cargo(stage, compiler, Mode::Librustc, Some(target),
"build");
cargo.arg("--features").arg(build.rustc_features())
.arg("--manifest-path")
.arg(build.src.join("src/rustc/Cargo.toml"));

// In stage0 we may not need to build as many executables
if stage == 0 {
cargo.arg("--bin").arg("rustc");
}

// Set some configuration variables picked up by build scripts and
// the compiler alike
cargo.env("CFG_RELEASE", &build.release)
Expand Down Expand Up @@ -200,14 +197,14 @@ pub fn rustc_link(build: &Build,
compiler: &Compiler,
host: &str) {
let libdir = build.sysroot_libdir(stage, host, target);
let out_dir = build.cargo_out(stage, compiler.host, false, target);
let out_dir = build.cargo_out(stage, compiler.host, Mode::Librustc, target);
add_to_sysroot(&out_dir, &libdir);
}

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
fn libstd_shim(build: &Build, stage: u32, host: &str, target: &str) -> PathBuf {
build.cargo_out(stage, host, true, target).join("libstd_shim.rlib")
build.cargo_out(stage, host, Mode::Libstd, target).join("libstd_shim.rlib")
}

fn compiler_file(compiler: &Path, file: &str) -> String {
Expand Down Expand Up @@ -239,7 +236,8 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
}
}

let out_dir = build.cargo_out(stage - 1, &build.config.build, false, host);
let out_dir = build.cargo_out(stage - 1, &build.config.build,
Mode::Librustc, host);

// Link the compiler binary itself into place
let rustc = out_dir.join(exe("rustc", host));
Expand Down Expand Up @@ -298,3 +296,27 @@ fn add_to_sysroot(out_dir: &Path, sysroot_dst: &Path) {
sysroot_dst.join(path.file_name().unwrap())));
}
}

/// Build a tool in `src/tools`
///
/// This will build the specified tool with the specified `host` compiler in
/// `stage` into the normal cargo output directory.
pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) {
println!("Building stage{} tool {} ({})", stage, tool, host);

let compiler = Compiler::new(stage, host);

// FIXME: need to clear out previous tool and ideally deps, may require
// isolating output directories or require a pseudo shim step to
// clear out all the info.
//
// Maybe when libstd is compiled it should clear out the rustc of the
// corresponding stage?
// let out_dir = build.cargo_out(stage, &host, Mode::Librustc, target);
// build.clear_if_dirty(&out_dir, &libstd_shim(build, stage, &host, target));

let mut cargo = build.cargo(stage, &compiler, Mode::Tool, None, "build");
cargo.arg("--manifest-path")
.arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool)));
build.run(&mut cargo);
}
60 changes: 55 additions & 5 deletions src/bootstrap/build/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::path::Path;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::Path;
use std::process::Command;

use build::{Build, Compiler};
use build::util::up_to_date;
use build::{Build, Compiler, Mode};
use build::util::{up_to_date, cp_r};

pub fn rustbook(build: &Build, stage: u32, host: &str, name: &str, out: &Path) {
t!(fs::create_dir_all(out));
Expand Down Expand Up @@ -69,7 +70,7 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
}

let html = out.join(filename).with_extension("html");
let rustdoc = build.tool(&compiler, "rustdoc");
let rustdoc = build.rustdoc(&compiler);
if up_to_date(&path, &html) &&
up_to_date(&footer, &html) &&
up_to_date(&favicon, &html) &&
Expand All @@ -79,7 +80,7 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
continue
}

let mut cmd = build.tool_cmd(&compiler, "rustdoc");
let mut cmd = Command::new(&rustdoc);
cmd.arg("--html-after-content").arg(&footer)
.arg("--html-before-content").arg(&version_info)
.arg("--html-in-header").arg(&favicon)
Expand All @@ -102,3 +103,52 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
build.run(&mut cmd);
}
}

pub fn std(build: &Build, stage: u32, host: &str, out: &Path) {
println!("Documenting stage{} std ({})", stage, host);
let compiler = Compiler::new(stage, host);
let out_dir = build.stage_out(stage, host, Mode::Libstd)
.join(host).join("doc");
let rustdoc = build.rustdoc(&compiler);

build.clear_if_dirty(&out_dir, &rustdoc);

let mut cargo = build.cargo(stage, &compiler, Mode::Libstd, Some(host),
"doc");
cargo.arg("--manifest-path")
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"))
.arg("--features").arg(build.std_features());
build.run(&mut cargo);
cp_r(&out_dir, out)
}

pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) {
println!("Documenting stage{} compiler ({})", stage, host);
let compiler = Compiler::new(stage, host);
let out_dir = build.stage_out(stage, host, Mode::Librustc)
.join(host).join("doc");
let rustdoc = build.rustdoc(&compiler);
if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) {
t!(fs::remove_dir_all(&out_dir));
}
let mut cargo = build.cargo(stage, &compiler, Mode::Librustc, Some(host),
"doc");
cargo.arg("--manifest-path")
.arg(build.src.join("src/rustc/Cargo.toml"))
.arg("--features").arg(build.rustc_features());
build.run(&mut cargo);
cp_r(&out_dir, out)
}

pub fn error_index(build: &Build, stage: u32, host: &str, out: &Path) {
println!("Documenting stage{} error index ({})", stage, host);
let compiler = Compiler::new(stage, host);
let mut index = Command::new(build.tool(&compiler, "error_index_generator"));
index.arg("html");
index.arg(out.join("error-index.html"));

// FIXME: shouldn't have to pass this env var
index.env("CFG_BUILD", &build.config.build);

build.run(&mut index);
}
Loading