aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xtask/src/flags.rs11
-rw-r--r--xtask/src/install.rs91
-rw-r--r--xtask/src/main.rs5
3 files changed, 37 insertions, 70 deletions
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs
index 2ca05d3df..56eda5b1e 100644
--- a/xtask/src/flags.rs
+++ b/xtask/src/flags.rs
@@ -141,14 +141,6 @@ impl Xtask {
141// generated end 141// generated end
142 142
143impl Install { 143impl Install {
144 pub(crate) fn validate(&self) -> xflags::Result<()> {
145 if let Some(code_bin) = &self.code_bin {
146 if let Err(err) = code_bin.parse::<ClientOpt>() {
147 return Err(xflags::Error::new(format!("failed to parse `--code-bin`: {}", err)));
148 }
149 }
150 Ok(())
151 }
152 pub(crate) fn server(&self) -> Option<ServerOpt> { 144 pub(crate) fn server(&self) -> Option<ServerOpt> {
153 if self.client && !self.server { 145 if self.client && !self.server {
154 return None; 146 return None;
@@ -166,7 +158,6 @@ impl Install {
166 if !self.client && self.server { 158 if !self.client && self.server {
167 return None; 159 return None;
168 } 160 }
169 let client_opt = self.code_bin.as_ref().and_then(|it| it.parse().ok()).unwrap_or_default(); 161 Some(ClientOpt { code_bin: self.code_bin.clone() })
170 Some(client_opt)
171 } 162 }
172} 163}
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)]
29pub(crate) enum ClientOpt { 29pub(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
38impl ClientOpt { 33const 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
51impl Default for ClientOpt {
52 fn default() -> Self {
53 ClientOpt::Any
54 }
55}
56
57impl 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
75pub(crate) struct ServerOpt { 35pub(crate) struct ServerOpt {
76 pub(crate) malloc: Malloc, 36 pub(crate) malloc: Malloc,
@@ -118,21 +78,12 @@ fn fix_path_for_mac() -> Result<()> {
118fn install_client(client_opt: ClientOpt) -> Result<()> { 78fn 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 };
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index ca27b6cec..3c4332f75 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -39,10 +39,7 @@ fn main() -> Result<()> {
39 println!("{}", flags::Xtask::HELP); 39 println!("{}", flags::Xtask::HELP);
40 return Ok(()); 40 return Ok(());
41 } 41 }
42 flags::XtaskCmd::Install(cmd) => { 42 flags::XtaskCmd::Install(cmd) => cmd.run(),
43 cmd.validate()?;
44 cmd.run()
45 }
46 flags::XtaskCmd::Codegen(cmd) => cmd.run(), 43 flags::XtaskCmd::Codegen(cmd) => cmd.run(),
47 flags::XtaskCmd::Lint(_) => run_clippy(), 44 flags::XtaskCmd::Lint(_) => run_clippy(),
48 flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), 45 flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),