Skip to content

Commit 2023cc3

Browse files
committed
Auto merge of #84586 - GuillaumeGomez:enforce-rustdoc-gui-test-suite-run, r=Mark-Simulacrum
Enforce rustdoc-gui test-suite run Part of #84550
2 parents f60a670 + 5358498 commit 2023cc3

File tree

5 files changed

+135
-77
lines changed

5 files changed

+135
-77
lines changed

src/bootstrap/mk/Makefile.in

-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ check-aux:
4545
src/tools/cargo \
4646
src/tools/cargotest \
4747
$(BOOTSTRAP_ARGS)
48-
check-aux-and-gui: check-aux
49-
$(Q)$(BOOTSTRAP) test --stage 2 \
50-
src/test/rustdoc-gui \
51-
$(BOOTSTRAP_ARGS)
5248
check-bootstrap:
5349
$(Q)$(CFG_PYTHON) $(CFG_SRC_DIR)src/bootstrap/bootstrap_test.py
5450
dist:

src/bootstrap/test.rs

+72-48
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,24 @@ impl Step for RustdocJSNotStd {
774774
}
775775
}
776776

777+
fn check_if_browser_ui_test_is_installed_global(npm: &Path, global: bool) -> bool {
778+
let mut command = Command::new(&npm);
779+
command.arg("list").arg("--depth=0");
780+
if global {
781+
command.arg("--global");
782+
}
783+
let lines = command
784+
.output()
785+
.map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
786+
.unwrap_or(String::new());
787+
lines.contains(&" browser-ui-test@")
788+
}
789+
790+
fn check_if_browser_ui_test_is_installed(npm: &Path) -> bool {
791+
check_if_browser_ui_test_is_installed_global(npm, false)
792+
|| check_if_browser_ui_test_is_installed_global(npm, true)
793+
}
794+
777795
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
778796
pub struct RustdocGUI {
779797
pub target: TargetSelection,
@@ -786,7 +804,17 @@ impl Step for RustdocGUI {
786804
const ONLY_HOSTS: bool = true;
787805

788806
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
789-
run.path("src/test/rustdoc-gui")
807+
let builder = run.builder;
808+
let run = run.path("src/test/rustdoc-gui");
809+
run.default_condition(
810+
builder.config.nodejs.is_some()
811+
&& builder
812+
.config
813+
.npm
814+
.as_ref()
815+
.map(|p| check_if_browser_ui_test_is_installed(p))
816+
.unwrap_or(false),
817+
)
790818
}
791819

792820
fn make_run(run: RunConfig<'_>) {
@@ -795,58 +823,54 @@ impl Step for RustdocGUI {
795823
}
796824

797825
fn run(self, builder: &Builder<'_>) {
798-
if let (Some(nodejs), Some(npm)) = (&builder.config.nodejs, &builder.config.npm) {
799-
builder.ensure(compile::Std { compiler: self.compiler, target: self.target });
800-
801-
// The goal here is to check if the necessary packages are installed, and if not, we
802-
// display a warning and move on.
803-
let mut command = Command::new(&npm);
804-
command.arg("list").arg("--depth=0");
805-
let lines = command
806-
.output()
807-
.map(|output| String::from_utf8_lossy(&output.stdout).to_string())
808-
.unwrap_or(String::new());
809-
if !lines.contains(&" browser-ui-test@") {
810-
println!(
811-
"warning: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
812-
dependency is missing",
813-
);
814-
println!(
815-
"If you want to install the `{0}` dependency, run `npm install {0}`",
816-
"browser-ui-test",
817-
);
818-
return;
819-
}
826+
let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
827+
let npm = builder.config.npm.as_ref().expect("npm isn't available");
820828

821-
let out_dir = builder.test_out(self.target).join("rustdoc-gui");
829+
builder.ensure(compile::Std { compiler: self.compiler, target: self.target });
822830

823-
// We remove existing folder to be sure there won't be artifacts remaining.
824-
let _ = fs::remove_dir_all(&out_dir);
831+
// The goal here is to check if the necessary packages are installed, and if not, we
832+
// panic.
833+
if !check_if_browser_ui_test_is_installed(&npm) {
834+
eprintln!(
835+
"error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
836+
dependency is missing",
837+
);
838+
eprintln!(
839+
"If you want to install the `{0}` dependency, run `npm install {0}`",
840+
"browser-ui-test",
841+
);
842+
panic!("Cannot run rustdoc-gui tests");
843+
}
825844

826-
// We generate docs for the libraries present in the rustdoc-gui's src folder.
827-
let libs_dir = builder.build.src.join("src/test/rustdoc-gui/src");
828-
for entry in libs_dir.read_dir().expect("read_dir call failed") {
829-
let entry = entry.expect("invalid entry");
830-
let path = entry.path();
831-
if path.extension().map(|e| e == "rs").unwrap_or(false) {
832-
let mut command = builder.rustdoc_cmd(self.compiler);
833-
command.arg(path).arg("-o").arg(&out_dir);
834-
builder.run(&mut command);
835-
}
836-
}
845+
let out_dir = builder.test_out(self.target).join("rustdoc-gui");
837846

838-
// We now run GUI tests.
839-
let mut command = Command::new(&nodejs);
840-
command
841-
.arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
842-
.arg("--doc-folder")
843-
.arg(out_dir)
844-
.arg("--tests-folder")
845-
.arg(builder.build.src.join("src/test/rustdoc-gui"));
846-
builder.run(&mut command);
847-
} else {
848-
builder.info("No nodejs found, skipping \"src/test/rustdoc-gui\" tests");
847+
// We remove existing folder to be sure there won't be artifacts remaining.
848+
let _ = fs::remove_dir_all(&out_dir);
849+
850+
let mut nb_generated = 0;
851+
// We generate docs for the libraries present in the rustdoc-gui's src folder.
852+
let libs_dir = builder.build.src.join("src/test/rustdoc-gui/src");
853+
for entry in libs_dir.read_dir().expect("read_dir call failed") {
854+
let entry = entry.expect("invalid entry");
855+
let path = entry.path();
856+
if path.extension().map(|e| e == "rs").unwrap_or(false) {
857+
let mut command = builder.rustdoc_cmd(self.compiler);
858+
command.arg(path).arg("-o").arg(&out_dir);
859+
builder.run(&mut command);
860+
nb_generated += 1;
861+
}
849862
}
863+
assert!(nb_generated > 0, "no documentation was generated...");
864+
865+
// We now run GUI tests.
866+
let mut command = Command::new(&nodejs);
867+
command
868+
.arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
869+
.arg("--doc-folder")
870+
.arg(out_dir)
871+
.arg("--tests-folder")
872+
.arg(builder.build.src.join("src/test/rustdoc-gui"));
873+
builder.run(&mut command);
850874
}
851875
}
852876

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

+2-22
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1717
libgl1-mesa-dev \
1818
llvm-dev \
1919
libfreetype6-dev \
20-
libexpat1-dev \
21-
libexpat1-dev \
22-
gnupg \
23-
apt-utils \
24-
wget \
25-
fonts-ipafont-gothic \
26-
fonts-wqy-zenhei \
27-
fonts-thai-tlwg \
28-
fonts-kacst \
29-
fonts-freefont-ttf \
30-
libxss1 \
31-
libxtst6
32-
33-
RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar -xJ
34-
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
35-
36-
# Install required dependencies from browser-UI-test framework
37-
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
38-
# to create a new folder. For reference:
39-
# https://github.com/puppeteer/puppeteer/issues/375
40-
RUN npm install browser-ui-test -g --unsafe-perm=true
20+
libexpat1-dev
4121

4222
COPY scripts/sccache.sh /scripts/
4323
RUN sh /scripts/sccache.sh
@@ -46,4 +26,4 @@ COPY scripts/cmake.sh /scripts/
4626
RUN /scripts/cmake.sh
4727

4828
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu
49-
ENV RUST_CHECK_TARGET check-aux-and-gui
29+
ENV RUST_CHECK_TARGET check-aux

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

+55-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,48 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1212
cmake \
1313
libssl-dev \
1414
sudo \
15-
xz-utils \
16-
pkg-config
15+
xz-utils
16+
17+
# Install dependencies for chromium browser
18+
RUN apt-get install -y \
19+
gconf-service \
20+
libasound2 \
21+
libatk1.0-0 \
22+
libatk-bridge2.0-0 \
23+
libc6 \
24+
libcairo2 \
25+
libcups2 \
26+
libdbus-1-3 \
27+
libexpat1 \
28+
libfontconfig1 \
29+
libgcc1 \
30+
libgconf-2-4 \
31+
libgdk-pixbuf2.0-0 \
32+
libglib2.0-0 \
33+
libgtk-3-0 \
34+
libnspr4 \
35+
libpango-1.0-0 \
36+
libpangocairo-1.0-0 \
37+
libstdc++6 \
38+
libx11-6 \
39+
libx11-xcb1 \
40+
libxcb1 \
41+
libxcomposite1 \
42+
libxcursor1 \
43+
libxdamage1 \
44+
libxext6 \
45+
libxfixes3 \
46+
libxi6 \
47+
libxrandr2 \
48+
libxrender1 \
49+
libxss1 \
50+
libxtst6 \
51+
fonts-liberation \
52+
libappindicator1 \
53+
libnss3 \
54+
lsb-release \
55+
xdg-utils \
56+
wget
1757

1858
COPY scripts/sccache.sh /scripts/
1959
RUN sh /scripts/sccache.sh
@@ -23,7 +63,19 @@ RUN /scripts/cmake.sh
2363

2464
COPY host-x86_64/x86_64-gnu-tools/checktools.sh /tmp/
2565

66+
RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar -xJ
67+
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
68+
69+
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
70+
# to create a new folder. For reference:
71+
# https://github.com/puppeteer/puppeteer/issues/375
72+
#
73+
# We also specify the version in case we need to update it to go around cache limitations.
74+
RUN npm install -g [email protected] --unsafe-perm=true
75+
2676
ENV RUST_CONFIGURE_ARGS \
2777
--build=x86_64-unknown-linux-gnu \
2878
--save-toolstates=/tmp/toolstate/toolstates.json
29-
ENV SCRIPT /tmp/checktools.sh ../x.py
79+
80+
ENV SCRIPT /tmp/checktools.sh ../x.py && \
81+
NODE_PATH=`npm root -g` python3 ../x.py test src/test/rustdoc-gui --stage 2

src/ci/scripts/should-skip-this.sh

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ elif ! git diff --quiet "$BASE_COMMIT" -- src/tools/clippy src/tools/rustfmt; th
2626
# There is not an easy blanket search for subtrees. For now, manually list
2727
# the subtrees.
2828
echo "Executing the job since clippy or rustfmt subtree was updated"
29+
elif ! (git diff --quiet "$BASE_COMMIT" -- \
30+
src/test/rustdoc-gui \
31+
src/librustdoc \
32+
src/tools/rustdoc-gui); then
33+
# There was a change in either rustdoc or in its GUI tests.
34+
echo "Executing the job since rustdoc was updated"
2935
else
3036
echo "Not executing this job since no submodules nor subtrees were updated"
3137
ciCommandSetEnv SKIP_JOB 1

0 commit comments

Comments
 (0)