2021-06-14 04:57:10 +00:00
|
|
|
//! See <https://github.com/matklad/cargo-xtask/>.
|
2019-10-26 14:20:44 +00:00
|
|
|
//!
|
|
|
|
//! This binary defines various auxiliary build commands, which are not
|
2021-03-12 14:10:33 +00:00
|
|
|
//! expressible with just `cargo`. Notably, it provides tests via `cargo test -p xtask`
|
2019-10-30 20:17:27 +00:00
|
|
|
//! for code generation and `cargo xtask install` for installation of
|
2019-10-26 14:20:44 +00:00
|
|
|
//! rust-analyzer server and client.
|
|
|
|
//!
|
|
|
|
//! This binary is integrated into the `cargo` command line by using an alias in
|
|
|
|
//! `.cargo/config`.
|
2022-07-20 12:59:42 +00:00
|
|
|
|
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
|
|
|
|
|
2021-03-01 18:12:44 +00:00
|
|
|
mod flags;
|
|
|
|
|
2021-03-01 17:16:23 +00:00
|
|
|
mod install;
|
|
|
|
mod release;
|
|
|
|
mod dist;
|
2022-12-11 14:49:28 +00:00
|
|
|
mod publish;
|
2021-03-01 17:16:23 +00:00
|
|
|
mod metrics;
|
2019-11-20 06:47:14 +00:00
|
|
|
|
2022-03-13 21:20:51 +00:00
|
|
|
use anyhow::bail;
|
2021-03-01 17:16:23 +00:00
|
|
|
use std::{
|
|
|
|
env,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
2022-03-13 21:20:51 +00:00
|
|
|
use xshell::{cmd, Shell};
|
2021-03-01 17:16:23 +00:00
|
|
|
|
2022-03-13 21:20:51 +00:00
|
|
|
fn main() -> anyhow::Result<()> {
|
2022-10-08 14:35:07 +00:00
|
|
|
let flags = flags::Xtask::from_env_or_exit();
|
|
|
|
|
2022-03-13 21:20:51 +00:00
|
|
|
let sh = &Shell::new()?;
|
|
|
|
sh.change_dir(project_root());
|
2020-03-04 16:58:22 +00:00
|
|
|
|
2021-03-01 18:12:44 +00:00
|
|
|
match flags.subcommand {
|
2022-03-13 21:20:51 +00: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),
|
2022-12-11 14:49:28 +00:00
|
|
|
flags::XtaskCmd::PublishReleaseNotes(cmd) => cmd.run(sh),
|
2022-03-13 21:20:51 +00:00
|
|
|
flags::XtaskCmd::Metrics(cmd) => cmd.run(sh),
|
2021-03-01 18:12:44 +00:00
|
|
|
flags::XtaskCmd::Bb(cmd) => {
|
2021-02-23 18:02:17 +00:00
|
|
|
{
|
2022-03-13 21:20:51 +00:00
|
|
|
let _d = sh.push_dir("./crates/rust-analyzer");
|
|
|
|
cmd!(sh, "cargo build --release --features jemalloc").run()?;
|
2021-02-23 18:02:17 +00:00
|
|
|
}
|
2022-03-13 21:20:51 +00:00
|
|
|
sh.copy_file(
|
|
|
|
"./target/release/rust-analyzer",
|
|
|
|
format!("./target/rust-analyzer-{}", cmd.suffix),
|
|
|
|
)?;
|
2020-01-07 13:42:56 +00:00
|
|
|
Ok(())
|
2019-11-14 08:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 16:56:45 +00:00
|
|
|
|
2021-03-01 17:16:23 +00: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 21:20:51 +00: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 17:16:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Expecting nightly rustc
|
2022-03-13 21:20:51 +00:00
|
|
|
let out = cmd!(sh, "rustc --version").read()?;
|
2021-03-01 17:16:23 +00:00
|
|
|
if !out.contains("nightly") {
|
|
|
|
bail!("fuzz tests require nightly rustc")
|
|
|
|
}
|
|
|
|
|
2022-03-13 21:20:51 +00:00
|
|
|
cmd!(sh, "cargo fuzz run parser").run()?;
|
2021-03-01 17:16:23 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-03-13 21:20:51 +00:00
|
|
|
fn date_iso(sh: &Shell) -> anyhow::Result<String> {
|
|
|
|
let res = cmd!(sh, "date -u +%Y-%m-%d").read()?;
|
2021-03-01 17:16:23 +00: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())
|
|
|
|
}
|