aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tools/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_tools/src/main.rs')
-rw-r--r--crates/ra_tools/src/main.rs141
1 files changed, 97 insertions, 44 deletions
diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs
index 7ed592f71..4fcb2adeb 100644
--- a/crates/ra_tools/src/main.rs
+++ b/crates/ra_tools/src/main.rs
@@ -1,70 +1,73 @@
1use clap::{App, SubCommand}; 1use clap::{App, Arg, SubCommand};
2use core::str; 2use core::str;
3use ra_tools::{ 3use ra_tools::{
4 gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, 4 gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, Cmd,
5 run_with_output, Overwrite, Result, 5 Overwrite, Result,
6}; 6};
7use std::{env, path::PathBuf}; 7use std::{env, path::PathBuf};
8 8
9struct InstallOpt {
10 client: Option<ClientOpt>,
11 server: Option<ServerOpt>,
12}
13
14enum ClientOpt {
15 VsCode,
16}
17
18struct ServerOpt {
19 jemalloc: bool,
20}
21
9fn main() -> Result<()> { 22fn main() -> Result<()> {
10 let matches = App::new("tasks") 23 let matches = App::new("tasks")
11 .setting(clap::AppSettings::SubcommandRequiredElseHelp) 24 .setting(clap::AppSettings::SubcommandRequiredElseHelp)
12 .subcommand(SubCommand::with_name("gen-syntax")) 25 .subcommand(SubCommand::with_name("gen-syntax"))
13 .subcommand(SubCommand::with_name("gen-tests")) 26 .subcommand(SubCommand::with_name("gen-tests"))
14 .subcommand(SubCommand::with_name("install-code")) 27 .subcommand(
28 SubCommand::with_name("install-ra")
29 .arg(Arg::with_name("server").long("--server"))
30 .arg(Arg::with_name("jemalloc").long("jemalloc"))
31 .arg(Arg::with_name("client-code").long("client-code").conflicts_with("server")),
32 )
33 .alias("install-code")
15 .subcommand(SubCommand::with_name("format")) 34 .subcommand(SubCommand::with_name("format"))
16 .subcommand(SubCommand::with_name("format-hook")) 35 .subcommand(SubCommand::with_name("format-hook"))
17 .subcommand(SubCommand::with_name("fuzz-tests")) 36 .subcommand(SubCommand::with_name("fuzz-tests"))
18 .subcommand(SubCommand::with_name("lint")) 37 .subcommand(SubCommand::with_name("lint"))
19 .get_matches(); 38 .get_matches();
20 match matches.subcommand_name().expect("Subcommand must be specified") { 39 match matches.subcommand() {
21 "install-code" => { 40 ("install-ra", Some(matches)) => {
22 if cfg!(target_os = "macos") { 41 let opts = InstallOpt {
23 fix_path_for_mac()?; 42 client: if matches.is_present("server") { None } else { Some(ClientOpt::VsCode) },
24 } 43 server: if matches.is_present("client-code") {
25 install_code_extension()?; 44 None
45 } else {
46 Some(ServerOpt { jemalloc: matches.is_present("jemalloc") })
47 },
48 };
49 install(opts)?
26 } 50 }
27 "gen-tests" => gen_tests(Overwrite)?, 51 ("gen-tests", _) => gen_tests(Overwrite)?,
28 "gen-syntax" => generate(Overwrite)?, 52 ("gen-syntax", _) => generate(Overwrite)?,
29 "format" => run_rustfmt(Overwrite)?, 53 ("format", _) => run_rustfmt(Overwrite)?,
30 "format-hook" => install_format_hook()?, 54 ("format-hook", _) => install_format_hook()?,
31 "lint" => run_clippy()?, 55 ("lint", _) => run_clippy()?,
32 "fuzz-tests" => run_fuzzer()?, 56 ("fuzz-tests", _) => run_fuzzer()?,
33 _ => unreachable!(), 57 _ => unreachable!(),
34 } 58 }
35 Ok(()) 59 Ok(())
36} 60}
37 61
38fn install_code_extension() -> Result<()> { 62fn install(opts: InstallOpt) -> Result<()> {
39 run("cargo install --path crates/ra_lsp_server --force", ".")?; 63 if cfg!(target_os = "macos") {
40 if cfg!(windows) { 64 fix_path_for_mac()?
41 run(r"cmd.exe /c npm.cmd ci", "./editors/code")?;
42 run(r"cmd.exe /c npm.cmd run package", "./editors/code")?;
43 } else {
44 run(r"npm ci", "./editors/code")?;
45 run(r"npm run package", "./editors/code")?;
46 } 65 }
47 if cfg!(windows) { 66 if let Some(client) = opts.client {
48 run( 67 install_client(client)?;
49 r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix --force",
50 "./editors/code",
51 )?;
52 } else {
53 run(r"code --install-extension ./ra-lsp-0.0.1.vsix --force", "./editors/code")?;
54 } 68 }
55 verify_installed_extensions()?; 69 if let Some(server) = opts.server {
56 Ok(()) 70 install_server(server)?;
57}
58
59fn verify_installed_extensions() -> Result<()> {
60 let exts = if cfg!(windows) {
61 run_with_output(r"cmd.exe /c code.cmd --list-extensions", ".")?
62 } else {
63 run_with_output(r"code --list-extensions", ".")?
64 };
65 if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") {
66 Err("Could not install the Visual Studio Code extension. Please make sure you \
67 have at least NodeJS 10.x installed and try again.")?;
68 } 71 }
69 Ok(()) 72 Ok(())
70} 73}
@@ -101,3 +104,53 @@ fn fix_path_for_mac() -> Result<()> {
101 104
102 Ok(()) 105 Ok(())
103} 106}
107
108fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
109 Cmd { unix: r"npm ci", windows: r"cmd.exe /c npm.cmd ci", work_dir: "./editors/code" }.run()?;
110 Cmd {
111 unix: r"npm run package",
112 windows: r"cmd.exe /c npm.cmd run package",
113 work_dir: "./editors/code",
114 }
115 .run()?;
116
117 let code_in_path = Cmd {
118 unix: r"code --version",
119 windows: r"cmd.exe /c code.cmd --version",
120 work_dir: "./editors/code",
121 }
122 .run()
123 .is_ok();
124 if !code_in_path {
125 Err("Can't execute `code --version`. Perhaps it is not in $PATH?")?;
126 }
127
128 Cmd {
129 unix: r"code --install-extension ./ra-lsp-0.0.1.vsix --force",
130 windows: r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix --force",
131 work_dir: "./editors/code",
132 }
133 .run()?;
134
135 let output = Cmd {
136 unix: r"code --list-extensions",
137 windows: r"cmd.exe /c code.cmd --list-extensions",
138 work_dir: ".",
139 }
140 .run_with_output()?;
141
142 if !str::from_utf8(&output.stdout)?.contains("ra-lsp") {
143 Err("Could not install the Visual Studio Code extension. \
144 Please make sure you have at least NodeJS 10.x installed and try again.")?;
145 }
146
147 Ok(())
148}
149
150fn install_server(opts: ServerOpt) -> Result<()> {
151 if opts.jemalloc {
152 run("cargo install --path crates/ra_lsp_server --force --features jemalloc", ".")
153 } else {
154 run("cargo install --path crates/ra_lsp_server --force", ".")
155 }
156}