Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect go binary from PATH before failing #3

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ func Generate(cfg Config) error {

// Compile generates a binary from the sources based on the configuration
func Compile(cfg Config) error {
goBinary := cfg.Distribution.Go
// first, we test to check if we have Go at all
if _, err := exec.Command(cfg.Distribution.Go, "env").CombinedOutput(); err != nil {
return ErrGoNotFound
if _, err := exec.Command(goBinary, "env").CombinedOutput(); err != nil {
path, err := exec.LookPath("go")
if err != nil {
return ErrGoNotFound
}
goBinary = path
cfg.Logger.Info("Using go from PATH", "Go executable", path)
}

cfg.Logger.Info("Compiling")
cmd := exec.Command(cfg.Distribution.Go, "build", "-trimpath", "-o", cfg.Distribution.ExeName)
cmd := exec.Command(goBinary, "build", "-trimpath", "-o", cfg.Distribution.ExeName)
cmd.Dir = cfg.Distribution.OutputPath
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to compile the OpenTelemetry Collector distribution: %w. Output: %q", err, out)
Expand Down