diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-18 19:26:45 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-18 19:26:45 +0000 |
commit | 7fc35d391c76aed4defc8600e75215845afa66b7 (patch) | |
tree | ccae2a9b37df57da996157d54113d2357edb8da3 /crates | |
parent | 132b207a228d0c588b08bbfffd53002b46521a1e (diff) | |
parent | 69edc10f3529add3de65b62a7304d3fc258c7a62 (diff) |
Merge #993
993: Fix installing vscode extension on MacOS r=matklad a=funkill
VSCode often installed in MacOS as `Visual Studio Code.app` package and `code` binary located at `Contents/Resources/app/bin` in package. This path not exists in `$PATH` variable and we can't run `code`.
In previous version of `do_run` function all before space was command and all after - arguments. If path or command has spaces, extracting command breaks. To fix this i extracted command to separated argument of function.
All packages can be placed in system app dir (`/Applications`) or user app dir (`~/Applications`). I created helper function for find app in this directories.
Co-authored-by: funkill2 <[email protected]>
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 | } | ||