From 2e2f9bc98acdc972a22add3d1015bd80cad20b41 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 10 Oct 2021 18:24:23 +0100 Subject: [PATCH] feat(build): handle macOS Big Sur and later version number --- build-emacs-for-macos | 2 +- pkg/osinfo/osinfo.go | 12 +++++++++++- pkg/plan/create.go | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/build-emacs-for-macos b/build-emacs-for-macos index 73d7468..59a8fb7 100755 --- a/build-emacs-for-macos +++ b/build-emacs-for-macos @@ -53,7 +53,7 @@ class OSVersion end def to_s - @to_s ||= "#{major}.#{minor}" + @to_s ||= major >= 11 ? major.to_s : "#{major}.#{minor}" end def major diff --git a/pkg/osinfo/osinfo.go b/pkg/osinfo/osinfo.go index e801117..31d35b8 100644 --- a/pkg/osinfo/osinfo.go +++ b/pkg/osinfo/osinfo.go @@ -2,6 +2,7 @@ package osinfo import ( "os/exec" + "strconv" "strings" ) @@ -29,8 +30,17 @@ func New() (*OSInfo, error) { }, nil } -func (s *OSInfo) MajorMinor() string { +// DistinctVersion returns macOS version down to a distinct "major" +// version. For macOS 10.x, this will include the first two numeric parts of the +// version (10.15), while for 11.x and later, the first numeric part is enough +// (11). +func (s *OSInfo) DistinctVersion() string { parts := strings.Split(s.Version, ".") + + if n, _ := strconv.Atoi(parts[0]); n >= 11 { + return parts[0] + } + max := len(parts) if max > 2 { max = 2 diff --git a/pkg/plan/create.go b/pkg/plan/create.go index 2859fdb..d9abe05 100644 --- a/pkg/plan/create.go +++ b/pkg/plan/create.go @@ -77,7 +77,7 @@ func Create(ctx context.Context, opts *Options) (*Plan, error) { buildName := fmt.Sprintf( "Emacs.%s.%s.%s", version, - sanitizeString(osInfo.Name+"-"+osInfo.MajorMinor()), + sanitizeString(osInfo.Name+"-"+osInfo.DistinctVersion()), sanitizeString(osInfo.Arch), ) diskImage := buildName + ".dmg"