diff options
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/dist.rs | 79 | ||||
-rw-r--r-- | xtask/src/install.rs | 6 | ||||
-rw-r--r-- | xtask/src/lib.rs | 2 | ||||
-rw-r--r-- | xtask/src/main.rs | 15 | ||||
-rw-r--r-- | xtask/src/not_bash.rs | 17 |
5 files changed, 109 insertions, 10 deletions
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs new file mode 100644 index 000000000..737751ae8 --- /dev/null +++ b/xtask/src/dist.rs | |||
@@ -0,0 +1,79 @@ | |||
1 | use std::path::PathBuf; | ||
2 | |||
3 | use anyhow::Result; | ||
4 | |||
5 | use crate::{ | ||
6 | not_bash::{fs2, pushd, pwd, rm_rf, run}, | ||
7 | project_root, | ||
8 | }; | ||
9 | |||
10 | pub fn run_dist(nightly: bool) -> Result<()> { | ||
11 | let dist = project_root().join("dist"); | ||
12 | rm_rf(&dist)?; | ||
13 | fs2::create_dir_all(&dist)?; | ||
14 | |||
15 | if cfg!(target_os = "linux") { | ||
16 | dist_client(nightly)?; | ||
17 | } | ||
18 | dist_server()?; | ||
19 | Ok(()) | ||
20 | } | ||
21 | |||
22 | fn dist_client(nightly: bool) -> Result<()> { | ||
23 | let _d = pushd("./editors/code"); | ||
24 | |||
25 | let package_json_path = pwd().join("package.json"); | ||
26 | let original_package_json = fs2::read_to_string(&package_json_path)?; | ||
27 | let _restore = | ||
28 | Restore { path: package_json_path.clone(), contents: original_package_json.clone() }; | ||
29 | |||
30 | let mut package_json = original_package_json.replace(r#""enableProposedApi": true,"#, r#""#); | ||
31 | |||
32 | if nightly { | ||
33 | package_json = package_json.replace( | ||
34 | r#""displayName": "rust-analyzer""#, | ||
35 | r#""displayName": "rust-analyzer nightly""#, | ||
36 | ); | ||
37 | } else { | ||
38 | package_json = original_package_json.replace(r#""enableProposedApi": true,"#, r#""#); | ||
39 | } | ||
40 | fs2::write(package_json_path, package_json)?; | ||
41 | |||
42 | run!("npx vsce package -o ../../dist/rust-analyzer.vsix")?; | ||
43 | Ok(()) | ||
44 | } | ||
45 | |||
46 | fn dist_server() -> Result<()> { | ||
47 | if cfg!(target_os = "linux") { | ||
48 | std::env::set_var("CC", "clang"); | ||
49 | run!("cargo build --package rust-analyzer --bin rust-analyzer --release --target x86_64-unknown-linux-musl")?; | ||
50 | run!("strip ./target/x86_64-unknown-linux-musl/release/rust-analyzer")?; | ||
51 | } else { | ||
52 | run!("cargo build --package rust-analyzer --bin rust-analyzer --release")?; | ||
53 | } | ||
54 | |||
55 | let (src, dst) = if cfg!(target_os = "linux") { | ||
56 | ("./target/x86_64-unknown-linux-musl/release/rust-analyzer", "./dist/rust-analyzer-linux") | ||
57 | } else if cfg!(target_os = "windows") { | ||
58 | ("/target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe") | ||
59 | } else if cfg!(target_os = "macos") { | ||
60 | ("/target/release/rust-analyzer", "./dist/rust-analyzer-mac") | ||
61 | } else { | ||
62 | panic!("Unsupported OS") | ||
63 | }; | ||
64 | |||
65 | fs2::copy(src, dst)?; | ||
66 | |||
67 | Ok(()) | ||
68 | } | ||
69 | |||
70 | struct Restore { | ||
71 | path: PathBuf, | ||
72 | contents: String, | ||
73 | } | ||
74 | |||
75 | impl Drop for Restore { | ||
76 | fn drop(&mut self) { | ||
77 | fs2::write(&self.path, &self.contents).unwrap(); | ||
78 | } | ||
79 | } | ||
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..014b61b37 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | pub mod not_bash; | 5 | pub mod not_bash; |
6 | pub mod install; | 6 | pub mod install; |
7 | pub mod dist; | ||
7 | pub mod pre_commit; | 8 | pub mod pre_commit; |
8 | 9 | ||
9 | pub mod codegen; | 10 | pub mod codegen; |
@@ -90,7 +91,6 @@ pub fn run_clippy() -> Result<()> { | |||
90 | 91 | ||
91 | let allowed_lints = [ | 92 | let allowed_lints = [ |
92 | "clippy::collapsible_if", | 93 | "clippy::collapsible_if", |
93 | "clippy::map_clone", // FIXME: remove when Iterator::copied stabilizes (1.36.0) | ||
94 | "clippy::needless_pass_by_value", | 94 | "clippy::needless_pass_by_value", |
95 | "clippy::nonminimal_bool", | 95 | "clippy::nonminimal_bool", |
96 | "clippy::redundant_pattern_matching", | 96 | "clippy::redundant_pattern_matching", |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index a7dffe2cc..7c8ea9001 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -13,8 +13,11 @@ use std::env; | |||
13 | use pico_args::Arguments; | 13 | use pico_args::Arguments; |
14 | use xtask::{ | 14 | use xtask::{ |
15 | codegen::{self, Mode}, | 15 | codegen::{self, Mode}, |
16 | dist::run_dist, | ||
16 | install::{ClientOpt, InstallCmd, ServerOpt}, | 17 | install::{ClientOpt, InstallCmd, ServerOpt}, |
17 | pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, Result, | 18 | not_bash::pushd, |
19 | pre_commit, project_root, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, | ||
20 | Result, | ||
18 | }; | 21 | }; |
19 | 22 | ||
20 | fn main() -> Result<()> { | 23 | fn main() -> Result<()> { |
@@ -22,6 +25,8 @@ fn main() -> Result<()> { | |||
22 | return pre_commit::run_hook(); | 25 | return pre_commit::run_hook(); |
23 | } | 26 | } |
24 | 27 | ||
28 | let _d = pushd(project_root()); | ||
29 | |||
25 | let mut args = Arguments::from_env(); | 30 | let mut args = Arguments::from_env(); |
26 | let subcommand = args.subcommand()?.unwrap_or_default(); | 31 | let subcommand = args.subcommand()?.unwrap_or_default(); |
27 | 32 | ||
@@ -97,6 +102,11 @@ FLAGS: | |||
97 | args.finish()?; | 102 | args.finish()?; |
98 | run_release(dry_run) | 103 | run_release(dry_run) |
99 | } | 104 | } |
105 | "dist" => { | ||
106 | let nightly = args.contains("--nightly"); | ||
107 | args.finish()?; | ||
108 | run_dist(nightly) | ||
109 | } | ||
100 | _ => { | 110 | _ => { |
101 | eprintln!( | 111 | eprintln!( |
102 | "\ | 112 | "\ |
@@ -112,7 +122,8 @@ SUBCOMMANDS: | |||
112 | fuzz-tests | 122 | fuzz-tests |
113 | codegen | 123 | codegen |
114 | install | 124 | install |
115 | lint" | 125 | lint |
126 | dist" | ||
116 | ); | 127 | ); |
117 | Ok(()) | 128 | Ok(()) |
118 | } | 129 | } |
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()?; |