aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/install.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-14 14:59:19 +0000
committerAleksey Kladov <[email protected]>2020-02-14 15:47:09 +0000
commitce29497e4324d3e2f2c7c696a212672dbdb46884 (patch)
treed75fa5d9994ec174371a16b1d42720833ecda85c /xtask/src/install.rs
parentbd3a41cc33a25491c19468aaf24dbba4b467edaf (diff)
Replace Cmd with not-bash
Diffstat (limited to 'xtask/src/install.rs')
-rw-r--r--xtask/src/install.rs109
1 files changed, 44 insertions, 65 deletions
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index 9bddc8d7f..f89c939b5 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -5,7 +5,7 @@ use std::{env, fs, path::PathBuf, str};
5use anyhow::{bail, format_err, Context, Result}; 5use anyhow::{bail, format_err, Context, Result};
6use walkdir::WalkDir; 6use walkdir::WalkDir;
7 7
8use crate::cmd::{run, run_with_output, Cmd}; 8use crate::not_bash::{pushd, run};
9 9
10// Latest stable, feel free to send a PR if this lags behind. 10// Latest stable, feel free to send a PR if this lags behind.
11const REQUIRED_RUST_VERSION: u32 = 41; 11const REQUIRED_RUST_VERSION: u32 = 41;
@@ -83,21 +83,9 @@ fn fix_path_for_mac() -> Result<()> {
83} 83}
84 84
85fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { 85fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
86 let npm_version = Cmd { 86 let _dir = pushd("./editors/code");
87 unix: r"npm --version",
88 windows: r"cmd.exe /c npm --version",
89 work_dir: "./editors/code",
90 }
91 .run();
92
93 if npm_version.is_err() {
94 bail!("`npm --version` failed, `npm` is required to build the VS Code plugin")
95 }
96 87
97 Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" } 88 let list_vsixes = || {
98 .run()?;
99
100 let vsixes = || {
101 WalkDir::new("./editors/code") 89 WalkDir::new("./editors/code")
102 .max_depth(1) 90 .max_depth(1)
103 .into_iter() 91 .into_iter()
@@ -106,50 +94,45 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
106 .filter(|it| it.file_name().unwrap_or_default().to_string_lossy().ends_with(".vsix")) 94 .filter(|it| it.file_name().unwrap_or_default().to_string_lossy().ends_with(".vsix"))
107 }; 95 };
108 96
109 for path in vsixes() { 97 let find_code = |f: fn(&str) -> bool| -> Result<&'static str> {
110 fs::remove_file(path)? 98 ["code", "code-insiders", "codium", "code-oss"]
111 } 99 .iter()
100 .copied()
101 .find(|bin| f(bin))
102 .ok_or_else(|| {
103 format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
104 })
105 };
112 106
113 Cmd { 107 let installed_extensions;
114 unix: r"npm run package --scripts-prepend-node-path", 108 if cfg!(unix) {
115 windows: r"cmd.exe /c npm run package", 109 run!("npm --version").context("`npm` is required to build the VS Code plugin")?;
116 work_dir: "./editors/code", 110 run!("npm install")?;
117 }
118 .run()?;
119
120 let extension = vsixes().next().unwrap().file_name().unwrap().to_string_lossy().to_string();
121
122 let code_binary = ["code", "code-insiders", "codium", "code-oss"]
123 .iter()
124 .find(|bin| {
125 Cmd {
126 unix: &format!("{} --version", bin),
127 windows: &format!("cmd.exe /c {}.cmd --version", bin),
128 work_dir: "./editors/code",
129 }
130 .run()
131 .is_ok()
132 })
133 .ok_or_else(|| {
134 format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
135 })?;
136
137 Cmd {
138 unix: &format!(r"{} --install-extension ./{} --force", code_binary, extension),
139 windows: &format!(
140 r"cmd.exe /c {}.cmd --install-extension ./{} --force",
141 code_binary, extension
142 ),
143 work_dir: "./editors/code",
144 }
145 .run()?;
146 111
147 let installed_extensions = Cmd { 112 let vsix_pkg = {
148 unix: &format!(r"{} --list-extensions", code_binary), 113 list_vsixes().try_for_each(fs::remove_file)?;
149 windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary), 114 run!("npm run package --scripts-prepend-node-path")?;
150 work_dir: ".", 115 list_vsixes().next().unwrap().file_name().unwrap().to_string_lossy().to_string()
116 };
117
118 let code = find_code(|bin| run!("{} --version", bin).is_ok())?;
119 run!("{} --install-extension ./{} --force", code, vsix_pkg)?;
120 installed_extensions = run!("{} --list-extensions", code; echo = false)?;
121 } else {
122 run!("cmd.exe /c npm --version")
123 .context("`npm` is required to build the VS Code plugin")?;
124 run!("cmd.exe /c npm install")?;
125
126 let vsix_pkg = {
127 list_vsixes().try_for_each(fs::remove_file)?;
128 run!("cmd.exe /c npm run package")?;
129 list_vsixes().next().unwrap().file_name().unwrap().to_string_lossy().to_string()
130 };
131
132 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)?;
134 installed_extensions = run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?;
151 } 135 }
152 .run_with_output()?;
153 136
154 if !installed_extensions.contains("rust-analyzer") { 137 if !installed_extensions.contains("rust-analyzer") {
155 bail!( 138 bail!(
@@ -163,8 +146,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
163 146
164fn install_server(opts: ServerOpt) -> Result<()> { 147fn install_server(opts: ServerOpt) -> Result<()> {
165 let mut old_rust = false; 148 let mut old_rust = false;
166 if let Ok(stdout) = run_with_output("cargo --version", ".") { 149 if let Ok(stdout) = run!("cargo --version") {
167 println!("{}", stdout);
168 if !check_version(&stdout, REQUIRED_RUST_VERSION) { 150 if !check_version(&stdout, REQUIRED_RUST_VERSION) {
169 old_rust = true; 151 old_rust = true;
170 } 152 }
@@ -177,20 +159,17 @@ fn install_server(opts: ServerOpt) -> Result<()> {
177 ) 159 )
178 } 160 }
179 161
180 let res = if opts.jemalloc { 162 let jemalloc = if opts.jemalloc { "--features jemalloc" } else { "" };
181 run("cargo install --path crates/ra_lsp_server --locked --force --features jemalloc", ".") 163 let res = run!("cargo install --path crates/ra_lsp_server --locked --force {}", jemalloc);
182 } else {
183 run("cargo install --path crates/ra_lsp_server --locked --force", ".")
184 };
185 164
186 if res.is_err() && old_rust { 165 if res.is_err() && old_rust {
187 eprintln!( 166 eprintln!(
188 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", 167 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
189 REQUIRED_RUST_VERSION, 168 REQUIRED_RUST_VERSION,
190 ) 169 );
191 } 170 }
192 171
193 res 172 res.map(drop)
194} 173}
195 174
196fn check_version(version_output: &str, min_minor_version: u32) -> bool { 175fn check_version(version_output: &str, min_minor_version: u32) -> bool {