add support for retaining multiline comments
including MAGEFILE_MULTILINE environment variable
and //mage:multiline in-code comment
and -multiline CLI flag.
* add tests
* fix lint errors and align ci and lint workflows
* update to require go 1.18 since golangci-lint requires it, and because it adds version control info into the binary automatically
* use built-in version info from go 1.18
* remove gopath from install docs
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.
* mage: cancel context on SIGINT
On receiving an interrupt signal, mage cancels the context allowing the magefile
to perform any cleanup before exiting.
A second interrupt signal will kill the magefile process without delay.
The behaviour for a timeout remains unchanged (context is cancelled and the magefile
exits).
* mage: add cleanup timeout to cancel
Co-authored-by: Nate Finch <nate.finch@gmail.com>
* Use magefolder if no directory set and it exists.
If no directory was passed by the user as an explicit option and there is a folder named "magefolder" use that.
Workdir is kept as it is likely still "."
* Remove the default . for -d flag
Also correct os.Stat error checking to expect no error
* Add tests and test data for magefolder
* Rename magefolder and accept untagged files
Magefolder was renamed to magefiles
We now accept files that are not tagged too when using a magefiles directory
* Assume tagging when mix tagging is present
When using magefiles directory, if there are mixed tagging files assume tagging is used for mage files
* Update error format to %v
We support building for older go versions so error formatting should use %v
* sort outputs
* Accept mixed tagging in magefiles folder
When mixed tagging is found within a magefiles folder, opt to use all files
* little tweak to only do go list once when using magefiles directory
* Add magefiles directory information to the website
* Add a preference for mage files over directories
Add a temporary preference for mage files over magefiles directories and warn users this is a temporary functionality leading to a change where directory will be preferred.
Co-authored-by: Nate Finch <natefinch@github.com>
* fix: determanistic compiled mainfile
sort template data so resulting mainfile is consistantly reproducible,
which is important to leverage build cache and results in a consistent
build id on output (given identical build parameters, e.g. ldflags,
output file name, etc.)
Result of `mage -compile ./mage_static && go tool buildid ./mage_static`
should now always be identical on repeated invocation.
Results in a probably imperceptible build time quickening, but solves a
minor peave of mine, and adds a test as protection from regression :)
* fix: poorly spelled test
Co-authored-by: Nate Finch <nate.finch@gmail.com>
* Update parse/parse.go
got caught out not using vim's spellcheck
Co-authored-by: Paul Burlumi <paul@burlumi.com>
* Update mage/main.go
got caught out not using vim's spellcheck
Co-authored-by: Paul Burlumi <paul@burlumi.com>
* fix spelling
Co-authored-by: Paul Burlumi <paul@burlumi.com>
Co-authored-by: Nate Finch <nate.finch@gmail.com>
Co-authored-by: Paul Burlumi <paul@burlumi.com>
Co-authored-by: Nate Finch <natefinch@github.com>
When calling mage import, we weren't prefiltering the list of go
files, so we'd get files with build tags and test files and such.
What we want is just the normal go files for building the library.
Using go list returns us that, so use that.
Simplify the code tremendously by using 'go list' instead of go/build, and remove the use of go/types to determine types (since we only care about a couple canonical types).
* add support for choose which go binary to run
* make the compiler configurable
* add a cli flag and update docs
* use go version as part of the binary hash
* add go version to what we display in mage -version
This change adds `sanitizeSynopsis()` function to perform basic
sanitization on the synopsis. If synopsis begins with the function name, it
removes the function to avoid repeating words.
* * Removed stale type declarations in parse.
* Updated parse and mg to make better use of types package.
* Added function to types package to test for valid function.
* Added function to to types package to wrap a valid FuncType as the
* most greedy of FuncType
* renamed IsFuncType and refactored to return error instead of bool. Made the return value of FuncTypeWrap more clear.
* removed unused type func declarations
* Helpers galore
This commit adds helper functions that should be commonly needed
by many magefiles. It includes command execution handlers as well
as error handlers.
This commit also removes the only two non-stdlib dependencies in
the codebase. Since mage will likely be vendored into a repo,
it would be nice to avoid cluttering the vendor directory with
dependencies that are only for the build script.
fixes#13
The bug was that non-stdlib imports were failing to be found by the parser.
The problem is that the default importer only imports from compiled files. But we specifically want to import from source files. For go 1.9 this is easy, go/importer has an importer.For that takes "source". However, previous to go 1.9, this doesn't exist. To keep the code working in previous versions, we just grab the code from 1.9's srcimporter and include it in the build, and then conditionally compile in that code if we're not running on go 1.9 or greater (if we are running on go 1.9, we can use the stdlib version, which is better because it'll get fixes etc automatically).
Also added a bunch of tests to ensure that this code won't break again without a test failing.