Skip to content

Commit

Permalink
Fix ko-build#530 Hanging behavior with ASDF installed Go on Darwin (k…
Browse files Browse the repository at this point in the history
…o-build#548)

Signed-off-by: Steve Coffman <[email protected]>
  • Loading branch information
StevenACoffman authored Dec 15, 2021
1 parent 5a13603 commit 6cc2d7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 15 additions & 3 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/commands/options/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 6cc2d7f

Please sign in to comment.