Skip to content

Commit

Permalink
xtask: add prep-lsp command to replace copy-lsp and `copy-lsp-rel…
Browse files Browse the repository at this point in the history
…ease`
  • Loading branch information
SpontanCombust committed Jan 27, 2024
1 parent 5ae9736 commit bf5dfc8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 62 deletions.
13 changes: 9 additions & 4 deletions xtask/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ pub struct Cli {

#[derive(Subcommand)]
pub enum Commands {
/// Copy debug build of the LSP server to the VSCode client
CopyLsp,
/// Copy release build of the LSP server to the VSCode client
CopyLspRelease,
// Build and copy LSP server into VSCode's extension directory
PrepLsp {
/// Should LSP be built with optimised release profile
#[arg(long)]
release: bool,
/// Compilation target triple
#[arg(long)]
target: Option<String>
},
/// Build and package VSCode extension into a .vsix file
Package {
/// Output directory for the .vsix file; default is the current working directory
Expand Down
26 changes: 0 additions & 26 deletions xtask/src/commands/copy_lsp.rs

This file was deleted.

26 changes: 0 additions & 26 deletions xtask/src/commands/copy_lsp_release.rs

This file was deleted.

6 changes: 2 additions & 4 deletions xtask/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod copy_lsp;
mod copy_lsp_release;
mod prep_lsp;
mod package;
mod install;

pub use copy_lsp::copy_lsp;
pub use copy_lsp_release::copy_lsp_release;
pub use prep_lsp::prep_lsp;
pub use package::package;
pub use install::install;
42 changes: 42 additions & 0 deletions xtask/src/commands/prep_lsp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::path::PathBuf;
use xshell::{Shell, cmd};


const LSP_DST: &str = "./editors/vscode/server/bin";

pub fn prep_lsp(release: bool, target: Option<String>) -> anyhow::Result<()> {
let sh = Shell::new()?;

let mut build = cmd!(sh, "cargo build --package witcherscript-lsp");

let mut lsp_src = PathBuf::from("./target");
if let Some(target) = target {
build = build.arg("--target").arg(&target);
lsp_src.push(target);
}

if release {
build = build.arg("--release");
lsp_src.push("release");
} else {
lsp_src.push("debug");
}

lsp_src.push("witcherscript-lsp");

if cfg!(windows) {
lsp_src.set_extension("exe");
}

println!("Building the LSP...");
build.run()?;


// make sure destination folder exists
sh.create_dir(LSP_DST)?;

sh.copy_file(lsp_src, LSP_DST)?;
println!("Copied LSP into {}", LSP_DST);

Ok(())
}
3 changes: 1 addition & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ fn main() -> anyhow::Result<()> {
let cli = Cli::parse();

match cli.command {
cli::Commands::CopyLsp => commands::copy_lsp(),
cli::Commands::CopyLspRelease => commands::copy_lsp_release(),
cli::Commands::PrepLsp { release, target } => commands::prep_lsp(release, target),
cli::Commands::Package { out_dir } => commands::package(out_dir),
cli::Commands::Install => commands::install()
}
Expand Down

0 comments on commit bf5dfc8

Please sign in to comment.