rust/xtask/src/main.rs

112 lines
3.0 KiB
Rust
Raw Normal View History

2019-10-26 09:20:44 -05: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 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`.
2020-01-07 07:42:56 -06:00
use std::env;
2019-11-20 00:47:14 -06:00
use pico_args::Arguments;
2019-10-17 11:36:55 -05:00
use xtask::{
2019-10-23 10:13:40 -05:00
codegen::{self, Mode},
2020-01-07 07:42:56 -06:00
install::{ClientOpt, InstallCmd, ServerOpt},
pre_commit, run_clippy, run_fuzzer, run_rustfmt, Result,
2018-12-31 07:14:06 -06:00
};
2018-07-30 06:06:22 -05:00
fn main() -> Result<()> {
2019-11-20 00:47:14 -06:00
if env::args().next().map(|it| it.contains("pre-commit")) == Some(true) {
2020-01-07 07:42:56 -06:00
return pre_commit::run_hook();
}
2020-01-07 07:42:56 -06:00
let subcommand = std::env::args().nth(1).unwrap_or_default();
let mut args = Arguments::from_vec(std::env::args_os().skip(2).collect());
match subcommand.as_str() {
2019-10-17 11:36:55 -05:00
"install" => {
2020-01-07 07:42:56 -06: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
--jemalloc Use jemalloc for server
-h, --help Prints help information
"
);
2019-09-10 10:17:11 -05:00
return Ok(());
}
2020-01-07 07:42:56 -06:00
let server = args.contains("--server");
let client_code = args.contains("--client-code");
2019-09-10 10:17:11 -05:00
if server && client_code {
2020-01-07 07:42:56 -06:00
eprintln!(
"error: The argument `--server` cannot be used with `--client-code`\n\n\
For more information try --help"
);
return Ok(());
}
2020-01-07 07:42:56 -06:00
let jemalloc = args.contains("--jemalloc");
args.finish()?;
InstallCmd {
2019-09-10 10:17:11 -05:00
client: if server { None } else { Some(ClientOpt::VsCode) },
2019-10-30 12:36:37 -05:00
server: if client_code { None } else { Some(ServerOpt { jemalloc }) },
2020-01-07 07:42:56 -06:00
}
.run()
}
2019-10-17 11:36:55 -05:00
"codegen" => {
2020-01-07 07:42:56 -06:00
args.finish()?;
codegen::generate_syntax(Mode::Overwrite)?;
codegen::generate_parser_tests(Mode::Overwrite)?;
2019-10-25 06:16:46 -05:00
codegen::generate_assists_docs(Mode::Overwrite)?;
2020-01-07 07:42:56 -06:00
Ok(())
}
2020-01-07 07:42:56 -06:00
"format" => {
args.finish()?;
run_rustfmt(Mode::Overwrite)
}
2020-01-07 07:42:56 -06:00
"install-pre-commit-hook" => {
args.finish()?;
pre_commit::install_hook()
2019-09-18 06:24:20 -05:00
}
2020-01-07 07:42:56 -06:00
"lint" => {
args.finish()?;
run_clippy()
}
"fuzz-tests" => {
args.finish()?;
run_fuzzer()
}
_ => {
eprintln!(
"\
cargo xtask
Run custom build command.
USAGE:
cargo xtask <SUBCOMMAND>
SUBCOMMANDS:
format
install-pre-commit-hook
fuzz-tests
codegen
install
lint"
);
Ok(())
}
}
}