diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/tools/src/main.rs | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 4a1b2ff9a..0c3339685 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -5,6 +5,7 @@ use tools::{ | |||
5 | generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, | 5 | generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, |
6 | Overwrite, Result, run_fuzzer, | 6 | Overwrite, Result, run_fuzzer, |
7 | }; | 7 | }; |
8 | use std::{path::{PathBuf}, env}; | ||
8 | 9 | ||
9 | fn main() -> Result<()> { | 10 | fn main() -> Result<()> { |
10 | let matches = App::new("tasks") | 11 | let matches = App::new("tasks") |
@@ -17,7 +18,12 @@ fn main() -> Result<()> { | |||
17 | .subcommand(SubCommand::with_name("fuzz-tests")) | 18 | .subcommand(SubCommand::with_name("fuzz-tests")) |
18 | .get_matches(); | 19 | .get_matches(); |
19 | match matches.subcommand_name().expect("Subcommand must be specified") { | 20 | match matches.subcommand_name().expect("Subcommand must be specified") { |
20 | "install-code" => install_code_extension()?, | 21 | "install-code" => { |
22 | if cfg!(target_os = "macos") { | ||
23 | fix_path_for_mac()?; | ||
24 | } | ||
25 | install_code_extension()?; | ||
26 | } | ||
21 | "gen-tests" => gen_tests(Overwrite)?, | 27 | "gen-tests" => gen_tests(Overwrite)?, |
22 | "gen-syntax" => generate(Overwrite)?, | 28 | "gen-syntax" => generate(Overwrite)?, |
23 | "format" => run_rustfmt(Overwrite)?, | 29 | "format" => run_rustfmt(Overwrite)?, |
@@ -63,3 +69,36 @@ fn verify_installed_extensions() -> Result<()> { | |||
63 | } | 69 | } |
64 | Ok(()) | 70 | Ok(()) |
65 | } | 71 | } |
72 | |||
73 | fn fix_path_for_mac() -> Result<()> { | ||
74 | let mut vscode_path: Vec<PathBuf> = { | ||
75 | const COMMON_APP_PATH: &str = | ||
76 | r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin"; | ||
77 | const ROOT_DIR: &str = ""; | ||
78 | let home_dir = match env::var("HOME") { | ||
79 | Ok(home) => home, | ||
80 | Err(e) => bail!("Failed getting HOME from environment with error: {}.", e), | ||
81 | }; | ||
82 | |||
83 | [ROOT_DIR, &home_dir] | ||
84 | .iter() | ||
85 | .map(|dir| String::from(dir.clone()) + COMMON_APP_PATH) | ||
86 | .map(PathBuf::from) | ||
87 | .filter(|path| path.exists()) | ||
88 | .collect() | ||
89 | }; | ||
90 | |||
91 | if !vscode_path.is_empty() { | ||
92 | let vars = match env::var_os("PATH") { | ||
93 | Some(path) => path, | ||
94 | None => bail!("Could not get PATH variable from env."), | ||
95 | }; | ||
96 | |||
97 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | ||
98 | paths.append(&mut vscode_path); | ||
99 | let new_paths = env::join_paths(paths)?; | ||
100 | env::set_var("PATH", &new_paths); | ||
101 | } | ||
102 | |||
103 | Ok(()) | ||
104 | } | ||