Automate the population of the windows exe metadata

This commit is contained in:
Justin Hawkins 2022-05-01 17:39:00 +09:30
parent 243c349366
commit 9423bc32e9
4 changed files with 35 additions and 10 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ discord-auto-upload.exe
*.png
*.jpg
.DS_Store
versioninfo.json

View File

@ -2,17 +2,27 @@
use strict;
use warnings;
use Mojo::JSON qw/encode_json decode_json/;
use Mojo::File;
open my $fh, "<", "version/version.go" || die $!;
my $version;
while (<$fh>) {
$version = $1 if /^const\s+CurrentVersion.*?"(v[\d\.]+)"/;
$version = $1 if /^const\s+CurrentVersion.*?"v([\d\.]+)"/;
}
close $fh;
die "no version?" unless defined $version;
my @version_parts = split /\./, $version;
die "bad version?" unless defined $version_parts[2];
foreach (@version_parts) {
$_ = 0 + $_;
}
$version = "v$version";
# quit if tests fail
system("go test ./...") && die "not building release with failing tests";
@ -42,6 +52,20 @@ foreach my $type (keys %build) {
my @ldflags = ();
if ($type eq "win") {
# create the versioninfo.json based on the current version
my $tmp = Mojo::File->new("versioninfo.json-template")->slurp();
my $vdata = decode_json($tmp);
$vdata->{FixedFileInfo}->{FileVersion}->{Major} = $version_parts[0] ;
$vdata->{FixedFileInfo}->{FileVersion}->{Minor} = $version_parts[1] ;
$vdata->{FixedFileInfo}->{FileVersion}->{Patch} = $version_parts[2] ;
$vdata->{FixedFileInfo}->{ProductVersion}->{Major} = $version_parts[0] ;
$vdata->{FixedFileInfo}->{ProductVersion}->{Minor} = $version_parts[1] ;
$vdata->{FixedFileInfo}->{ProductVersion}->{Patch} = $version_parts[2] ;
$vdata->{StringFileInfo}->{ProductVersion} = $version;
Mojo::File->new("versioninfo.json")->spurt(encode_json($vdata));
@ldflags = (qw/ -ldflags -H=windowsgui/);
system "go", "generate";
}

View File

@ -13,7 +13,7 @@ import (
//go:embed dau.ico
var appIcon []byte
//go:generate goversioninfo -icon=dau.ico
//go:generate goversioninfo
// -manifest=testdata/resource/goversioninfo.exe.manifest

View File

@ -1,13 +1,13 @@
{
"FixedFileInfo": {
"FileVersion": {
"Major": 1,
"Major": 0,
"Minor": 0,
"Patch": 0,
"Build": 0
},
"ProductVersion": {
"Major": 1,
"Major": 0,
"Minor": 0,
"Patch": 0,
"Build": 0
@ -20,16 +20,16 @@
},
"StringFileInfo": {
"Comments": "",
"CompanyName": "",
"FileDescription": "",
"CompanyName": "tardisx@github",
"FileDescription": "https://github.com/tardisx/discord-auto-upload",
"FileVersion": "",
"InternalName": "",
"LegalCopyright": "",
"LegalCopyright": "https://github.com/tardisx/discord-auto-upload/blob/master/LICENSE",
"LegalTrademarks": "",
"OriginalFilename": "",
"PrivateBuild": "",
"ProductName": "",
"ProductVersion": "v1.0.0.0",
"ProductName": "discord-auto-upload",
"ProductVersion": "v0.0.0",
"SpecialBuild": ""
},
"VarFileInfo": {