1
1
use std:: path:: { Path , PathBuf } ;
2
2
use std:: process:: Command ;
3
3
use std:: sync:: Arc ;
4
- use std:: { env, fs} ;
4
+ use std:: { env, fs, io } ;
5
5
6
+ use build_helper:: npm;
6
7
use build_helper:: util:: try_run;
7
8
use compiletest:: directives:: TestProps ;
8
9
use config:: Config ;
9
10
10
11
mod config;
11
12
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 (
13
+ fn get_desired_browser_ui_test_version ( src : & Path ) -> Result < String , io:: Error > {
14
+ fs:: read_to_string (
41
15
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
- }
16
+ )
59
17
}
60
18
61
19
fn find_librs < P : AsRef < Path > > ( path : P ) -> Option < PathBuf > {
@@ -71,27 +29,6 @@ fn find_librs<P: AsRef<Path>>(path: P) -> Option<PathBuf> {
71
29
fn main ( ) -> Result < ( ) , ( ) > {
72
30
let config = Arc :: new ( Config :: from_args ( env:: args ( ) . collect ( ) ) ) ;
73
31
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
-
95
32
let src_path = config. rust_src . join ( "tests/rustdoc-gui/src" ) ;
96
33
for entry in src_path. read_dir ( ) . expect ( "read_dir call failed" ) {
97
34
if let Ok ( entry) = entry {
@@ -138,16 +75,16 @@ If you want to install the `browser-ui-test` dependency, run `npm install browse
138
75
}
139
76
}
140
77
141
- let mut command = Command :: new ( & config. nodejs ) ;
78
+ let local_node_modules = npm:: install_one (
79
+ & config. out_dir ,
80
+ "browser-ui-test" ,
81
+ & get_desired_browser_ui_test_version ( & config. rust_src )
82
+ . expect ( "unable to get desired version for browser-ui-test" )
83
+ . trim ( ) ,
84
+ )
85
+ . expect ( "unable to install browser-ui-test" ) ;
142
86
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
- }
87
+ let mut command = Command :: new ( & config. nodejs ) ;
151
88
152
89
command
153
90
. arg ( config. rust_src . join ( "src/tools/rustdoc-gui/tester.js" ) )
@@ -158,6 +95,12 @@ If you want to install the `browser-ui-test` dependency, run `npm install browse
158
95
. arg ( "--tests-folder" )
159
96
. arg ( config. rust_src . join ( "tests/rustdoc-gui" ) ) ;
160
97
98
+ if local_node_modules. exists ( ) {
99
+ // Link the local node_modules if exists.
100
+ // This is useful when we run rustdoc-gui-test from outside of the source root.
101
+ command. env ( "NODE_PATH" , local_node_modules) ;
102
+ }
103
+
161
104
for file in & config. goml_files {
162
105
command. arg ( "--file" ) . arg ( file) ;
163
106
}
0 commit comments