From 6cc2d7fc64b70c9fcaa538fcb2a418827bf59a13 Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Wed, 15 Dec 2021 14:38:01 -0500 Subject: [PATCH] Fix #530 Hanging behavior with ASDF installed Go on Darwin (#548) Signed-off-by: Steve Coffman --- pkg/build/gobuild.go | 18 +++++++++++++++--- pkg/commands/options/build.go | 7 +++++-- 2 files changed, 20 insertions(+), 5 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..4e15fed95d 100644 --- a/pkg/commands/options/build.go +++ b/pkg/commands/options/build.go @@ -180,8 +180,11 @@ func createBuildConfigMap(workingDirectory string, configs []build.Config) (map[ // local import paths, therefore add a "./" equivalent as a prefix to // the constructured import path localImportPath := fmt.Sprint(".", string(filepath.Separator), path) - - pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName, Dir: baseDir}, localImportPath) + dir := baseDir + if filepath.Clean(dir) == "." { + dir = "" + } + pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName, Dir: 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) }