magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.14k stars 257 forks source link

Cannot import `mg` for a mage file #13

Closed interlock closed 7 years ago

interlock commented 7 years ago

Problem: When running mage with the included example code below the following error is reported.

make.go:8:2: could not import github.com/magefile/mage/mg (can't find import: github.com/magefile/mage/mg)

Expected: mage -l to generate and build with the example code, allowing the use of mg for mg.Dep(...).

// +build mage

package main

import (
    "fmt"

    "github.com/magefile/mage/mg"
)

func Build() {
    mg.Deps(Clean)
    fmt.Println("Building")
}

func Clean() {
    fmt.Println("Cleaning")
}

Results of go env


GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/interlock/src/go"
GORACE=""
GOROOT="/home/interlock/.asdf/installs/golang/1.8.3/go"
GOTOOLDIR="/home/interlock/.asdf/installs/golang/1.8.3/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build518538770=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"```
interlock commented 7 years ago

Narrowed this error down to here:

https://github.com/magefile/mage/blob/master/parse/parse.go#L139

natefinch commented 7 years ago

deleting my $GOPATH/pkg allowed me to repro this on my dev machine. So that explains why it wasn't happening on my machine, but not sure why it's happening. I think I'm just missing something to include imports.