Skip to content

Commit f303b86

Browse files
committed
tidy: don't hardcode build/, use outdir
1 parent 5e00f42 commit f303b86

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,16 @@ fn check_impl(
296296
}
297297

298298
if js_lint || js_typecheck {
299-
rustdoc_js::npm_install()?;
299+
rustdoc_js::npm_install(outdir)?;
300300
}
301301

302302
if js_lint {
303-
rustdoc_js::lint(librustdoc_path, tools_path, src_path)?;
304-
rustdoc_js::es_check(librustdoc_path)?;
303+
rustdoc_js::lint(outdir, librustdoc_path, tools_path, src_path)?;
304+
rustdoc_js::es_check(outdir, librustdoc_path)?;
305305
}
306306

307307
if js_typecheck {
308-
rustdoc_js::typecheck(librustdoc_path)?;
308+
rustdoc_js::typecheck(outdir, librustdoc_path)?;
309309
}
310310

311311
Ok(())

src/tools/tidy/src/ext_tool_checks/rustdoc_js.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ use ignore::DirEntry;
1111

1212
use crate::walk::walk_no_read;
1313

14-
fn node_module_bin(name: &str) -> String {
15-
format!("build/node_modules/.bin/{name}")
14+
fn node_module_bin(outdir: &Path, name: &str) -> PathBuf {
15+
outdir.join(name)
1616
}
1717

1818
/// install all js dependencies from package.json.
19-
pub(super) fn npm_install() -> Result<(), super::Error> {
20-
// will error if already exists, so ignore the error.
21-
// if there is a filesystem permission issue,
22-
// later commands will error.
23-
let _ = fs::create_dir("build");
24-
// copy stuff to build/ to make node_modules get put there.
25-
fs::copy("package.json", "build/package.json")?;
26-
fs::copy("package-lock.json", "build/package-lock.json")?;
19+
pub(super) fn npm_install(outdir: &Path) -> Result<(), super::Error> {
20+
let copy_to_build = |p| fs::copy(p, outdir.join(p));
21+
// copy stuff to the output directory to make node_modules get put there.
22+
copy_to_build("package.json")?;
23+
copy_to_build("package-lock.json")?;
2724

2825
let mut cmd = Command::new("npm");
2926
if CiEnv::is_ci() {
@@ -36,7 +33,7 @@ pub(super) fn npm_install() -> Result<(), super::Error> {
3633
// this makes tidy output less noisy, and also significantly improves runtime
3734
// of repeated tidy invokations.
3835
cmd.args(&["--audit=false", "--save=false", "--fund=false"]);
39-
cmd.current_dir("build");
36+
cmd.current_dir(outdir);
4037
let mut child = cmd.spawn()?;
4138
match child.wait() {
4239
Ok(exit_status) => {
@@ -61,8 +58,8 @@ fn rustdoc_js_files(librustdoc_path: &Path) -> Vec<PathBuf> {
6158
return files;
6259
}
6360

64-
fn run_eslint(args: &[PathBuf], config_folder: PathBuf) -> Result<(), super::Error> {
65-
let mut child = Command::new(node_module_bin("eslint"))
61+
fn run_eslint(outdir: &Path, args: &[PathBuf], config_folder: PathBuf) -> Result<(), super::Error> {
62+
let mut child = Command::new(node_module_bin(outdir, "eslint"))
6663
.arg("-c")
6764
.arg(config_folder.join(".eslintrc.js"))
6865
.args(args)
@@ -94,6 +91,7 @@ fn get_eslint_version() -> Option<String> {
9491
}
9592

9693
pub(super) fn lint(
94+
outdir: &Path,
9795
librustdoc_path: &Path,
9896
tools_path: &Path,
9997
src_path: &Path,
@@ -135,16 +133,20 @@ pub(super) fn lint(
135133
}
136134
let files_to_check = rustdoc_js_files(librustdoc_path);
137135
println!("Running eslint on rustdoc JS files");
138-
run_eslint(&files_to_check, librustdoc_path.join("html/static"))?;
136+
run_eslint(outdir, &files_to_check, librustdoc_path.join("html/static"))?;
139137

140-
run_eslint(&[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"))?;
141-
run_eslint(&[tools_path.join("rustdoc-gui/tester.js")], tools_path.join("rustdoc-gui"))?;
138+
run_eslint(outdir, &[tools_path.join("rustdoc-js/tester.js")], tools_path.join("rustdoc-js"))?;
139+
run_eslint(
140+
outdir,
141+
&[tools_path.join("rustdoc-gui/tester.js")],
142+
tools_path.join("rustdoc-gui"),
143+
)?;
142144
Ok(())
143145
}
144146

145-
pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
147+
pub(super) fn typecheck(outdir: &Path, librustdoc_path: &Path) -> Result<(), super::Error> {
146148
// use npx to ensure correct version
147-
let mut child = Command::new(node_module_bin("tsc"))
149+
let mut child = Command::new(node_module_bin(outdir, "tsc"))
148150
.arg("-p")
149151
.arg(librustdoc_path.join("html/static/js/tsconfig.json"))
150152
.spawn()?;
@@ -159,9 +161,9 @@ pub(super) fn typecheck(librustdoc_path: &Path) -> Result<(), super::Error> {
159161
}
160162
}
161163

162-
pub(super) fn es_check(librustdoc_path: &Path) -> Result<(), super::Error> {
164+
pub(super) fn es_check(outdir: &Path, librustdoc_path: &Path) -> Result<(), super::Error> {
163165
let files_to_check = rustdoc_js_files(librustdoc_path);
164-
let mut cmd = Command::new(node_module_bin("es-check"));
166+
let mut cmd = Command::new(node_module_bin(outdir, "es-check"));
165167
cmd.arg("es2019");
166168
for f in files_to_check {
167169
cmd.arg(f);

0 commit comments

Comments
 (0)