aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/ast_src.rs8
-rw-r--r--xtask/src/cmd.rs9
-rw-r--r--xtask/src/install.rs36
-rw-r--r--xtask/src/lib.rs46
-rw-r--r--xtask/src/main.rs6
-rw-r--r--xtask/src/pre_commit.rs2
6 files changed, 83 insertions, 24 deletions
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index efe1e795b..2d9ae904b 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -120,6 +120,8 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
120 "FOR_TYPE", 120 "FOR_TYPE",
121 "IMPL_TRAIT_TYPE", 121 "IMPL_TRAIT_TYPE",
122 "DYN_TRAIT_TYPE", 122 "DYN_TRAIT_TYPE",
123 "OR_PAT",
124 "PAREN_PAT",
123 "REF_PAT", 125 "REF_PAT",
124 "BOX_PAT", 126 "BOX_PAT",
125 "BIND_PAT", 127 "BIND_PAT",
@@ -412,7 +414,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
412 struct MatchExpr { Expr, MatchArmList } 414 struct MatchExpr { Expr, MatchArmList }
413 struct MatchArmList: AttrsOwner { arms: [MatchArm] } 415 struct MatchArmList: AttrsOwner { arms: [MatchArm] }
414 struct MatchArm: AttrsOwner { 416 struct MatchArm: AttrsOwner {
415 pats: [Pat], 417 pat: Pat,
416 guard: MatchGuard, 418 guard: MatchGuard,
417 Expr, 419 Expr,
418 } 420 }
@@ -425,6 +427,8 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
425 } 427 }
426 struct RecordField { NameRef, Expr } 428 struct RecordField { NameRef, Expr }
427 429
430 struct OrPat { pats: [Pat] }
431 struct ParenPat { Pat }
428 struct RefPat { Pat } 432 struct RefPat { Pat }
429 struct BoxPat { Pat } 433 struct BoxPat { Pat }
430 struct BindPat: NameOwner { Pat } 434 struct BindPat: NameOwner { Pat }
@@ -601,6 +605,8 @@ pub(crate) const AST_SRC: AstSrc = AstSrc {
601 } 605 }
602 606
603 enum Pat { 607 enum Pat {
608 OrPat,
609 ParenPat,
604 RefPat, 610 RefPat,
605 BoxPat, 611 BoxPat,
606 BindPat, 612 BindPat,
diff --git a/xtask/src/cmd.rs b/xtask/src/cmd.rs
index 2027f4893..37497fb74 100644
--- a/xtask/src/cmd.rs
+++ b/xtask/src/cmd.rs
@@ -18,7 +18,7 @@ impl Cmd<'_> {
18 run(self.unix, self.work_dir) 18 run(self.unix, self.work_dir)
19 } 19 }
20 } 20 }
21 pub fn run_with_output(self) -> Result<Output> { 21 pub fn run_with_output(self) -> Result<String> {
22 if cfg!(windows) { 22 if cfg!(windows) {
23 run_with_output(self.windows, self.work_dir) 23 run_with_output(self.windows, self.work_dir)
24 } else { 24 } else {
@@ -34,8 +34,11 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> {
34 .map(|_| ()) 34 .map(|_| ())
35} 35}
36 36
37pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> { 37pub fn run_with_output(cmdline: &str, dir: &str) -> Result<String> {
38 do_run(cmdline, dir, &mut |_| {}) 38 let output = do_run(cmdline, dir, &mut |_| {})?;
39 let stdout = String::from_utf8(output.stdout)?;
40 let stdout = stdout.trim().to_string();
41 Ok(stdout)
39} 42}
40 43
41fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> { 44fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> {
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index 8c65b51e3..99e1eddb1 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -24,6 +24,7 @@ pub struct ServerOpt {
24 24
25impl InstallCmd { 25impl InstallCmd {
26 pub fn run(self) -> Result<()> { 26 pub fn run(self) -> Result<()> {
27 let both = self.server.is_some() && self.client.is_some();
27 if cfg!(target_os = "macos") { 28 if cfg!(target_os = "macos") {
28 fix_path_for_mac().context("Fix path for mac")? 29 fix_path_for_mac().context("Fix path for mac")?
29 } 30 }
@@ -33,6 +34,16 @@ impl InstallCmd {
33 if let Some(client) = self.client { 34 if let Some(client) = self.client {
34 install_client(client).context("install client")?; 35 install_client(client).context("install client")?;
35 } 36 }
37 if both {
38 eprintln!(
39 "
40 Installation complete.
41
42 Add `\"rust-analyzer.raLspServerPath\": \"ra_lsp_server\",` to VS Code settings,
43 otherwise it will use the latest release from GitHub.
44"
45 )
46 }
36 Ok(()) 47 Ok(())
37 } 48 }
38} 49}
@@ -116,15 +127,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
116 } 127 }
117 .run()?; 128 .run()?;
118 129
119 let installed_extensions = { 130 let installed_extensions = Cmd {
120 let output = Cmd { 131 unix: &format!(r"{} --list-extensions", code_binary),
121 unix: &format!(r"{} --list-extensions", code_binary), 132 windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary),
122 windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary), 133 work_dir: ".",
123 work_dir: ".", 134 }
124 } 135 .run_with_output()?;
125 .run_with_output()?;
126 String::from_utf8(output.stdout)?
127 };
128 136
129 if !installed_extensions.contains("rust-analyzer") { 137 if !installed_extensions.contains("rust-analyzer") {
130 anyhow::bail!( 138 anyhow::bail!(
@@ -150,12 +158,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
150 158
151fn install_server(opts: ServerOpt) -> Result<()> { 159fn install_server(opts: ServerOpt) -> Result<()> {
152 let mut old_rust = false; 160 let mut old_rust = false;
153 if let Ok(output) = run_with_output("cargo --version", ".") { 161 if let Ok(stdout) = run_with_output("cargo --version", ".") {
154 if let Ok(stdout) = String::from_utf8(output.stdout) { 162 println!("{}", stdout);
155 println!("{}", stdout); 163 if !check_version(&stdout, REQUIRED_RUST_VERSION) {
156 if !check_version(&stdout, REQUIRED_RUST_VERSION) { 164 old_rust = true;
157 old_rust = true;
158 }
159 } 165 }
160 } 166 }
161 167
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index 9b0afe8e0..1bb1882b0 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -15,7 +15,10 @@ use std::{
15 process::{Command, Stdio}, 15 process::{Command, Stdio},
16}; 16};
17 17
18use crate::{cmd::run, codegen::Mode}; 18use crate::{
19 cmd::{run, run_with_output},
20 codegen::Mode,
21};
19 22
20pub use anyhow::Result; 23pub use anyhow::Result;
21 24
@@ -53,8 +56,7 @@ fn reformat(text: impl std::fmt::Display) -> Result<String> {
53 write!(rustfmt.stdin.take().unwrap(), "{}", text)?; 56 write!(rustfmt.stdin.take().unwrap(), "{}", text)?;
54 let output = rustfmt.wait_with_output()?; 57 let output = rustfmt.wait_with_output()?;
55 let stdout = String::from_utf8(output.stdout)?; 58 let stdout = String::from_utf8(output.stdout)?;
56 // TODO: update the preable: replace ra_tools with the relevant path 59 let preamble = "Generated file, do not edit by hand, see `xtask/src/codegen`";
57 let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`";
58 Ok(format!("//! {}\n\n{}", preamble, stdout)) 60 Ok(format!("//! {}\n\n{}", preamble, stdout))
59} 61}
60 62
@@ -157,3 +159,41 @@ fn rm_rf(path: &Path) -> Result<()> {
157 if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) } 159 if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
158 .with_context(|| format!("failed to remove {:?}", path)) 160 .with_context(|| format!("failed to remove {:?}", path))
159} 161}
162
163pub fn run_release() -> Result<()> {
164 run("git switch release", ".")?;
165 run("git fetch upstream", ".")?;
166 run("git reset --hard upstream/master", ".")?;
167 run("git push", ".")?;
168
169 let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts");
170
171 let today = run_with_output("date --iso", ".")?;
172 let commit = run_with_output("git rev-parse HEAD", ".")?;
173 let changelog_n = fs::read_dir(changelog_dir.as_path())?.count();
174
175 let contents = format!(
176 "\
177= Changelog #{}
178:sectanchors:
179:page-layout: post
180
181Commit: commit:{}[] +
182Release: release:{}[]
183
184== New Features
185
186* pr:[] .
187
188== Fixes
189
190== Internal Improvements
191",
192 changelog_n, commit, today
193 );
194
195 let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n));
196 fs::write(&path, &contents)?;
197
198 Ok(())
199}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index c347de9ab..7ca727bde 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -14,7 +14,7 @@ use pico_args::Arguments;
14use xtask::{ 14use xtask::{
15 codegen::{self, Mode}, 15 codegen::{self, Mode},
16 install::{ClientOpt, InstallCmd, ServerOpt}, 16 install::{ClientOpt, InstallCmd, ServerOpt},
17 pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result, 17 pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, Result,
18}; 18};
19 19
20fn main() -> Result<()> { 20fn main() -> Result<()> {
@@ -92,6 +92,10 @@ FLAGS:
92 args.finish()?; 92 args.finish()?;
93 run_pre_cache() 93 run_pre_cache()
94 } 94 }
95 "release" => {
96 args.finish()?;
97 run_release()
98 }
95 _ => { 99 _ => {
96 eprintln!( 100 eprintln!(
97 "\ 101 "\
diff --git a/xtask/src/pre_commit.rs b/xtask/src/pre_commit.rs
index 88e868ca6..1533f64dc 100644
--- a/xtask/src/pre_commit.rs
+++ b/xtask/src/pre_commit.rs
@@ -14,7 +14,7 @@ pub fn run_hook() -> Result<()> {
14 let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?; 14 let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?;
15 15
16 let root = project_root(); 16 let root = project_root();
17 for line in String::from_utf8(diff.stdout)?.lines() { 17 for line in diff.lines() {
18 run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; 18 run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
19 } 19 }
20 20