Skip to content

Commit 11d1591

Browse files
authored
dont use -tags=mage when doing mage:imports and compiling (#189)
fixes #188
1 parent 0f9693c commit 11d1591

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

mage/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func getNamedImports(gocmd string, pkgs map[string]string) ([]*Import, error) {
447447
}
448448

449449
func getImport(gocmd, importpath, alias string) (*Import, error) {
450-
out, err := outputDebug(gocmd, "list", "-tags=mage", "-f", "{{.Dir}}||{{.Name}}", importpath)
450+
out, err := outputDebug(gocmd, "list", "-f", "{{.Dir}}||{{.Name}}", importpath)
451451
if err != nil {
452452
return nil, err
453453
}
@@ -569,7 +569,7 @@ func Compile(magePath, goCmd, compileTo string, gofiles []string, isDebug bool,
569569
gofiles[i] = filepath.Base(gofiles[i])
570570
}
571571
debug.Printf("running %s -tag=mage build -o %s %s", goCmd, compileTo, strings.Join(gofiles, " "))
572-
c := exec.Command(goCmd, append([]string{"build", "-tags=mage", "-o", compileTo}, gofiles...)...)
572+
c := exec.Command(goCmd, append([]string{"build", "-o", compileTo}, gofiles...)...)
573573
c.Env = os.Environ()
574574
c.Stderr = stderr
575575
c.Stdout = stdout

mage/main_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ func TestListMagefilesLib(t *testing.T) {
128128
}
129129
}
130130

131+
func TestMixedMageImports(t *testing.T) {
132+
stderr := &bytes.Buffer{}
133+
stdout := &bytes.Buffer{}
134+
inv := Invocation{
135+
Dir: "./testdata/mixed_lib_files",
136+
Stdout: stdout,
137+
Stderr: stderr,
138+
List: true,
139+
}
140+
code := Invoke(inv)
141+
if code != 0 {
142+
t.Errorf("expected to exit with code 0, but got %v, stderr: %s", code, stderr)
143+
}
144+
expected := "Targets:\n build \n"
145+
actual := stdout.String()
146+
if actual != expected {
147+
t.Fatalf("expected %q but got %q", expected, actual)
148+
}
149+
}
150+
131151
func TestGoRun(t *testing.T) {
132152
c := exec.Command("go", "run", "main.go")
133153
c.Dir = "./testdata"

mage/testdata/mixed_lib_files/magefile.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
package main
44

5-
func Build() {}
5+
import "./subdir"
6+
7+
func Build() {
8+
subdir.Build()
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// +build mage
2+
3+
package main
4+
5+
func Build() {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package subdir
2+
3+
func Build() {}

0 commit comments

Comments
 (0)