-
Notifications
You must be signed in to change notification settings - Fork 264
Traverse upwards for magefiles #290
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
base: master
Are you sure you want to change the base?
Conversation
With this change, when a user is not in the root of their mage-powered project and executes mage, we iteratively traverse the path upwards until we find some magefiles. This should help with overall usability.
@ryanfaerman I'm not saying that |
What if I were to add an environment variable that could be used to control this behavior? Something like Or, this could be an option for the I generally prefer not to have options, but either one would be a decent compromise. |
I like that idea. |
If you consider other build systems they have the concept of a workspace. In go, the "workspace" is where In Google's Bazel, it is defined with the There could be a The difference in behaviour is that with the concept of a workspace, I would expect mage to show me targets for all directories in my workspace, not just those directly upwards in my tree. On the other hand just going upwards without introducing the whole workspace concept might just be easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on adding an environment variable. I would vote for having the behavior turned on by default, and using the env var to opt out.
FINDFILES: | ||
files, err := Magefiles(inv.Dir, inv.GOOS, inv.GOARCH, inv.GoCmd, inv.Stderr, inv.Debug) | ||
if err != nil { | ||
errlog.Println("Error determining list of magefiles:", err) | ||
return 1 | ||
} | ||
|
||
if len(files) == 0 { | ||
if strings.HasSuffix(inv.Dir, "/") { | ||
debug.Println("Reached root searching for magefiles") | ||
} else { | ||
inv.Dir = filepath.Dir(inv.Dir) | ||
debug.Println("No .go files marked with the mage build tag in this directory") | ||
debug.Println("Moving to parent to find magefiles") | ||
goto FINDFILES | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend against using the label in favor of pulling this all out into a function + function call here. A recursion is far easier to reason about than this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's like bigfoot. First goto
I've seen in years 😆 (not saying it doesn't have it's uses, just rare to see it in the wild!)
Is this going to work if our magefiles are in a subdirectory, and would be for example in the @DavidGamba
|
Currently, if you attempt to run
mage
from somewhere other than your project root you get an error:Coming from rake, I'm used to being able to run my tasks from any level deep within my project and be confident everything will run.
This change allows the resolution of the magefiles to traverse upwards until it reaches the root
/
. With this update, you can runmage
from any level deep of your project and it will still find the magefiles and work as expected.Also, despite invoking at some (possibly deep) nested path, the actual binary's working directory is the directory where the magefiles are located.