Skip to content

Commit

Permalink
xtask: remove build stage in package and install + add args to th…
Browse files Browse the repository at this point in the history
…ose commands
  • Loading branch information
SpontanCombust committed Jan 27, 2024
1 parent bf5dfc8 commit 4a070aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 44 deletions.
5 changes: 4 additions & 1 deletion xtask/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub enum Commands {
Package {
/// Output directory for the .vsix file; default is the current working directory
#[arg(long)]
out_dir: Option<String>
out_dir: Option<String>,
/// Name of the output file without the extension
#[arg(long)]
out_name: Option<String>
},
/// Build, package and install the VSCode extension
Install
Expand Down
18 changes: 0 additions & 18 deletions xtask/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,12 @@ use anyhow::{Context, bail};
use xshell::{Shell, cmd};


const LSP_SRC: &str = "./target/release/witcherscript-lsp";
const LSP_DST: &str = "./editors/vscode/server/bin";
const EXT_DIR: &str = "./editors/vscode";
const VSIX_NAME: &str = "witcherscript-ide.vsix";

pub fn install() -> anyhow::Result<()> {
let sh = Shell::new()?;

println!("Building LSP release...");
cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?;

let lsp_src = if cfg!(unix) {
LSP_SRC.to_string()
} else {
format!("{LSP_SRC}.exe")
};

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

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


sh.change_dir(EXT_DIR);

if cfg!(unix) {
Expand Down
30 changes: 6 additions & 24 deletions xtask/src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,20 @@ use anyhow::Context;
use xshell::{Shell, cmd};


const LSP_SRC: &str = "./target/release/witcherscript-lsp";
const LSP_DST: &str = "./editors/vscode/server/bin";
const EXT_DIR: &str = "./editors/vscode";
const VSIX_NAME: &str = "witcherscript-ide.vsix";

pub fn package(out_dir: Option<String>) -> anyhow::Result<()> {
pub fn package(out_dir: Option<String>, out_name: Option<String>) -> anyhow::Result<()> {
let sh = Shell::new()?;

// normalize the output path so it stays valid when we change cwd
let output_dir = if let Some(output_dir) = out_dir {
Some(PathBuf::from(&output_dir).canonicalize()?)
let out_dir = if let Some(out_dir) = out_dir {
// can't just use Option::map because of error propagation here
Some(PathBuf::from(&out_dir).canonicalize()?)
} else {
None
};

println!("Building LSP release...");
cmd!(sh, "cargo build --package witcherscript-lsp --release").run()?;

let lsp_src = if cfg!(unix) {
LSP_SRC.to_string()
} else {
format!("{LSP_SRC}.exe")
};

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

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


sh.change_dir(EXT_DIR);

if cfg!(unix) {
Expand All @@ -48,9 +31,8 @@ pub fn package(out_dir: Option<String>) -> anyhow::Result<()> {
cmd!(sh, "cmd.exe /c npm run package").run()?;
}

let version = env!("CARGO_PKG_VERSION");
let vsix_file = format!("witcherscript-ide-{version}.vsix");
let vsix_dst = if let Some(output_dir) = output_dir {
let vsix_file = format!("{}.vsix", out_name.unwrap_or("witcherscript-ide".to_string()));
let vsix_dst = if let Some(output_dir) = out_dir {
output_dir.join(vsix_file)
} else {
PathBuf::from(&vsix_file).canonicalize()?
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() -> anyhow::Result<()> {

match cli.command {
cli::Commands::PrepLsp { release, target } => commands::prep_lsp(release, target),
cli::Commands::Package { out_dir } => commands::package(out_dir),
cli::Commands::Package { out_dir, out_name } => commands::package(out_dir, out_name),
cli::Commands::Install => commands::install()
}
}

0 comments on commit 4a070aa

Please sign in to comment.