From 4395eb835bb1d30656723b5b470002e02b6b35da Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 24 Feb 2022 15:57:38 +1030 Subject: [PATCH 1/2] use no-space directive comment syntax in docs --- mage/testdata/mageimport/magefile.go | 4 ++-- mage/testdata/mageimport/oneline/magefile.go | 2 +- mage/testdata/mageimport/tagged/magefile.go | 2 +- parse/testdata/importself/magefile.go | 6 +++--- site/content/importing/_index.en.md | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mage/testdata/mageimport/magefile.go b/mage/testdata/mageimport/magefile.go index f5d286f5..f37a8953 100644 --- a/mage/testdata/mageimport/magefile.go +++ b/mage/testdata/mageimport/magefile.go @@ -12,9 +12,9 @@ package main import ( "fmt" - // mage:import + //mage:import _ "github.com/magefile/mage/mage/testdata/mageimport/subdir1" - // mage:import zz + //mage:import zz "github.com/magefile/mage/mage/testdata/mageimport/subdir2" ) diff --git a/mage/testdata/mageimport/oneline/magefile.go b/mage/testdata/mageimport/oneline/magefile.go index b6bd5ea8..fdbbc213 100644 --- a/mage/testdata/mageimport/oneline/magefile.go +++ b/mage/testdata/mageimport/oneline/magefile.go @@ -2,5 +2,5 @@ package main -// mage:import +//mage:import import _ "github.com/magefile/mage/mage/testdata/mageimport/oneline/other" diff --git a/mage/testdata/mageimport/tagged/magefile.go b/mage/testdata/mageimport/tagged/magefile.go index 027ed904..c04d933b 100644 --- a/mage/testdata/mageimport/tagged/magefile.go +++ b/mage/testdata/mageimport/tagged/magefile.go @@ -3,6 +3,6 @@ package main import ( - // mage:import + //mage:import _ "github.com/magefile/mage/mage/testdata/mageimport/tagged/pkg" ) diff --git a/parse/testdata/importself/magefile.go b/parse/testdata/importself/magefile.go index e448a84c..e1978e52 100644 --- a/parse/testdata/importself/magefile.go +++ b/parse/testdata/importself/magefile.go @@ -5,10 +5,10 @@ package main import ( "fmt" - // mage:import + //mage:import _ "github.com/magefile/mage/parse/testdata/importself" ) -func Build(){ +func Build() { fmt.Println("built") -} \ No newline at end of file +} diff --git a/site/content/importing/_index.en.md b/site/content/importing/_index.en.md index ff1f300d..15a196ab 100644 --- a/site/content/importing/_index.en.md +++ b/site/content/importing/_index.en.md @@ -27,15 +27,15 @@ like a normal magefile. ## Two Ways to Import -Importing targets from a package simply requires adding a `// mage:import` +Importing targets from a package simply requires adding a `//mage:import` comment on an import statement in your magefile. If there is a name after this tag, the targets will be imported into what is effectively like a namespace. ```go import ( - // mage:import + //mage:import _ "example.com/me/foobar" - // mage:import build + //mage:import build "example.com/me/builder" ) ``` From a93ae4ab97ca7cffdc2a311634838fd3b7b2b2c5 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 24 Feb 2022 16:08:22 +1030 Subject: [PATCH 2/2] update build tag mentions in docs to use go:build over +build and make template conform --- mage/magefile_tmpl.go | 3 ++- site/content/howitworks/_index.en.md | 2 +- site/content/importing/_index.en.md | 2 +- site/content/index.md | 2 +- site/content/magefiles/_index.en.md | 4 ++-- site/content/zeroInstall/_index.en.md | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mage/magefile_tmpl.go b/mage/magefile_tmpl.go index 01b87860..1df97037 100644 --- a/mage/magefile_tmpl.go +++ b/mage/magefile_tmpl.go @@ -1,6 +1,7 @@ package mage -var mageTpl = `// +build mage +var mageTpl = `//go:build mage +// +build mage package main diff --git a/site/content/howitworks/_index.en.md b/site/content/howitworks/_index.en.md index 699356af..57e3be81 100644 --- a/site/content/howitworks/_index.en.md +++ b/site/content/howitworks/_index.en.md @@ -4,7 +4,7 @@ weight = 50 +++ Mage scans the current directory for go files with the `mage` build tag (i.e. -`// +build mage`), using the normal go build rules for following build +`//go:build mage`), using the normal go build rules for following build constraints (aside from requiring the mage tag). It then parses those files to find the build targets, generates a main file for the command, and compiles a binary from those files. The magefiles are hashed so that if they remain diff --git a/site/content/importing/_index.en.md b/site/content/importing/_index.en.md index 15a196ab..db469a01 100644 --- a/site/content/importing/_index.en.md +++ b/site/content/importing/_index.en.md @@ -16,7 +16,7 @@ let you import a main package. In addition, all package files will be imported, so long as they don't have a build tag. If you try to import a package consisting only of files with build -tags (e.g. `//+build mage`), it will cause an error since mage doesn't set any +tags (e.g. `//go:build mage`), it will cause an error since mage doesn't set any build tags when importing packages. Any exported function, in imported packages, that matches Mage's allowed formats will be picked up as a target. diff --git a/site/content/index.md b/site/content/index.md index dc12a809..8caa43f0 100644 --- a/site/content/index.md +++ b/site/content/index.md @@ -45,7 +45,7 @@ You may also install a binary release from our ## Example Magefile ```go -//+build mage +//go:build mage package main diff --git a/site/content/magefiles/_index.en.md b/site/content/magefiles/_index.en.md index 6f908172..2831f81a 100644 --- a/site/content/magefiles/_index.en.md +++ b/site/content/magefiles/_index.en.md @@ -8,7 +8,7 @@ A mage file is any regular go file marked with a build target of "mage" and in package main. ```go -// +build mage +//go:build mage package main ``` @@ -25,7 +25,7 @@ use any of Go's usual build constraints, so you can include and exclude magefiles based on OS, arch, etc, whether in the filename or in the +build line. ```go -// +build mage +//go:build mage // A comment on the package will be output when you list the targets of a // magefile. diff --git a/site/content/zeroInstall/_index.en.md b/site/content/zeroInstall/_index.en.md index d7f60054..ccc32567 100644 --- a/site/content/zeroInstall/_index.en.md +++ b/site/content/zeroInstall/_index.en.md @@ -8,7 +8,7 @@ Don't want to depend on another binary in your environment? You can run mage directly out of your vendor directory (or GOPATH) with `go run`. Just save a file like this (I'll call it `mage.go`, but it can be named -anything) and note that the build tag is *not* `+build mage`. Mage will +anything) and note that the build tag is *not* `go:build mage`. Mage will create its own main file, so we need this one to be excluded from when your magefiles are compiled.