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

Test themes #47761

Merged
merged 9 commits into from
Feb 9, 2018
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: 4 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"tools/rls",
"tools/rustfmt",
"tools/miri",
"tools/rustdoc-themes",
# FIXME(https://github.com/rust-lang/cargo/issues/4089): move these to exclude
"tools/rls/test_data/bin_lib",
"tools/rls/test_data/borrow_error",
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl<'a> Builder<'a> {
test::HostCompiletest, test::Crate, test::CrateLibrustc, test::Rustdoc,
test::Linkcheck, test::Cargotest, test::Cargo, test::Rls, test::Docs,
test::ErrorIndex, test::Distcheck, test::Rustfmt, test::Miri, test::Clippy,
test::RustdocJS),
test::RustdocJS, test::RustdocTheme),
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,3 @@ pub fn libtest_stamp(build: &Build, compiler: Compiler, target: Interned<String>
pub fn librustc_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
build.cargo_out(compiler, Mode::Librustc, target).join(".librustc-check.stamp")
}

43 changes: 42 additions & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Step for Linkcheck {

let _time = util::timeit();
try_run(build, builder.tool_cmd(Tool::Linkchecker)
.arg(build.out.join(host).join("doc")));
.arg(build.out.join(host).join("doc")));
}

fn should_run(run: ShouldRun) -> ShouldRun {
Expand Down Expand Up @@ -424,6 +424,47 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocTheme {
pub compiler: Compiler,
}

impl Step for RustdocTheme {
type Output = ();
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/tools/rustdoc-themes")
}

fn make_run(run: RunConfig) {
let compiler = run.builder.compiler(run.builder.top_stage, run.host);

run.builder.ensure(RustdocTheme {
compiler: compiler,
});
}

fn run(self, builder: &Builder) {
let rustdoc = builder.rustdoc(self.compiler.host);
let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
cmd.arg(rustdoc.to_str().unwrap())
.arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
.env("RUSTC_STAGE", self.compiler.stage.to_string())
.env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
.env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
.env("CFG_RELEASE_CHANNEL", &builder.build.config.channel)
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
.env("RUSTDOC_CRATE_VERSION", builder.build.rust_version())
.env("RUSTC_BOOTSTRAP", "1");
if let Some(linker) = builder.build.linker(self.compiler.host) {
cmd.env("RUSTC_TARGET_LINKER", linker);
}
try_run(builder.build, &mut cmd);
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocJS {
pub host: Interned<String>,
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ tool!(
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Libstd;
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::Libstd;
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::Libstd;
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::Libstd;
);

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ pre {
}
.content .highlighted a, .content .highlighted span { color: #eee !important; }
.content .highlighted.trait { background-color: #013191; }
.content .highlighted.mod,
.content .highlighted.externcrate { background-color: #afc6e4; }
.content .highlighted.mod { background-color: #803a1b; }
.content .highlighted.externcrate { background-color: #396bac; }
.content .highlighted.enum { background-color: #5b4e68; }
.content .highlighted.struct { background-color: #194e9f; }
.content .highlighted.union { background-color: #b7bd49; }
.content .highlighted.fn,
.content .highlighted.method,
.content .highlighted.tymethod { background-color: #4950ed; }
Expand Down
53 changes: 48 additions & 5 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub mod plugins;
pub mod visit_ast;
pub mod visit_lib;
pub mod test;
pub mod theme;

use clean::AttributesExt;

Expand Down Expand Up @@ -267,6 +268,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
"additional themes which will be added to the generated docs",
"FILES")
}),
unstable("theme-checker", |o| {
o.optmulti("", "theme-checker",
"check if given theme is valid",
"FILES")
}),
]
}

Expand Down Expand Up @@ -316,6 +322,31 @@ pub fn main_args(args: &[String]) -> isize {
return 0;
}

let to_check = matches.opt_strs("theme-checker");
if !to_check.is_empty() {
let paths = theme::load_css_paths(include_bytes!("html/static/themes/main.css"));
let mut errors = 0;

println!("rustdoc: [theme-checker] Starting tests!");
for theme_file in to_check.iter() {
print!(" - Checking \"{}\"...", theme_file);
let (success, differences) = theme::test_theme_against(theme_file, &paths);
if !differences.is_empty() || !success {
println!(" FAILED");
errors += 1;
if !differences.is_empty() {
println!("{}", differences.join("\n"));
}
} else {
println!(" OK");
}
}
if errors != 0 {
return 1;
}
return 0;
}

if matches.free.is_empty() {
print_error("missing file operand");
return 1;
Expand Down Expand Up @@ -369,12 +400,24 @@ pub fn main_args(args: &[String]) -> isize {
}

let mut themes = Vec::new();
for theme in matches.opt_strs("themes").iter().map(|s| PathBuf::from(&s)) {
if !theme.is_file() {
eprintln!("rustdoc: option --themes arguments must all be files");
return 1;
if matches.opt_present("themes") {
let paths = theme::load_css_paths(include_bytes!("html/static/themes/main.css"));

for (theme_file, theme_s) in matches.opt_strs("themes")
.iter()
.map(|s| (PathBuf::from(&s), s.to_owned())) {
if !theme_file.is_file() {
println!("rustdoc: option --themes arguments must all be files");
return 1;
}
let (success, ret) = theme::test_theme_against(&theme_file, &paths);
if !success || !ret.is_empty() {
println!("rustdoc: invalid theme: \"{}\"", theme_s);
println!(" Check what's wrong with the \"theme-checker\" option");
return 1;
}
themes.push(theme_file);
}
themes.push(theme);
}

let external_html = match ExternalHtml::load(
Expand Down
Loading