gogio: change -version parameter to accept semver versions

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2024-01-09 14:38:03 -05:00
parent 607a9e37c5
commit cb72b91a92
5 changed files with 43 additions and 17 deletions
+3 -3
View File
@@ -42,7 +42,7 @@ var exeSuffix string
type manifestData struct {
AppID string
Version int
Version Semver
MinSDK int
TargetSDK int
Permissions []string
@@ -451,8 +451,8 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="{{.AppID}}"
android:versionCode="{{.Version}}"
android:versionName="1.0.{{.Version}}">
android:versionCode="{{.Version.Version32}}"
android:versionName="{{.Version}}">
<uses-sdk android:minSdkVersion="{{.MinSDK}}" android:targetSdkVersion="{{.TargetSDK}}" />
{{range .Permissions}} <uses-permission android:name="{{.}}"/>
{{end}}{{range .Features}} <uses-feature android:{{.}} android:required="false"/>
+34 -2
View File
@@ -22,7 +22,7 @@ type buildInfo struct {
iconPath string
tags string
target string
version int
version Semver
key string
password string
notaryAppleID string
@@ -30,6 +30,11 @@ type buildInfo struct {
notaryTeamID string
}
type Semver struct {
Major uint16
Minor, Patch uint8
}
func newBuildInfo(pkgPath string) (*buildInfo, error) {
pkgMetadata, err := getPkgMetadata(pkgPath)
if err != nil {
@@ -44,6 +49,10 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
if *name != "" {
appName = *name
}
ver, err := parseSemver(*version)
if err != nil {
return nil, err
}
bi := &buildInfo{
appID: appID,
archs: getArchs(),
@@ -55,7 +64,7 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
iconPath: appIcon,
tags: *extraTags,
target: *target,
version: *version,
version: ver,
key: *signKey,
password: *signPass,
notaryAppleID: *notaryID,
@@ -65,6 +74,29 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
return bi, nil
}
func (s Semver) String() string {
return fmt.Sprintf("%d.%d.%d", s.Major, s.Minor, s.Patch)
}
// Version32 returns a 32-bit integer version packed as such:
//
// major<<16 | minor<<8 | patch
func (s Semver) Version32() uint32 {
return uint32(s.Major)<<16 | uint32(s.Minor)<<8 | uint32(s.Patch)
}
func parseSemver(v string) (Semver, error) {
var sv Semver
_, err := fmt.Sscanf(v, "%d.%d.%d", &sv.Major, &sv.Minor, &sv.Patch)
if err != nil {
return Semver{}, fmt.Errorf("invalid semver: %q", v)
}
if sv.String() != v {
return Semver{}, fmt.Errorf("invalid semver: %q", v)
}
return sv, nil
}
func getArchs() []string {
if *archNames != "" {
return strings.Split(*archNames, ",")
+2 -2
View File
@@ -336,7 +336,7 @@ func buildInfoPlist(bi *buildInfo) string {
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.%d</string>
<string>%s</string>
<key>CFBundleVersion</key>
<string>%d</string>
<key>UILaunchStoryboardName</key>
@@ -377,7 +377,7 @@ func buildInfoPlist(bi *buildInfo) string {
<key>DTXcodeBuild</key>
<string>10G8</string>
</dict>
</plist>`, appName, bi.appID, appName, bi.version, bi.version, platform, minIOSVersion, supportPlatform, platform)
</plist>`, appName, bi.appID, appName, bi.version, bi.version.Version32(), platform, minIOSVersion, supportPlatform, platform)
}
func iosPlatformFor(target string) string {
+1 -1
View File
@@ -29,7 +29,7 @@ var (
destPath = flag.String("o", "", "output file or directory.\nFor -target ios or tvos, use the .app suffix to target simulators.")
appID = flag.String("appid", "", "app identifier (for -buildmode=exe)")
name = flag.String("name", "", "app name (for -buildmode=exe)")
version = flag.Int("version", 1, "app version (for -buildmode=exe)")
version = flag.String("version", "1.0.0", "semver app version (for -buildmode=exe) on the form major.minor.patch")
printCommands = flag.Bool("x", false, "print the commands")
keepWorkdir = flag.Bool("work", false, "print the name of the temporary work directory and do not delete it when exiting.")
linkMode = flag.String("linkmode", "", "set the -linkmode flag of the go tool")
+3 -9
View File
@@ -7,12 +7,10 @@ import (
"fmt"
"image/png"
"io"
"math"
"os"
"os/exec"
"path/filepath"
"reflect"
"strconv"
"strings"
"text/template"
@@ -40,10 +38,6 @@ func buildWindows(tmpDir string, bi *buildInfo) error {
if sdk > 10 {
return fmt.Errorf("invalid minsdk (%d) it's higher than Windows 10", sdk)
}
version := strconv.Itoa(bi.version)
if bi.version > math.MaxUint16 {
return fmt.Errorf("version (%d) is larger than the maximum (%d)", bi.version, math.MaxUint16)
}
for _, arch := range bi.archs {
builder.Coff = coff.NewRSRC()
@@ -54,7 +48,7 @@ func buildWindows(tmpDir string, bi *buildInfo) error {
}
if err := builder.embedManifest(windowsManifest{
Version: "1.0.0." + version,
Version: bi.version.String(),
WindowsVersion: sdk,
Name: name,
}); err != nil {
@@ -62,8 +56,8 @@ func buildWindows(tmpDir string, bi *buildInfo) error {
}
if err := builder.embedInfo(windowsResources{
Version: [2]uint32{uint32(1) << 16, uint32(bi.version)},
VersionHuman: "1.0.0." + version,
Version: [2]uint32{uint32(bi.version.Major), uint32(bi.version.Minor)<<16 | uint32(bi.version.Patch)},
VersionHuman: bi.version.String(),
Name: name,
Language: 0x0400, // Process Default Language: https://docs.microsoft.com/en-us/previous-versions/ms957130(v=msdn.10)
}); err != nil {