Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Magefile in .mage subdirectory stopped working in Go 1.16 #336

Closed
mirogta opened this issue Feb 25, 2021 · 4 comments
Closed

Bug: Magefile in .mage subdirectory stopped working in Go 1.16 #336

mirogta opened this issue Feb 25, 2021 · 4 comments

Comments

@mirogta
Copy link
Member

mirogta commented Feb 25, 2021

We are now using Magefile quite extensively in majority of our projects.

In order to separate it from the app code, we put the magefile.go or other mage-related files into a .mage subdirectory and configure the mage run like this in our Makefile:

MAGE = go run .mage/mage.go -d .mage -w .

help:
	@$(MAGE)

mage:
	@$(MAGE) $(args)

.DEFAULT:
	@$(MAGE) -v $@

The .mage\mage.go

// +build ignore

package main

import (
	"os"
	"github.com/magefile/mage/mage"
)

func main() { os.Exit(mage.Main()) }

… is just a wrapper around the magefile.go

// +build mage

package main
…
// Build…
func Build() {
…
}

// Clean…
func Clean() {
…
}

The .DEFAULT target allows us to run any mage target like a make target, so we can run e.g. make build instead of make mage args="build"

This has stopped working after upgrading to Go 1.16.

The problem is this line:

cmd = exec.Command(goCmd, "list", "-tags=mage", "-e", "-f", `{{join .GoFiles "||"}}`)

It doesn't find any Go files:

No .go files marked with the mage build tag in this directory.

How to reproduce:

  • create a magefile.go in a subdirectory, e.g. .mage\magefile.go
  • run mage
  • observe the error

Expected behaviour:

  • mage should keep working even if the mage files are in a subdirectory
@mirogta
Copy link
Member Author

mirogta commented Feb 25, 2021

Looks like the problem is this:

$ …/<module repo>/.mage> go list .
malformed import path "<module>/.mage": leading dot in path element

I have simply renamed the .mage directory to mage and things have started working. I'm trying to find out where is this breaking change coming from in Go 1.16, but if anyone has a clue how to make it still work with .mage it would be much appreciated. Otherwise we should yet again modify the build steps in all our repos :-(

@mirogta
Copy link
Member Author

mirogta commented Feb 25, 2021

I think I've found the reason here:

A valid path element is a non-empty string made up of ASCII letters, ASCII digits, and limited ASCII punctuation: - . _ and ~. It must not begin or end with a dot (U+002E), nor contain two dots in a row.

@mirogta
Copy link
Member Author

mirogta commented Feb 25, 2021

The problem is in Go, not in Mage… will close this issue.

@mirogta mirogta closed this as completed Feb 25, 2021
@ntrrg
Copy link
Contributor

ntrrg commented Feb 25, 2021

Hey! sorry for commenting this closed issue, but could you try creating a go.mod file in .mage? that way even the magefiles dependecies are in their own module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants