From 832528aedf877d26363cb63dea41387849c3791d Mon Sep 17 00:00:00 2001 From: jonathanpv Date: Thu, 9 Mar 2023 14:34:03 -0500 Subject: [PATCH] rewrite package-msi.sh --- scripts/package-msi.sh | 22 ------- .../commands/{package.rs => package/mod.rs} | 10 ++-- vdev/src/commands/package/msi.rs | 58 +++++++++++++++++++ 3 files changed, 63 insertions(+), 27 deletions(-) delete mode 100644 scripts/package-msi.sh rename vdev/src/commands/{package.rs => package/mod.rs} (77%) create mode 100644 vdev/src/commands/package/msi.rs diff --git a/scripts/package-msi.sh b/scripts/package-msi.sh deleted file mode 100644 index cc8f39e10afec..0000000000000 --- a/scripts/package-msi.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -set -euo pipefail - -# package-msi.sh -# -# SUMMARY -# -# Creates a .msi package for Windows. - -set -x - -ARCHIVE_VERSION="${VECTOR_VERSION:-"$(cargo vdev version)"}" - -rm -rf target/msi-x64 -cp -R distribution/msi target/msi-x64 -cp target/artifacts/vector-"${ARCHIVE_VERSION}"-x86_64-pc-windows-msvc.zip target/msi-x64 -pushd target/msi-x64 -# shellcheck disable=SC2016 -powershell '$progressPreference = "silentlyContinue"; Expand-Archive vector-'"$ARCHIVE_VERSION"'-x86_64-pc-windows-msvc.zip' -./build.sh "${ARCHIVE_VERSION}" -popd -cp target/msi-x64/vector.msi target/artifacts/vector-"${ARCHIVE_VERSION}"-x64.msi diff --git a/vdev/src/commands/package.rs b/vdev/src/commands/package/mod.rs similarity index 77% rename from vdev/src/commands/package.rs rename to vdev/src/commands/package/mod.rs index 3bc13abf0c0b9..7ab570b33dc01 100644 --- a/vdev/src/commands/package.rs +++ b/vdev/src/commands/package/mod.rs @@ -1,6 +1,9 @@ crate::cli_subcommands! { "Package Vector in various formats..." - archive, deb, msi, rpm, + archive, + deb, + mod msi, + rpm, } crate::script_wrapper! { @@ -11,11 +14,8 @@ crate::script_wrapper! { deb = "Create a .deb package to be distributed in the APT package manager" => "package-deb.sh" } -crate::script_wrapper! { - msi = "Create a .msi package for Windows" - => "package-msi.sh" -} crate::script_wrapper! { rpm = "Create a .rpm package to be distributed in the YUM package manager" => "package-rpm.sh" } + diff --git a/vdev/src/commands/package/msi.rs b/vdev/src/commands/package/msi.rs new file mode 100644 index 0000000000000..0a7d77001cc37 --- /dev/null +++ b/vdev/src/commands/package/msi.rs @@ -0,0 +1,58 @@ +use anyhow::Result; + +#[cfg(windows)] +use { + crate::{app, util}, + std::env, + std::fs, + std::iter::once, + std::path::Path, +}; + +/// Create a .msi package for Windows +#[derive(clap::Args, Debug)] +#[command()] +pub struct Cli {} + +impl Cli { + pub fn exec(self) -> Result<()> { + #[cfg(windows)] + { + // TODO: wait for other PR to be merged then replace the below line with app::version() + let archive_version = env::var("VERSION").or_else(|_| util::read_version())?; + + // rm -rf target/msi-x64 + // cp -R distribution/msi target/msi-x64 + let msi_x64_dir = Path::new("target").join("msi-x64"); + fs::remove_dir_all(&msi_x64_dir).ok(); + fs::create_dir_all(&msi_x64_dir)?; + fs::copy("distribution/msi", &msi_x64_dir)?; + + // cp target/artifacts/vector-"${ARCHIVE_VERSION}"-x86_64-pc-windows-msvc.zip target/msi-x64 + let artifacts_dir = Path::new("target").join("artifacts"); + let zip_file = format!("vector-{archive_version}-x86_64-pc-windows-msvc.zip"); + fs::copy(artifacts_dir.join(&zip_file), msi_x64_dir.join(&zip_file))?; + + // pushd target/msi-x64 + env::set_current_dir(&msi_x64_dir)?; + + // powershell '$progressPreference = "silentlyContinue"; Expand-Archive vector-'"$ARCHIVE_VERSION"'-x86_64-pc-windows-msvc.zip' + let powershell_command = format!( + "$progressPreference = 'silentlyContinue'; Expand-Archive vector-{zip_file}" + ); + app::exec("powershell", ["-Command", &powershell_command], false)?; + + // ./build.sh "${ARCHIVE_VERSION}" + app::exec("build.sh", once(&archive_version), true)?; + + // popd + env::set_current_dir(app::path())?; + + // cp target/msi-x64/vector.msi target/artifacts/vector-"${ARCHIVE_VERSION}"-x64.msi + let msi_file = format!("vector-{archive_version}-x64.msi"); + let dest_file = artifacts_dir.join(msi_file); + fs::copy(msi_x64_dir.join("vector.msi"), dest_file)?; + } + Ok(()) + } +}