aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/dist.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-10-16 18:46:03 +0100
committerAleksey Kladov <[email protected]>2020-10-17 01:42:42 +0100
commit49a90d4c31148a6533d9ee9a288f42b454b2f421 (patch)
treecf93fa6a4f3d18e8be27acf56ee85927fd6f66c7 /xtask/src/dist.rs
parentf0412da4a2c06e50030d13e37002d0440fc7cded (diff)
Switch from not_bash to xshell
Diffstat (limited to 'xtask/src/dist.rs')
-rw-r--r--xtask/src/dist.rs33
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 @@
1use flate2::{write::GzEncoder, Compression};
2use std::{ 1use std::{
3 env, 2 env,
4 fs::File, 3 fs::File,
@@ -7,11 +6,10 @@ use std::{
7}; 6};
8 7
9use anyhow::Result; 8use anyhow::Result;
9use flate2::{write::GzEncoder, Compression};
10use xshell::{cmd, cp, mkdir_p, pushd, read_file, rm_rf, write_file};
10 11
11use crate::{ 12use crate::{date_iso, project_root};
12 not_bash::{date_iso, fs2, pushd, rm_rf, run},
13 project_root,
14};
15 13
16pub struct DistCmd { 14pub 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
36fn dist_client(version: &str, release_tag: &str) -> Result<()> { 34fn 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
62fn dist_server() -> Result<()> { 60fn 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 {
105impl Patch { 99impl 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
123impl Drop for Patch { 118impl 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}