diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-14 18:04:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-14 18:04:32 +0000 |
commit | 53cee86666166c6a7316253317d5d40fc20f30f2 (patch) | |
tree | 5e4e50b502de134813b6d247b57f079f9c9fa71a /xtask/src | |
parent | 619b0e16513fe73054262463340c109028f0e11e (diff) | |
parent | 5acb467894053cb0342eb6ded4d162b4a6912483 (diff) |
Merge #3140
3140: Start manual r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/lib.rs | 32 | ||||
-rw-r--r-- | xtask/src/main.rs | 3 | ||||
-rw-r--r-- | xtask/src/not_bash.rs | 46 |
3 files changed, 62 insertions, 19 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index d2ef2e95b..25b64301c 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -9,7 +9,7 @@ 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}, |
@@ -17,7 +17,7 @@ use std::{ | |||
17 | 17 | ||
18 | use crate::{ | 18 | use crate::{ |
19 | codegen::Mode, | 19 | codegen::Mode, |
20 | not_bash::{pushd, run}, | 20 | not_bash::{fs2, pushd, rm_rf, run}, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | pub use anyhow::Result; | 23 | pub use anyhow::Result; |
@@ -139,7 +139,7 @@ pub fn run_pre_cache() -> Result<()> { | |||
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | fs::remove_file("./target/.rustc_info.json")?; | 142 | fs2::remove_file("./target/.rustc_info.json")?; |
143 | let to_delete = ["ra_", "heavy_test"]; | 143 | let to_delete = ["ra_", "heavy_test"]; |
144 | for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { | 144 | for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { |
145 | for entry in Path::new(dir).read_dir()? { | 145 | for entry in Path::new(dir).read_dir()? { |
@@ -153,22 +153,20 @@ pub fn run_pre_cache() -> Result<()> { | |||
153 | Ok(()) | 153 | Ok(()) |
154 | } | 154 | } |
155 | 155 | ||
156 | fn rm_rf(path: &Path) -> Result<()> { | 156 | pub fn run_release(dry_run: bool) -> Result<()> { |
157 | if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) } | 157 | if !dry_run { |
158 | .with_context(|| format!("failed to remove {:?}", path)) | 158 | run!("git switch release")?; |
159 | } | 159 | run!("git fetch upstream")?; |
160 | 160 | run!("git reset --hard upstream/master")?; | |
161 | pub fn run_release() -> Result<()> { | 161 | run!("git push")?; |
162 | run!("git switch release")?; | 162 | } |
163 | run!("git fetch upstream")?; | ||
164 | run!("git reset --hard upstream/master")?; | ||
165 | run!("git push")?; | ||
166 | 163 | ||
167 | let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts"); | 164 | let website_root = project_root().join("../rust-analyzer.github.io"); |
165 | let changelog_dir = website_root.join("./thisweek/_posts"); | ||
168 | 166 | ||
169 | let today = run!("date --iso")?; | 167 | let today = run!("date --iso")?; |
170 | let commit = run!("git rev-parse HEAD")?; | 168 | let commit = run!("git rev-parse HEAD")?; |
171 | let changelog_n = fs::read_dir(changelog_dir.as_path())?.count(); | 169 | let changelog_n = fs2::read_dir(changelog_dir.as_path())?.count(); |
172 | 170 | ||
173 | let contents = format!( | 171 | let contents = format!( |
174 | "\ | 172 | "\ |
@@ -191,7 +189,9 @@ Release: release:{}[] | |||
191 | ); | 189 | ); |
192 | 190 | ||
193 | let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); | 191 | let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); |
194 | fs::write(&path, &contents)?; | 192 | fs2::write(&path, &contents)?; |
193 | |||
194 | fs2::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; | ||
195 | 195 | ||
196 | Ok(()) | 196 | Ok(()) |
197 | } | 197 | } |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7ca727bde..a7dffe2cc 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -93,8 +93,9 @@ FLAGS: | |||
93 | run_pre_cache() | 93 | run_pre_cache() |
94 | } | 94 | } |
95 | "release" => { | 95 | "release" => { |
96 | let dry_run = args.contains("--dry-run"); | ||
96 | args.finish()?; | 97 | args.finish()?; |
97 | run_release() | 98 | run_release(dry_run) |
98 | } | 99 | } |
99 | _ => { | 100 | _ => { |
100 | eprintln!( | 101 | eprintln!( |
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 56d6c6c2d..3e30e7279 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs | |||
@@ -4,12 +4,45 @@ use std::{ | |||
4 | env, | 4 | env, |
5 | ffi::OsStr, | 5 | ffi::OsStr, |
6 | fs, | 6 | fs, |
7 | path::PathBuf, | 7 | path::{Path, PathBuf}, |
8 | process::{Command, Stdio}, | 8 | process::{Command, Stdio}, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use anyhow::{bail, Context, Result}; | 11 | use anyhow::{bail, Context, Result}; |
12 | 12 | ||
13 | pub mod fs2 { | ||
14 | use std::{fs, path::Path}; | ||
15 | |||
16 | use anyhow::{Context, Result}; | ||
17 | |||
18 | pub fn read_dir<P: AsRef<Path>>(path: P) -> Result<fs::ReadDir> { | ||
19 | let path = path.as_ref(); | ||
20 | fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display())) | ||
21 | } | ||
22 | |||
23 | pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { | ||
24 | let path = path.as_ref(); | ||
25 | fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display())) | ||
26 | } | ||
27 | |||
28 | pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> { | ||
29 | let from = from.as_ref(); | ||
30 | let to = to.as_ref(); | ||
31 | fs::copy(from, to) | ||
32 | .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) | ||
33 | } | ||
34 | |||
35 | pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> { | ||
36 | let path = path.as_ref(); | ||
37 | fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display())) | ||
38 | } | ||
39 | |||
40 | pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> { | ||
41 | let path = path.as_ref(); | ||
42 | fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) | ||
43 | } | ||
44 | } | ||
45 | |||
13 | macro_rules! _run { | 46 | macro_rules! _run { |
14 | ($($expr:expr),*) => { | 47 | ($($expr:expr),*) => { |
15 | run!($($expr),*; echo = true) | 48 | run!($($expr),*; echo = true) |
@@ -41,6 +74,15 @@ pub fn rm(glob: &str) -> Result<()> { | |||
41 | Ok(()) | 74 | Ok(()) |
42 | } | 75 | } |
43 | 76 | ||
77 | pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> { | ||
78 | let path = path.as_ref(); | ||
79 | if path.is_file() { | ||
80 | fs2::remove_file(path) | ||
81 | } else { | ||
82 | fs2::remove_dir_all(path) | ||
83 | } | ||
84 | } | ||
85 | |||
44 | pub fn ls(glob: &str) -> Result<Vec<PathBuf>> { | 86 | pub fn ls(glob: &str) -> Result<Vec<PathBuf>> { |
45 | let cwd = Env::with(|env| env.cwd()); | 87 | let cwd = Env::with(|env| env.cwd()); |
46 | let mut res = Vec::new(); | 88 | let mut res = Vec::new(); |
@@ -90,7 +132,7 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result<String> { | |||
90 | bail!("{}", output.status) | 132 | bail!("{}", output.status) |
91 | } | 133 | } |
92 | 134 | ||
93 | Ok(stdout) | 135 | Ok(stdout.trim().to_string()) |
94 | } | 136 | } |
95 | 137 | ||
96 | // FIXME: some real shell lexing here | 138 | // FIXME: some real shell lexing here |