2020-03-04 11:36:16 -06:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
use crate::{
|
2020-03-05 04:15:55 -06:00
|
|
|
not_bash::{fs2, pushd, rm_rf, run},
|
2020-03-04 11:36:16 -06:00
|
|
|
project_root,
|
|
|
|
};
|
|
|
|
|
2020-03-23 08:33:44 -05:00
|
|
|
pub struct ClientOpts {
|
|
|
|
pub version: String,
|
|
|
|
pub release_tag: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn run_dist(client_opts: Option<ClientOpts>) -> Result<()> {
|
2020-03-04 11:36:16 -06:00
|
|
|
let dist = project_root().join("dist");
|
|
|
|
rm_rf(&dist)?;
|
|
|
|
fs2::create_dir_all(&dist)?;
|
|
|
|
|
2020-03-23 09:20:49 -05:00
|
|
|
if let Some(ClientOpts { version, release_tag }) = client_opts {
|
2020-03-23 08:33:44 -05:00
|
|
|
dist_client(&version, &release_tag)?;
|
2020-03-04 11:36:16 -06:00
|
|
|
}
|
|
|
|
dist_server()?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-03-19 03:32:57 -05:00
|
|
|
fn dist_client(version: &str, release_tag: &str) -> Result<()> {
|
2020-03-04 11:36:16 -06:00
|
|
|
let _d = pushd("./editors/code");
|
2020-03-19 03:32:57 -05:00
|
|
|
let nightly = release_tag == "nightly";
|
2020-03-04 11:36:16 -06:00
|
|
|
|
2020-03-19 03:32:57 -05:00
|
|
|
let mut patch = Patch::new("./package.json")?;
|
2020-03-04 11:36:16 -06:00
|
|
|
|
2020-03-19 03:32:57 -05:00
|
|
|
patch
|
|
|
|
.replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
|
2020-03-20 06:50:50 -05:00
|
|
|
.replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag));
|
2020-03-04 11:36:16 -06:00
|
|
|
|
|
|
|
if nightly {
|
2020-03-18 07:23:44 -05:00
|
|
|
patch.replace(
|
2020-03-04 14:35:31 -06:00
|
|
|
r#""displayName": "rust-analyzer""#,
|
2020-03-18 07:23:44 -05:00
|
|
|
r#""displayName": "rust-analyzer (nightly)""#,
|
2020-03-04 14:35:31 -06:00
|
|
|
);
|
2020-03-04 11:36:16 -06:00
|
|
|
}
|
2020-03-18 07:23:44 -05:00
|
|
|
if !nightly {
|
|
|
|
patch.replace(r#""enableProposedApi": true,"#, r#""#);
|
|
|
|
}
|
|
|
|
patch.commit()?;
|
2020-03-04 11:36:16 -06:00
|
|
|
|
2020-03-05 04:11:47 -06:00
|
|
|
run!("npm ci")?;
|
2020-03-04 11:36:16 -06:00
|
|
|
run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dist_server() -> Result<()> {
|
|
|
|
if cfg!(target_os = "linux") {
|
|
|
|
std::env::set_var("CC", "clang");
|
2020-03-09 06:35:31 -05:00
|
|
|
run!(
|
|
|
|
"cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release
|
|
|
|
--target x86_64-unknown-linux-musl
|
2020-03-09 07:55:14 -05:00
|
|
|
"
|
|
|
|
// We'd want to add, but that requires setting the right linker somehow
|
|
|
|
// --features=jemalloc
|
2020-03-09 06:35:31 -05:00
|
|
|
)?;
|
2020-03-04 11:36:16 -06:00
|
|
|
run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?;
|
|
|
|
} else {
|
2020-03-09 06:35:31 -05:00
|
|
|
run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?;
|
2020-03-04 11:36:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let (src, dst) = if cfg!(target_os = "linux") {
|
|
|
|
("./target/x86_64-unknown-linux-musl/release/rust-analyzer", "./dist/rust-analyzer-linux")
|
|
|
|
} else if cfg!(target_os = "windows") {
|
2020-03-05 04:55:34 -06:00
|
|
|
("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe")
|
2020-03-04 11:36:16 -06:00
|
|
|
} else if cfg!(target_os = "macos") {
|
2020-03-05 04:55:34 -06:00
|
|
|
("./target/release/rust-analyzer", "./dist/rust-analyzer-mac")
|
2020-03-04 11:36:16 -06:00
|
|
|
} else {
|
|
|
|
panic!("Unsupported OS")
|
|
|
|
};
|
|
|
|
|
|
|
|
fs2::copy(src, dst)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-03-18 07:23:44 -05:00
|
|
|
struct Patch {
|
2020-03-04 11:36:16 -06:00
|
|
|
path: PathBuf,
|
2020-03-18 07:23:44 -05:00
|
|
|
original_contents: String,
|
2020-03-04 11:36:16 -06:00
|
|
|
contents: String,
|
|
|
|
}
|
|
|
|
|
2020-03-18 07:23:44 -05:00
|
|
|
impl Patch {
|
2020-03-19 03:32:57 -05:00
|
|
|
fn new(path: impl Into<PathBuf>) -> Result<Patch> {
|
|
|
|
let path = path.into();
|
2020-03-18 07:23:44 -05:00
|
|
|
let contents = fs2::read_to_string(&path)?;
|
|
|
|
Ok(Patch { path, original_contents: contents.clone(), contents })
|
|
|
|
}
|
|
|
|
|
|
|
|
fn replace(&mut self, from: &str, to: &str) -> &mut Patch {
|
|
|
|
assert!(self.contents.contains(from));
|
|
|
|
self.contents = self.contents.replace(from, to);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
fn commit(&self) -> Result<()> {
|
|
|
|
fs2::write(&self.path, &self.contents)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Patch {
|
2020-03-04 11:36:16 -06:00
|
|
|
fn drop(&mut self) {
|
2020-03-18 07:23:44 -05:00
|
|
|
fs2::write(&self.path, &self.original_contents).unwrap();
|
2020-03-04 11:36:16 -06:00
|
|
|
}
|
|
|
|
}
|