Skip to content

Commit dec9fab

Browse files
Convert python script to rust
1 parent b1b11d4 commit dec9fab

File tree

7 files changed

+81
-63
lines changed

7 files changed

+81
-63
lines changed

src/Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ members = [
2222
"tools/rls",
2323
"tools/rustfmt",
2424
"tools/miri",
25+
"tools/rustdoc-themes",
2526
# FIXME(https://github.com/rust-lang/cargo/issues/4089): move these to exclude
2627
"tools/rls/test_data/bin_lib",
2728
"tools/rls/test_data/borrow_error",

src/bootstrap/test.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl Step for Linkcheck {
113113

114114
let _time = util::timeit();
115115
try_run(build, builder.tool_cmd(Tool::Linkchecker)
116-
.arg(build.out.join(host).join("doc")));
116+
.arg(build.out.join(host).join("doc")));
117117
}
118118

119119
fn should_run(run: ShouldRun) -> ShouldRun {
@@ -427,7 +427,6 @@ fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
427427
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
428428
pub struct RustdocTheme {
429429
pub compiler: Compiler,
430-
pub host: Interned<String>,
431430
}
432431

433432
impl Step for RustdocTheme {
@@ -444,27 +443,25 @@ impl Step for RustdocTheme {
444443

445444
run.builder.ensure(RustdocTheme {
446445
compiler: compiler,
447-
host: run.builder.build.build,
448446
});
449447
}
450448

451449
fn run(self, builder: &Builder) {
452450
let rustdoc = builder.rustdoc(self.compiler.host);
453-
let mut cmd = Command::new(builder.config.python.clone().expect("python not defined"));
454-
cmd.args(&[builder.src.join("src/tools/rustdoc-themes/test-themes.py").to_str().unwrap(),
455-
rustdoc.to_str().unwrap(),
456-
builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap()]);
457-
cmd.env("RUSTC_STAGE", self.compiler.stage.to_string())
451+
let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
452+
cmd.arg(rustdoc.to_str().unwrap())
453+
.arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
454+
.env("RUSTC_STAGE", self.compiler.stage.to_string())
458455
.env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
459456
.env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
460457
.env("CFG_RELEASE_CHANNEL", &builder.build.config.channel)
461-
.env("RUSTDOC_REAL", builder.rustdoc(self.host))
458+
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
462459
.env("RUSTDOC_CRATE_VERSION", builder.build.rust_version())
463460
.env("RUSTC_BOOTSTRAP", "1");
464-
if let Some(linker) = builder.build.linker(self.host) {
461+
if let Some(linker) = builder.build.linker(self.compiler.host) {
465462
cmd.env("RUSTC_TARGET_LINKER", linker);
466463
}
467-
builder.run(&mut cmd);
464+
try_run(builder.build, &mut cmd);
468465
}
469466
}
470467

src/bootstrap/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ tool!(
260260
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Libstd;
261261
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::Libstd;
262262
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::Libstd;
263+
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::Libstd;
263264
);
264265

265266
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]

src/tools/rustdoc-themes/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "rustdoc-themes"
3+
version = "0.1.0"
4+
authors = ["Guillaume Gomez <guillaume1.gomez@gmail.com>"]
5+
6+
[[bin]]
7+
name = "rustdoc-themes"
8+
path = "main.rs"

src/tools/rustdoc-themes/main.rs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2018 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.
4+
//
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.
10+
11+
use std::env::args;
12+
use std::fs::read_dir;
13+
use std::path::Path;
14+
use std::process::{Command, exit};
15+
16+
const FILES_TO_IGNORE: &[&str] = &["main.css"];
17+
18+
fn get_folders<P: AsRef<Path>>(folder_path: P) -> Vec<String> {
19+
let mut ret = Vec::with_capacity(10);
20+
21+
for entry in read_dir(folder_path.as_ref()).expect("read_dir failed") {
22+
let entry = entry.expect("Couldn't unwrap entry");
23+
let path = entry.path();
24+
25+
if !path.is_file() {
26+
continue
27+
}
28+
let filename = path.file_name().expect("file_name failed");
29+
if FILES_TO_IGNORE.iter().any(|x| x == &filename) {
30+
continue
31+
}
32+
ret.push(format!("{}", path.display()));
33+
}
34+
ret
35+
}
36+
37+
fn main() {
38+
let argv: Vec<String> = args().collect();
39+
40+
if argv.len() < 3 {
41+
eprintln!("Needs rustdoc binary path");
42+
exit(1);
43+
}
44+
let rustdoc_bin = &argv[1];
45+
let themes_folder = &argv[2];
46+
let themes = get_folders(&themes_folder);
47+
if themes.is_empty() {
48+
eprintln!("No theme found in \"{}\"...", themes_folder);
49+
exit(1);
50+
}
51+
let status = Command::new(rustdoc_bin)
52+
.args(&["-Z", "unstable-options", "--theme-checker"])
53+
.args(&themes)
54+
.status()
55+
.expect("failed to execute child");
56+
if !status.success() {
57+
exit(1);
58+
}
59+
}

src/tools/rustdoc-themes/test-themes.py

-52
This file was deleted.

0 commit comments

Comments
 (0)