-
Notifications
You must be signed in to change notification settings - Fork 13
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
Adds a process entry for all of the binaries #142
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package gobuild | |
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
@@ -13,7 +14,6 @@ import ( | |
|
||
"github.com/paketo-buildpacks/packit/chronos" | ||
"github.com/paketo-buildpacks/packit/pexec" | ||
"github.com/paketo-buildpacks/packit/scribe" | ||
) | ||
|
||
//go:generate faux --interface Executable --output fakes/executable.go | ||
|
@@ -32,24 +32,24 @@ type GoBuildConfiguration struct { | |
|
||
type GoBuildProcess struct { | ||
executable Executable | ||
logs scribe.Emitter | ||
logs LogEmitter | ||
clock chronos.Clock | ||
} | ||
|
||
func NewGoBuildProcess(executable Executable, logs scribe.Emitter, clock chronos.Clock) GoBuildProcess { | ||
func NewGoBuildProcess(executable Executable, logs LogEmitter, clock chronos.Clock) GoBuildProcess { | ||
return GoBuildProcess{ | ||
executable: executable, | ||
logs: logs, | ||
clock: clock, | ||
} | ||
} | ||
|
||
func (p GoBuildProcess) Execute(config GoBuildConfiguration) (string, error) { | ||
func (p GoBuildProcess) Execute(config GoBuildConfiguration) ([]string, error) { | ||
p.logs.Process("Executing build process") | ||
|
||
err := os.MkdirAll(config.Output, os.ModePerm) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to create targets output directory: %w", err) | ||
return nil, fmt.Errorf("failed to create targets output directory: %w", err) | ||
} | ||
|
||
contains := func(flags []string, match string) bool { | ||
|
@@ -94,22 +94,44 @@ func (p GoBuildProcess) Execute(config GoBuildConfiguration) (string, error) { | |
p.logs.Action("Failed after %s", duration.Round(time.Millisecond)) | ||
p.logs.Detail(buffer.String()) | ||
|
||
return "", fmt.Errorf("failed to execute 'go build': %w", err) | ||
return nil, fmt.Errorf("failed to execute 'go build': %w", err) | ||
} | ||
|
||
p.logs.Action("Completed in %s", duration.Round(time.Millisecond)) | ||
p.logs.Break() | ||
|
||
paths, err := filepath.Glob(fmt.Sprintf("%s/*", config.Output)) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to list targets: %w", err) | ||
var paths []string | ||
for _, target := range config.Targets { | ||
buffer = bytes.NewBuffer(nil) | ||
err := p.executable.Execute(pexec.Execution{ | ||
Args: []string{"list", "--json", target}, | ||
Dir: config.Workspace, | ||
Env: env, | ||
Stdout: buffer, | ||
Stderr: buffer, | ||
}) | ||
if err != nil { | ||
p.logs.Detail(buffer.String()) | ||
|
||
return nil, fmt.Errorf("failed to execute 'go list': %w", err) | ||
} | ||
|
||
var list struct { | ||
ImportPath string `json:"ImportPath"` | ||
} | ||
err = json.Unmarshal(buffer.Bytes(), &list) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse 'go list' output: %w", err) | ||
} | ||
|
||
paths = append(paths, filepath.Join(config.Output, filepath.Base(list.ImportPath))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small optional microoptimization: Since the length of |
||
} | ||
|
||
if len(paths) == 0 { | ||
return "", errors.New("failed to determine go executable start command") | ||
return nil, errors.New("failed to determine go executable start command") | ||
} | ||
|
||
return paths[0], nil | ||
return paths, nil | ||
} | ||
|
||
func formatArg(arg string) string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ForestEckhardt do you know why this code existed before or when you could ever get into the failure case where
command
would not be defined as a string?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use to reuse the binary layer from cache if nothing changed workspace directory. We no longer do that and always rebuild from source. This was metadata that we used to rewrite the start command on a rebuild where we reused the binary layer. That functionality has been removed so this is just dead code.