Skip to content

Commit

Permalink
internal/imports: set the Dir field on the build.Context (instead of …
Browse files Browse the repository at this point in the history
…WorkingDir) if present

Updates golang/go#36168

Change-Id: Ibdb277176a28da72d85a4c7c8ed7c903c278125e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/211599
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
Bryan C. Mills committed Dec 17, 2019
1 parent 0b43622 commit 01c78d5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/imports/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,20 @@ func (e *ProcessEnv) buildContext() *build.Context {
ctx.GOROOT = e.GOROOT
ctx.GOPATH = e.GOPATH

// As of Go 1.14, build.Context has a WorkingDir field
// As of Go 1.14, build.Context has a Dir field
// (see golang.org/issue/34860).
// Populate it only if present.
if wd := reflect.ValueOf(&ctx).Elem().FieldByName("WorkingDir"); wd.IsValid() && wd.Kind() == reflect.String {
wd.SetString(e.WorkingDir)
rc := reflect.ValueOf(&ctx).Elem()
dir := rc.FieldByName("Dir")
if !dir.IsValid() {
// Working drafts of Go 1.14 named the field "WorkingDir" instead.
// TODO(bcmills): Remove this case after the Go 1.14 beta has been released.
dir = rc.FieldByName("WorkingDir")
}
if dir.IsValid() && dir.Kind() == reflect.String {
dir.SetString(e.WorkingDir)
}

return &ctx
}

Expand Down

0 comments on commit 01c78d5

Please sign in to comment.