Skip to content

Commit

Permalink
Merge branch 'master' into feat-riscv64-support
Browse files Browse the repository at this point in the history
  • Loading branch information
perrito666 authored Nov 24, 2024
2 parents 2dae4bf + 0800736 commit 6bf38a5
Show file tree
Hide file tree
Showing 52 changed files with 143 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ jobs:
matrix:
go-version:
- stable
- 1.21.x
- 1.20.x
- 1.19.x
- 1.18.x
- 1.17.x
- 1.16.x
- 1.15.x
Expand Down
3 changes: 2 additions & 1 deletion bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build ignore
//go:build ignore
// +build ignore

package main

Expand Down
3 changes: 2 additions & 1 deletion install_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build CI
//go:build CI
// +build CI

package main

Expand Down
20 changes: 20 additions & 0 deletions mage/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ func TestMageImportsOneLine(t *testing.T) {
t.Fatalf("expected: %q got: %q", expected, actual)
}
}
func TestMageImportsTrailing(t *testing.T) {
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
inv := Invocation{
Dir: "./testdata/mageimport/trailing",
Stdout: stdout,
Stderr: stderr,
Args: []string{"build"},
}

code := Invoke(inv)
if code != 0 {
t.Fatalf("expected to exit with code 0, but got %v, stderr:\n%s", code, stderr)
}
actual := stdout.String()
expected := "build\n"
if actual != expected {
t.Fatalf("expected: %q got: %q", expected, actual)
}
}

func TestMageImportsTaggedPackage(t *testing.T) {
stdout := &bytes.Buffer{}
Expand Down
8 changes: 4 additions & 4 deletions mage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1739,14 +1739,14 @@ func TestGoModules(t *testing.T) {
t.Fatal(err)
}
defer os.RemoveAll(dir)
err = ioutil.WriteFile(filepath.Join(dir, "magefile.go"), []byte(`//+build mage
// beware, mage builds in go versions older than 1.17 so both build tag formats need to be present
err = ioutil.WriteFile(filepath.Join(dir, "magefile.go"), []byte(`//go:build mage
// +build mage
package main
import "golang.org/x/text/unicode/norm"
func Test() {
print("unicode version: " + norm.Version)
print("nothing is imported here for >1.17 compatibility")
}
`), 0600)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion mage/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package mage
// this template uses the "data"

// var only for tests
var mageMainfileTplString = `// +build ignore
var mageMainfileTplString = `//go:build ignore
// +build ignore
package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/alias/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/args/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/compiled/custom.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

// Compiled package description.
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/context/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/error.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/func.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/goos_magefiles/magefile_nonwindows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage && !windows
// +build mage,!windows

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/goos_magefiles/magefile_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/invalid_alias/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/keep_flag/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/list/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

// This is a comment on the package which should get turned into output with the
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/mageimport/oneline/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package sametarget
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/tagged/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mageimport/tagged/pkg/mage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package pkg

Expand Down
6 changes: 6 additions & 0 deletions mage/testdata/mageimport/trailing/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build mage
// +build mage

package main

import _ "github.com/magefile/mage/mage/testdata/mageimport/oneline/other" //mage:import
7 changes: 7 additions & 0 deletions mage/testdata/mageimport/trailing/other/other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package other

import "fmt"

func Build() {
fmt.Println("build")
}
1 change: 1 addition & 0 deletions mage/testdata/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_lib_files/mage_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_lib_files/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/mixed_lib_files/subdir/magefile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_main_files/mage_helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/mixed_main_files/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/namespaces/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/no_default/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions mage/testdata/onlyStdLib/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions mage/testdata/panic.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/setdir/setdir.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/setworkdir/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/signals/signals.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/transitiveDeps/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
3 changes: 2 additions & 1 deletion mage/testdata/wrong_dep/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
48 changes: 33 additions & 15 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type PkgInfo struct {
Imports Imports
}

// Function represented a job function from a mage file
// Function represents a job function from a mage file
type Function struct {
PkgAlias string
Package string
Expand Down Expand Up @@ -456,19 +456,18 @@ func setImports(gocmd string, pi *PkgInfo) error {
}

func getImportPath(imp *ast.ImportSpec) (path, alias string, ok bool) {
if imp.Doc == nil || len(imp.Doc.List) == 9 {
return "", "", false
}
// import is always the last comment
s := imp.Doc.List[len(imp.Doc.List)-1].Text

// trim comment start and normalize for anyone who has spaces or not between
// "//"" and the text
vals := strings.Fields(strings.ToLower(s[2:]))
if len(vals) == 0 {
return "", "", false
}
if vals[0] != importTag {
leadingVals := getImportPathFromCommentGroup(imp.Doc)
trailingVals := getImportPathFromCommentGroup(imp.Comment)

var vals []string
if len(leadingVals) > 0 {
vals = leadingVals
if len(trailingVals) > 0 {
log.Println("warning:", importTag, "specified both before and after, picking first")
}
} else if len(trailingVals) > 0 {
vals = trailingVals
} else {
return "", "", false
}
path, ok = lit2string(imp.Path)
Expand All @@ -489,6 +488,25 @@ func getImportPath(imp *ast.ImportSpec) (path, alias string, ok bool) {
}
}

func getImportPathFromCommentGroup(comments *ast.CommentGroup) []string {
if comments == nil || len(comments.List) == 9 {
return nil
}
// import is always the last comment
s := comments.List[len(comments.List)-1].Text

// trim comment start and normalize for anyone who has spaces or not between
// "//"" and the text
vals := strings.Fields(strings.ToLower(s[2:]))
if len(vals) == 0 {
return nil
}
if vals[0] != importTag {
return nil
}
return vals
}

func isNamespace(t *doc.Type) bool {
if len(t.Decl.Specs) != 1 {
return false
Expand Down Expand Up @@ -653,7 +671,7 @@ func getFunction(exp ast.Expr, pi *PkgInfo) (*Function, error) {
for _, imp := range pi.Imports {
if firstname == imp.Name {
for _, f := range imp.Info.Funcs {
if funcname == f.Name {
if funcname == f.Name && f.Receiver == "" {
return f, nil
}
}
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/alias.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/command.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
1 change: 1 addition & 0 deletions parse/testdata/func.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
3 changes: 2 additions & 1 deletion parse/testdata/importself/magefile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build mage
//go:build mage
// +build mage

package main

Expand Down
1 change: 1 addition & 0 deletions parse/testdata/repeating_synopsis.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build mage
// +build mage

package main
Expand Down
Loading

0 comments on commit 6bf38a5

Please sign in to comment.