diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-27 12:36:17 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-27 12:36:17 +0100 |
commit | 442072d746c06c61923d85b8e33f4201a7bd57ab (patch) | |
tree | c6a49bf13df5cd5529f9145391c7922ef17eb3a7 | |
parent | d23a7558702bcffd9c551bea444475f4a76ba201 (diff) | |
parent | ecb1327fed1ece4083aa09255dbd927c5df304ef (diff) |
Merge #1597
1597: Overhaul installation process r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | .cargo/config | 12 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | crates/ra_tools/src/lib.rs | 23 | ||||
-rw-r--r-- | crates/ra_tools/src/main.rs | 135 | ||||
-rw-r--r-- | docs/dev/README.md | 8 | ||||
-rw-r--r-- | docs/user/README.md | 4 |
6 files changed, 128 insertions, 58 deletions
diff --git a/.cargo/config b/.cargo/config index 3ac2ce336..92a3acfd0 100644 --- a/.cargo/config +++ b/.cargo/config | |||
@@ -1,23 +1,23 @@ | |||
1 | [alias] | 1 | [alias] |
2 | # Automatically generates the ast and syntax kinds files | 2 | # Automatically generates the ast and syntax kinds files |
3 | gen-syntax = "run --package ra_tools --bin ra_tools -- gen-syntax" | 3 | gen-syntax = "run --package ra_tools --bin ra_tools -- gen-syntax" |
4 | |||
4 | # Extracts the tests from | 5 | # Extracts the tests from |
5 | gen-tests = "run --package ra_tools --bin ra_tools -- gen-tests" | 6 | gen-tests = "run --package ra_tools --bin ra_tools -- gen-tests" |
6 | # Installs ra_lsp_server | 7 | |
7 | install-lsp = "install --path crates/ra_lsp_server --force" | ||
8 | # Installs ra_lsp_server with the jemalloc feature | ||
9 | jinstall-lsp = "install --path crates/ra_lsp_server --force --features jemalloc" | ||
10 | # Installs the visual studio code extension | 8 | # Installs the visual studio code extension |
11 | install-code = "run --package ra_tools --bin ra_tools -- install-code" | 9 | install-ra = "run --package ra_tools --bin ra_tools -- install-ra" |
10 | install-code = "run --package ra_tools --bin ra_tools -- install-ra" # just an alias | ||
11 | |||
12 | # Formats the full repository or installs the git hook to do it automatically. | 12 | # Formats the full repository or installs the git hook to do it automatically. |
13 | format = "run --package ra_tools --bin ra_tools -- format" | 13 | format = "run --package ra_tools --bin ra_tools -- format" |
14 | format-hook = "run --package ra_tools --bin ra_tools -- format-hook" | 14 | format-hook = "run --package ra_tools --bin ra_tools -- format-hook" |
15 | |||
15 | # Run clippy | 16 | # Run clippy |
16 | lint = "run --package ra_tools --bin ra_tools -- lint" | 17 | lint = "run --package ra_tools --bin ra_tools -- lint" |
17 | 18 | ||
18 | # Runs the fuzzing test suite (currently only parser) | 19 | # Runs the fuzzing test suite (currently only parser) |
19 | fuzz-tests = "run --package ra_tools --bin ra_tools -- fuzz-tests" | 20 | fuzz-tests = "run --package ra_tools --bin ra_tools -- fuzz-tests" |
20 | 21 | ||
21 | render-test = "run --package ra_cli -- render-test" | ||
22 | # Parse a file. This should be piped the file contents | 22 | # Parse a file. This should be piped the file contents |
23 | parse = "run --package ra_cli -- parse" | 23 | parse = "run --package ra_cli -- parse" |
@@ -32,10 +32,10 @@ For setup for other editors, see [./docs/user](./docs/user). | |||
32 | $ git clone https://github.com/rust-analyzer/rust-analyzer && cd rust-analyzer | 32 | $ git clone https://github.com/rust-analyzer/rust-analyzer && cd rust-analyzer |
33 | 33 | ||
34 | # install both the language server and VS Code extension | 34 | # install both the language server and VS Code extension |
35 | $ cargo install-code | 35 | $ cargo install-ra |
36 | 36 | ||
37 | # alternatively, install only the server. Binary name is `ra_lsp_server`. | 37 | # alternatively, install only the server. Binary name is `ra_lsp_server`. |
38 | $ cargo install-lsp | 38 | $ cargo install-ra --server |
39 | ``` | 39 | ``` |
40 | ## Documentation | 40 | ## Documentation |
41 | 41 | ||
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 | ||
82 | pub struct Cmd { | ||
83 | pub unix: &'static str, | ||
84 | pub windows: &'static str, | ||
85 | pub work_dir: &'static str, | ||
86 | } | ||
87 | |||
88 | impl 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 | |||
82 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { | 105 | pub 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 @@ | |||
1 | use clap::{App, SubCommand}; | 1 | use clap::{App, Arg, SubCommand}; |
2 | use core::str; | 2 | use core::str; |
3 | use ra_tools::{ | 3 | use 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 | }; |
7 | use std::{env, path::PathBuf}; | 7 | use std::{env, path::PathBuf}; |
8 | 8 | ||
9 | struct InstallOpt { | ||
10 | client: Option<ClientOpt>, | ||
11 | server: Option<ServerOpt>, | ||
12 | } | ||
13 | |||
14 | enum ClientOpt { | ||
15 | VsCode, | ||
16 | } | ||
17 | |||
18 | struct ServerOpt { | ||
19 | jemalloc: bool, | ||
20 | } | ||
21 | |||
9 | fn main() -> Result<()> { | 22 | fn 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 | ||
38 | fn install_code_extension() -> Result<()> { | 62 | fn 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 | |||
59 | fn 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 | |||
108 | fn 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 | |||
144 | fn 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 | } | ||
diff --git a/docs/dev/README.md b/docs/dev/README.md index 0a148ed32..74c58d4af 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -66,7 +66,7 @@ typescript) and Emacs (in elisp). The `docs` top-level directory contains both | |||
66 | developer and user documentation. | 66 | developer and user documentation. |
67 | 67 | ||
68 | We have some automation infra in Rust in the `crates/tool` package. It contains | 68 | We have some automation infra in Rust in the `crates/tool` package. It contains |
69 | stuff like formatting checking, code generation and powers `cargo install-code`. | 69 | stuff like formatting checking, code generation and powers `cargo install-ra`. |
70 | The latter syntax is achieved with the help of cargo aliases (see `.cargo` | 70 | The latter syntax is achieved with the help of cargo aliases (see `.cargo` |
71 | directory). | 71 | directory). |
72 | 72 | ||
@@ -84,7 +84,7 @@ However, launching a VS Code instance with locally build language server is | |||
84 | possible. There's even a VS Code task for this, so just <kbd>F5</kbd> should | 84 | possible. There's even a VS Code task for this, so just <kbd>F5</kbd> should |
85 | work (thanks, [@andrew-w-ross](https://github.com/andrew-w-ross)!). | 85 | work (thanks, [@andrew-w-ross](https://github.com/andrew-w-ross)!). |
86 | 86 | ||
87 | I often just install development version with `cargo jinstall-lsp` and | 87 | I often just install development version with `cargo install-ra --server --jemalloc` and |
88 | restart the host VS Code. | 88 | restart the host VS Code. |
89 | 89 | ||
90 | See [./debugging.md](./debugging.md) for how to attach to rust-analyzer with | 90 | See [./debugging.md](./debugging.md) for how to attach to rust-analyzer with |
@@ -110,7 +110,7 @@ ways: | |||
110 | 110 | ||
111 | 2. Run `npm test` from the command line. Although this is initiated from the | 111 | 2. Run `npm test` from the command line. Although this is initiated from the |
112 | command line it is not headless; it will also launch a temporary instance of | 112 | command line it is not headless; it will also launch a temporary instance of |
113 | VS Code. | 113 | VS Code. |
114 | 114 | ||
115 | Due to the requirements of running the tests inside VS Code they are **not run | 115 | Due to the requirements of running the tests inside VS Code they are **not run |
116 | on CI**. When making changes to the extension please ensure the tests are not | 116 | on CI**. When making changes to the extension please ensure the tests are not |
@@ -151,7 +151,7 @@ There's also two VS Code commands which might be of interest: | |||
151 | $ cargo install --path crates/ra_lsp_server --force --features jemalloc | 151 | $ cargo install --path crates/ra_lsp_server --force --features jemalloc |
152 | ``` | 152 | ``` |
153 | 153 | ||
154 | There's an alias for this: `cargo jinstall-lsp`. | 154 | There's an alias for this: `cargo install-ra --server --jemalloc`. |
155 | 155 | ||
156 | * `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection. | 156 | * `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection. |
157 | 157 | ||
diff --git a/docs/user/README.md b/docs/user/README.md index 8a5767849..122388a42 100644 --- a/docs/user/README.md +++ b/docs/user/README.md | |||
@@ -1,6 +1,6 @@ | |||
1 | The main interface to rust-analyzer is the | 1 | The main interface to rust-analyzer is the |
2 | [LSP](https://microsoft.github.io/language-server-protocol/) implementation. To | 2 | [LSP](https://microsoft.github.io/language-server-protocol/) implementation. To |
3 | install lsp server, use `cargo install-lsp`, which is a shorthand for `cargo | 3 | install lsp server, use `cargo install-ra --server`, which is a shorthand for `cargo |
4 | install --package ra_lsp_server`. The binary is named `ra_lsp_server`, you | 4 | install --package ra_lsp_server`. The binary is named `ra_lsp_server`, you |
5 | should be able to use it with any LSP-compatible editor. We use custom | 5 | should be able to use it with any LSP-compatible editor. We use custom |
6 | extensions to LSP, so special client-side support is required to take full | 6 | extensions to LSP, so special client-side support is required to take full |
@@ -33,7 +33,7 @@ following commands: | |||
33 | ``` | 33 | ``` |
34 | $ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1 | 34 | $ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1 |
35 | $ cd rust-analyzer | 35 | $ cd rust-analyzer |
36 | $ cargo install-code | 36 | $ cargo install-ra |
37 | ``` | 37 | ``` |
38 | 38 | ||
39 | The automatic installation is expected to *just work* for common cases, if it | 39 | The automatic installation is expected to *just work* for common cases, if it |