mirror of
https://git.sr.ht/~eliasnaur/gio-cmd
synced 2026-07-01 07:35:37 +00:00
gogio: change -version parameter to accept semver versions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -42,7 +42,7 @@ var exeSuffix string
|
|||||||
|
|
||||||
type manifestData struct {
|
type manifestData struct {
|
||||||
AppID string
|
AppID string
|
||||||
Version int
|
Version Semver
|
||||||
MinSDK int
|
MinSDK int
|
||||||
TargetSDK int
|
TargetSDK int
|
||||||
Permissions []string
|
Permissions []string
|
||||||
@@ -451,8 +451,8 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
|
|||||||
`<?xml version="1.0" encoding="utf-8"?>
|
`<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="{{.AppID}}"
|
package="{{.AppID}}"
|
||||||
android:versionCode="{{.Version}}"
|
android:versionCode="{{.Version.Version32}}"
|
||||||
android:versionName="1.0.{{.Version}}">
|
android:versionName="{{.Version}}">
|
||||||
<uses-sdk android:minSdkVersion="{{.MinSDK}}" android:targetSdkVersion="{{.TargetSDK}}" />
|
<uses-sdk android:minSdkVersion="{{.MinSDK}}" android:targetSdkVersion="{{.TargetSDK}}" />
|
||||||
{{range .Permissions}} <uses-permission android:name="{{.}}"/>
|
{{range .Permissions}} <uses-permission android:name="{{.}}"/>
|
||||||
{{end}}{{range .Features}} <uses-feature android:{{.}} android:required="false"/>
|
{{end}}{{range .Features}} <uses-feature android:{{.}} android:required="false"/>
|
||||||
|
|||||||
+34
-2
@@ -22,7 +22,7 @@ type buildInfo struct {
|
|||||||
iconPath string
|
iconPath string
|
||||||
tags string
|
tags string
|
||||||
target string
|
target string
|
||||||
version int
|
version Semver
|
||||||
key string
|
key string
|
||||||
password string
|
password string
|
||||||
notaryAppleID string
|
notaryAppleID string
|
||||||
@@ -30,6 +30,11 @@ type buildInfo struct {
|
|||||||
notaryTeamID string
|
notaryTeamID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Semver struct {
|
||||||
|
Major uint16
|
||||||
|
Minor, Patch uint8
|
||||||
|
}
|
||||||
|
|
||||||
func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
||||||
pkgMetadata, err := getPkgMetadata(pkgPath)
|
pkgMetadata, err := getPkgMetadata(pkgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -44,6 +49,10 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
|||||||
if *name != "" {
|
if *name != "" {
|
||||||
appName = *name
|
appName = *name
|
||||||
}
|
}
|
||||||
|
ver, err := parseSemver(*version)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
bi := &buildInfo{
|
bi := &buildInfo{
|
||||||
appID: appID,
|
appID: appID,
|
||||||
archs: getArchs(),
|
archs: getArchs(),
|
||||||
@@ -55,7 +64,7 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
|||||||
iconPath: appIcon,
|
iconPath: appIcon,
|
||||||
tags: *extraTags,
|
tags: *extraTags,
|
||||||
target: *target,
|
target: *target,
|
||||||
version: *version,
|
version: ver,
|
||||||
key: *signKey,
|
key: *signKey,
|
||||||
password: *signPass,
|
password: *signPass,
|
||||||
notaryAppleID: *notaryID,
|
notaryAppleID: *notaryID,
|
||||||
@@ -65,6 +74,29 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
|||||||
return bi, nil
|
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 {
|
func getArchs() []string {
|
||||||
if *archNames != "" {
|
if *archNames != "" {
|
||||||
return strings.Split(*archNames, ",")
|
return strings.Split(*archNames, ",")
|
||||||
|
|||||||
+2
-2
@@ -336,7 +336,7 @@ func buildInfoPlist(bi *buildInfo) string {
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.0.%d</string>
|
<string>%s</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>%d</string>
|
<string>%d</string>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
@@ -377,7 +377,7 @@ func buildInfoPlist(bi *buildInfo) string {
|
|||||||
<key>DTXcodeBuild</key>
|
<key>DTXcodeBuild</key>
|
||||||
<string>10G8</string>
|
<string>10G8</string>
|
||||||
</dict>
|
</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 {
|
func iosPlatformFor(target string) string {
|
||||||
|
|||||||
+1
-1
@@ -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.")
|
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)")
|
appID = flag.String("appid", "", "app identifier (for -buildmode=exe)")
|
||||||
name = flag.String("name", "", "app name (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")
|
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.")
|
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")
|
linkMode = flag.String("linkmode", "", "set the -linkmode flag of the go tool")
|
||||||
|
|||||||
@@ -7,12 +7,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image/png"
|
"image/png"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@@ -40,10 +38,6 @@ func buildWindows(tmpDir string, bi *buildInfo) error {
|
|||||||
if sdk > 10 {
|
if sdk > 10 {
|
||||||
return fmt.Errorf("invalid minsdk (%d) it's higher than Windows 10", sdk)
|
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 {
|
for _, arch := range bi.archs {
|
||||||
builder.Coff = coff.NewRSRC()
|
builder.Coff = coff.NewRSRC()
|
||||||
@@ -54,7 +48,7 @@ func buildWindows(tmpDir string, bi *buildInfo) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := builder.embedManifest(windowsManifest{
|
if err := builder.embedManifest(windowsManifest{
|
||||||
Version: "1.0.0." + version,
|
Version: bi.version.String(),
|
||||||
WindowsVersion: sdk,
|
WindowsVersion: sdk,
|
||||||
Name: name,
|
Name: name,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@@ -62,8 +56,8 @@ func buildWindows(tmpDir string, bi *buildInfo) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := builder.embedInfo(windowsResources{
|
if err := builder.embedInfo(windowsResources{
|
||||||
Version: [2]uint32{uint32(1) << 16, uint32(bi.version)},
|
Version: [2]uint32{uint32(bi.version.Major), uint32(bi.version.Minor)<<16 | uint32(bi.version.Patch)},
|
||||||
VersionHuman: "1.0.0." + version,
|
VersionHuman: bi.version.String(),
|
||||||
Name: name,
|
Name: name,
|
||||||
Language: 0x0400, // Process Default Language: https://docs.microsoft.com/en-us/previous-versions/ms957130(v=msdn.10)
|
Language: 0x0400, // Process Default Language: https://docs.microsoft.com/en-us/previous-versions/ms957130(v=msdn.10)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user