2020-03-04 17:36:16 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
use crate::{
|
2020-03-05 10:15:55 +00:00
|
|
|
not_bash::{fs2, pushd, rm_rf, run},
|
2020-03-04 17:36:16 +00:00
|
|
|
project_root,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn run_dist(nightly: bool) -> Result<()> {
|
|
|
|
let dist = project_root().join("dist");
|
|
|
|
rm_rf(&dist)?;
|
|
|
|
fs2::create_dir_all(&dist)?;
|
|
|
|
|
|
|
|
if cfg!(target_os = "linux") {
|
|
|
|
dist_client(nightly)?;
|
|
|
|
}
|
|
|
|
dist_server()?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dist_client(nightly: bool) -> Result<()> {
|
|
|
|
let _d = pushd("./editors/code");
|
|
|
|
|
2020-03-05 10:15:55 +00:00
|
|
|
let package_json_path = PathBuf::from("./package.json");
|
2020-03-18 12:23:44 +00:00
|
|
|
let mut patch = Patch::new(package_json_path.clone())?;
|
2020-03-04 17:36:16 +00:00
|
|
|
|
2020-03-09 13:20:40 +00:00
|
|
|
let date = run!("date --utc +%Y%m%d")?;
|
|
|
|
let version_suffix = if nightly { "-nightly" } else { "" };
|
|
|
|
|
2020-03-18 12:23:44 +00:00
|
|
|
patch.replace(
|
2020-03-16 12:39:13 +00:00
|
|
|
r#""version": "0.2.20200309-nightly""#,
|
2020-03-09 13:20:40 +00:00
|
|
|
&format!(r#""version": "0.1.{}{}""#, date, version_suffix),
|
|
|
|
);
|
2020-03-04 17:36:16 +00:00
|
|
|
|
|
|
|
if nightly {
|
2020-03-18 12:23:44 +00:00
|
|
|
patch.replace(
|
2020-03-04 20:35:31 +00:00
|
|
|
r#""displayName": "rust-analyzer""#,
|
2020-03-18 12:23:44 +00:00
|
|
|
r#""displayName": "rust-analyzer (nightly)""#,
|
2020-03-04 20:35:31 +00:00
|
|
|
);
|
2020-03-04 17:36:16 +00:00
|
|
|
}
|
2020-03-18 12:23:44 +00:00
|
|
|
if !nightly {
|
|
|
|
patch.replace(r#""enableProposedApi": true,"#, r#""#);
|
|
|
|
}
|
|
|
|
patch.commit()?;
|
2020-03-04 17:36:16 +00:00
|
|
|
|
2020-03-05 10:11:47 +00:00
|
|
|
run!("npm ci")?;
|
2020-03-04 17:36:16 +00: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 11:35:31 +00:00
|
|
|
run!(
|
|
|
|
"cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release
|
|
|
|
--target x86_64-unknown-linux-musl
|
2020-03-09 12:55:14 +00:00
|
|
|
"
|
|
|
|
// We'd want to add, but that requires setting the right linker somehow
|
|
|
|
// --features=jemalloc
|
2020-03-09 11:35:31 +00:00
|
|
|
)?;
|
2020-03-04 17:36:16 +00:00
|
|
|
run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?;
|
|
|
|
} else {
|
2020-03-09 11:35:31 +00:00
|
|
|
run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?;
|
2020-03-04 17:36:16 +00: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 10:55:34 +00:00
|
|
|
("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe")
|
2020-03-04 17:36:16 +00:00
|
|
|
} else if cfg!(target_os = "macos") {
|
2020-03-05 10:55:34 +00:00
|
|
|
("./target/release/rust-analyzer", "./dist/rust-analyzer-mac")
|
2020-03-04 17:36:16 +00:00
|
|
|
} else {
|
|
|
|
panic!("Unsupported OS")
|
|
|
|
};
|
|
|
|
|
|
|
|
fs2::copy(src, dst)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-03-18 12:23:44 +00:00
|
|
|
struct Patch {
|
2020-03-04 17:36:16 +00:00
|
|
|
path: PathBuf,
|
2020-03-18 12:23:44 +00:00
|
|
|
original_contents: String,
|
2020-03-04 17:36:16 +00:00
|
|
|
contents: String,
|
|
|
|
}
|
|
|
|
|
2020-03-18 12:23:44 +00:00
|
|
|
impl Patch {
|
|
|
|
fn new(path: PathBuf) -> Result<Patch> {
|
|
|
|
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 17:36:16 +00:00
|
|
|
fn drop(&mut self) {
|
2020-03-18 12:23:44 +00:00
|
|
|
fs2::write(&self.path, &self.original_contents).unwrap();
|
2020-03-04 17:36:16 +00:00
|
|
|
}
|
|
|
|
}
|