Skip to content

Commit

Permalink
dont use -tags=mage when doing mage:imports and compiling (#189)
Browse files Browse the repository at this point in the history
fixes #188
  • Loading branch information
natefinch authored Oct 17, 2018
1 parent 0f9693c commit 11d1591
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions mage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func getNamedImports(gocmd string, pkgs map[string]string) ([]*Import, error) {
}

func getImport(gocmd, importpath, alias string) (*Import, error) {
out, err := outputDebug(gocmd, "list", "-tags=mage", "-f", "{{.Dir}}||{{.Name}}", importpath)
out, err := outputDebug(gocmd, "list", "-f", "{{.Dir}}||{{.Name}}", importpath)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -569,7 +569,7 @@ func Compile(magePath, goCmd, compileTo string, gofiles []string, isDebug bool,
gofiles[i] = filepath.Base(gofiles[i])
}
debug.Printf("running %s -tag=mage build -o %s %s", goCmd, compileTo, strings.Join(gofiles, " "))
c := exec.Command(goCmd, append([]string{"build", "-tags=mage", "-o", compileTo}, gofiles...)...)
c := exec.Command(goCmd, append([]string{"build", "-o", compileTo}, gofiles...)...)
c.Env = os.Environ()
c.Stderr = stderr
c.Stdout = stdout
Expand Down
20 changes: 20 additions & 0 deletions mage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ func TestListMagefilesLib(t *testing.T) {
}
}

func TestMixedMageImports(t *testing.T) {
stderr := &bytes.Buffer{}
stdout := &bytes.Buffer{}
inv := Invocation{
Dir: "./testdata/mixed_lib_files",
Stdout: stdout,
Stderr: stderr,
List: true,
}
code := Invoke(inv)
if code != 0 {
t.Errorf("expected to exit with code 0, but got %v, stderr: %s", code, stderr)
}
expected := "Targets:\n build \n"
actual := stdout.String()
if actual != expected {
t.Fatalf("expected %q but got %q", expected, actual)
}
}

func TestGoRun(t *testing.T) {
c := exec.Command("go", "run", "main.go")
c.Dir = "./testdata"
Expand Down
6 changes: 5 additions & 1 deletion mage/testdata/mixed_lib_files/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

package main

func Build() {}
import "./subdir"

func Build() {
subdir.Build()
}
5 changes: 5 additions & 0 deletions mage/testdata/mixed_lib_files/subdir/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build mage

package main

func Build() {}
3 changes: 3 additions & 0 deletions mage/testdata/mixed_lib_files/subdir/nonmage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package subdir

func Build() {}

0 comments on commit 11d1591

Please sign in to comment.