fix go plugin build/install

This commit is contained in:
Jeff Carr 2024-12-14 14:30:45 -06:00
parent b1d6923ca2
commit 5673e2cc2e
1 changed files with 18 additions and 5 deletions

View File

@ -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")