Skip to content

Commit de6c170

Browse files
authored
Rollup merge of rust-lang#94848 - GuillaumeGomez:browser-ui-test-version, r=Mark-Simulacrum
Compare installed browser-ui-test version to the one used in CI I happened a few times to run into (local) rustdoc GUI tests errors because I forgot to update my browser-ui-test version. I know at least two others who encountered the same problem so I think emitting a warning to let us know about this version mismatch would make it easier to figure out. So now, I'm not too sure that this PR is the right approach because it requires to parse a Dockerfile, which feels pretty bad. I had the idea to instead store the browser-ui-test version into a docker ARG like: ```docker ARG BROWSER_UI_TEST_VERSION=0.8.0 ``` And then use it as such in the command to make the parsing more reliable. Or we could store this version into a file and import this file into the Dockerfile and read it from the builder. Any preference or maybe another solution? r? `@Mark-Simulacrum`
2 parents a62cf66 + c8158e9 commit de6c170

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

src/bootstrap/test.rs

+41-17
Original file line numberDiff line numberDiff line change
@@ -836,22 +836,39 @@ impl Step for RustdocJSNotStd {
836836
}
837837
}
838838

839-
fn check_if_browser_ui_test_is_installed_global(npm: &Path, global: bool) -> bool {
839+
fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
840840
let mut command = Command::new(&npm);
841-
command.arg("list").arg("--depth=0");
841+
command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
842842
if global {
843843
command.arg("--global");
844844
}
845845
let lines = command
846846
.output()
847847
.map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
848848
.unwrap_or(String::new());
849-
lines.contains(&" browser-ui-test@")
849+
lines.lines().find_map(|l| l.split(":browser-ui-test@").skip(1).next()).map(|v| v.to_owned())
850850
}
851851

852-
fn check_if_browser_ui_test_is_installed(npm: &Path) -> bool {
853-
check_if_browser_ui_test_is_installed_global(npm, false)
854-
|| check_if_browser_ui_test_is_installed_global(npm, true)
852+
fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
853+
get_browser_ui_test_version_inner(npm, false)
854+
.or_else(|| get_browser_ui_test_version_inner(npm, true))
855+
}
856+
857+
fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
858+
match fs::read_to_string(
859+
src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
860+
) {
861+
Ok(v) => {
862+
if v.trim() != installed_version {
863+
eprintln!(
864+
"⚠️ Installed version of browser-ui-test (`{}`) is different than the \
865+
one used in the CI (`{}`)",
866+
installed_version, v
867+
);
868+
}
869+
}
870+
Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
871+
}
855872
}
856873

857874
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
@@ -874,7 +891,7 @@ impl Step for RustdocGUI {
874891
.config
875892
.npm
876893
.as_ref()
877-
.map(|p| check_if_browser_ui_test_is_installed(p))
894+
.map(|p| get_browser_ui_test_version(p).is_some())
878895
.unwrap_or(false)
879896
}))
880897
}
@@ -892,16 +909,23 @@ impl Step for RustdocGUI {
892909

893910
// The goal here is to check if the necessary packages are installed, and if not, we
894911
// panic.
895-
if !check_if_browser_ui_test_is_installed(&npm) {
896-
eprintln!(
897-
"error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
898-
dependency is missing",
899-
);
900-
eprintln!(
901-
"If you want to install the `{0}` dependency, run `npm install {0}`",
902-
"browser-ui-test",
903-
);
904-
panic!("Cannot run rustdoc-gui tests");
912+
match get_browser_ui_test_version(&npm) {
913+
Some(version) => {
914+
// We also check the version currently used in CI and emit a warning if it's not the
915+
// same one.
916+
compare_browser_ui_test_version(&version, &builder.build.src);
917+
}
918+
None => {
919+
eprintln!(
920+
"error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
921+
dependency is missing",
922+
);
923+
eprintln!(
924+
"If you want to install the `{0}` dependency, run `npm install {0}`",
925+
"browser-ui-test",
926+
);
927+
panic!("Cannot run rustdoc-gui tests");
928+
}
905929
}
906930

907931
let out_dir = builder.test_out(self.target).join("rustdoc-gui");

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,20 @@ RUN /scripts/cmake.sh
6565
COPY host-x86_64/x86_64-gnu-tools/checktools.sh /tmp/
6666

6767
RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar -xJ
68-
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
68+
ENV NODE_FOLDER=/node-v14.4.0-linux-x64/bin
69+
ENV PATH="$NODE_FOLDER:${PATH}"
70+
71+
COPY host-x86_64/x86_64-gnu-tools/browser-ui-test.version /tmp/
6972

7073
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
7174
# to create a new folder. For reference:
7275
# https://github.com/puppeteer/puppeteer/issues/375
7376
#
7477
# We also specify the version in case we need to update it to go around cache limitations.
75-
RUN npm install -g [email protected] --unsafe-perm=true
78+
#
79+
# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
80+
# the local version of the package is different than the one used by the CI.
81+
RUN npm install -g browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true
7682

7783
ENV RUST_CONFIGURE_ARGS \
7884
--build=x86_64-unknown-linux-gnu \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.8.3

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

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if [[ -n "${CI_ONLY_WHEN_SUBMODULES_CHANGED-}" ]]; then
2626
src/test/rustdoc-gui \
2727
src/librustdoc \
2828
src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile \
29+
src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version \
2930
src/tools/rustdoc-gui); then
3031
# There was a change in either rustdoc or in its GUI tests.
3132
echo "Rustdoc was updated"

0 commit comments

Comments
 (0)