rust-analyzer/crates/tools/src/main.rs

66 lines
2.2 KiB
Rust
Raw Normal View History

use clap::{App, SubCommand};
2019-03-05 21:19:36 +00:00
use core::str;
use failure::bail;
2018-12-31 13:14:06 +00:00
use tools::{
2019-03-05 21:19:36 +00:00
generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
Overwrite, Result, run_fuzzer,
2018-12-31 13:14:06 +00:00
};
2018-07-30 11:06:22 +00:00
fn main() -> Result<()> {
let matches = App::new("tasks")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
2018-10-16 18:09:22 +00:00
.subcommand(SubCommand::with_name("gen-syntax"))
2018-07-30 11:06:22 +00:00
.subcommand(SubCommand::with_name("gen-tests"))
2018-07-30 19:17:33 +00:00
.subcommand(SubCommand::with_name("install-code"))
2018-10-26 13:08:21 +00:00
.subcommand(SubCommand::with_name("format"))
2018-12-09 10:29:13 +00:00
.subcommand(SubCommand::with_name("format-hook"))
2018-12-31 13:14:06 +00:00
.subcommand(SubCommand::with_name("fuzz-tests"))
2018-07-30 11:06:22 +00:00
.get_matches();
2019-02-08 11:49:43 +00:00
match matches.subcommand_name().expect("Subcommand must be specified") {
2018-12-09 10:29:13 +00:00
"install-code" => install_code_extension()?,
"gen-tests" => gen_tests(Overwrite)?,
2018-12-09 10:29:13 +00:00
"gen-syntax" => generate(Overwrite)?,
"format" => run_rustfmt(Overwrite)?,
2018-12-09 10:29:13 +00:00
"format-hook" => install_format_hook()?,
2018-12-31 13:14:06 +00:00
"fuzz-tests" => run_fuzzer()?,
2018-07-30 11:06:22 +00:00
_ => unreachable!(),
}
2018-08-09 14:43:39 +00:00
Ok(())
2018-07-30 11:06:22 +00:00
}
2018-07-30 19:17:33 +00:00
fn install_code_extension() -> Result<()> {
2018-09-16 09:54:24 +00:00
run("cargo install --path crates/ra_lsp_server --force", ".")?;
2018-09-15 23:02:25 +00:00
if cfg!(windows) {
2019-01-23 18:23:15 +00:00
run(r"cmd.exe /c npm.cmd ci", "./editors/code")?;
2018-12-17 08:26:41 +00:00
run(r"cmd.exe /c npm.cmd run package", "./editors/code")?;
2018-09-16 00:06:56 +00:00
} else {
2019-01-23 18:23:15 +00:00
run(r"npm ci", "./editors/code")?;
2018-12-17 08:26:41 +00:00
run(r"npm run package", "./editors/code")?;
2018-09-15 23:02:25 +00:00
}
if cfg!(windows) {
run(
2019-01-12 15:00:03 +00:00
r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix --force",
"./editors/code",
)?;
2018-09-15 23:02:25 +00:00
} else {
2019-02-08 11:49:43 +00:00
run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?;
2018-09-15 23:02:25 +00:00
}
2019-03-05 21:19:36 +00:00
verify_installed_extensions()?;
Ok(())
}
fn verify_installed_extensions() -> Result<()> {
let exts = if cfg!(windows) {
run_with_output(r"cmd.exe /c code.cmd --list-extensions", ".")?
} else {
run_with_output(r"code --list-extensions", ".")?
};
if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") {
bail!(
"Could not install the Visual Studio Code extension. Please make sure you \
have at least NodeJS 10.x installed and try again."
);
}
2018-09-15 23:12:53 +00:00
Ok(())
}