]>
Commit | Line | Data |
---|---|---|
1 | //! Common executables that can be reused by various tests. | |
2 | ||
3 | use crate::{basic_manifest, paths, project, Project}; | |
4 | use lazy_static::lazy_static; | |
5 | use std::path::PathBuf; | |
6 | use std::sync::Mutex; | |
7 | ||
8 | lazy_static! { | |
9 | static ref ECHO_WRAPPER: Mutex<Option<PathBuf>> = Mutex::new(None); | |
10 | } | |
11 | ||
12 | /// Returns the path to an executable that works as a wrapper around rustc. | |
13 | /// | |
14 | /// The wrapper will echo the command line it was called with to stderr. | |
15 | pub fn echo_wrapper() -> PathBuf { | |
16 | let mut lock = ECHO_WRAPPER.lock().unwrap(); | |
17 | if let Some(path) = &*lock { | |
18 | return path.clone(); | |
19 | } | |
20 | let p = project() | |
21 | .at(paths::global_root().join("rustc-echo-wrapper")) | |
22 | .file("Cargo.toml", &basic_manifest("rustc-echo-wrapper", "1.0.0")) | |
23 | .file( | |
24 | "src/main.rs", | |
25 | r#" | |
26 | fn main() { | |
27 | let args = std::env::args().collect::<Vec<_>>(); | |
28 | eprintln!("WRAPPER CALLED: {}", args[1..].join(" ")); | |
29 | let status = std::process::Command::new(&args[1]) | |
30 | .args(&args[2..]).status().unwrap(); | |
31 | std::process::exit(status.code().unwrap_or(1)); | |
32 | } | |
33 | "#, | |
34 | ) | |
35 | .build(); | |
36 | p.cargo("build").run(); | |
37 | let path = p.bin("rustc-echo-wrapper"); | |
38 | *lock = Some(path.clone()); | |
39 | path | |
40 | } | |
41 | ||
42 | /// Returns a project which builds a cargo-echo simple subcommand | |
43 | pub fn echo_subcommand() -> Project { | |
44 | let p = project() | |
45 | .at("cargo-echo") | |
46 | .file("Cargo.toml", &basic_manifest("cargo-echo", "0.0.1")) | |
47 | .file( | |
48 | "src/main.rs", | |
49 | r#" | |
50 | fn main() { | |
51 | let args: Vec<_> = ::std::env::args().skip(1).collect(); | |
52 | println!("{}", args.join(" ")); | |
53 | } | |
54 | "#, | |
55 | ) | |
56 | .build(); | |
57 | p.cargo("build").run(); | |
58 | p | |
59 | } |