From ce29497e4324d3e2f2c7c696a212672dbdb46884 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 15:59:19 +0100 Subject: Replace Cmd with not-bash --- xtask/src/lib.rs | 58 +++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) (limited to 'xtask/src/lib.rs') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 1bb1882b0..d2ef2e95b 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -mod cmd; +pub mod not_bash; pub mod install; pub mod pre_commit; @@ -16,8 +16,8 @@ use std::{ }; use crate::{ - cmd::{run, run_with_output}, codegen::Mode, + not_bash::{pushd, run}, }; pub use anyhow::Result; @@ -38,9 +38,9 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { ensure_rustfmt()?; if mode == Mode::Verify { - run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?; + run!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN)?; } else { - run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; + run!("rustup run {} -- cargo fmt", TOOLCHAIN)?; } Ok(()) } @@ -70,8 +70,9 @@ fn ensure_rustfmt() -> Result<()> { Ok(status) if status.success() => return Ok(()), _ => (), }; - run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; - run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") + run!("rustup toolchain install {}", TOOLCHAIN)?; + run!("rustup component add rustfmt --toolchain {}", TOOLCHAIN)?; + Ok(()) } pub fn run_clippy() -> Result<()> { @@ -92,34 +93,31 @@ pub fn run_clippy() -> Result<()> { "clippy::nonminimal_bool", "clippy::redundant_pattern_matching", ]; - run( - &format!( - "rustup run {} -- cargo clippy --all-features --all-targets -- -A {}", - TOOLCHAIN, - allowed_lints.join(" -A ") - ), - ".", + run!( + "rustup run {} -- cargo clippy --all-features --all-targets -- -A {}", + TOOLCHAIN, + allowed_lints.join(" -A ") )?; Ok(()) } fn install_clippy() -> Result<()> { - run(&format!("rustup toolchain install {}", TOOLCHAIN), ".")?; - run(&format!("rustup component add clippy --toolchain {}", TOOLCHAIN), ".") + run!("rustup toolchain install {}", TOOLCHAIN)?; + run!("rustup component add clippy --toolchain {}", TOOLCHAIN)?; + Ok(()) } pub fn run_fuzzer() -> Result<()> { - match Command::new("cargo") - .args(&["fuzz", "--help"]) - .stderr(Stdio::null()) - .stdout(Stdio::null()) - .status() - { - Ok(status) if status.success() => (), - _ => run("cargo install cargo-fuzz", ".")?, + let _d = pushd("./crates/ra_syntax"); + match run!("cargo fuzz --help") { + Ok(_) => (), + _ => { + run!("cargo install cargo-fuzz")?; + } }; - run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") + run!("rustup run nightly -- cargo fuzz run parser")?; + Ok(()) } /// Cleans the `./target` dir after the build such that only @@ -161,15 +159,15 @@ fn rm_rf(path: &Path) -> Result<()> { } pub fn run_release() -> Result<()> { - run("git switch release", ".")?; - run("git fetch upstream", ".")?; - run("git reset --hard upstream/master", ".")?; - run("git push", ".")?; + 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"); - let today = run_with_output("date --iso", ".")?; - let commit = run_with_output("git rev-parse HEAD", ".")?; + let today = run!("date --iso")?; + let commit = run!("git rev-parse HEAD")?; let changelog_n = fs::read_dir(changelog_dir.as_path())?.count(); let contents = format!( -- cgit v1.2.3 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 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'xtask/src/lib.rs') 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"); -- 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/src/lib.rs') 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 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'xtask/src/lib.rs') 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(()) } -- 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 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'xtask/src/lib.rs') 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")?; -- cgit v1.2.3 From 2ae71a9ed0df471b8982b847873ab5440463d78d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 14 Feb 2020 19:13:26 +0100 Subject: Simplify --- xtask/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'xtask/src/lib.rs') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 25b64301c..2bcd76d60 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -109,11 +109,8 @@ fn install_clippy() -> Result<()> { pub fn run_fuzzer() -> Result<()> { let _d = pushd("./crates/ra_syntax"); - match run!("cargo fuzz --help") { - Ok(_) => (), - _ => { - run!("cargo install cargo-fuzz")?; - } + if run!("cargo fuzz --help").is_err() { + run!("cargo install cargo-fuzz")?; }; run!("rustup run nightly -- cargo fuzz run parser")?; -- cgit v1.2.3