diff options
Diffstat (limited to 'xtask/src/install.rs')
-rw-r--r-- | xtask/src/install.rs | 91 |
1 files changed, 35 insertions, 56 deletions
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index 3e8fbe0a6..177028b08 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -25,52 +25,12 @@ impl flags::Install { | |||
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | #[derive(Clone, Copy)] | 28 | #[derive(Clone)] |
29 | pub(crate) enum ClientOpt { | 29 | pub(crate) struct ClientOpt { |
30 | VsCode, | 30 | pub(crate) code_bin: Option<String>, |
31 | VsCodeExploration, | ||
32 | VsCodeInsiders, | ||
33 | VsCodium, | ||
34 | VsCodeOss, | ||
35 | Any, | ||
36 | } | 31 | } |
37 | 32 | ||
38 | impl ClientOpt { | 33 | const VS_CODES: &[&str] = &["code", "code-exploration", "code-insiders", "codium", "code-oss"]; |
39 | pub(crate) const fn as_cmds(&self) -> &'static [&'static str] { | ||
40 | match self { | ||
41 | ClientOpt::VsCode => &["code"], | ||
42 | ClientOpt::VsCodeExploration => &["code-exploration"], | ||
43 | ClientOpt::VsCodeInsiders => &["code-insiders"], | ||
44 | ClientOpt::VsCodium => &["codium"], | ||
45 | ClientOpt::VsCodeOss => &["code-oss"], | ||
46 | ClientOpt::Any => &["code", "code-exploration", "code-insiders", "codium", "code-oss"], | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | |||
51 | impl Default for ClientOpt { | ||
52 | fn default() -> Self { | ||
53 | ClientOpt::Any | ||
54 | } | ||
55 | } | ||
56 | |||
57 | impl std::str::FromStr for ClientOpt { | ||
58 | type Err = anyhow::Error; | ||
59 | |||
60 | fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
61 | [ | ||
62 | ClientOpt::VsCode, | ||
63 | ClientOpt::VsCodeExploration, | ||
64 | ClientOpt::VsCodeInsiders, | ||
65 | ClientOpt::VsCodium, | ||
66 | ClientOpt::VsCodeOss, | ||
67 | ] | ||
68 | .iter() | ||
69 | .copied() | ||
70 | .find(|c| [s] == c.as_cmds()) | ||
71 | .ok_or_else(|| anyhow::format_err!("no such client")) | ||
72 | } | ||
73 | } | ||
74 | 34 | ||
75 | pub(crate) struct ServerOpt { | 35 | pub(crate) struct ServerOpt { |
76 | pub(crate) malloc: Malloc, | 36 | pub(crate) malloc: Malloc, |
@@ -118,21 +78,12 @@ fn fix_path_for_mac() -> Result<()> { | |||
118 | fn install_client(client_opt: ClientOpt) -> Result<()> { | 78 | fn install_client(client_opt: ClientOpt) -> Result<()> { |
119 | let _dir = pushd("./editors/code"); | 79 | let _dir = pushd("./editors/code"); |
120 | 80 | ||
121 | let find_code = |f: fn(&str) -> bool| -> Result<&'static str> { | 81 | // Package extension. |
122 | client_opt.as_cmds().iter().copied().find(|bin| f(bin)).ok_or_else(|| { | 82 | if cfg!(unix) { |
123 | format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?") | ||
124 | }) | ||
125 | }; | ||
126 | |||
127 | let installed_extensions = if cfg!(unix) { | ||
128 | cmd!("npm --version").run().context("`npm` is required to build the VS Code plugin")?; | 83 | cmd!("npm --version").run().context("`npm` is required to build the VS Code plugin")?; |
129 | cmd!("npm ci").run()?; | 84 | cmd!("npm ci").run()?; |
130 | 85 | ||
131 | cmd!("npm run package --scripts-prepend-node-path").run()?; | 86 | cmd!("npm run package --scripts-prepend-node-path").run()?; |
132 | |||
133 | let code = find_code(|bin| cmd!("{bin} --version").read().is_ok())?; | ||
134 | cmd!("{code} --install-extension rust-analyzer.vsix --force").run()?; | ||
135 | cmd!("{code} --list-extensions").read()? | ||
136 | } else { | 87 | } else { |
137 | cmd!("cmd.exe /c npm --version") | 88 | cmd!("cmd.exe /c npm --version") |
138 | .run() | 89 | .run() |
@@ -140,8 +91,36 @@ fn install_client(client_opt: ClientOpt) -> Result<()> { | |||
140 | cmd!("cmd.exe /c npm ci").run()?; | 91 | cmd!("cmd.exe /c npm ci").run()?; |
141 | 92 | ||
142 | cmd!("cmd.exe /c npm run package").run()?; | 93 | cmd!("cmd.exe /c npm run package").run()?; |
94 | }; | ||
95 | |||
96 | // Find the appropriate VS Code binary. | ||
97 | let lifetime_extender; | ||
98 | let candidates: &[&str] = match client_opt.code_bin.as_deref() { | ||
99 | Some(it) => { | ||
100 | lifetime_extender = [it]; | ||
101 | &lifetime_extender[..] | ||
102 | } | ||
103 | None => VS_CODES, | ||
104 | }; | ||
105 | let code = candidates | ||
106 | .iter() | ||
107 | .copied() | ||
108 | .find(|&bin| { | ||
109 | if cfg!(unix) { | ||
110 | cmd!("{bin} --version").read().is_ok() | ||
111 | } else { | ||
112 | cmd!("cmd.exe /c {bin}.cmd --version").read().is_ok() | ||
113 | } | ||
114 | }) | ||
115 | .ok_or_else(|| { | ||
116 | format_err!("Can't execute `{} --version`. Perhaps it is not in $PATH?", candidates[0]) | ||
117 | })?; | ||
143 | 118 | ||
144 | let code = find_code(|bin| cmd!("cmd.exe /c {bin}.cmd --version").read().is_ok())?; | 119 | // Install & verify. |
120 | let installed_extensions = if cfg!(unix) { | ||
121 | cmd!("{code} --install-extension rust-analyzer.vsix --force").run()?; | ||
122 | cmd!("{code} --list-extensions").read()? | ||
123 | } else { | ||
145 | cmd!("cmd.exe /c {code}.cmd --install-extension rust-analyzer.vsix --force").run()?; | 124 | cmd!("cmd.exe /c {code}.cmd --install-extension rust-analyzer.vsix --force").run()?; |
146 | cmd!("cmd.exe /c {code}.cmd --list-extensions").read()? | 125 | cmd!("cmd.exe /c {code}.cmd --list-extensions").read()? |
147 | }; | 126 | }; |