From dd058e16375fcc56c81f227f8af82e49984e7c68 Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Mon, 5 Oct 2020 21:58:10 +0100 Subject: [PATCH] autogenerate version --- .gitignore | 1 + artwork/versioninfo.rc | 26 ------------------ main.go | 4 +-- makefile | 5 ++-- scripts/generate_versioninfo.go | 48 +++++++++++++++++++++++++++++++++ scripts/package_macos.go | 23 ++++++++-------- 6 files changed, 66 insertions(+), 41 deletions(-) delete mode 100644 artwork/versioninfo.rc create mode 100644 scripts/generate_versioninfo.go diff --git a/.gitignore b/.gitignore index 1edaee5b..2d69e6d4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /yarr *.db *.syso +versioninfo.rc diff --git a/artwork/versioninfo.rc b/artwork/versioninfo.rc deleted file mode 100644 index db446b8f..00000000 --- a/artwork/versioninfo.rc +++ /dev/null @@ -1,26 +0,0 @@ -1 VERSIONINFO -FILEVERSION 1,0,0,0 -PRODUCTVERSION 1,0,0,0 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "080904E4" - BEGIN - VALUE "CompanyName", "Old MacDonald's Farm" - VALUE "FileDescription", "Yet another RSS reader" - VALUE "FileVersion", "1.0" - VALUE "InternalName", "yarr" - VALUE "LegalCopyright", "nkanaev" - VALUE "OriginalFilename", "yarr.exe" - VALUE "ProductName", "yarr" - VALUE "ProductVersion", "1.0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x809, 1252 - END -END - -1 ICON "icon.ico" - diff --git a/main.go b/main.go index 09779639..e4c89d82 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( "path/filepath" ) -var Version string = "v0.0" +var Version string = "0.0" var GitHash string = "unknown" func main() { @@ -23,7 +23,7 @@ func main() { flag.Parse() if ver { - fmt.Printf("%s (%s)\n", Version, GitHash) + fmt.Printf("v%s (%s)\n", Version, GitHash) return } diff --git a/makefile b/makefile index 83c30420..a40e760c 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VERSION=v1.0 +VERSION=1.0 GITHASH=$(shell git rev-parse --short=8 HEAD) ASSETS = assets/javascripts/* assets/stylesheets/* assets/graphicarts/* assets/index.html @@ -24,7 +24,7 @@ build_macos: bundle mkdir -p _output/macos go build -tags "sqlite_foreign_keys release macos" -ldflags="$(GO_LDFLAGS)" -o _output/macos/yarr main.go cp artwork/icon.png _output/macos/icon.png - go run scripts/package_macos.go _output/macos + go run scripts/package_macos.go -outdir _output/macos -version "$(VERSION)" build_linux: bundle set GOOS=linux @@ -36,5 +36,6 @@ build_windows: bundle set GOOS=windows set GOARCH=386 mkdir -p _output/windows + go run scripts/generate_versioninfo.go -version "$(VERSION)" -outfile artwork/versioninfo.rc windres -i artwork/versioninfo.rc -O coff -o platform/versioninfo.syso go build -tags "sqlite_foreign_keys release windows" -ldflags="$(GO_LDFLAGS) -H windowsgui" -o _output/windows/yarr.exe main.go diff --git a/scripts/generate_versioninfo.go b/scripts/generate_versioninfo.go new file mode 100644 index 00000000..b05f9fb0 --- /dev/null +++ b/scripts/generate_versioninfo.go @@ -0,0 +1,48 @@ +package main + +import ( + "io/ioutil" + "flag" + "strings" +) + +var rsrc = `1 VERSIONINFO +FILEVERSION {VERSION_COMMA},0,0 +PRODUCTVERSION {VERSION_COMMA},0,0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080904E4" + BEGIN + VALUE "CompanyName", "Old MacDonald's Farm" + VALUE "FileDescription", "Yet another RSS reader" + VALUE "FileVersion", "{VERSION}" + VALUE "InternalName", "yarr" + VALUE "LegalCopyright", "nkanaev" + VALUE "OriginalFilename", "yarr.exe" + VALUE "ProductName", "yarr" + VALUE "ProductVersion", "{VERSION}" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x809, 1252 + END +END + +1 ICON "icon.ico" +` + +func main() { + var version, outfile string + flag.StringVar(&version, "version", "0.0", "") + flag.StringVar(&outfile, "outfile", "versioninfo.rc", "") + flag.Parse() + + version_comma := strings.ReplaceAll(version, ".", ",") + + out := strings.ReplaceAll(rsrc, "{VERSION}", version) + out = strings.ReplaceAll(out, "{VERSION_COMMA}", version_comma) + + ioutil.WriteFile(outfile, []byte(out), 0644) +} diff --git a/scripts/package_macos.go b/scripts/package_macos.go index 75a8e6f3..43c0b2f5 100644 --- a/scripts/package_macos.go +++ b/scripts/package_macos.go @@ -1,13 +1,15 @@ package main import ( - "os" - "path" + "flag" "fmt" "io/ioutil" + "log" + "os" "os/exec" + "path" "strconv" - "log" + "strings" ) var plist = ` @@ -21,7 +23,7 @@ var plist = ` CFBundleIdentifier nkanaev.yarr CFBundleVersion - 1.0 + VERSION CFBundlePackageType APPL CFBundleExecutable @@ -35,11 +37,6 @@ var plist = ` NSHighResolutionCapable True - CFBundleInfoDictionaryVersion - 6.0 - CFBundleShortVersionString - 1.0 - LSMinimumSystemVersion 10.13 LSUIElement @@ -59,7 +56,11 @@ func run(cmd ...string) { } func main() { - outdir := os.Args[1] + var version, outdir string + flag.StringVar(&version, "version", "0.0", "") + flag.StringVar(&outdir, "outdir", "", "") + flag.Parse() + outfile := "yarr" binDir := path.Join(outdir, "yarr.app", "Contents/MacOS") @@ -74,7 +75,7 @@ func main() { f, _ := ioutil.ReadFile(path.Join(outdir, outfile)) ioutil.WriteFile(path.Join(binDir, outfile), f, 0755) - ioutil.WriteFile(plistFile, []byte(plist), 0644) + ioutil.WriteFile(plistFile, []byte(strings.Replace(plist, "VERSION", version, 1)), 0644) ioutil.WriteFile(pkginfoFile, []byte("APPL????"), 0644) iconFile := path.Join(outdir, "icon.png")