Convert python script to rust
This commit is contained in:
parent
b1b11d4589
commit
dec9fab768
4
src/Cargo.lock
generated
4
src/Cargo.lock
generated
@ -2217,6 +2217,10 @@ dependencies = [
|
||||
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustdoc-themes"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "rustdoc-tool"
|
||||
version = "0.0.0"
|
||||
|
@ -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",
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)]
|
||||
|
8
src/tools/rustdoc-themes/Cargo.toml
Normal file
8
src/tools/rustdoc-themes/Cargo.toml
Normal file
@ -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
src/tools/rustdoc-themes/main.rs
Normal file
59
src/tools/rustdoc-themes/main.rs
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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.
|
||||
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
FILES_TO_IGNORE = ['main.css']
|
||||
|
||||
|
||||
def print_err(msg):
|
||||
sys.stderr.write('{}\n'.format(msg))
|
||||
|
||||
|
||||
def exec_command(command):
|
||||
child = subprocess.Popen(command)
|
||||
stdout, stderr = child.communicate()
|
||||
return child.returncode
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) < 2:
|
||||
print_err("Needs rustdoc binary path")
|
||||
return 1
|
||||
rustdoc_bin = argv[0]
|
||||
themes_folder = argv[1]
|
||||
themes = [join(themes_folder, f) for f in listdir(themes_folder)
|
||||
if isfile(join(themes_folder, f)) and f not in FILES_TO_IGNORE]
|
||||
if len(themes) < 1:
|
||||
print_err('No theme found in "{}"...'.format(themes_folder))
|
||||
return 1
|
||||
args = [rustdoc_bin, '-Z', 'unstable-options', '--theme-checker']
|
||||
args.extend(themes)
|
||||
return exec_command(args)
|
||||
|
||||
|
||||
if __name__ != '__main__':
|
||||
print_err("Needs to be run as main")
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(main(sys.argv[1:]))
|
Loading…
Reference in New Issue
Block a user