Skip to content

Commit 4deb8eb

Browse files
committed
ci cleanup: rustdoc-gui-test now installs browser-ui-test
this removes the need for --unsafe-perm in the Dockerfile.
1 parent bfc046a commit 4deb8eb

File tree

6 files changed

+44
-100
lines changed

6 files changed

+44
-100
lines changed

src/build_helper/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod drop_bomb;
55
pub mod fs;
66
pub mod git;
77
pub mod metrics;
8+
pub mod npm;
89
pub mod stage0_parser;
910
pub mod targets;
1011
pub mod util;

src/build_helper/src/npm.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::error::Error;
2+
use std::path::{Path, PathBuf};
3+
use std::process::Command;
4+
use std::{fs, io};
5+
6+
/// Install an exact package version, and return the path of `node_modules`.
7+
pub fn install_one(
8+
out_dir: &Path,
9+
npm_bin: &Path,
10+
pkg_name: &str,
11+
pkg_version: &str,
12+
) -> Result<PathBuf, io::Error> {
13+
let nm_path = out_dir.join("node_modules");
14+
let _ = fs::create_dir(&nm_path);
15+
let mut child = Command::new(npm_bin)
16+
.arg("install")
17+
.arg("--audit=false")
18+
.arg("--fund=false")
19+
.arg(format!("{pkg_name}@{pkg_version}"))
20+
.current_dir(out_dir)
21+
.spawn()?;
22+
let exit_status = child.wait()?;
23+
if !exit_status.success() {
24+
eprintln!("npm install did not exit successfully");
25+
return Err(io::Error::other(Box::<dyn Error + Send + Sync>::from(format!(
26+
"npm install returned exit code {exit_status}"
27+
))));
28+
}
29+
Ok(nm_path)
30+
}

src/ci/docker/host-x86_64/x86_64-gnu-miri/Dockerfile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,4 @@ ENV HOST_TARGET x86_64-unknown-linux-gnu
4646

4747
COPY scripts/shared.sh /scripts/
4848

49-
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
50-
# to create a new folder. For reference:
51-
# https://github.com/puppeteer/puppeteer/issues/375
52-
#
53-
# We also specify the version in case we need to update it to go around cache limitations.
54-
#
55-
# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
56-
# the local version of the package is different than the one used by the CI.
5749
ENV SCRIPT /tmp/check-miri.sh ../x.py

src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ COPY scripts/nodejs.sh /scripts/
7676
RUN sh /scripts/nodejs.sh /node
7777
ENV PATH="/node/bin:${PATH}"
7878

79-
COPY host-x86_64/x86_64-gnu-tools/browser-ui-test.version /tmp/
80-
8179
ENV RUST_CONFIGURE_ARGS \
8280
--build=x86_64-unknown-linux-gnu \
8381
--save-toolstates=/tmp/toolstate/toolstates.json \
@@ -91,15 +89,6 @@ ENV HOST_TARGET x86_64-unknown-linux-gnu
9189

9290
COPY scripts/shared.sh /scripts/
9391

94-
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
95-
# to create a new folder. For reference:
96-
# https://github.com/puppeteer/puppeteer/issues/375
97-
#
98-
# We also specify the version in case we need to update it to go around cache limitations.
99-
#
100-
# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
101-
# the local version of the package is different than the one used by the CI.
10292
ENV SCRIPT /tmp/checktools.sh ../x.py && \
103-
npm install browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true && \
10493
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
10594
python3 ../x.py test tests/rustdoc-gui --stage 2 --test-args "'--jobs 1'"

src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tools/rustdoc-gui-test/src/main.rs

Lines changed: 13 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,15 @@
11
use std::path::{Path, PathBuf};
22
use std::process::Command;
33
use std::sync::Arc;
4-
use std::{env, fs};
4+
use std::env;
55

6+
use build_helper::npm;
67
use build_helper::util::try_run;
78
use compiletest::directives::TestProps;
89
use config::Config;
910

1011
mod config;
1112

12-
fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
13-
let mut command = Command::new(&npm);
14-
command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
15-
if global {
16-
command.arg("--global");
17-
}
18-
let lines = match command.output() {
19-
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
20-
Err(e) => {
21-
eprintln!(
22-
"path to npm can be wrong, provided path: {npm:?}. Try to set npm path \
23-
in bootstrap.toml in [build.npm]",
24-
);
25-
panic!("{:?}", e)
26-
}
27-
};
28-
lines
29-
.lines()
30-
.find_map(|l| l.rsplit(':').next()?.strip_prefix("browser-ui-test@"))
31-
.map(|v| v.to_owned())
32-
}
33-
34-
fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
35-
get_browser_ui_test_version_inner(npm, false)
36-
.or_else(|| get_browser_ui_test_version_inner(npm, true))
37-
}
38-
39-
fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
40-
match fs::read_to_string(
41-
src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
42-
) {
43-
Ok(v) => {
44-
if v.trim() != installed_version {
45-
eprintln!(
46-
"⚠️ Installed version of browser-ui-test (`{}`) is different than the \
47-
one used in the CI (`{}`)",
48-
installed_version, v
49-
);
50-
eprintln!(
51-
"You can install this version using `npm update browser-ui-test` or by using \
52-
`npm install browser-ui-test@{}`",
53-
v,
54-
);
55-
}
56-
}
57-
Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
58-
}
59-
}
60-
6113
fn find_librs<P: AsRef<Path>>(path: P) -> Option<PathBuf> {
6214
for entry in walkdir::WalkDir::new(path) {
6315
let entry = entry.ok()?;
@@ -71,27 +23,6 @@ fn find_librs<P: AsRef<Path>>(path: P) -> Option<PathBuf> {
7123
fn main() -> Result<(), ()> {
7224
let config = Arc::new(Config::from_args(env::args().collect()));
7325

74-
// The goal here is to check if the necessary packages are installed, and if not, we
75-
// panic.
76-
match get_browser_ui_test_version(&config.npm) {
77-
Some(version) => {
78-
// We also check the version currently used in CI and emit a warning if it's not the
79-
// same one.
80-
compare_browser_ui_test_version(&version, &config.rust_src);
81-
}
82-
None => {
83-
eprintln!(
84-
r#"
85-
error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` dependency is missing.
86-
87-
If you want to install the `browser-ui-test` dependency, run `npm install browser-ui-test`
88-
"#,
89-
);
90-
91-
panic!("Cannot run rustdoc-gui tests");
92-
}
93-
}
94-
9526
let src_path = config.rust_src.join("tests/rustdoc-gui/src");
9627
for entry in src_path.read_dir().expect("read_dir call failed") {
9728
if let Ok(entry) = entry {
@@ -138,16 +69,12 @@ If you want to install the `browser-ui-test` dependency, run `npm install browse
13869
}
13970
}
14071

141-
let mut command = Command::new(&config.nodejs);
72+
// FIXME(binarycat): once we get package.json in version control, this should be updated to install via that instead
73+
let local_node_modules =
74+
npm::install_one(&config.out_dir, &config.npm, "browser-ui-test", "0.21.1")
75+
.expect("unable to install browser-ui-test");
14276

143-
if let Ok(current_dir) = env::current_dir() {
144-
let local_node_modules = current_dir.join("node_modules");
145-
if local_node_modules.exists() {
146-
// Link the local node_modules if exists.
147-
// This is useful when we run rustdoc-gui-test from outside of the source root.
148-
env::set_var("NODE_PATH", local_node_modules);
149-
}
150-
}
77+
let mut command = Command::new(&config.nodejs);
15178

15279
command
15380
.arg(config.rust_src.join("src/tools/rustdoc-gui/tester.js"))
@@ -158,6 +85,12 @@ If you want to install the `browser-ui-test` dependency, run `npm install browse
15885
.arg("--tests-folder")
15986
.arg(config.rust_src.join("tests/rustdoc-gui"));
16087

88+
if local_node_modules.exists() {
89+
// Link the local node_modules if exists.
90+
// This is useful when we run rustdoc-gui-test from outside of the source root.
91+
command.env("NODE_PATH", local_node_modules);
92+
}
93+
16194
for file in &config.goml_files {
16295
command.arg("--file").arg(file);
16396
}

0 commit comments

Comments
 (0)