diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/install.rs | 26 | ||||
-rw-r--r-- | xtask/src/not_bash.rs | 27 |
2 files changed, 35 insertions, 18 deletions
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index f89c939b5..540a66130 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -1,11 +1,10 @@ | |||
1 | //! Installs rust-analyzer language server and/or editor plugin. | 1 | //! Installs rust-analyzer language server and/or editor plugin. |
2 | 2 | ||
3 | use std::{env, fs, path::PathBuf, str}; | 3 | use std::{env, path::PathBuf, str}; |
4 | 4 | ||
5 | use anyhow::{bail, format_err, Context, Result}; | 5 | use anyhow::{bail, format_err, Context, Result}; |
6 | use walkdir::WalkDir; | ||
7 | 6 | ||
8 | use crate::not_bash::{pushd, run}; | 7 | use crate::not_bash::{ls, pushd, rm, run}; |
9 | 8 | ||
10 | // Latest stable, feel free to send a PR if this lags behind. | 9 | // Latest stable, feel free to send a PR if this lags behind. |
11 | const REQUIRED_RUST_VERSION: u32 = 41; | 10 | const REQUIRED_RUST_VERSION: u32 = 41; |
@@ -85,15 +84,6 @@ fn fix_path_for_mac() -> Result<()> { | |||
85 | fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | 84 | fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { |
86 | let _dir = pushd("./editors/code"); | 85 | let _dir = pushd("./editors/code"); |
87 | 86 | ||
88 | let list_vsixes = || { | ||
89 | WalkDir::new("./editors/code") | ||
90 | .max_depth(1) | ||
91 | .into_iter() | ||
92 | .map(|it| it.unwrap()) | ||
93 | .map(|it| it.path().to_owned()) | ||
94 | .filter(|it| it.file_name().unwrap_or_default().to_string_lossy().ends_with(".vsix")) | ||
95 | }; | ||
96 | |||
97 | let find_code = |f: fn(&str) -> bool| -> Result<&'static str> { | 87 | let find_code = |f: fn(&str) -> bool| -> Result<&'static str> { |
98 | ["code", "code-insiders", "codium", "code-oss"] | 88 | ["code", "code-insiders", "codium", "code-oss"] |
99 | .iter() | 89 | .iter() |
@@ -110,13 +100,13 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
110 | run!("npm install")?; | 100 | run!("npm install")?; |
111 | 101 | ||
112 | let vsix_pkg = { | 102 | let vsix_pkg = { |
113 | list_vsixes().try_for_each(fs::remove_file)?; | 103 | rm("*.vsix")?; |
114 | run!("npm run package --scripts-prepend-node-path")?; | 104 | run!("npm run package --scripts-prepend-node-path")?; |
115 | list_vsixes().next().unwrap().file_name().unwrap().to_string_lossy().to_string() | 105 | ls("*.vsix")?.pop().unwrap() |
116 | }; | 106 | }; |
117 | 107 | ||
118 | let code = find_code(|bin| run!("{} --version", bin).is_ok())?; | 108 | let code = find_code(|bin| run!("{} --version", bin).is_ok())?; |
119 | run!("{} --install-extension ./{} --force", code, vsix_pkg)?; | 109 | run!("{} --install-extension {} --force", code, vsix_pkg.display())?; |
120 | installed_extensions = run!("{} --list-extensions", code; echo = false)?; | 110 | installed_extensions = run!("{} --list-extensions", code; echo = false)?; |
121 | } else { | 111 | } else { |
122 | run!("cmd.exe /c npm --version") | 112 | run!("cmd.exe /c npm --version") |
@@ -124,13 +114,13 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
124 | run!("cmd.exe /c npm install")?; | 114 | run!("cmd.exe /c npm install")?; |
125 | 115 | ||
126 | let vsix_pkg = { | 116 | let vsix_pkg = { |
127 | list_vsixes().try_for_each(fs::remove_file)?; | 117 | rm("*.vsix")?; |
128 | run!("cmd.exe /c npm run package")?; | 118 | run!("cmd.exe /c npm run package")?; |
129 | list_vsixes().next().unwrap().file_name().unwrap().to_string_lossy().to_string() | 119 | ls("*.vsix")?.pop().unwrap() |
130 | }; | 120 | }; |
131 | 121 | ||
132 | let code = find_code(|bin| run!("cmd.exe /c {}.cmd --version", bin).is_ok())?; | 122 | let code = find_code(|bin| run!("cmd.exe /c {}.cmd --version", bin).is_ok())?; |
133 | run!(r"cmd.exe /c {}.cmd --install-extension ./{} --force", code, vsix_pkg)?; | 123 | run!(r"cmd.exe /c {}.cmd --install-extension {} --force", code, vsix_pkg.display())?; |
134 | installed_extensions = run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?; | 124 | installed_extensions = run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?; |
135 | } | 125 | } |
136 | 126 | ||
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index a2e47c7af..4ec1efa73 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs | |||
@@ -2,6 +2,8 @@ | |||
2 | use std::{ | 2 | use std::{ |
3 | cell::RefCell, | 3 | cell::RefCell, |
4 | env, | 4 | env, |
5 | ffi::OsStr, | ||
6 | fs, | ||
5 | path::PathBuf, | 7 | path::PathBuf, |
6 | process::{Command, Stdio}, | 8 | process::{Command, Stdio}, |
7 | }; | 9 | }; |
@@ -33,6 +35,31 @@ impl Drop for Pushd { | |||
33 | } | 35 | } |
34 | } | 36 | } |
35 | 37 | ||
38 | pub fn rm(glob: &str) -> Result<()> { | ||
39 | let cwd = Env::with(|env| env.cwd()); | ||
40 | ls(glob)?.into_iter().try_for_each(|it| fs::remove_file(cwd.join(it)))?; | ||
41 | Ok(()) | ||
42 | } | ||
43 | |||
44 | pub fn ls(glob: &str) -> Result<Vec<PathBuf>> { | ||
45 | let cwd = Env::with(|env| env.cwd()); | ||
46 | let mut res = Vec::new(); | ||
47 | for entry in fs::read_dir(&cwd)? { | ||
48 | let entry = entry?; | ||
49 | if matches(&entry.file_name(), glob) { | ||
50 | let path = entry.path(); | ||
51 | let path = path.strip_prefix(&cwd).unwrap(); | ||
52 | res.push(path.to_path_buf()) | ||
53 | } | ||
54 | } | ||
55 | return Ok(res); | ||
56 | |||
57 | fn matches(file_name: &OsStr, glob: &str) -> bool { | ||
58 | assert!(glob.starts_with('*')); | ||
59 | file_name.to_string_lossy().ends_with(&glob[1..]) | ||
60 | } | ||
61 | } | ||
62 | |||
36 | #[doc(hidden)] | 63 | #[doc(hidden)] |
37 | pub fn run_process(cmd: String, echo: bool) -> Result<String> { | 64 | pub fn run_process(cmd: String, echo: bool) -> Result<String> { |
38 | run_process_inner(&cmd, echo).with_context(|| format!("process `{}` failed", cmd)) | 65 | run_process_inner(&cmd, echo).with_context(|| format!("process `{}` failed", cmd)) |