8000 implement importing magefiles by natefinch · Pull Request #187 · magefile/mage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

implement importing magefiles #187

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

Merged
merged 7 commits into from
Oct 11, 2018
Merged

implement importing magefiles #187

merged 7 commits into from
Oct 11, 2018

Conversation

natefinch
Copy link
Member
@natefinch natefinch commented Oct 6, 2018

This is stll a work in progress (needs tests and validation code) but the core works. What you do is underscore import the package that has the mage targets you want in the current magefile, and then add // mage:import as a comment on the import. Note that the package you import will include all files, not just those with //+build mage. This is unfortunately a restriction of the go compiler and not something that I can really get around.

By default mage:import drops the targets into the root namespace of this magefile, but if you'd like to make a namespace for those targets you can do so by adding a namespace after the mage:import statement. For example, // mage:import build would prefix the targets in that
package with build:

full example:

// +build mage

import (
    "fmt"

    // targets imported as if they were defined in this file
    // mage:import
    _ "github.com/foo/bar/mage/common" 
   
    // targets imported as if they were in a "build" namespace in this file
    // mage:import build
    _ "github.com/foo/bar/mage/builder"  
)

It technically doesn't have to be an underscore import, any import will work, but the other imports will cause "unused import" errors (if they're not used).

@natefinch natefinch merged commit 0f9693c into 605D master Oct 11, 2018
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

Successfully merging this pull request may close these issues.

1 participant
0