From 11d15918ff3aa6f75cd6d3340a9507bb5309c679 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Wed, 17 Oct 2018 13:03:14 -0400 Subject: [PATCH] dont use -tags=mage when doing mage:imports and compiling (#189) fixes #188 --- mage/main.go | 4 ++-- mage/main_test.go | 20 +++++++++++++++++++ mage/testdata/mixed_lib_files/magefile.go | 6 +++++- .../mixed_lib_files/subdir/magefile.go | 5 +++++ .../mixed_lib_files/subdir/nonmage.go | 3 +++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 mage/testdata/mixed_lib_files/subdir/magefile.go create mode 100644 mage/testdata/mixed_lib_files/subdir/nonmage.go diff --git a/mage/main.go b/mage/main.go index b2aec2c6..7e9250cc 100644 --- a/mage/main.go +++ b/mage/main.go @@ -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 } @@ -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 diff --git a/mage/main_test.go b/mage/main_test.go index 154f7ba8..415d1f47 100644 --- a/mage/main_test.go +++ b/mage/main_test.go @@ -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" diff --git a/mage/testdata/mixed_lib_files/magefile.go b/mage/testdata/mixed_lib_files/magefile.go index f4248496..e9604289 100644 --- a/mage/testdata/mixed_lib_files/magefile.go +++ b/mage/testdata/mixed_lib_files/magefile.go @@ -2,4 +2,8 @@ package main -func Build() {} +import "./subdir" + +func Build() { + subdir.Build() +} diff --git a/mage/testdata/mixed_lib_files/subdir/magefile.go b/mage/testdata/mixed_lib_files/subdir/magefile.go new file mode 100644 index 00000000..20a9fe49 --- /dev/null +++ b/mage/testdata/mixed_lib_files/subdir/magefile.go @@ -0,0 +1,5 @@ +// +build mage + +package main + +func Build() {} diff --git a/mage/testdata/mixed_lib_files/subdir/nonmage.go b/mage/testdata/mixed_lib_files/subdir/nonmage.go new file mode 100644 index 00000000..8c5f6931 --- /dev/null +++ b/mage/testdata/mixed_lib_files/subdir/nonmage.go @@ -0,0 +1,3 @@ +package subdir + +func Build() {}