mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Underengineer cargo xtask install --client
This commit is contained in:
parent
142f9a03fd
commit
bf4aaa4fb0
3 changed files with 37 additions and 70 deletions
|
@ -141,14 +141,6 @@ impl Xtask {
|
||||||
// generated end
|
// generated end
|
||||||
|
|
||||||
impl Install {
|
impl Install {
|
||||||
pub(crate) fn validate(&self) -> xflags::Result<()> {
|
|
||||||
if let Some(code_bin) = &self.code_bin {
|
|
||||||
if let Err(err) = code_bin.parse::<ClientOpt>() {
|
|
||||||
return Err(xflags::Error::new(format!("failed to parse `--code-bin`: {}", err)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub(crate) fn server(&self) -> Option<ServerOpt> {
|
pub(crate) fn server(&self) -> Option<ServerOpt> {
|
||||||
if self.client && !self.server {
|
if self.client && !self.server {
|
||||||
return None;
|
return None;
|
||||||
|
@ -166,7 +158,6 @@ impl Install {
|
||||||
if !self.client && self.server {
|
if !self.client && self.server {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let client_opt = self.code_bin.as_ref().and_then(|it| it.parse().ok()).unwrap_or_default();
|
Some(ClientOpt { code_bin: self.code_bin.clone() })
|
||||||
Some(client_opt)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,52 +25,12 @@ impl flags::Install {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone)]
|
||||||
pub(crate) enum ClientOpt {
|
pub(crate) struct ClientOpt {
|
||||||
VsCode,
|
pub(crate) code_bin: Option<String>,
|
||||||
VsCodeExploration,
|
|
||||||
VsCodeInsiders,
|
|
||||||
VsCodium,
|
|
||||||
VsCodeOss,
|
|
||||||
Any,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientOpt {
|
const VS_CODES: &[&str] = &["code", "code-exploration", "code-insiders", "codium", "code-oss"];
|
||||||
pub(crate) const fn as_cmds(&self) -> &'static [&'static str] {
|
|
||||||
match self {
|
|
||||||
ClientOpt::VsCode => &["code"],
|
|
||||||
ClientOpt::VsCodeExploration => &["code-exploration"],
|
|
||||||
ClientOpt::VsCodeInsiders => &["code-insiders"],
|
|
||||||
ClientOpt::VsCodium => &["codium"],
|
|
||||||
ClientOpt::VsCodeOss => &["code-oss"],
|
|
||||||
ClientOpt::Any => &["code", "code-exploration", "code-insiders", "codium", "code-oss"],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ClientOpt {
|
|
||||||
fn default() -> Self {
|
|
||||||
ClientOpt::Any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::str::FromStr for ClientOpt {
|
|
||||||
type Err = anyhow::Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
[
|
|
||||||
ClientOpt::VsCode,
|
|
||||||
ClientOpt::VsCodeExploration,
|
|
||||||
ClientOpt::VsCodeInsiders,
|
|
||||||
ClientOpt::VsCodium,
|
|
||||||
ClientOpt::VsCodeOss,
|
|
||||||
]
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.find(|c| [s] == c.as_cmds())
|
|
||||||
.ok_or_else(|| anyhow::format_err!("no such client"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct ServerOpt {
|
pub(crate) struct ServerOpt {
|
||||||
pub(crate) malloc: Malloc,
|
pub(crate) malloc: Malloc,
|
||||||
|
@ -118,21 +78,12 @@ fn fix_path_for_mac() -> Result<()> {
|
||||||
fn install_client(client_opt: ClientOpt) -> Result<()> {
|
fn install_client(client_opt: ClientOpt) -> Result<()> {
|
||||||
let _dir = pushd("./editors/code");
|
let _dir = pushd("./editors/code");
|
||||||
|
|
||||||
let find_code = |f: fn(&str) -> bool| -> Result<&'static str> {
|
// Package extension.
|
||||||
client_opt.as_cmds().iter().copied().find(|bin| f(bin)).ok_or_else(|| {
|
if cfg!(unix) {
|
||||||
format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
let installed_extensions = if cfg!(unix) {
|
|
||||||
cmd!("npm --version").run().context("`npm` is required to build the VS Code plugin")?;
|
cmd!("npm --version").run().context("`npm` is required to build the VS Code plugin")?;
|
||||||
cmd!("npm ci").run()?;
|
cmd!("npm ci").run()?;
|
||||||
|
|
||||||
cmd!("npm run package --scripts-prepend-node-path").run()?;
|
cmd!("npm run package --scripts-prepend-node-path").run()?;
|
||||||
|
|
||||||
let code = find_code(|bin| cmd!("{bin} --version").read().is_ok())?;
|
|
||||||
cmd!("{code} --install-extension rust-analyzer.vsix --force").run()?;
|
|
||||||
cmd!("{code} --list-extensions").read()?
|
|
||||||
} else {
|
} else {
|
||||||
cmd!("cmd.exe /c npm --version")
|
cmd!("cmd.exe /c npm --version")
|
||||||
.run()
|
.run()
|
||||||
|
@ -140,8 +91,36 @@ fn install_client(client_opt: ClientOpt) -> Result<()> {
|
||||||
cmd!("cmd.exe /c npm ci").run()?;
|
cmd!("cmd.exe /c npm ci").run()?;
|
||||||
|
|
||||||
cmd!("cmd.exe /c npm run package").run()?;
|
cmd!("cmd.exe /c npm run package").run()?;
|
||||||
|
};
|
||||||
|
|
||||||
let code = find_code(|bin| cmd!("cmd.exe /c {bin}.cmd --version").read().is_ok())?;
|
// Find the appropriate VS Code binary.
|
||||||
|
let lifetime_extender;
|
||||||
|
let candidates: &[&str] = match client_opt.code_bin.as_deref() {
|
||||||
|
Some(it) => {
|
||||||
|
lifetime_extender = [it];
|
||||||
|
&lifetime_extender[..]
|
||||||
|
}
|
||||||
|
None => VS_CODES,
|
||||||
|
};
|
||||||
|
let code = candidates
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.find(|&bin| {
|
||||||
|
if cfg!(unix) {
|
||||||
|
cmd!("{bin} --version").read().is_ok()
|
||||||
|
} else {
|
||||||
|
cmd!("cmd.exe /c {bin}.cmd --version").read().is_ok()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok_or_else(|| {
|
||||||
|
format_err!("Can't execute `{} --version`. Perhaps it is not in $PATH?", candidates[0])
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// Install & verify.
|
||||||
|
let installed_extensions = if cfg!(unix) {
|
||||||
|
cmd!("{code} --install-extension rust-analyzer.vsix --force").run()?;
|
||||||
|
cmd!("{code} --list-extensions").read()?
|
||||||
|
} else {
|
||||||
cmd!("cmd.exe /c {code}.cmd --install-extension rust-analyzer.vsix --force").run()?;
|
cmd!("cmd.exe /c {code}.cmd --install-extension rust-analyzer.vsix --force").run()?;
|
||||||
cmd!("cmd.exe /c {code}.cmd --list-extensions").read()?
|
cmd!("cmd.exe /c {code}.cmd --list-extensions").read()?
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,10 +39,7 @@ fn main() -> Result<()> {
|
||||||
println!("{}", flags::Xtask::HELP);
|
println!("{}", flags::Xtask::HELP);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
flags::XtaskCmd::Install(cmd) => {
|
flags::XtaskCmd::Install(cmd) => cmd.run(),
|
||||||
cmd.validate()?;
|
|
||||||
cmd.run()
|
|
||||||
}
|
|
||||||
flags::XtaskCmd::Codegen(cmd) => cmd.run(),
|
flags::XtaskCmd::Codegen(cmd) => cmd.run(),
|
||||||
flags::XtaskCmd::Lint(_) => run_clippy(),
|
flags::XtaskCmd::Lint(_) => run_clippy(),
|
||||||
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),
|
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),
|
||||||
|
|
Loading…
Reference in a new issue