2021-06-13 23:57:10 -05:00
|
|
|
//! See <https://github.com/matklad/cargo-xtask/>.
|
2019-10-26 09:20:44 -05:00
|
|
|
//!
|
|
|
|
//! This binary defines various auxiliary build commands, which are not
|
2021-03-12 08:10:33 -06:00
|
|
|
//! expressible with just `cargo`. Notably, it provides tests via `cargo test -p xtask`
|
2019-10-30 15:17:27 -05:00
|
|
|
//! for code generation and `cargo xtask install` for installation of
|
2019-10-26 09:20:44 -05:00
|
|
|
//! rust-analyzer server and client.
|
|
|
|
//!
|
|
|
|
//! This binary is integrated into the `cargo` command line by using an alias in
|
|
|
|
//! `.cargo/config`.
|
2021-03-01 12:12:44 -06:00
|
|
|
mod flags;
|
|
|
|
|
2021-03-01 11:16:23 -06:00
|
|
|
mod install;
|
|
|
|
mod release;
|
|
|
|
mod dist;
|
|
|
|
mod metrics;
|
2019-11-20 00:47:14 -06:00
|
|
|
|
2022-03-13 16:20:51 -05:00
|
|
|
use anyhow::bail;
|
2021-03-01 11:16:23 -06:00
|
|
|
use std::{
|
|
|
|
env,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
2022-03-13 16:20:51 -05:00
|
|
|
use xshell::{cmd, Shell};
|
2021-03-01 11:16:23 -06:00
|
|
|
|
2022-03-13 16:20:51 -05:00
|
|
|
fn main() -> anyhow::Result<()> {
|
|
|
|
let sh = &Shell::new()?;
|
|
|
|
sh.change_dir(project_root());
|
2020-03-04 10:58:22 -06:00
|
|
|
|
2021-03-01 12:12:44 -06:00
|
|
|
let flags = flags::Xtask::from_env()?;
|
|
|
|
match flags.subcommand {
|
|
|
|
flags::XtaskCmd::Help(_) => {
|
|
|
|
println!("{}", flags::Xtask::HELP);
|
2021-03-21 09:33:18 -05:00
|
|
|
Ok(())
|
2021-03-01 12:12:44 -06:00
|
|
|
}
|
2022-03-13 16:20:51 -05:00
|
|
|
flags::XtaskCmd::Install(cmd) => cmd.run(sh),
|
|
|
|
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(sh),
|
|
|
|
flags::XtaskCmd::Release(cmd) => cmd.run(sh),
|
|
|
|
flags::XtaskCmd::Promote(cmd) => cmd.run(sh),
|
|
|
|
flags::XtaskCmd::Dist(cmd) => cmd.run(sh),
|
|
|
|
flags::XtaskCmd::Metrics(cmd) => cmd.run(sh),
|
2021-03-01 12:12:44 -06:00
|
|
|
flags::XtaskCmd::Bb(cmd) => {
|
2021-02-23 12:02:17 -06:00
|
|
|
{
|
2022-03-13 16:20:51 -05:00
|
|
|
let _d = sh.push_dir("./crates/rust-analyzer");
|
|
|
|
cmd!(sh, "cargo build --release --features jemalloc").run()?;
|
2021-02-23 12:02:17 -06:00
|
|
|
}
|
2022-03-13 16:20:51 -05:00
|
|
|
sh.copy_file(
|
|
|
|
"./target/release/rust-analyzer",
|
|
|
|
format!("./target/rust-analyzer-{}", cmd.suffix),
|
|
|
|
)?;
|
2020-01-07 07:42:56 -06:00
|
|
|
Ok(())
|
2019-11-14 02:11:32 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 10:56:45 -06:00
|
|
|
|
2021-03-01 11:16:23 -06:00
|
|
|
fn project_root() -> PathBuf {
|
|
|
|
Path::new(
|
|
|
|
&env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned()),
|
|
|
|
)
|
|
|
|
.ancestors()
|
|
|
|
.nth(1)
|
|
|
|
.unwrap()
|
|
|
|
.to_path_buf()
|
|
|
|
}
|
|
|
|
|
2022-03-13 16:20:51 -05:00
|
|
|
fn run_fuzzer(sh: &Shell) -> anyhow::Result<()> {
|
|
|
|
let _d = sh.push_dir("./crates/syntax");
|
|
|
|
let _e = sh.push_env("RUSTUP_TOOLCHAIN", "nightly");
|
|
|
|
if cmd!(sh, "cargo fuzz --help").read().is_err() {
|
|
|
|
cmd!(sh, "cargo install cargo-fuzz").run()?;
|
2021-03-01 11:16:23 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// Expecting nightly rustc
|
2022-03-13 16:20:51 -05:00
|
|
|
let out = cmd!(sh, "rustc --version").read()?;
|
2021-03-01 11:16:23 -06:00
|
|
|
if !out.contains("nightly") {
|
|
|
|
bail!("fuzz tests require nightly rustc")
|
|
|
|
}
|
|
|
|
|
2022-03-13 16:20:51 -05:00
|
|
|
cmd!(sh, "cargo fuzz run parser").run()?;
|
2021-03-01 11:16:23 -06:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-03-13 16:20:51 -05:00
|
|
|
fn date_iso(sh: &Shell) -> anyhow::Result<String> {
|
|
|
|
let res = cmd!(sh, "date -u +%Y-%m-%d").read()?;
|
2021-03-01 11:16:23 -06:00
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_release_tag(tag: &str) -> bool {
|
|
|
|
tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit())
|
|
|
|
}
|