Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(vdev): Rewrite package-msi.sh to vdev #16748

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ jobs:
shell: bash
run: |
export PATH="/c/wix:$PATH"
./scripts/package-msi.sh
cargo vdev package msi
- name: Stage package artifacts for publish
uses: actions/upload-artifact@v3
with:
Expand Down
32 changes: 0 additions & 32 deletions distribution/msi/build.sh

This file was deleted.

22 changes: 0 additions & 22 deletions scripts/package-msi.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
crate::cli_subcommands! {
"Package Vector in various formats..."
archive, deb, msi, rpm,
archive,
deb,
mod msi,
rpm,
}

crate::script_wrapper! {
Expand All @@ -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"
}

149 changes: 149 additions & 0 deletions vdev/src/commands/package/msi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
use anyhow::Result;

#[cfg(windows)]
use {
crate::app,
crate::app::CommandExt as _,
crate::util,
std::env,
std::fs::File,
std::io::Write,
std::fs,
std::path::{Path},
std::process::Command,
};

/// Create a .msi package for Windows
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {}

impl Cli {
pub fn exec(self) -> Result<()> {
#[cfg(not(windows))]
{
println!("Sorry, the package-msi command is not supported on non-Windows platforms. Nothing was performed.");
}
#[cfg(windows)]
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
{
let archive_version = app::version()?;

let package_version = {
let channel = util::release_channel()?;
if channel == "custom" {
// Extract the version before ".custom"
archive_version.split(".custom").next().unwrap().to_string()
} else {
archive_version.clone()
}
};
// Make sure we start with a fresh `target/msi-x64` target directory and
// copy the `distribution/msi` directory to `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)?;


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))?;

// Ensure in the `msi-x64` directory
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
env::set_current_dir(&msi_x64_dir)?;

// Extract the zip file with PowerShell and build the MSI package
let powershell_command = format!(
"$progressPreference = 'silentlyContinue'; Expand-Archive {zip_file}"
);
app::exec("powershell", ["-Command", &powershell_command], false)?;
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

Check failure

Code scanning / check-spelling

Unrecognized Spelling

[ommand](#security-tab) is not a recognized word. \(unrecognized-spelling\)
build(&archive_version, &package_version)?;

// Change the current directory back to the original path
env::set_current_dir(app::path())?;

// Copy the MSI file to the artifacts directory
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(())
}
}

#[cfg(windows)]
fn build(archive_version: &str, package_version: &str) -> Result<()> {
println!("Running Build with args: {archive_version}");
println!("Copying ZIP archive...");

Comment on lines +76 to +78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know these status messages were copied from the original script, but I don't think they inform anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this in my local branch and will push shortly

println!("Preparing LICENSE.rtf..");
let mut license_rtf_file = File::create("LICENSE.rtf")?;
writeln!(
license_rtf_file,
"{{\\rtf1\\ansi\\ansicpg1252\\deff0\\nouicompat{{\\fonttbl{{\\f0\\fnil\\fcharset0 Lucida Console;}}}}\n\\viewkind4\\uc1\n\\pard\\f0\\fs14\\lang1033\\par"

Check failure

Code scanning / check-spelling

Unrecognized Spelling

[nouicompat](#security-tab) is not a recognized word. \(unrecognized-spelling\)
)?;

let license_content_path = format!("vector-{archive_version}-x86_64-pc-windows-msvc/LICENSE.txt");
let license_content = std::fs::read_to_string(license_content_path)?;
for line in license_content.lines() {
writeln!(license_rtf_file, "{line}\\")?;
}
writeln!(license_rtf_file, "\n}}")?;
bruceg marked this conversation as resolved.
Show resolved Hide resolved

println!("Substituting version...");
let vector_tmpl = std::fs::read_to_string("vector.wxs.tmpl")?;
let vector_tmpl_updated = vector_tmpl.replace("${VERSION}", package_version);
let mut vector_wxs_file = File::create("vector.wxs")?;
writeln!(vector_wxs_file, "{vector_tmpl_updated}")?;
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved

println!("Building the MSI package...");
let vector_dir = format!("vector-{archive_version}-x86_64-pc-windows-msvc");
let args = &[
&format!("dir {vector_dir}"),
"-cg Vector",
"-dr INSTALLDIR",
"-gg",
"-sfrag",
"-srd",
"-var var.VectorDir",
"-out components.wxs"
];
Command::new("heat").args(args).capture_output()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't use the output, and any messages from this command (and below) would end up being thrown away by this, I think you want check_run here:

Suggested change
Command::new("heat").args(args).capture_output()?;
Command::new("heat").args(args).check_run()?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented locally and will push


// Add Win64="yes" to Component elements
// See https://stackoverflow.com/questions/22932942/wix-heat-exe-win64-components-win64-yes
let components_text = std::fs::read_to_string("components.wxs")?;
let components_text = components_text.replace("<Component ", r#"<Component Win64="yes" "#);
let mut components_file = File::create("components.wxs")?;
write!(components_file, "{components_text}")?;
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved

// Call WiX toolset to build MSI package
let binding = &format!("-dVectorDir={vector_dir}");
let mut args = vec![
"candle",
"components.wxs",
binding
];
Command::new("candle").args(&args).capture_output()?;

args = vec![
"candle",
"vector.wxs",
"-ext",
"WiXUtilExtension",
];
Command::new("candle").args(&args).capture_output()?;

args = vec![
"vector.wixobj",
"components.wixobj",
"-out",
"vector.msi",
"-ext",
"WixUIExtension",
"-ext",
"WiXUtilExtension",
];
Command::new("light").args(&args).capture_output()?;
Ok(())
}