-
Notifications
You must be signed in to change notification settings - Fork 290
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
Update bufcheck.RunnerProvider to use the plugin config #3328
Changes from 1 commit
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 |
---|---|---|
|
@@ -331,21 +331,17 @@ func (c *client) getMultiClient( | |
) | ||
} | ||
for _, pluginConfig := range pluginConfigs { | ||
if pluginConfig.Type() != bufconfig.PluginConfigTypeLocal { | ||
return nil, syserror.New("we only handle local plugins for now with lint and breaking") | ||
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. Error message is moved to the runner provider. |
||
} | ||
options, err := check.NewOptions(pluginConfig.Options()) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not parse options for plugin %q: %w", pluginConfig.Name(), err) | ||
} | ||
pluginPath := pluginConfig.Path() | ||
runner, err := c.runnerProvider.NewRunner(pluginConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not create runner for plugin %q: %w", pluginConfig.Name(), err) | ||
} | ||
checkClient := check.NewClient( | ||
pluginrpc.NewClient( | ||
c.runnerProvider.NewRunner( | ||
// We know that Path is of at least length 1. | ||
pluginPath[0], | ||
pluginPath[1:]..., | ||
), | ||
runner, | ||
pluginrpc.ClientWithStderr(c.stderr), | ||
// We have to set binary as some things cannot be encoded as JSON. | ||
// Example: google.protobuf.Timestamps with positive seconds and negative nanos. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,13 +101,13 @@ func (c *multiClient) Check(ctx context.Context, request check.Request) ([]*anno | |
} | ||
return fmt.Errorf("plugin %q failed: %w", delegate.PluginName, err) | ||
} | ||
lock.Lock() | ||
annotations := slicesext.Map( | ||
delegateResponse.Annotations(), | ||
func(checkAnnotation check.Annotation) *annotation { | ||
return newAnnotation(checkAnnotation, delegate.PluginName) | ||
}, | ||
) | ||
lock.Lock() | ||
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. Unrelated change, looks like we can move the lock to wrap just the append. |
||
allAnnotations = append(allAnnotations, annotations...) | ||
lock.Unlock() | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,29 +23,3 @@ import ( | |
func NewRunner(delegate command.Runner, programName string, programArgs ...string) pluginrpc.Runner { | ||
return newRunner(delegate, programName, programArgs...) | ||
} | ||
|
||
// RunnerProvider provides pluginrpc.Runners for program names and args. | ||
type RunnerProvider interface { | ||
NewRunner(programName string, programArgs ...string) pluginrpc.Runner | ||
} | ||
|
||
// RunnerProviderFunc is a function that implements RunnerProvider. | ||
type RunnerProviderFunc func(programName string, programArgs ...string) pluginrpc.Runner | ||
|
||
// NewRunner implements RunnerProvider. | ||
func (r RunnerProviderFunc) NewRunner(programName string, programArgs ...string) pluginrpc.Runner { | ||
return r(programName, programArgs...) | ||
} | ||
|
||
// NewRunnerProvider returns a new RunnerProvider for the command.Runner. | ||
func NewRunnerProvider(delegate command.Runner) RunnerProvider { | ||
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. To avoid import of |
||
return RunnerProviderFunc( | ||
func(programName string, programArgs ...string) pluginrpc.Runner { | ||
return NewRunner( | ||
delegate, | ||
programName, | ||
programArgs..., | ||
) | ||
}, | ||
) | ||
} |
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.
I believe this is the primary motivation of this PR, otherwise, this interface is tightly coupled to executing local binaries command exec style. Specifically here:
buf/private/bufpkg/bufcheck/client.go
Lines 344 to 348 in 6df73b9
By taking a
PluginConfig,
we can have constructors for various configs likeNewLocalPluginConfig
andNewRemotePluginConfig
NewLocalWASMPluginConfig
(bad name, but something to differentiate).This lifts the
pluginConfig.Type() != bufconfig.PluginConfigTypeLocal
check to theNewRunnerProvider
constructor. The provider now has more information about what theRunnerProvider
should be.I think it'd be awesome if in the end state, we had a common runner provider interface that could support: