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

Create an interface for executing Bazel commands #16

Merged
merged 1 commit into from
Jul 4, 2022

Conversation

sitaktif
Copy link
Collaborator

@sitaktif sitaktif commented Jul 4, 2022

This makes it easier to plug the Target Determinator into larger
applications that already have tight control over how Bazel is executed
(eg. when using this as a plugin of Aspect's CLI tool).

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a few really minor thoughts

pkg/bazel.go Outdated

type BazelCmdConfig struct {
// Dir represents the working directory to use for the command.
// If Dir is the empty string, use the calling process' current directory.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If Dir is the empty string, use the calling process' current directory.
// If Dir is the empty string, use the calling process's current directory.

pkg/bazel.go Outdated
}

type BazelCmd interface {
Run(config BazelCmdConfig, args ...string) (int, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly I'm being overly cautious here, but how would you feel about naming this Exec or Execute instead of Run? I can imagine reading bazel.Run as if it does a bazel run (and having BazelCmd.{Build,Test,Run}(...) rather than BazelCmd.Execute("build", ...) would be a completely reasonable alternate API choice)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll change that.

pkg/bazel.go Outdated
Comment on lines 35 to 41
switch err.(type) {
case *exec.ExitError:
exitError, _ := err.(*exec.ExitError)
return exitError.ExitCode(), err
default:
return -1, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch err.(type) {
case *exec.ExitError:
exitError, _ := err.(*exec.ExitError)
return exitError.ExitCode(), err
default:
return -1, err
}
if exitError, ok := err.(*exec.ExitError); ok {
return exitError.ExitCode(), err
} else {
return -1, err
}

@sitaktif
Copy link
Collaborator Author

sitaktif commented Jul 4, 2022

Addressed comments

This makes it easier to plug the Target Determinator into larger
applications that already have tight control over how Bazel is executed
(eg. when using this as a plugin of Aspect's CLI tool).
@sitaktif sitaktif merged commit 8fb39d6 into bazel-contrib:main Jul 4, 2022
@sitaktif sitaktif deleted the bazel-cmd-interface branch July 4, 2022 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants