Skip to content

Commit

Permalink
dev: Exec go tools from correct directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Volosatovs committed May 20, 2020
1 parent bd1372d commit 9bc0c12
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
5 changes: 4 additions & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ replace gopkg.in/DATA-DOG/go-sqlmock.v1 => gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.
// See https://github.com/Azure/go-autorest/issues/414.
replace github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.3.1+incompatible

// TODO: Remove once https://github.com/magefile/mage/pull/307 is merged.
replace github.com/magefile/mage v1.9.1 => github.com/TheThingsIndustries/mage v1.9.1-0.20200520191129-8bccc5d0bd6f

require (
github.com/Azure/go-autorest/autorest v0.10.1 // indirect
github.com/Azure/go-autorest/autorest/adal v0.8.3 // indirect
Expand All @@ -26,7 +29,7 @@ require (
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gohugoio/hugo v0.71.0
github.com/goreleaser/goreleaser v0.135.0
github.com/magefile/mage v1.9.0
github.com/magefile/mage v1.9.1
github.com/mattn/goveralls v0.0.5
github.com/mdempsky/unconvert v0.0.0-20200228143138-95ecdbfc0b5f
github.com/mgechev/revive v1.0.2
Expand Down
3 changes: 2 additions & 1 deletion tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/TheThingsIndustries/grpc-gateway v1.14.5-gogo h1:xzFC5AIxzOYcKs9c2lDDdoPPYAyuV1bRc/j/2yd2w/0=
github.com/TheThingsIndustries/grpc-gateway v1.14.5-gogo/go.mod h1:bFQmqYuGlhKMjSbGctoZbxvPTOHxI+x+N2+FoeVeklI=
github.com/TheThingsIndustries/mage v1.9.1-0.20200520191129-8bccc5d0bd6f h1:aKWel19F+gwfZKsyXnU5yUAuX5nrDQ86KwQOnnjttAk=
github.com/TheThingsIndustries/mage v1.9.1-0.20200520191129-8bccc5d0bd6f/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/TheThingsIndustries/magepkg v0.0.0-20190214092847-6c0299b7c3ed h1:rsGbnyV9cP0ocol1W17uTbZ1iWcEeg+gp3ivzW6NQ6Q=
github.com/TheThingsIndustries/magepkg v0.0.0-20190214092847-6c0299b7c3ed/go.mod h1:InVSk9cxzZR1y4QaHF4CbDQ/uFeoTnbJfnwiKM04UNo=
github.com/TheThingsIndustries/mystique v0.0.0-20200127144137-4aa959111fe7 h1:Vb+sqm8nZUi+3N10QB8g2Gio2luOgfQnLlO6eLTuYDY=
Expand Down Expand Up @@ -644,7 +646,6 @@ github.com/lib/pq v1.5.2 h1:yTSXVswvWUOQ3k1sd7vJfDrbSl8lKuscqFJRqjC0ifw=
github.com/lib/pq v1.5.2/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/magefile/mage v1.8.0/go.mod h1:IUDi13rsHje59lecXokTfGX0QIzO45uVPlXnJYsXepA=
github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE=
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.7.4-0.20170902060319-8d7837e64d3c/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
Expand Down
30 changes: 10 additions & 20 deletions tools/mage/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,19 @@ func execGo(stdout, stderr io.Writer, cmd string, args ...string) error {
return err
}

func execGoFrom(dir string, stdout, stderr io.Writer, cmd string, args ...string) error {
_, err := sh.ExecFrom(dir, goModuleEnv, stdout, stderr, "go", buildGoArgs(cmd, args...)...)
return err
}

func runGo(args ...string) error {
return execGo(os.Stdout, os.Stderr, "run", args...)
}

func runGoFrom(dir string, args ...string) error {
return execGoFrom(dir, os.Stdout, os.Stderr, "run", args...)
}

func outputGo(cmd string, args ...string) (string, error) {
var buf bytes.Buffer
if err := execGo(&buf, os.Stderr, cmd, args...); err != nil {
Expand All @@ -63,27 +72,8 @@ func outputGo(cmd string, args ...string) (string, error) {
return buf.String(), nil
}

func pushd(dir string) func() {
old, err := os.Getwd()
if err != nil {
fmt.Printf("Failed to get working directory: %s", err)
os.Exit(1)
}
if err := os.Chdir(dir); err != nil {
fmt.Printf("Failed to chdir to `%s`: %s", dir, err)
os.Exit(1)
}
return func() {
if err := os.Chdir(old); err != nil {
fmt.Printf("Failed to chdir to previous working directory `%s`: %s", old, err)
os.Exit(1)
}
}
}

func runGoTool(args ...string) error {
defer pushd("tools")()
return runGo(append([]string{"-exec", "go run exec_from.go -dir .."}, args...)...)
return runGoFrom("tools", append([]string{"-exec", "go run exec_from.go -dir .."}, args...)...)
}

func runUnconvert(pkgs ...string) error {
Expand Down

0 comments on commit 9bc0c12

Please sign in to comment.