aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tools
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-07-27 12:35:18 +0100
committerAleksey Kladov <[email protected]>2019-07-27 12:35:18 +0100
commitecb1327fed1ece4083aa09255dbd927c5df304ef (patch)
treec6a49bf13df5cd5529f9145391c7922ef17eb3a7 /crates/ra_tools
parentd23a7558702bcffd9c551bea444475f4a76ba201 (diff)
Overhaul installation process
The new commands are $ cargo install-ra --client-code $ cargo install-ra --server --jemalloc
Diffstat (limited to 'crates/ra_tools')
-rw-r--r--crates/ra_tools/src/lib.rs23
-rw-r--r--crates/ra_tools/src/main.rs135
2 files changed, 114 insertions, 44 deletions
diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs
index 79fbcd11d..bb7845f7d 100644
--- a/crates/ra_tools/src/lib.rs
+++ b/crates/ra_tools/src/lib.rs
@@ -79,6 +79,29 @@ pub fn project_root() -> PathBuf {
79 Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf() 79 Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf()
80} 80}
81 81
82pub struct Cmd {
83 pub unix: &'static str,
84 pub windows: &'static str,
85 pub work_dir: &'static str,
86}
87
88impl Cmd {
89 pub fn run(self) -> Result<()> {
90 if cfg!(windows) {
91 run(self.windows, self.work_dir)
92 } else {
93 run(self.unix, self.work_dir)
94 }
95 }
96 pub fn run_with_output(self) -> Result<Output> {
97 if cfg!(windows) {
98 run_with_output(self.windows, self.work_dir)
99 } else {
100 run_with_output(self.unix, self.work_dir)
101 }
102 }
103}
104
82pub fn run(cmdline: &str, dir: &str) -> Result<()> { 105pub fn run(cmdline: &str, dir: &str) -> Result<()> {
83 do_run(cmdline, dir, |c| { 106 do_run(cmdline, dir, |c| {
84 c.stdout(Stdio::inherit()); 107 c.stdout(Stdio::inherit());
diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs
index 7ed592f71..59d4ea6d3 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").requires("server"))
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,47 @@ 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
111 let code_in_path = Cmd {
112 unix: r"code --version",
113 windows: r"cmd.exe /c code.cmd --version",
114 work_dir: "./editors/code",
115 }
116 .run()
117 .is_ok();
118 if !code_in_path {
119 Err("Can't execute `code --version`. Perhaps it is not in $PATH?")?;
120 }
121
122 Cmd {
123 unix: r"code --install-extension ./ra-lsp-0.0.1.vsix --force",
124 windows: r"cmd.exe /c code.cmd --install-extension ./ra-lsp-0.0.1.vsix --force",
125 work_dir: "./editors/code",
126 }
127 .run()?;
128
129 let output = Cmd {
130 unix: r"code --list-extensions",
131 windows: r"cmd.exe /c code.cmd --list-extensions",
132 work_dir: ".",
133 }
134 .run_with_output()?;
135
136 if !str::from_utf8(&output.stdout)?.contains("ra-lsp") {
137 Err("Could not install the Visual Studio Code extension. \
138 Please make sure you have at least NodeJS 10.x installed and try again.")?;
139 }
140
141 Ok(())
142}
143
144fn install_server(opts: ServerOpt) -> Result<()> {
145 if opts.jemalloc {
146 run("cargo install --path crates/ra_lsp_server --force --features jemalloc", ".")
147 } else {
148 run("cargo install --path crates/ra_lsp_server --force", ".")
149 }
150}