Skip to content

Commit

Permalink
autogenerate version
Browse files Browse the repository at this point in the history
  • Loading branch information
nkanaev committed Oct 5, 2020
1 parent 63f6242 commit dd058e1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/yarr
*.db
*.syso
versioninfo.rc
26 changes: 0 additions & 26 deletions artwork/versioninfo.rc

This file was deleted.

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"path/filepath"
)

var Version string = "v0.0"
var Version string = "0.0"
var GitHash string = "unknown"

func main() {
Expand All @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
48 changes: 48 additions & 0 deletions scripts/generate_versioninfo.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 12 additions & 11 deletions scripts/package_macos.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main

import (
"os"
"path"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"strconv"
"log"
"strings"
)

var plist = `<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -21,7 +23,7 @@ var plist = `<?xml version="1.0" encoding="UTF-8"?>
<key>CFBundleIdentifier</key>
<string>nkanaev.yarr</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>VERSION</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleExecutable</key>
Expand All @@ -35,11 +37,6 @@ var plist = `<?xml version="1.0" encoding="UTF-8"?>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
<key>LSUIElement</key>
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit dd058e1

Please sign in to comment.