11use colored:: * ;
22use regex:: bytes:: Regex ;
3+ use std:: ffi:: OsString ;
34use std:: path:: { Path , PathBuf } ;
45use std:: { env, process:: Command } ;
56use ui_test:: status_emitter:: StatusEmitter ;
@@ -45,7 +46,7 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
4546 so_file_path
4647}
4748
48- fn run_tests ( mode : Mode , path : & str , target : & str , with_dependencies : bool ) -> Result < ( ) > {
49+ fn test_config ( target : & str , path : & str , mode : Mode , with_dependencies : bool ) -> Config {
4950 // Miri is rustc-like, so we create a default builder for rustc and modify it
5051 let mut program = CommandBuilder :: rustc ( ) ;
5152 program. program = miri_path ( ) ;
@@ -103,6 +104,26 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
103104 ..Config :: default ( )
104105 } ;
105106
107+ let use_std = env:: var_os ( "MIRI_NO_STD" ) . is_none ( ) ;
108+
109+ if with_dependencies && use_std {
110+ config. dependencies_crate_manifest_path =
111+ Some ( Path :: new ( "test_dependencies" ) . join ( "Cargo.toml" ) ) ;
112+ config. dependency_builder . args = vec ! [
113+ "run" . into( ) ,
114+ "--manifest-path" . into( ) ,
115+ "cargo-miri/Cargo.toml" . into( ) ,
116+ "--" . into( ) ,
117+ "miri" . into( ) ,
118+ "run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
119+ ] ;
120+ }
121+ config
122+ }
123+
124+ fn run_tests ( mode : Mode , path : & str , target : & str , with_dependencies : bool ) -> Result < ( ) > {
125+ let mut config = test_config ( target, path, mode, with_dependencies) ;
126+
106127 // Handle command-line arguments.
107128 let mut after_dashdash = false ;
108129 config. path_filter . extend ( std:: env:: args ( ) . skip ( 1 ) . filter ( |arg| {
@@ -126,21 +147,6 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
126147 }
127148 } ) ) ;
128149
129- let use_std = env:: var_os ( "MIRI_NO_STD" ) . is_none ( ) ;
130-
131- if with_dependencies && use_std {
132- config. dependencies_crate_manifest_path =
133- Some ( Path :: new ( "test_dependencies" ) . join ( "Cargo.toml" ) ) ;
134- config. dependency_builder . args = vec ! [
135- "run" . into( ) ,
136- "--manifest-path" . into( ) ,
137- "cargo-miri/Cargo.toml" . into( ) ,
138- "--" . into( ) ,
139- "miri" . into( ) ,
140- "run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
141- ] ;
142- }
143-
144150 eprintln ! ( " Compiler: {}" , config. program. display( ) ) ;
145151 ui_test:: run_tests_generic (
146152 config,
@@ -226,8 +232,18 @@ fn get_target() -> String {
226232
227233fn main ( ) -> Result < ( ) > {
228234 ui_test:: color_eyre:: install ( ) ?;
235+
229236 let target = get_target ( ) ;
230237
238+ let mut args = std:: env:: args_os ( ) ;
239+
240+ // Skip the program name and check whether this is a `./miri run-dep` invocation
241+ if let Some ( first) = args. nth ( 1 ) {
242+ if first == "--miri-run-dep-mode" {
243+ return run_dep_mode ( target, args) ;
244+ }
245+ }
246+
231247 // Add a test env var to do environment communication tests.
232248 env:: set_var ( "MIRI_ENV_VAR_TEST" , "0" ) ;
233249 // Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
@@ -250,6 +266,21 @@ fn main() -> Result<()> {
250266 Ok ( ( ) )
251267}
252268
269+ fn run_dep_mode ( target : String , mut args : impl Iterator < Item = OsString > ) -> Result < ( ) > {
270+ let path = args. next ( ) . expect ( "./miri run-dep must be followed by a file name" ) ;
271+ let mut config = test_config ( & target, "" , Mode :: Yolo , /* with dependencies */ true ) ;
272+ config. program . args . remove ( 0 ) ; // remove the `--error-format=json` argument
273+ config. program . args . push ( "--color" . into ( ) ) ;
274+ config. program . args . push ( "always" . into ( ) ) ;
275+ let mut cmd = ui_test:: test_command ( config, Path :: new ( & path) ) ?;
276+ // Separate the arguments to the `cargo miri` invocation from
277+ // the arguments to the interpreted prog
278+ cmd. arg ( "--" ) ;
279+ cmd. args ( args) ;
280+ println ! ( "{cmd:?}" ) ;
281+ if cmd. spawn ( ) ?. wait ( ) ?. success ( ) { Ok ( ( ) ) } else { std:: process:: exit ( 1 ) }
282+ }
283+
253284/// This is a custom renderer for `ui_test` output that does not emit github actions
254285/// `group`s, while still producing regular github actions messages on test failures.
255286struct TextAndGha ;
0 commit comments