Skip to content

Commit

Permalink
Convert python script to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 8, 2018
1 parent b1b11d4 commit dec9fab
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 63 deletions.
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
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
19 changes: 8 additions & 11 deletions src/bootstrap/test.rs
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 @@ -427,7 +427,6 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustdocTheme {
pub compiler: Compiler,
pub host: Interned<String>,
}

impl Step for RustdocTheme {
Expand All @@ -444,27 +443,25 @@ impl Step for RustdocTheme {

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

fn run(self, builder: &Builder) {
let rustdoc = builder.rustdoc(self.compiler.host);
let mut cmd = Command::new(builder.config.python.clone().expect("python not defined"));
cmd.args(&[builder.src.join("src/tools/rustdoc-themes/test-themes.py").to_str().unwrap(),
rustdoc.to_str().unwrap(),
builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap()]);
cmd.env("RUSTC_STAGE", self.compiler.stage.to_string())
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.host))
.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.host) {
if let Some(linker) = builder.build.linker(self.compiler.host) {
cmd.env("RUSTC_TARGET_LINKER", linker);
}
builder.run(&mut cmd);
try_run(builder.build, &mut cmd);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/tool.rs
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
8 changes: 8 additions & 0 deletions src/tools/rustdoc-themes/Cargo.toml
@@ -0,0 +1,8 @@
[package]
name = "rustdoc-themes"
version = "0.1.0"
authors = ["Guillaume Gomez <guillaume1.gomez@gmail.com>"]

[[bin]]
name = "rustdoc-themes"
path = "main.rs"
59 changes: 59 additions & 0 deletions src/tools/rustdoc-themes/main.rs
@@ -0,0 +1,59 @@
// Copyright 2018 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::env::args;
use std::fs::read_dir;
use std::path::Path;
use std::process::{Command, exit};

const FILES_TO_IGNORE: &[&str] = &["main.css"];

fn get_folders<P: AsRef<Path>>(folder_path: P) -> Vec<String> {
let mut ret = Vec::with_capacity(10);

for entry in read_dir(folder_path.as_ref()).expect("read_dir failed") {
let entry = entry.expect("Couldn't unwrap entry");
let path = entry.path();

if !path.is_file() {
continue
}
let filename = path.file_name().expect("file_name failed");
if FILES_TO_IGNORE.iter().any(|x| x == &filename) {
continue
}
ret.push(format!("{}", path.display()));
}
ret
}

fn main() {
let argv: Vec<String> = args().collect();

if argv.len() < 3 {
eprintln!("Needs rustdoc binary path");
exit(1);
}
let rustdoc_bin = &argv[1];
let themes_folder = &argv[2];
let themes = get_folders(&themes_folder);
if themes.is_empty() {
eprintln!("No theme found in \"{}\"...", themes_folder);
exit(1);
}
let status = Command::new(rustdoc_bin)
.args(&["-Z", "unstable-options", "--theme-checker"])
.args(&themes)
.status()
.expect("failed to execute child");
if !status.success() {
exit(1);
}
}
52 changes: 0 additions & 52 deletions src/tools/rustdoc-themes/test-themes.py

This file was deleted.

0 comments on commit dec9fab

Please sign in to comment.