rust-analyzer/xtask/src/main.rs

145 lines
4 KiB
Rust
Raw Normal View History

2019-10-26 14:20:44 +00:00
//! See https://github.com/matklad/cargo-xtask/.
//!
//! This binary defines various auxiliary build commands, which are not
//! expressible with just `cargo`. Notably, it provides `cargo xtask codegen`
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`.
2020-01-07 13:42:56 +00:00
use std::env;
2019-11-20 06:47:14 +00:00
use pico_args::Arguments;
2019-10-17 16:36:55 +00:00
use xtask::{
2019-10-23 15:13:40 +00:00
codegen::{self, Mode},
2020-07-24 13:59:01 +00:00
dist::DistCmd,
2020-07-14 00:12:49 +00:00
install::{ClientOpt, InstallCmd, Malloc, ServerOpt},
2020-07-24 14:28:07 +00:00
metrics::run_metrics,
not_bash::pushd,
2020-06-08 11:58:54 +00:00
pre_commit, project_root,
2020-07-07 16:12:22 +00:00
release::{PromoteCmd, ReleaseCmd},
2020-06-08 11:58:54 +00:00
run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result,
2018-12-31 13:14:06 +00:00
};
2018-07-30 11:06:22 +00:00
fn main() -> Result<()> {
2019-11-20 06:47:14 +00:00
if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) {
2020-01-07 13:42:56 +00:00
return pre_commit::run_hook();
}
let _d = pushd(project_root());
2020-01-08 10:27:31 +00:00
let mut args = Arguments::from_env();
let subcommand = args.subcommand()?.unwrap_or_default();
2020-01-07 13:42:56 +00:00
match subcommand.as_str() {
2019-10-17 16:36:55 +00:00
"install" => {
2020-01-07 13:42:56 +00:00
if args.contains(["-h", "--help"]) {
eprintln!(
"\
cargo xtask install
Install rust-analyzer server or editor plugin.
USAGE:
cargo xtask install [FLAGS]
FLAGS:
--client-code Install only VS Code plugin
--server Install only the language server
2020-07-14 00:12:49 +00:00
--mimalloc Use mimalloc for server
2020-01-07 13:42:56 +00:00
-h, --help Prints help information
"
);
2019-09-10 15:17:11 +00:00
return Ok(());
}
2020-01-07 13:42:56 +00:00
let server = args.contains("--server");
let client_code = args.contains("--client-code");
2019-09-10 15:17:11 +00:00
if server && client_code {
2020-01-07 13:42:56 +00:00
eprintln!(
"error: The argument `--server` cannot be used with `--client-code`\n\n\
For more information try --help"
);
return Ok(());
}
2020-01-07 13:42:56 +00:00
let malloc =
if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
2020-01-07 13:42:56 +00:00
args.finish()?;
InstallCmd {
2019-09-10 15:17:11 +00:00
client: if server { None } else { Some(ClientOpt::VsCode) },
2020-07-14 00:12:49 +00:00
server: if client_code { None } else { Some(ServerOpt { malloc }) },
2020-01-07 13:42:56 +00:00
}
.run()
}
2019-10-17 16:36:55 +00:00
"codegen" => {
2020-01-07 13:42:56 +00:00
args.finish()?;
codegen::generate_syntax(Mode::Overwrite)?;
codegen::generate_parser_tests(Mode::Overwrite)?;
2020-06-03 16:22:05 +00:00
codegen::generate_assists_tests(Mode::Overwrite)?;
2019-10-25 11:16:46 +00:00
codegen::generate_assists_docs(Mode::Overwrite)?;
2020-05-30 23:54:54 +00:00
codegen::generate_feature_docs(Mode::Overwrite)?;
2020-01-07 13:42:56 +00:00
Ok(())
}
2020-01-07 13:42:56 +00:00
"format" => {
args.finish()?;
run_rustfmt(Mode::Overwrite)
}
2020-01-07 13:42:56 +00:00
"install-pre-commit-hook" => {
args.finish()?;
pre_commit::install_hook()
2019-09-18 11:24:20 +00:00
}
2020-01-07 13:42:56 +00:00
"lint" => {
args.finish()?;
run_clippy()
}
"fuzz-tests" => {
args.finish()?;
run_fuzzer()
}
"pre-cache" => {
args.finish()?;
run_pre_cache()
}
2020-02-10 14:32:03 +00:00
"release" => {
2020-02-14 17:33:30 +00:00
let dry_run = args.contains("--dry-run");
2020-02-10 14:32:03 +00:00
args.finish()?;
2020-06-08 12:00:30 +00:00
ReleaseCmd { dry_run }.run()
2020-02-10 14:32:03 +00:00
}
2020-07-07 16:12:22 +00:00
"promote" => {
let dry_run = args.contains("--dry-run");
args.finish()?;
PromoteCmd { dry_run }.run()
}
"dist" => {
2020-04-08 09:47:40 +00:00
let nightly = args.contains("--nightly");
let client_version: Option<String> = args.opt_value_from_str("--client")?;
args.finish()?;
2020-07-24 13:59:01 +00:00
DistCmd { nightly, client_version }.run()
}
2020-07-24 14:28:07 +00:00
"metrics" => run_metrics(),
2020-01-07 13:42:56 +00:00
_ => {
eprintln!(
"\
cargo xtask
Run custom build command.
USAGE:
cargo xtask <SUBCOMMAND>
SUBCOMMANDS:
format
install-pre-commit-hook
fuzz-tests
codegen
install
lint
2020-07-24 13:59:01 +00:00
dist
promote"
2020-01-07 13:42:56 +00:00
);
Ok(())
}
}
}