diff options
Diffstat (limited to 'xtask/src/lib.rs')
-rw-r--r-- | xtask/src/lib.rs | 94 |
1 files changed, 65 insertions, 29 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 8fdf43e4a..2bcd76d60 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | mod cmd; | 3 | pub mod not_bash; |
4 | pub mod install; | 4 | pub mod install; |
5 | pub mod pre_commit; | 5 | pub mod pre_commit; |
6 | 6 | ||
@@ -9,13 +9,16 @@ mod ast_src; | |||
9 | 9 | ||
10 | use anyhow::Context; | 10 | use anyhow::Context; |
11 | use std::{ | 11 | use std::{ |
12 | env, fs, | 12 | env, |
13 | io::Write, | 13 | io::Write, |
14 | path::{Path, PathBuf}, | 14 | path::{Path, PathBuf}, |
15 | process::{Command, Stdio}, | 15 | process::{Command, Stdio}, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | use crate::{cmd::run, codegen::Mode}; | 18 | use crate::{ |
19 | codegen::Mode, | ||
20 | not_bash::{fs2, pushd, rm_rf, run}, | ||
21 | }; | ||
19 | 22 | ||
20 | pub use anyhow::Result; | 23 | pub use anyhow::Result; |
21 | 24 | ||
@@ -35,9 +38,9 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
35 | ensure_rustfmt()?; | 38 | ensure_rustfmt()?; |
36 | 39 | ||
37 | if mode == Mode::Verify { | 40 | if mode == Mode::Verify { |
38 | run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?; | 41 | run!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN)?; |
39 | } else { | 42 | } else { |
40 | run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; | 43 | run!("rustup run {} -- cargo fmt", TOOLCHAIN)?; |
41 | } | 44 | } |
42 | Ok(()) | 45 | Ok(()) |
43 | } | 46 | } |
@@ -67,8 +70,9 @@ fn ensure_rustfmt() -> Result<()> { | |||
67 | Ok(status) if status.success() => return Ok(()), | 70 | Ok(status) if status.success() => return Ok(()), |
68 | _ => (), | 71 | _ => (), |
69 | }; | 72 | }; |
70 | run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; | 73 | run!("rustup toolchain install {}", TOOLCHAIN)?; |
71 | run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") | 74 | run!("rustup component add rustfmt --toolchain {}", TOOLCHAIN)?; |
75 | Ok(()) | ||
72 | } | 76 | } |
73 | 77 | ||
74 | pub fn run_clippy() -> Result<()> { | 78 | pub fn run_clippy() -> Result<()> { |
@@ -89,34 +93,28 @@ pub fn run_clippy() -> Result<()> { | |||
89 | "clippy::nonminimal_bool", | 93 | "clippy::nonminimal_bool", |
90 | "clippy::redundant_pattern_matching", | 94 | "clippy::redundant_pattern_matching", |
91 | ]; | 95 | ]; |
92 | run( | 96 | run!( |
93 | &format!( | 97 | "rustup run {} -- cargo clippy --all-features --all-targets -- -A {}", |
94 | "rustup run {} -- cargo clippy --all-features --all-targets -- -A {}", | 98 | TOOLCHAIN, |
95 | TOOLCHAIN, | 99 | allowed_lints.join(" -A ") |
96 | allowed_lints.join(" -A ") | ||
97 | ), | ||
98 | ".", | ||
99 | )?; | 100 | )?; |
100 | Ok(()) | 101 | Ok(()) |
101 | } | 102 | } |
102 | 103 | ||
103 | fn install_clippy() -> Result<()> { | 104 | fn install_clippy() -> Result<()> { |
104 | run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; | 105 | run!("rustup toolchain install {}", TOOLCHAIN)?; |
105 | run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".") | 106 | run!("rustup component add clippy --toolchain {}", TOOLCHAIN)?; |
107 | Ok(()) | ||
106 | } | 108 | } |
107 | 109 | ||
108 | pub fn run_fuzzer() -> Result<()> { | 110 | pub fn run_fuzzer() -> Result<()> { |
109 | match Command::new("cargo") | 111 | let _d = pushd("./crates/ra_syntax"); |
110 | .args(&["fuzz", "--help"]) | 112 | if run!("cargo fuzz --help").is_err() { |
111 | .stderr(Stdio::null()) | 113 | run!("cargo install cargo-fuzz")?; |
112 | .stdout(Stdio::null()) | ||
113 | .status() | ||
114 | { | ||
115 | Ok(status) if status.success() => (), | ||
116 | _ => run("cargo install cargo-fuzz", ".")?, | ||
117 | }; | 114 | }; |
118 | 115 | ||
119 | run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") | 116 | run!("rustup run nightly -- cargo fuzz run parser")?; |
117 | Ok(()) | ||
120 | } | 118 | } |
121 | 119 | ||
122 | /// Cleans the `./target` dir after the build such that only | 120 | /// Cleans the `./target` dir after the build such that only |
@@ -138,7 +136,7 @@ pub fn run_pre_cache() -> Result<()> { | |||
138 | } | 136 | } |
139 | } | 137 | } |
140 | 138 | ||
141 | fs::remove_file("./target/.rustc_info.json")?; | 139 | fs2::remove_file("./target/.rustc_info.json")?; |
142 | let to_delete = ["ra_", "heavy_test"]; | 140 | let to_delete = ["ra_", "heavy_test"]; |
143 | for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { | 141 | for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { |
144 | for entry in Path::new(dir).read_dir()? { | 142 | for entry in Path::new(dir).read_dir()? { |
@@ -152,7 +150,45 @@ pub fn run_pre_cache() -> Result<()> { | |||
152 | Ok(()) | 150 | Ok(()) |
153 | } | 151 | } |
154 | 152 | ||
155 | fn rm_rf(path: &Path) -> Result<()> { | 153 | pub fn run_release(dry_run: bool) -> Result<()> { |
156 | if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) } | 154 | if !dry_run { |
157 | .with_context(|| format!("failed to remove {:?}", path)) | 155 | run!("git switch release")?; |
156 | run!("git fetch upstream")?; | ||
157 | run!("git reset --hard upstream/master")?; | ||
158 | run!("git push")?; | ||
159 | } | ||
160 | |||
161 | let website_root = project_root().join("../rust-analyzer.github.io"); | ||
162 | let changelog_dir = website_root.join("./thisweek/_posts"); | ||
163 | |||
164 | let today = run!("date --iso")?; | ||
165 | let commit = run!("git rev-parse HEAD")?; | ||
166 | let changelog_n = fs2::read_dir(changelog_dir.as_path())?.count(); | ||
167 | |||
168 | let contents = format!( | ||
169 | "\ | ||
170 | = Changelog #{} | ||
171 | :sectanchors: | ||
172 | :page-layout: post | ||
173 | |||
174 | Commit: commit:{}[] + | ||
175 | Release: release:{}[] | ||
176 | |||
177 | == New Features | ||
178 | |||
179 | * pr:[] . | ||
180 | |||
181 | == Fixes | ||
182 | |||
183 | == Internal Improvements | ||
184 | ", | ||
185 | changelog_n, commit, today | ||
186 | ); | ||
187 | |||
188 | let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); | ||
189 | fs2::write(&path, &contents)?; | ||
190 | |||
191 | fs2::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; | ||
192 | |||
193 | Ok(()) | ||
158 | } | 194 | } |