From 1ec35c80cf6964d950868a626374743d75cae169 Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Tue, 14 Dec 2021 20:14:37 -0500 Subject: [PATCH] Fix #530 Hanging behavior with ASDF installed Go on Darwin Signed-off-by: Steve Coffman --- pkg/build/gobuild.go | 18 +++++++++++++++--- pkg/commands/options/build.go | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go index cfce11b2d9..4a946a578c 100644 --- a/pkg/build/gobuild.go +++ b/pkg/build/gobuild.go @@ -161,9 +161,13 @@ func NewGo(ctx context.Context, dir string, options ...Option) (Interface, error } func (g *gobuild) qualifyLocalImport(importpath string) (string, error) { + dir := g.dir + if filepath.Clean(g.dir) == "." { + dir = "" + } cfg := &packages.Config{ Mode: packages.NeedName, - Dir: g.dir, + Dir: dir, } pkgs, err := packages.Load(cfg, importpath) if err != nil { @@ -199,7 +203,11 @@ func (g *gobuild) IsSupportedReference(s string) error { if !ref.IsStrict() { return errors.New("importpath does not start with ko://") } - pkgs, err := packages.Load(&packages.Config{Dir: g.dir, Mode: packages.NeedName}, ref.Path()) + dir := g.dir + if filepath.Clean(g.dir) == "." { + dir = "" + } + pkgs, err := packages.Load(&packages.Config{Dir: dir, Mode: packages.NeedName}, ref.Path()) if err != nil { return fmt.Errorf("error loading package from %s: %w", ref.Path(), err) } @@ -440,7 +448,11 @@ func tarBinary(name, binary string, creationTime v1.Time, platform *v1.Platform) } func (g *gobuild) kodataPath(ref reference) (string, error) { - pkgs, err := packages.Load(&packages.Config{Dir: g.dir, Mode: packages.NeedFiles}, ref.Path()) + dir := g.dir + if filepath.Clean(g.dir) == "." { + dir = "" + } + pkgs, err := packages.Load(&packages.Config{Dir: dir, Mode: packages.NeedFiles}, ref.Path()) if err != nil { return "", fmt.Errorf("error loading package from %s: %w", ref.Path(), err) } diff --git a/pkg/commands/options/build.go b/pkg/commands/options/build.go index e1f7c26f8d..0a2533d4b1 100644 --- a/pkg/commands/options/build.go +++ b/pkg/commands/options/build.go @@ -181,7 +181,7 @@ func createBuildConfigMap(workingDirectory string, configs []build.Config) (map[ // the constructured import path localImportPath := fmt.Sprint(".", string(filepath.Separator), path) - pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName, Dir: baseDir}, localImportPath) + pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName, Dir: ""}, localImportPath) if err != nil { return nil, fmt.Errorf("'builds': entry #%d does not contain a valid local import path (%s) for directory (%s): %w", i, localImportPath, baseDir, err) }