Skip to content

Commit

Permalink
fix gomips support (#1331)
Browse files Browse the repository at this point in the history
* wip: fix gomips

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* wip: fix gomips

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: added more

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: added more

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 6, 2020
1 parent 16fe0ea commit d85fff0
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 42 deletions.
2 changes: 1 addition & 1 deletion internal/artifact/artifact.go
Expand Up @@ -144,7 +144,7 @@ func (artifacts Artifacts) List() []*Artifact {
func (artifacts Artifacts) GroupByPlatform() map[string][]*Artifact {
var result = map[string][]*Artifact{}
for _, a := range artifacts.items {
plat := a.Goos + a.Goarch + a.Goarm
plat := a.Goos + a.Goarch + a.Goarm + a.Gomips
result[plat] = append(result[plat], a)
}
return result
Expand Down
14 changes: 14 additions & 0 deletions internal/artifact/artifact_test.go
Expand Up @@ -124,6 +124,18 @@ func TestGroupByPlatform(t *testing.T) {
Goarch: "arm",
Goarm: "6",
},
{
Name: "foobar",
Goos: "linux",
Goarch: "mips",
Goarm: "softfloat",
},
{
Name: "foobar",
Goos: "linux",
Goarch: "mips",
Goarm: "hardfloat",
},
{
Name: "check",
Type: Checksum,
Expand All @@ -137,6 +149,8 @@ func TestGroupByPlatform(t *testing.T) {
var groups = artifacts.GroupByPlatform()
assert.Len(t, groups["linuxamd64"], 2)
assert.Len(t, groups["linuxarm6"], 1)
assert.Len(t, groups["linuxmipssoftfloat"], 1)
assert.Len(t, groups["linuxmipshardfloat"], 1)
}

func TestChecksum(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/linux/arch.go
Expand Up @@ -19,6 +19,7 @@ func Arch(key string) string {
return "armhf"
case "arm7": // GOARCH + GOARM
return "armhf"
default:
return arch
}
return arch
}
6 changes: 4 additions & 2 deletions internal/pipe/archive/archive.go
Expand Up @@ -25,8 +25,8 @@ import (
)

const (
defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
defaultBinaryNameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
defaultBinaryNameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
)

// nolint: gochecknoglobals
Expand Down Expand Up @@ -162,6 +162,7 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A
Goos: binaries[0].Goos,
Goarch: binaries[0].Goarch,
Goarm: binaries[0].Goarm,
Gomips: binaries[0].Gomips,
Extra: map[string]interface{}{
"Builds": binaries,
"ID": archive.ID,
Expand Down Expand Up @@ -198,6 +199,7 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
Goos: binary.Goos,
Goarch: binary.Goarch,
Goarm: binary.Goarm,
Gomips: binary.Gomips,
Extra: map[string]interface{}{
"Builds": []*artifact.Artifact{binary},
"ID": archive.ID,
Expand Down
103 changes: 73 additions & 30 deletions internal/pipe/archive/archive_test.go
Expand Up @@ -22,20 +22,24 @@ func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
}

func createFakeBinary(t *testing.T, dist, arch, bin string) {
require.NoError(t, os.Mkdir(filepath.Join(dist, arch), 0755))
_, err := os.Create(filepath.Join(dist, arch, bin))
require.NoError(t, err)
}

func TestRunPipe(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
for _, format := range []string{"tar.gz", "zip"} {
t.Run("Archive format "+format, func(tt *testing.T) {
var dist = filepath.Join(folder, format+"_dist")
require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
require.NoError(t, err)
_, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe"))
require.NoError(t, err)
_, err = os.Create(filepath.Join(folder, "README.md"))
for _, arch := range []string{"darwinamd64", "linux386", "linuxarm7", "linuxmipssoftfloat"} {
createFakeBinary(t, dist, arch, "mybin")
}
createFakeBinary(t, dist, "windowsamd64", "mybin.exe")
_, err := os.Create(filepath.Join(folder, "README.md"))
require.NoError(t, err)
require.NoError(t, os.MkdirAll(filepath.Join(folder, "foo", "bar", "foobar"), 0755))
_, err = os.Create(filepath.Join(filepath.Join(folder, "foo", "bar", "foobar", "blah.txt")))
Expand All @@ -46,7 +50,7 @@ func TestRunPipe(t *testing.T) {
ProjectName: "foobar",
Archives: []config.Archive{
{
ID: "defaultarch",
ID: "myid",
Builds: []string{"default"},
NameTemplate: defaultNameTemplate,
Files: []string{
Expand Down Expand Up @@ -74,6 +78,41 @@ func TestRunPipe(t *testing.T) {
"ID": "default",
},
}
var linux386Build = &artifact.Artifact{
Goos: "linux",
Goarch: "386",
Name: "mybin",
Path: filepath.Join(dist, "linux386", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
},
}
var linuxArmBuild = &artifact.Artifact{
Goos: "linux",
Goarch: "arm",
Goarm: "7",
Name: "mybin",
Path: filepath.Join(dist, "linuxarm7", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
},
}
var linuxMipsBuild = &artifact.Artifact{
Goos: "linux",
Goarch: "mips",
Gomips: "softfloat",
Name: "mybin",
Path: filepath.Join(dist, "linuxmipssoftfloat", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"ID": "default",
},
}
var windowsBuild = &artifact.Artifact{
Goos: "windows",
Goarch: "amd64",
Expand All @@ -87,37 +126,41 @@ func TestRunPipe(t *testing.T) {
},
}
ctx.Artifacts.Add(darwinBuild)
ctx.Artifacts.Add(linux386Build)
ctx.Artifacts.Add(linuxArmBuild)
ctx.Artifacts.Add(linuxMipsBuild)
ctx.Artifacts.Add(windowsBuild)
ctx.Version = "0.0.1"
ctx.Git.CurrentTag = "v0.0.1"
ctx.Config.Archives[0].Format = format
require.NoError(tt, Pipe{}.Run(ctx))
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive))
for _, arch := range archives.List() {
require.Equal(t, "defaultarch", arch.Extra["ID"].(string), "all archives should have the archive ID set")
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
for _, arch := range archives {
require.Equal(t, "myid", arch.Extra["ID"].(string), "all archives should have the archive ID set")
}
require.Len(tt, archives.List(), 2)
darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0]
windows := archives.Filter(artifact.ByGoos("windows")).List()[0]
require.Equal(tt, "foobar_0.0.1_darwin_amd64."+format, darwin.Name)
require.Equal(tt, "foobar_0.0.1_windows_amd64.zip", windows.Name)

require.Equal(t, []*artifact.Artifact{darwinBuild}, darwin.Extra["Builds"].([]*artifact.Artifact))
require.Equal(t, []*artifact.Artifact{windowsBuild}, windows.Extra["Builds"].([]*artifact.Artifact))
require.Len(t, archives, 5)
// TODO: should verify the artifact fields here too

if format == "tar.gz" {
// Check archive contents
require.Equal(
t,
[]string{
"README.md",
"foo/bar",
"foo/bar/foobar",
"foo/bar/foobar/blah.txt",
"mybin",
},
tarFiles(t, filepath.Join(dist, "foobar_0.0.1_darwin_amd64.tar.gz")),
)
for _, name := range []string{
"foobar_0.0.1_darwin_amd64.tar.gz",
"foobar_0.0.1_linux_386.tar.gz",
"foobar_0.0.1_linux_armv7.tar.gz",
"foobar_0.0.1_linux_mips_softfloat.tar.gz",
} {
require.Equal(
t,
[]string{
"README.md",
"foo/bar",
"foo/bar/foobar",
"foo/bar/foobar/blah.txt",
"mybin",
},
tarFiles(t, filepath.Join(dist, name)),
)
}
}
if format == "zip" {
require.Equal(
Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/nfpm/nfpm.go
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/goreleaser/goreleaser/pkg/context"
)

const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"

// Pipe for fpm packaging
type Pipe struct{}
Expand Down
14 changes: 12 additions & 2 deletions internal/pipe/snapcraft/snapcraft.go
Expand Up @@ -55,7 +55,7 @@ type AppMetadata struct {
Completer string `yaml:",omitempty"`
}

const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"

// Pipe for snapcraft packaging
type Pipe struct{}
Expand Down Expand Up @@ -117,7 +117,7 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error {
),
).GroupByPlatform() {
arch := linux.Arch(platform)
if arch == "armel" {
if !isValidArch(arch) {
log.WithField("arch", arch).Warn("ignored unsupported arch")
continue
}
Expand All @@ -129,6 +129,16 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error {
return g.Wait()
}

func isValidArch(arch string) bool {
// https://snapcraft.io/docs/architectures
for _, a := range []string{"s390x", "ppc64el", "arm64", "armhf", "amd64", "i386"} {
if arch == a {
return true
}
}
return false
}

// Publish packages
func (Pipe) Publish(ctx *context.Context) error {
snaps := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List()
Expand Down
23 changes: 22 additions & 1 deletion internal/pipe/snapcraft/snapcraft_test.go
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
)

func TestDescription(t *testing.T) {
Expand Down Expand Up @@ -397,3 +397,24 @@ func TestSeveralSnapssWithTheSameID(t *testing.T) {
}
require.EqualError(t, Pipe{}.Default(ctx), "found 2 snapcrafts with the ID 'a', please fix your config")
}

func Test_isValidArch(t *testing.T) {
tests := []struct {
arch string
want bool
}{
{"s390x", true},
{"ppc64el", true},
{"arm64", true},
{"armhf", true},
{"amd64", true},
{"i386", true},
{"mips", false},
{"armel", false},
}
for _, tt := range tests {
t.Run(tt.arch, func(t *testing.T) {
require.Equal(t, tt.want, isValidArch(tt.arch))
})
}
}
2 changes: 2 additions & 0 deletions internal/tmpl/tmpl.go
Expand Up @@ -38,6 +38,7 @@ const (
os = "Os"
arch = "Arch"
arm = "Arm"
mips = "Mips"
binary = "Binary"
artifactName = "ArtifactName"
// gitlab only
Expand Down Expand Up @@ -92,6 +93,7 @@ func (t *Template) WithArtifact(a *artifact.Artifact, replacements map[string]st
t.fields[os] = replace(replacements, a.Goos)
t.fields[arch] = replace(replacements, a.Goarch)
t.fields[arm] = replace(replacements, a.Goarm)
t.fields[mips] = replace(replacements, a.Gomips)
t.fields[binary] = bin.(string)
t.fields[artifactName] = a.Name
if val, ok := a.Extra["ArtifactUploadHash"]; ok {
Expand Down
2 changes: 2 additions & 0 deletions internal/tmpl/tmpl_test.go
Expand Up @@ -31,6 +31,7 @@ func TestWithArtifact(t *testing.T) {
"Linux": "{{.Os}}",
"amd64": "{{.Arch}}",
"6": "{{.Arm}}",
"softfloat": "{{.Mips}}",
"1.2.3": "{{.Version}}",
"v1.2.3": "{{.Tag}}",
"1-2-3": "{{.Major}}-{{.Minor}}-{{.Patch}}",
Expand All @@ -51,6 +52,7 @@ func TestWithArtifact(t *testing.T) {
Goarch: "amd64",
Goos: "linux",
Goarm: "6",
Gomips: "softfloat",
Extra: map[string]interface{}{
"Binary": "binary",
},
Expand Down
4 changes: 2 additions & 2 deletions www/content/archive.md
Expand Up @@ -26,9 +26,9 @@ archives:
# Archive name template.
# Defaults:
# - if format is `tar.gz`, `gz` or `zip`:
# - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
# - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}`
# - if format is `binary`:
# - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
# - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}`
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

# Replacements for GOOS and GOARCH in the archive name.
Expand Down
2 changes: 1 addition & 1 deletion www/content/nfpm.md
Expand Up @@ -24,7 +24,7 @@ nfpms:
package_name: foo

# You can change the file name of the package.
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}`
file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

# Build IDs for the builds you want to create NFPM packages for.
Expand Down
2 changes: 1 addition & 1 deletion www/content/snapcraft.md
Expand Up @@ -31,7 +31,7 @@ snapcrafts:
- bar

# You can change the name of the package.
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}`
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

# Replacements for GOOS and GOARCH in the package name.
Expand Down
1 change: 1 addition & 0 deletions www/content/templates.md
Expand Up @@ -37,6 +37,7 @@ may have some extra fields:
| `.Os` | `GOOS` (usually allow replacements) |
| `.Arch` | `GOARCH` (usually allow replacements) |
| `.Arm` | `GOARM` (usually allow replacements) |
| `.Mips` | `GOMIPS` (usually allow replacements) |
| `.Binary` | Binary name |
| `.ArtifactName` | Archive name |

Expand Down

0 comments on commit d85fff0

Please sign in to comment.