diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/install.rs | 6 | ||||
-rw-r--r-- | xtask/src/lib.rs | 41 | ||||
-rw-r--r-- | xtask/src/main.rs | 14 | ||||
-rw-r--r-- | xtask/src/not_bash.rs | 17 |
4 files changed, 68 insertions, 10 deletions
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index f76467cac..d0d745b05 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -4,10 +4,7 @@ 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 | 6 | ||
7 | use crate::{ | 7 | use crate::not_bash::{pushd, run}; |
8 | not_bash::{pushd, run}, | ||
9 | project_root, | ||
10 | }; | ||
11 | 8 | ||
12 | // 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. |
13 | const REQUIRED_RUST_VERSION: u32 = 41; | 10 | const REQUIRED_RUST_VERSION: u32 = 41; |
@@ -27,7 +24,6 @@ pub struct ServerOpt { | |||
27 | 24 | ||
28 | impl InstallCmd { | 25 | impl InstallCmd { |
29 | pub fn run(self) -> Result<()> { | 26 | pub fn run(self) -> Result<()> { |
30 | let _dir = pushd(project_root()); | ||
31 | let both = self.server.is_some() && self.client.is_some(); | 27 | let both = self.server.is_some() && self.client.is_some(); |
32 | if cfg!(target_os = "macos") { | 28 | if cfg!(target_os = "macos") { |
33 | fix_path_for_mac().context("Fix path for mac")? | 29 | fix_path_for_mac().context("Fix path for mac")? |
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index f48045d17..adbee10ee 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -19,7 +19,7 @@ use std::{ | |||
19 | 19 | ||
20 | use crate::{ | 20 | use crate::{ |
21 | codegen::Mode, | 21 | codegen::Mode, |
22 | not_bash::{fs2, pushd, rm_rf, run}, | 22 | not_bash::{fs2, pushd, pwd, rm_rf, run}, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | pub use anyhow::Result; | 25 | pub use anyhow::Result; |
@@ -206,3 +206,42 @@ Release: release:{}[] | |||
206 | fn is_release_tag(tag: &str) -> bool { | 206 | fn is_release_tag(tag: &str) -> bool { |
207 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) | 207 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) |
208 | } | 208 | } |
209 | |||
210 | pub fn run_dist(nightly: bool) -> Result<()> { | ||
211 | let dist = project_root().join("dist"); | ||
212 | rm_rf(&dist)?; | ||
213 | fs2::create_dir_all(&dist)?; | ||
214 | |||
215 | let _d = pushd("./editors/code"); | ||
216 | |||
217 | let package_json_path = pwd().join("package.json"); | ||
218 | let original_package_json = fs2::read_to_string(&package_json_path)?; | ||
219 | let _restore = | ||
220 | Restore { path: package_json_path.clone(), contents: original_package_json.clone() }; | ||
221 | |||
222 | let mut package_json = original_package_json.replace(r#""enableProposedApi": true,"#, r#""#); | ||
223 | |||
224 | if nightly { | ||
225 | package_json = package_json | ||
226 | .replace(r#""name": "rust-analyzer""#, r#""name": "rust-analyzer-nightly""#) | ||
227 | .replace( | ||
228 | r#""displayName": "rust-analyzer""#, | ||
229 | r#""displayName": "rust-analyzer nightly""#, | ||
230 | ); | ||
231 | } | ||
232 | fs2::write(package_json_path, package_json)?; | ||
233 | |||
234 | run!("npx vsce package -o {}/rust-analyzer.vsix", dist.display())?; | ||
235 | Ok(()) | ||
236 | } | ||
237 | |||
238 | struct Restore { | ||
239 | path: PathBuf, | ||
240 | contents: String, | ||
241 | } | ||
242 | |||
243 | impl Drop for Restore { | ||
244 | fn drop(&mut self) { | ||
245 | fs2::write(&self.path, &self.contents).unwrap(); | ||
246 | } | ||
247 | } | ||
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index a7dffe2cc..17a2f1c68 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -14,7 +14,9 @@ use pico_args::Arguments; | |||
14 | use xtask::{ | 14 | use xtask::{ |
15 | codegen::{self, Mode}, | 15 | codegen::{self, Mode}, |
16 | install::{ClientOpt, InstallCmd, ServerOpt}, | 16 | install::{ClientOpt, InstallCmd, ServerOpt}, |
17 | pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, Result, | 17 | not_bash::pushd, |
18 | pre_commit, project_root, run_clippy, run_dist, run_fuzzer, run_pre_cache, run_release, | ||
19 | run_rustfmt, Result, | ||
18 | }; | 20 | }; |
19 | 21 | ||
20 | fn main() -> Result<()> { | 22 | fn main() -> Result<()> { |
@@ -22,6 +24,8 @@ fn main() -> Result<()> { | |||
22 | return pre_commit::run_hook(); | 24 | return pre_commit::run_hook(); |
23 | } | 25 | } |
24 | 26 | ||
27 | let _d = pushd(project_root()); | ||
28 | |||
25 | let mut args = Arguments::from_env(); | 29 | let mut args = Arguments::from_env(); |
26 | let subcommand = args.subcommand()?.unwrap_or_default(); | 30 | let subcommand = args.subcommand()?.unwrap_or_default(); |
27 | 31 | ||
@@ -97,6 +101,11 @@ FLAGS: | |||
97 | args.finish()?; | 101 | args.finish()?; |
98 | run_release(dry_run) | 102 | run_release(dry_run) |
99 | } | 103 | } |
104 | "dist" => { | ||
105 | let nightly = args.contains("--nightly"); | ||
106 | args.finish()?; | ||
107 | run_dist(nightly) | ||
108 | } | ||
100 | _ => { | 109 | _ => { |
101 | eprintln!( | 110 | eprintln!( |
102 | "\ | 111 | "\ |
@@ -112,7 +121,8 @@ SUBCOMMANDS: | |||
112 | fuzz-tests | 121 | fuzz-tests |
113 | codegen | 122 | codegen |
114 | install | 123 | install |
115 | lint" | 124 | lint |
125 | dist" | ||
116 | ); | 126 | ); |
117 | Ok(()) | 127 | Ok(()) |
118 | } | 128 | } |
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 40f706d9f..1697b7fcd 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs | |||
@@ -19,6 +19,11 @@ pub mod fs2 { | |||
19 | fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display())) | 19 | fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display())) |
20 | } | 20 | } |
21 | 21 | ||
22 | pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> { | ||
23 | let path = path.as_ref(); | ||
24 | fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display())) | ||
25 | } | ||
26 | |||
22 | pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { | 27 | pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { |
23 | let path = path.as_ref(); | 28 | let path = path.as_ref(); |
24 | fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display())) | 29 | fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display())) |
@@ -40,6 +45,11 @@ pub mod fs2 { | |||
40 | let path = path.as_ref(); | 45 | let path = path.as_ref(); |
41 | fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) | 46 | fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) |
42 | } | 47 | } |
48 | |||
49 | pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> { | ||
50 | let path = path.as_ref(); | ||
51 | fs::create_dir_all(path).with_context(|| format!("Failed to create dir {}", path.display())) | ||
52 | } | ||
43 | } | 53 | } |
44 | 54 | ||
45 | macro_rules! _run { | 55 | macro_rules! _run { |
@@ -61,6 +71,10 @@ pub fn pushd(path: impl Into<PathBuf>) -> Pushd { | |||
61 | Pushd { _p: () } | 71 | Pushd { _p: () } |
62 | } | 72 | } |
63 | 73 | ||
74 | pub fn pwd() -> PathBuf { | ||
75 | Env::with(|env| env.cwd()) | ||
76 | } | ||
77 | |||
64 | impl Drop for Pushd { | 78 | impl Drop for Pushd { |
65 | fn drop(&mut self) { | 79 | fn drop(&mut self) { |
66 | Env::with(|env| env.popd()) | 80 | Env::with(|env| env.popd()) |
@@ -85,7 +99,6 @@ pub fn run_process(cmd: String, echo: bool) -> Result<String> { | |||
85 | } | 99 | } |
86 | 100 | ||
87 | fn run_process_inner(cmd: &str, echo: bool) -> Result<String> { | 101 | fn run_process_inner(cmd: &str, echo: bool) -> Result<String> { |
88 | let cwd = Env::with(|env| env.cwd()); | ||
89 | let mut args = shelx(cmd); | 102 | let mut args = shelx(cmd); |
90 | let binary = args.remove(0); | 103 | let binary = args.remove(0); |
91 | 104 | ||
@@ -95,7 +108,7 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result<String> { | |||
95 | 108 | ||
96 | let output = Command::new(binary) | 109 | let output = Command::new(binary) |
97 | .args(args) | 110 | .args(args) |
98 | .current_dir(cwd) | 111 | .current_dir(pwd()) |
99 | .stdin(Stdio::null()) | 112 | .stdin(Stdio::null()) |
100 | .stderr(Stdio::inherit()) | 113 | .stderr(Stdio::inherit()) |
101 | .output()?; | 114 | .output()?; |