diff options
Diffstat (limited to 'xtask/src/dist.rs')
-rw-r--r-- | xtask/src/dist.rs | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index aa7d94967..9e15a5a4c 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | use flate2::{write::GzEncoder, Compression}; | ||
2 | use std::{ | 1 | use std::{ |
3 | env, | 2 | env, |
4 | fs::File, | 3 | fs::File, |
@@ -7,11 +6,10 @@ use std::{ | |||
7 | }; | 6 | }; |
8 | 7 | ||
9 | use anyhow::Result; | 8 | use anyhow::Result; |
9 | use flate2::{write::GzEncoder, Compression}; | ||
10 | use xshell::{cmd, cp, mkdir_p, pushd, read_file, rm_rf, write_file}; | ||
10 | 11 | ||
11 | use crate::{ | 12 | use crate::{date_iso, project_root}; |
12 | not_bash::{date_iso, fs2, pushd, rm_rf, run}, | ||
13 | project_root, | ||
14 | }; | ||
15 | 13 | ||
16 | pub struct DistCmd { | 14 | pub struct DistCmd { |
17 | pub nightly: bool, | 15 | pub nightly: bool, |
@@ -22,7 +20,7 @@ impl DistCmd { | |||
22 | pub fn run(self) -> Result<()> { | 20 | pub fn run(self) -> Result<()> { |
23 | let dist = project_root().join("dist"); | 21 | let dist = project_root().join("dist"); |
24 | rm_rf(&dist)?; | 22 | rm_rf(&dist)?; |
25 | fs2::create_dir_all(&dist)?; | 23 | mkdir_p(&dist)?; |
26 | 24 | ||
27 | if let Some(version) = self.client_version { | 25 | if let Some(version) = self.client_version { |
28 | let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? }; | 26 | let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? }; |
@@ -34,7 +32,7 @@ impl DistCmd { | |||
34 | } | 32 | } |
35 | 33 | ||
36 | fn dist_client(version: &str, release_tag: &str) -> Result<()> { | 34 | fn dist_client(version: &str, release_tag: &str) -> Result<()> { |
37 | let _d = pushd("./editors/code"); | 35 | let _d = pushd("./editors/code")?; |
38 | let nightly = release_tag == "nightly"; | 36 | let nightly = release_tag == "nightly"; |
39 | 37 | ||
40 | let mut patch = Patch::new("./package.json")?; | 38 | let mut patch = Patch::new("./package.json")?; |
@@ -54,20 +52,16 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> { | |||
54 | } | 52 | } |
55 | patch.commit()?; | 53 | patch.commit()?; |
56 | 54 | ||
57 | run!("npm ci")?; | 55 | cmd!("npm ci").run()?; |
58 | run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?; | 56 | cmd!("npx vsce package -o ../../dist/rust-analyzer.vsix").run()?; |
59 | Ok(()) | 57 | Ok(()) |
60 | } | 58 | } |
61 | 59 | ||
62 | fn dist_server() -> Result<()> { | 60 | fn dist_server() -> Result<()> { |
63 | if cfg!(target_os = "linux") { | 61 | if cfg!(target_os = "linux") { |
64 | env::set_var("CC", "clang"); | 62 | env::set_var("CC", "clang"); |
65 | run!( | ||
66 | "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" | ||
67 | )?; | ||
68 | } else { | ||
69 | run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; | ||
70 | } | 63 | } |
64 | cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release").run()?; | ||
71 | 65 | ||
72 | let (src, dst) = if cfg!(target_os = "linux") { | 66 | let (src, dst) = if cfg!(target_os = "linux") { |
73 | ("./target/release/rust-analyzer", "./dist/rust-analyzer-linux") | 67 | ("./target/release/rust-analyzer", "./dist/rust-analyzer-linux") |
@@ -82,7 +76,7 @@ fn dist_server() -> Result<()> { | |||
82 | let src = Path::new(src); | 76 | let src = Path::new(src); |
83 | let dst = Path::new(dst); | 77 | let dst = Path::new(dst); |
84 | 78 | ||
85 | fs2::copy(&src, &dst)?; | 79 | cp(&src, &dst)?; |
86 | gzip(&src, &dst.with_extension("gz"))?; | 80 | gzip(&src, &dst.with_extension("gz"))?; |
87 | 81 | ||
88 | Ok(()) | 82 | Ok(()) |
@@ -105,7 +99,7 @@ struct Patch { | |||
105 | impl Patch { | 99 | impl Patch { |
106 | fn new(path: impl Into<PathBuf>) -> Result<Patch> { | 100 | fn new(path: impl Into<PathBuf>) -> Result<Patch> { |
107 | let path = path.into(); | 101 | let path = path.into(); |
108 | let contents = fs2::read_to_string(&path)?; | 102 | let contents = read_file(&path)?; |
109 | Ok(Patch { path, original_contents: contents.clone(), contents }) | 103 | Ok(Patch { path, original_contents: contents.clone(), contents }) |
110 | } | 104 | } |
111 | 105 | ||
@@ -115,13 +109,14 @@ impl Patch { | |||
115 | self | 109 | self |
116 | } | 110 | } |
117 | 111 | ||
118 | fn commit(&self) -> io::Result<()> { | 112 | fn commit(&self) -> Result<()> { |
119 | fs2::write(&self.path, &self.contents) | 113 | write_file(&self.path, &self.contents)?; |
114 | Ok(()) | ||
120 | } | 115 | } |
121 | } | 116 | } |
122 | 117 | ||
123 | impl Drop for Patch { | 118 | impl Drop for Patch { |
124 | fn drop(&mut self) { | 119 | fn drop(&mut self) { |
125 | fs2::write(&self.path, &self.original_contents).unwrap(); | 120 | write_file(&self.path, &self.original_contents).unwrap(); |
126 | } | 121 | } |
127 | } | 122 | } |