aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock16
-rw-r--r--xtask/src/flags.rs11
-rw-r--r--xtask/src/install.rs91
-rw-r--r--xtask/src/main.rs5
4 files changed, 45 insertions, 78 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e8f10b938..39f27098a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -113,9 +113,9 @@ checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b"
113 113
114[[package]] 114[[package]]
115name = "camino" 115name = "camino"
116version = "1.0.1" 116version = "1.0.2"
117source = "registry+https://github.com/rust-lang/crates.io-index" 117source = "registry+https://github.com/rust-lang/crates.io-index"
118checksum = "9bb47ab72bdba43021afa16dc1ef4d80c980d366b17ed37ea8d2ebe2087075b9" 118checksum = "cd065703998b183ed0b348a22555691373a9345a1431141e5778b48bb17e4703"
119dependencies = [ 119dependencies = [
120 "serde", 120 "serde",
121] 121]
@@ -789,9 +789,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
789 789
790[[package]] 790[[package]]
791name = "libc" 791name = "libc"
792version = "0.2.87" 792version = "0.2.88"
793source = "registry+https://github.com/rust-lang/crates.io-index" 793source = "registry+https://github.com/rust-lang/crates.io-index"
794checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" 794checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a"
795 795
796[[package]] 796[[package]]
797name = "libloading" 797name = "libloading"
@@ -1127,9 +1127,9 @@ dependencies = [
1127 1127
1128[[package]] 1128[[package]]
1129name = "pin-project-lite" 1129name = "pin-project-lite"
1130version = "0.2.5" 1130version = "0.2.6"
1131source = "registry+https://github.com/rust-lang/crates.io-index" 1131source = "registry+https://github.com/rust-lang/crates.io-index"
1132checksum = "0cf491442e4b033ed1c722cb9f0df5fcfcf4de682466c46469c36bc47dc5548a" 1132checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
1133 1133
1134[[package]] 1134[[package]]
1135name = "proc-macro-hack" 1135name = "proc-macro-hack"
@@ -1561,9 +1561,9 @@ dependencies = [
1561 1561
1562[[package]] 1562[[package]]
1563name = "syn" 1563name = "syn"
1564version = "1.0.60" 1564version = "1.0.61"
1565source = "registry+https://github.com/rust-lang/crates.io-index" 1565source = "registry+https://github.com/rust-lang/crates.io-index"
1566checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" 1566checksum = "ed22b90a0e734a23a7610f4283ac9e5acfb96cbb30dfefa540d66f866f1c09c5"
1567dependencies = [ 1567dependencies = [
1568 "proc-macro2", 1568 "proc-macro2",
1569 "quote", 1569 "quote",
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(),