From 5673e2cc2e82206cf4c864dd1b56538895fe6a6e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 14 Dec 2024 14:30:45 -0600 Subject: [PATCH] fix go plugin build/install --- build.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/build.go b/build.go index 327a19e..fc15d36 100644 --- a/build.go +++ b/build.go @@ -44,8 +44,11 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err defer os.Unsetenv("GO111MODULE") } - if err := repo.ValidGoSum(); err != nil { - return err + if f.IsGoWork() { + // there must be a valid go.mod file if compiling with go.work + if err := repo.ValidGoSum(); err != nil { + return err + } } if repo.Exists(".forge") { @@ -77,17 +80,27 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err if repo.CheckDirty() { version = version + "-dirty" } + cmd := []string{"go"} if repo.RepoType() == "plugin" { if goWhat == "install" { - return errors.New("Can not go install plugins yet") + log.Info("Can not go install plugins yet. just building to ~/go/lib/") } + cmd = append(cmd, "build") + } else { + cmd = append(cmd, goWhat) } - cmd := []string{"go", goWhat} // if this is a plugin, use buildmode=plugin if repo.RepoType() == "plugin" { _, fname := filepath.Split(repo.FullPath) - cmd = append(cmd, "-buildmode=plugin", "-o", fname+".so") + soname := fname + "." + version + ".so" + if goWhat == "install" { + homeDir, _ := os.UserHomeDir() + fullname := filepath.Join(homeDir, "go/lib", soname) + cmd = append(cmd, "-buildmode=plugin", "-o", fullname) + } else { + cmd = append(cmd, "-buildmode=plugin", "-o", soname) + } } cmd = append(cmd, "-v")