From 9fc2748d476066675dddaf54dfc6c6a8b5e5f450 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 18:33:30 +0100 Subject: Add dry run mode to xtask release --- xtask/src/lib.rs | 12 +++++++----- xtask/src/main.rs | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'xtask') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index d2ef2e95b..301a88324 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -158,11 +158,13 @@ fn rm_rf(path: &Path) -> Result<()> { .with_context(|| format!("failed to remove {:?}", path)) } -pub fn run_release() -> Result<()> { - run!("git switch release")?; - run!("git fetch upstream")?; - run!("git reset --hard upstream/master")?; - run!("git push")?; +pub fn run_release(dry_run: bool) -> Result<()> { + if !dry_run { + run!("git switch release")?; + run!("git fetch upstream")?; + run!("git reset --hard upstream/master")?; + run!("git push")?; + } let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts"); 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: run_pre_cache() } "release" => { + let dry_run = args.contains("--dry-run"); args.finish()?; - run_release() + run_release(dry_run) } _ => { eprintln!( -- cgit v1.2.3 From 705f8820c93277768ddc38a743b1ce02a97a9750 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 18:36:42 +0100 Subject: Update the manual on release --- xtask/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'xtask') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 301a88324..4050f9d01 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -166,7 +166,8 @@ pub fn run_release(dry_run: bool) -> Result<()> { run!("git push")?; } - let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts"); + let website_root = project_root().join("../rust-analyzer.github.io"); + let changelog_dir = website_root.join("/thisweek/_posts"); let today = run!("date --iso")?; let commit = run!("git rev-parse HEAD")?; @@ -195,5 +196,7 @@ Release: release:{}[] let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); fs::write(&path, &contents)?; + fs::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; + Ok(()) } -- cgit v1.2.3 From 3f675179e5566514fde2730c0a8b47195a688d6d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 18:56:07 +0100 Subject: Add fs2 module for better error messages --- xtask/src/lib.rs | 10 +++++----- xtask/src/not_bash.rs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'xtask') 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::{ use crate::{ codegen::Mode, - not_bash::{pushd, run}, + not_bash::{fs2, pushd, run}, }; pub use anyhow::Result; @@ -167,11 +167,11 @@ pub fn run_release(dry_run: bool) -> Result<()> { } let website_root = project_root().join("../rust-analyzer.github.io"); - let changelog_dir = website_root.join("/thisweek/_posts"); + let changelog_dir = website_root.join("./thisweek/_posts"); let today = run!("date --iso")?; let commit = run!("git rev-parse HEAD")?; - let changelog_n = fs::read_dir(changelog_dir.as_path())?.count(); + let changelog_n = fs2::read_dir(changelog_dir.as_path())?.count(); let contents = format!( "\ @@ -194,9 +194,9 @@ Release: release:{}[] ); let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); - fs::write(&path, &contents)?; + fs2::write(&path, &contents)?; - fs::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; + fs2::copy(project_root().join("./docs/user/readme.adoc"), website_root.join("manual.adoc"))?; Ok(()) } 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::{ use anyhow::{bail, Context, Result}; +pub mod fs2 { + use std::{fs, path::Path}; + + use anyhow::{Context, Result}; + + pub fn read_dir>(path: P) -> Result { + let path = path.as_ref(); + fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display())) + } + + pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { + let path = path.as_ref(); + fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display())) + } + + pub fn copy, Q: AsRef>(from: P, to: Q) -> Result { + let from = from.as_ref(); + let to = to.as_ref(); + fs::copy(from, to) + .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) + } +} + macro_rules! _run { ($($expr:expr),*) => { run!($($expr),*; echo = true) -- cgit v1.2.3 From cd956a191f8cb32573be7a78139ad322051e949e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 18:59:26 +0100 Subject: Trim output --- xtask/src/not_bash.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xtask') diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 027571b62..1a7cb7114 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -113,7 +113,7 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result { bail!("{}", output.status) } - Ok(stdout) + Ok(stdout.trim().to_string()) } // FIXME: some real shell lexing here -- cgit v1.2.3 From 5acb467894053cb0342eb6ded4d162b4a6912483 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 19:03:45 +0100 Subject: Move rm_rf to not-bash --- xtask/src/lib.rs | 11 +++-------- xtask/src/not_bash.rs | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'xtask') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index cebb14abc..25b64301c 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -9,7 +9,7 @@ mod ast_src; use anyhow::Context; use std::{ - env, fs, + env, io::Write, path::{Path, PathBuf}, process::{Command, Stdio}, @@ -17,7 +17,7 @@ use std::{ use crate::{ codegen::Mode, - not_bash::{fs2, pushd, run}, + not_bash::{fs2, pushd, rm_rf, run}, }; pub use anyhow::Result; @@ -139,7 +139,7 @@ pub fn run_pre_cache() -> Result<()> { } } - fs::remove_file("./target/.rustc_info.json")?; + fs2::remove_file("./target/.rustc_info.json")?; let to_delete = ["ra_", "heavy_test"]; for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { for entry in Path::new(dir).read_dir()? { @@ -153,11 +153,6 @@ pub fn run_pre_cache() -> Result<()> { Ok(()) } -fn rm_rf(path: &Path) -> Result<()> { - if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) } - .with_context(|| format!("failed to remove {:?}", path)) -} - pub fn run_release(dry_run: bool) -> Result<()> { if !dry_run { run!("git switch release")?; diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 1a7cb7114..3e30e7279 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -4,7 +4,7 @@ use std::{ env, ffi::OsStr, fs, - path::PathBuf, + path::{Path, PathBuf}, process::{Command, Stdio}, }; @@ -31,6 +31,16 @@ pub mod fs2 { fs::copy(from, to) .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) } + + pub fn remove_file>(path: P) -> Result<()> { + let path = path.as_ref(); + fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display())) + } + + pub fn remove_dir_all>(path: P) -> Result<()> { + let path = path.as_ref(); + fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) + } } macro_rules! _run { @@ -64,6 +74,15 @@ pub fn rm(glob: &str) -> Result<()> { Ok(()) } +pub fn rm_rf(path: impl AsRef) -> Result<()> { + let path = path.as_ref(); + if path.is_file() { + fs2::remove_file(path) + } else { + fs2::remove_dir_all(path) + } +} + pub fn ls(glob: &str) -> Result> { let cwd = Env::with(|env| env.cwd()); let mut res = Vec::new(); -- cgit v1.2.3