aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-14 17:56:07 +0000
committerAleksey Kladov <[email protected]>2020-02-14 17:56:07 +0000
commit3f675179e5566514fde2730c0a8b47195a688d6d (patch)
treebfbf6346e0e7240f56b28de22af8eb2c16c9e89a /xtask
parent705f8820c93277768ddc38a743b1ce02a97a9750 (diff)
Add fs2 module for better error messages
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/lib.rs10
-rw-r--r--xtask/src/not_bash.rs23
2 files changed, 28 insertions, 5 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index 4050f9d01..cebb14abc 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -17,7 +17,7 @@ use std::{
17 17
18use crate::{ 18use crate::{
19 codegen::Mode, 19 codegen::Mode,
20 not_bash::{pushd, run}, 20 not_bash::{fs2, pushd, run},
21}; 21};
22 22
23pub use anyhow::Result; 23pub use anyhow::Result;
@@ -167,11 +167,11 @@ pub fn run_release(dry_run: bool) -> Result<()> {
167 } 167 }
168 168
169 let website_root = project_root().join("../rust-analyzer.github.io"); 169 let website_root = project_root().join("../rust-analyzer.github.io");
170 let changelog_dir = website_root.join("/thisweek/_posts"); 170 let changelog_dir = website_root.join("./thisweek/_posts");
171 171
172 let today = run!("date --iso")?; 172 let today = run!("date --iso")?;
173 let commit = run!("git rev-parse HEAD")?; 173 let commit = run!("git rev-parse HEAD")?;
174 let changelog_n = fs::read_dir(changelog_dir.as_path())?.count(); 174 let changelog_n = fs2::read_dir(changelog_dir.as_path())?.count();
175 175
176 let contents = format!( 176 let contents = format!(
177 "\ 177 "\
@@ -194,9 +194,9 @@ Release: release:{}[]
194 ); 194 );
195 195
196 let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); 196 let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n));
197 fs::write(&path, &contents)?; 197 fs2::write(&path, &contents)?;
198 198
199 fs::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; 199 fs2::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?;
200 200
201 Ok(()) 201 Ok(())
202} 202}
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index 56d6c6c2d..027571b62 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -10,6 +10,29 @@ use std::{
10 10
11use anyhow::{bail, Context, Result}; 11use anyhow::{bail, Context, Result};
12 12
13pub 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
13macro_rules! _run { 36macro_rules! _run {
14 ($($expr:expr),*) => { 37 ($($expr:expr),*) => {
15 run!($($expr),*; echo = true) 38 run!($($expr),*; echo = true)