From 9f54e0f83e2a8d2976c07037ad74aa20c62797a5 Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Wed, 13 Sep 2023 00:24:18 +0900 Subject: [PATCH 1/6] feat: support trailing line comment for mage:import (#480) --- mage/import_test.go | 20 +++++++++ mage/testdata/mageimport/trailing/magefile.go | 5 +++ .../mageimport/trailing/other/other.go | 7 +++ parse/parse.go | 44 +++++++++++++------ 4 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 mage/testdata/mageimport/trailing/magefile.go create mode 100644 mage/testdata/mageimport/trailing/other/other.go diff --git a/mage/import_test.go b/mage/import_test.go index 83949b27..df40a3fb 100644 --- a/mage/import_test.go +++ b/mage/import_test.go @@ -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{} diff --git a/mage/testdata/mageimport/trailing/magefile.go b/mage/testdata/mageimport/trailing/magefile.go new file mode 100644 index 00000000..ed3691b9 --- /dev/null +++ b/mage/testdata/mageimport/trailing/magefile.go @@ -0,0 +1,5 @@ +// +build mage + +package main + +import _ "github.com/magefile/mage/mage/testdata/mageimport/oneline/other" //mage:import diff --git a/mage/testdata/mageimport/trailing/other/other.go b/mage/testdata/mageimport/trailing/other/other.go new file mode 100644 index 00000000..5d40570b --- /dev/null +++ b/mage/testdata/mageimport/trailing/other/other.go @@ -0,0 +1,7 @@ +package other + +import "fmt" + +func Build() { + fmt.Println("build") +} diff --git a/parse/parse.go b/parse/parse.go index 48cf1ece..cf8b62a5 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -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) @@ -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 From c97c20563ff9240ece7c978a35de106a6e10ddfe Mon Sep 17 00:00:00 2001 From: WilliamRoyNelson Date: Wed, 11 Oct 2023 09:58:51 -0700 Subject: [PATCH 2/6] Update documentation to include Windows Magefile Cache (#484) * Update _index.en.md * Update documentation to include Windows Magefile Cache --- site/content/environment/_index.en.md | 2 +- site/content/howitworks/_index.en.md | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/site/content/environment/_index.en.md b/site/content/environment/_index.en.md index 33d774d6..c2c6bc52 100644 --- a/site/content/environment/_index.en.md +++ b/site/content/environment/_index.en.md @@ -14,7 +14,7 @@ Set to "1" or "true" to turn on debug mode (like running with -debug) ## MAGEFILE_CACHE Sets the directory where mage will store binaries compiled from magefiles -(default is $HOME/.magefile) +(default is $HOME/. or %USERPROFILE%\magefile) ## MAGEFILE_GOCMD diff --git a/site/content/howitworks/_index.en.md b/site/content/howitworks/_index.en.md index 57e3be81..2aa8110a 100644 --- a/site/content/howitworks/_index.en.md +++ b/site/content/howitworks/_index.en.md @@ -14,12 +14,13 @@ binary is also used in the hash. ## Binary Cache -Compiled magefile binaries are stored in $HOME/.magefile. This location can be -customized by setting the MAGEFILE_CACHE environment variable. +Compiled magefile binaries are stored by default in $HOME/.magefile or in +%USERPROFILE%\magefile. This location can be customized by setting the +MAGEFILE_CACHE environment variable. ## Go Environment Mage itself requires no dependencies to run. However, because it is compiling go code, you must have a valid go environment set up on your machine. Mage is compatible with any go 1.7+ environment (earlier versions may work but are not -tested). \ No newline at end of file +tested). From 2edffd16656bfa043110ee2173aee012ba9616d4 Mon Sep 17 00:00:00 2001 From: szTheory Date: Sat, 18 Nov 2023 12:50:02 +0000 Subject: [PATCH 3/6] Comment typo: parse.go (#485) --- parse/parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse/parse.go b/parse/parse.go index cf8b62a5..34216690 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -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 From 0fddccbc366b566bbb0ea972208c54f1066654df Mon Sep 17 00:00:00 2001 From: michalbiesek Date: Sat, 18 Nov 2023 14:16:19 +0100 Subject: [PATCH 4/6] ci: Extend `go-version` with `1.21.x` (#479) --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8dc45c2e..e6bff518 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 From 2385abb49a1fa8f1e160556889f4ba9704a2ddb7 Mon Sep 17 00:00:00 2001 From: Horacio Duran Date: Sat, 18 Nov 2023 18:05:41 +0100 Subject: [PATCH 5/6] Correct test input code to support older go versions (#490) Samples used for testing need to have build tags for new and old style: ``` //go:build tag // +build tag ``` The particular problem here seems to be that 1.16 was actually importing the package referred in the `TestGoModules` test (`import "golang.org/x/text/unicode/norm"`) which, in the CI system's version lacks an old style go tag comment. Hence go complaining of a `//go:build` without a `// +build`. I made all files bi-tagged for consistency. --- bootstrap.go | 3 ++- install_test.go | 3 ++- mage/main_test.go | 8 ++++---- mage/template.go | 3 ++- mage/testdata/alias/magefile.go | 3 ++- mage/testdata/args/magefile.go | 3 ++- mage/testdata/command.go | 1 + mage/testdata/compiled/custom.go | 1 + mage/testdata/context/context.go | 3 ++- mage/testdata/error.go | 1 + mage/testdata/func.go | 1 + mage/testdata/goos_magefiles/magefile_nonwindows.go | 1 + mage/testdata/goos_magefiles/magefile_windows.go | 1 + mage/testdata/invalid_alias/magefile.go | 1 + mage/testdata/keep_flag/magefile.go | 1 + mage/testdata/list/command.go | 1 + mage/testdata/mageimport/magefile.go | 3 ++- mage/testdata/mageimport/oneline/magefile.go | 1 + .../mageimport/samenamespace/duptargets/magefile.go | 1 + .../mageimport/samenamespace/uniquetargets/magefile.go | 1 + mage/testdata/mageimport/tagged/magefile.go | 3 ++- mage/testdata/mageimport/tagged/pkg/mage.go | 3 ++- mage/testdata/mageimport/trailing/magefile.go | 1 + mage/testdata/main.go | 1 + mage/testdata/mixed_lib_files/mage_helpers.go | 3 ++- mage/testdata/mixed_lib_files/magefile.go | 3 ++- mage/testdata/mixed_lib_files/subdir/magefile.go | 1 + mage/testdata/mixed_main_files/mage_helpers.go | 3 ++- mage/testdata/mixed_main_files/magefile.go | 3 ++- mage/testdata/namespaces/magefile.go | 3 ++- mage/testdata/no_default/magefile.go | 3 ++- mage/testdata/onlyStdLib/command.go | 1 + mage/testdata/panic.go | 1 + mage/testdata/setdir/setdir.go | 3 ++- mage/testdata/setworkdir/magefile.go | 3 ++- mage/testdata/signals/signals.go | 3 ++- mage/testdata/transitiveDeps/magefile.go | 3 ++- mage/testdata/wrong_dep/magefile.go | 3 ++- parse/testdata/alias.go | 1 + parse/testdata/command.go | 1 + parse/testdata/func.go | 1 + parse/testdata/importself/magefile.go | 3 ++- parse/testdata/repeating_synopsis.go | 1 + parse/testdata/subcommand_1.9.go | 3 ++- parse/testdata/subcommands.go | 1 + site/content/zeroInstall/_index.en.md | 1 + 46 files changed, 71 insertions(+), 26 deletions(-) diff --git a/bootstrap.go b/bootstrap.go index c37f6fc8..136aa66a 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -1,4 +1,5 @@ -//+build ignore +//go:build ignore +// +build ignore package main diff --git a/install_test.go b/install_test.go index d7923c8d..8e3cf9e7 100644 --- a/install_test.go +++ b/install_test.go @@ -1,4 +1,5 @@ -//+build CI +//go:build CI +// +build CI package main diff --git a/mage/main_test.go b/mage/main_test.go index b722d842..07e598e5 100644 --- a/mage/main_test.go +++ b/mage/main_test.go @@ -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 { diff --git a/mage/template.go b/mage/template.go index af822f0f..e6dc1306 100644 --- a/mage/template.go +++ b/mage/template.go @@ -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 diff --git a/mage/testdata/alias/magefile.go b/mage/testdata/alias/magefile.go index d68326d3..97b86f6d 100644 --- a/mage/testdata/alias/magefile.go +++ b/mage/testdata/alias/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/args/magefile.go b/mage/testdata/args/magefile.go index e7f7b262..de0f262e 100644 --- a/mage/testdata/args/magefile.go +++ b/mage/testdata/args/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/command.go b/mage/testdata/command.go index ac2b7350..74b2b845 100644 --- a/mage/testdata/command.go +++ b/mage/testdata/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/compiled/custom.go b/mage/testdata/compiled/custom.go index 41aaabe3..2a1bdfd1 100644 --- a/mage/testdata/compiled/custom.go +++ b/mage/testdata/compiled/custom.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage // Compiled package description. diff --git a/mage/testdata/context/context.go b/mage/testdata/context/context.go index aaf08fbe..876bc520 100644 --- a/mage/testdata/context/context.go +++ b/mage/testdata/context/context.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/error.go b/mage/testdata/error.go index bb98a097..a639fd60 100644 --- a/mage/testdata/error.go +++ b/mage/testdata/error.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/func.go b/mage/testdata/func.go index b33fe4b3..503ccdf7 100644 --- a/mage/testdata/func.go +++ b/mage/testdata/func.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/goos_magefiles/magefile_nonwindows.go b/mage/testdata/goos_magefiles/magefile_nonwindows.go index 420f4f89..3be85d86 100644 --- a/mage/testdata/goos_magefiles/magefile_nonwindows.go +++ b/mage/testdata/goos_magefiles/magefile_nonwindows.go @@ -1,3 +1,4 @@ +//go:build mage && !windows // +build mage,!windows package main diff --git a/mage/testdata/goos_magefiles/magefile_windows.go b/mage/testdata/goos_magefiles/magefile_windows.go index 1b8248bb..15173da0 100644 --- a/mage/testdata/goos_magefiles/magefile_windows.go +++ b/mage/testdata/goos_magefiles/magefile_windows.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/invalid_alias/magefile.go b/mage/testdata/invalid_alias/magefile.go index e3f985f1..59e013eb 100644 --- a/mage/testdata/invalid_alias/magefile.go +++ b/mage/testdata/invalid_alias/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/keep_flag/magefile.go b/mage/testdata/keep_flag/magefile.go index ce97b22a..1ab8e212 100644 --- a/mage/testdata/keep_flag/magefile.go +++ b/mage/testdata/keep_flag/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/list/command.go b/mage/testdata/list/command.go index ae36007e..3795cec4 100644 --- a/mage/testdata/list/command.go +++ b/mage/testdata/list/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage // This is a comment on the package which should get turned into output with the diff --git a/mage/testdata/mageimport/magefile.go b/mage/testdata/mageimport/magefile.go index f37a8953..ec69c14c 100644 --- a/mage/testdata/mageimport/magefile.go +++ b/mage/testdata/mageimport/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mageimport/oneline/magefile.go b/mage/testdata/mageimport/oneline/magefile.go index fdbbc213..d8b5c9fe 100644 --- a/mage/testdata/mageimport/oneline/magefile.go +++ b/mage/testdata/mageimport/oneline/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mageimport/samenamespace/duptargets/magefile.go b/mage/testdata/mageimport/samenamespace/duptargets/magefile.go index 5c585304..edf4078b 100644 --- a/mage/testdata/mageimport/samenamespace/duptargets/magefile.go +++ b/mage/testdata/mageimport/samenamespace/duptargets/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package sametarget diff --git a/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go b/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go index aebacbb6..c93b2d2f 100644 --- a/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go +++ b/mage/testdata/mageimport/samenamespace/uniquetargets/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mageimport/tagged/magefile.go b/mage/testdata/mageimport/tagged/magefile.go index c04d933b..9efe85fe 100644 --- a/mage/testdata/mageimport/tagged/magefile.go +++ b/mage/testdata/mageimport/tagged/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mageimport/tagged/pkg/mage.go b/mage/testdata/mageimport/tagged/pkg/mage.go index d5991482..014e2fa2 100644 --- a/mage/testdata/mageimport/tagged/pkg/mage.go +++ b/mage/testdata/mageimport/tagged/pkg/mage.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package pkg diff --git a/mage/testdata/mageimport/trailing/magefile.go b/mage/testdata/mageimport/trailing/magefile.go index ed3691b9..13360367 100644 --- a/mage/testdata/mageimport/trailing/magefile.go +++ b/mage/testdata/mageimport/trailing/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/main.go b/mage/testdata/main.go index a3f23b4b..53c564a8 100644 --- a/mage/testdata/main.go +++ b/mage/testdata/main.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package main diff --git a/mage/testdata/mixed_lib_files/mage_helpers.go b/mage/testdata/mixed_lib_files/mage_helpers.go index 19c713a0..e4b8872f 100644 --- a/mage/testdata/mixed_lib_files/mage_helpers.go +++ b/mage/testdata/mixed_lib_files/mage_helpers.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_lib_files/magefile.go b/mage/testdata/mixed_lib_files/magefile.go index 3c30feba..ce6b9c47 100644 --- a/mage/testdata/mixed_lib_files/magefile.go +++ b/mage/testdata/mixed_lib_files/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_lib_files/subdir/magefile.go b/mage/testdata/mixed_lib_files/subdir/magefile.go index 20a9fe49..63584509 100644 --- a/mage/testdata/mixed_lib_files/subdir/magefile.go +++ b/mage/testdata/mixed_lib_files/subdir/magefile.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/mixed_main_files/mage_helpers.go b/mage/testdata/mixed_main_files/mage_helpers.go index 19c713a0..e4b8872f 100644 --- a/mage/testdata/mixed_main_files/mage_helpers.go +++ b/mage/testdata/mixed_main_files/mage_helpers.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/mixed_main_files/magefile.go b/mage/testdata/mixed_main_files/magefile.go index f4248496..63584509 100644 --- a/mage/testdata/mixed_main_files/magefile.go +++ b/mage/testdata/mixed_main_files/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/namespaces/magefile.go b/mage/testdata/namespaces/magefile.go index d1ae0456..c2b8f4da 100644 --- a/mage/testdata/namespaces/magefile.go +++ b/mage/testdata/namespaces/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/no_default/magefile.go b/mage/testdata/no_default/magefile.go index 4e3d4941..a0046682 100644 --- a/mage/testdata/no_default/magefile.go +++ b/mage/testdata/no_default/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/onlyStdLib/command.go b/mage/testdata/onlyStdLib/command.go index 3822a80a..e1c4b825 100644 --- a/mage/testdata/onlyStdLib/command.go +++ b/mage/testdata/onlyStdLib/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/panic.go b/mage/testdata/panic.go index 3714c0d5..2cd54a9e 100644 --- a/mage/testdata/panic.go +++ b/mage/testdata/panic.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/mage/testdata/setdir/setdir.go b/mage/testdata/setdir/setdir.go index 3fc20d83..9b8571d6 100644 --- a/mage/testdata/setdir/setdir.go +++ b/mage/testdata/setdir/setdir.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/setworkdir/magefile.go b/mage/testdata/setworkdir/magefile.go index 2eb93235..d0c0ab78 100644 --- a/mage/testdata/setworkdir/magefile.go +++ b/mage/testdata/setworkdir/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/signals/signals.go b/mage/testdata/signals/signals.go index 96d62552..07d0e942 100644 --- a/mage/testdata/signals/signals.go +++ b/mage/testdata/signals/signals.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/transitiveDeps/magefile.go b/mage/testdata/transitiveDeps/magefile.go index 379d6eab..336f1c0d 100644 --- a/mage/testdata/transitiveDeps/magefile.go +++ b/mage/testdata/transitiveDeps/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/mage/testdata/wrong_dep/magefile.go b/mage/testdata/wrong_dep/magefile.go index 8da309d8..30c441d7 100644 --- a/mage/testdata/wrong_dep/magefile.go +++ b/mage/testdata/wrong_dep/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/parse/testdata/alias.go b/parse/testdata/alias.go index 0c5d3136..6b1c111f 100644 --- a/parse/testdata/alias.go +++ b/parse/testdata/alias.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/command.go b/parse/testdata/command.go index d8e6f74a..ab54994c 100644 --- a/parse/testdata/command.go +++ b/parse/testdata/command.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/func.go b/parse/testdata/func.go index 94927756..ffc81fda 100644 --- a/parse/testdata/func.go +++ b/parse/testdata/func.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/importself/magefile.go b/parse/testdata/importself/magefile.go index e1978e52..4440b9dd 100644 --- a/parse/testdata/importself/magefile.go +++ b/parse/testdata/importself/magefile.go @@ -1,4 +1,5 @@ -//+build mage +//go:build mage +// +build mage package main diff --git a/parse/testdata/repeating_synopsis.go b/parse/testdata/repeating_synopsis.go index bcac14d4..602516f1 100644 --- a/parse/testdata/repeating_synopsis.go +++ b/parse/testdata/repeating_synopsis.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/parse/testdata/subcommand_1.9.go b/parse/testdata/subcommand_1.9.go index 21d1d95d..ee820ae5 100644 --- a/parse/testdata/subcommand_1.9.go +++ b/parse/testdata/subcommand_1.9.go @@ -1,4 +1,5 @@ -//+build mage,go1.9 +//go:build mage && go1.9 +// +build mage,go1.9 package main diff --git a/parse/testdata/subcommands.go b/parse/testdata/subcommands.go index 4eb31bdb..502f00e2 100644 --- a/parse/testdata/subcommands.go +++ b/parse/testdata/subcommands.go @@ -1,3 +1,4 @@ +//go:build mage // +build mage package main diff --git a/site/content/zeroInstall/_index.en.md b/site/content/zeroInstall/_index.en.md index 1a7b1c98..4b8c2212 100644 --- a/site/content/zeroInstall/_index.en.md +++ b/site/content/zeroInstall/_index.en.md @@ -16,6 +16,7 @@ Now you can `go run mage.go ` and it'll work just as if you ran `mage `: ```go +//go:build ignore // +build ignore package main From 0800736cf7b88a1eb03e2a2b05fe0281a9eb9225 Mon Sep 17 00:00:00 2001 From: na4ma4 <25967676+na4ma4@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:53:19 +1000 Subject: [PATCH 6/6] fix default selector ignoring Receiver and returning first matching function name (#509) Co-authored-by: na4ma4 --- parse/parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse/parse.go b/parse/parse.go index 34216690..e68703bd 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -671,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 } }