From f734b503d4f9f9720f5527c9e7fce2e6498c196e Mon Sep 17 00:00:00 2001 From: Ryan Currah Date: Fri, 25 Feb 2022 19:57:46 -0500 Subject: [PATCH] feat(pipe/brew): install amd64 binaries when no arm64 binaries present (#2939) Currently on a M1 macbook when adding a tap with formulas that only support amd64 it fails to add the tap. This prevents new arm64 users from using the tap. By allowing arm64 users to install an amd64 binary if no arm64 binary is avialable will atleast allow the user to use the tap. --- internal/pipe/brew/brew.go | 4 ++ internal/pipe/brew/brew_test.go | 7 +-- internal/pipe/brew/template.go | 51 +++++++++++++------ .../TestFullPipe/custom_block.rb.golden | 18 +++++-- .../custom_download_strategy.rb.golden | 18 +++++-- .../TestFullPipe/custom_require.rb.golden | 18 +++++-- .../testdata/TestFullPipe/default.rb.golden | 18 +++++-- .../TestFullPipe/default_gitlab.rb.golden | 18 +++++-- .../valid_tap_templates.rb.golden | 18 +++++-- .../multiple_armv5.rb.golden | 18 +++++-- .../multiple_armv6.rb.golden | 18 +++++-- .../multiple_armv7.rb.golden | 18 +++++-- .../TestRunPipeNameTemplate.rb.golden | 16 ++++-- 13 files changed, 173 insertions(+), 67 deletions(-) diff --git a/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go index 519b4ead7..02260c90a 100644 --- a/internal/pipe/brew/brew.go +++ b/internal/pipe/brew/brew.go @@ -374,6 +374,10 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifa } } + if len(result.MacOSPackages) == 1 && result.MacOSPackages[0].Arch == "amd64" { + result.HasOnlyAmd64MacOsPkg = true + } + sort.Slice(result.LinuxPackages, lessFnFor(result.LinuxPackages)) sort.Slice(result.MacOSPackages, lessFnFor(result.MacOSPackages)) return result, nil diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go index dfe6e7b76..8a18af480 100644 --- a/internal/pipe/brew/brew_test.go +++ b/internal/pipe/brew/brew_test.go @@ -81,9 +81,10 @@ var defaultTemplateData = templateData{ Install: []string{`bin.install "test"`}, }, }, - Name: "Test", - Version: "0.1.3", - Caveats: []string{}, + Name: "Test", + Version: "0.1.3", + Caveats: []string{}, + HasOnlyAmd64MacOsPkg: false, } func assertDefaultTemplateData(t *testing.T, formulae string) { diff --git a/internal/pipe/brew/template.go b/internal/pipe/brew/template.go index 29348af6a..5859d8368 100644 --- a/internal/pipe/brew/template.go +++ b/internal/pipe/brew/template.go @@ -3,21 +3,22 @@ package brew import "github.com/goreleaser/goreleaser/pkg/config" type templateData struct { - Name string - Desc string - Homepage string - Version string - License string - Caveats []string - Plist string - PostInstall string - Dependencies []config.HomebrewDependency - Conflicts []string - Tests []string - CustomRequire string - CustomBlock []string - LinuxPackages []releasePackage - MacOSPackages []releasePackage + Name string + Desc string + Homepage string + Version string + License string + Caveats []string + Plist string + PostInstall string + Dependencies []config.HomebrewDependency + Conflicts []string + Tests []string + CustomRequire string + CustomBlock []string + LinuxPackages []releasePackage + MacOSPackages []releasePackage + HasOnlyAmd64MacOsPkg bool } type releasePackage struct { @@ -64,6 +65,26 @@ class {{ .Name }} < Formula {{ . -}} {{- end }} end + {{- else if $.HasOnlyAmd64MacOsPkg }} + url "{{ $element.DownloadURL }}" + {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }} + sha256 "{{ $element.SHA256 }}" + + def install + {{- range $index, $element := .Install }} + {{ . -}} + {{- end }} + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the {{ $.Name }} + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS + end + end {{- else }} {{- if eq $element.Arch "amd64" }} if Hardware::CPU.intel? diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden index c1c498f4f..f5bde09dd 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden @@ -9,12 +9,20 @@ class CustomBlock < Formula depends_on :macos on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "custom_block" + def install + bin.install "custom_block" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the CustomBlock + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden index 3e22288a0..512b986f4 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden @@ -9,12 +9,20 @@ class CustomDownloadStrategy < Formula depends_on :macos on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "custom_download_strategy" + def install + bin.install "custom_download_strategy" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the CustomDownloadStrategy + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden index d76428d14..7ad3661a3 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden @@ -10,12 +10,20 @@ class CustomRequire < Formula depends_on :macos on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => CustomDownloadStrategy - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => CustomDownloadStrategy + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "custom_require" + def install + bin.install "custom_require" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the CustomRequire + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden index ea4470467..97e8afdaf 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden @@ -9,12 +9,20 @@ class Default < Formula depends_on :macos on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "default" + def install + bin.install "default" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the Default + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden index 1f6018d50..ffff82dc9 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden @@ -9,12 +9,20 @@ class DefaultGitlab < Formula depends_on :macos on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "default_gitlab" + def install + bin.install "default_gitlab" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the DefaultGitlab + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden index bba29a048..d8cf31df9 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden @@ -9,12 +9,20 @@ class ValidTapTemplates < Formula depends_on :macos on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "valid_tap_templates" + def install + bin.install "valid_tap_templates" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the ValidTapTemplates + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.rb.golden b/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.rb.golden index 6e878f172..fe5df905a 100644 --- a/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.rb.golden +++ b/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.rb.golden @@ -8,12 +8,20 @@ class MultipleArmv5 < Formula version "1.0.1" on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "multiple_armv5" + def install + bin.install "multiple_armv5" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the MultipleArmv5 + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.rb.golden b/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.rb.golden index ed6d392c8..92bcf99d7 100644 --- a/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.rb.golden +++ b/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.rb.golden @@ -8,12 +8,20 @@ class MultipleArmv6 < Formula version "1.0.1" on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "multiple_armv6" + def install + bin.install "multiple_armv6" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the MultipleArmv6 + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.rb.golden b/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.rb.golden index 37b7472d4..cbf3f0c50 100644 --- a/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.rb.golden +++ b/internal/pipe/brew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.rb.golden @@ -8,12 +8,20 @@ class MultipleArmv7 < Formula version "1.0.1" on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install - bin.install "multiple_armv7" + def install + bin.install "multiple_armv7" + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the MultipleArmv7 + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end diff --git a/internal/pipe/brew/testdata/TestRunPipeNameTemplate.rb.golden b/internal/pipe/brew/testdata/TestRunPipeNameTemplate.rb.golden index a917e9f31..6199ba135 100644 --- a/internal/pipe/brew/testdata/TestRunPipeNameTemplate.rb.golden +++ b/internal/pipe/brew/testdata/TestRunPipeNameTemplate.rb.golden @@ -9,11 +9,19 @@ class FooIsBar < Formula depends_on :macos on_macos do - if Hardware::CPU.intel? - url "https://dummyhost/download/v1.0.1/bin.tar.gz" - sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + url "https://dummyhost/download/v1.0.1/bin.tar.gz" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - def install + def install + end + + if Hardware::CPU.arm? + def caveats + <<~EOS + The darwin_arm64 architecture is not supported for the FooIsBar + formula at this time. The darwin_amd64 binary may work in compatibility + mode, but it might not be fully supported. + EOS end end end