Skip to content

Commit

Permalink
Merge pull request #322 from yue9944882/bugfix/ensure-goroot
Browse files Browse the repository at this point in the history
Bugfix: Ensure GOROOT env var on running openapi-gen
  • Loading branch information
k8s-ci-robot authored Mar 12, 2019
2 parents aa1182e + 75fc29f commit f3a6545
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/apiserver-boot/boot/build/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"

"github.com/kubernetes-incubator/apiserver-builder-alpha/cmd/apiserver-boot/boot/util"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/sets"
"path"
"k8s.io/klog"
)

var versionedAPIs []string
Expand Down Expand Up @@ -189,6 +190,19 @@ func RunGenerate(cmd *cobra.Command, args []string) {
"--report-filename", "violations.report",
"--output-package", filepath.Join(util.Repo, "pkg", "openapi"))...,
)

// HACK: ensure GOROOT env var
c.Env = os.Environ()
if len(os.Getenv("GOROOT")) == 0 {
if p, err := exec.Command("which", "go").CombinedOutput(); err == nil {
// The returned string will have some/path/bin/go, so remove the last two elements.
c.Env = append(c.Env,
fmt.Sprintf("GOROOT=%s", filepath.Dir(filepath.Dir(strings.Trim(string(p), "\n")))))
} else {
klog.Warningf("Warning: $GOROOT not set, and unable to run `which go` to find it: %v\n", err)
}
}

fmt.Printf("%s\n", strings.Join(c.Args, " "))
out, err := c.CombinedOutput()
if err != nil {
Expand Down

0 comments on commit f3a6545

Please sign in to comment.