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

Add bufplugin.RunnerProvider for remote plugins #3548

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion private/buf/bufmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/normalpath"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/storage"
Expand Down Expand Up @@ -695,7 +696,11 @@ func equivalentCheckConfigInV2(
) (bufconfig.CheckConfig, error) {
// No need for custom lint/breaking plugins since there's no plugins to migrate from <=v1.
// TODO: If we ever need v3, then we will have to deal with this.
client, err := bufcheck.NewClient(logger, bufcheck.NewRunnerProvider(wasm.UnimplementedRuntime))
client, err := bufcheck.NewClient(logger, bufcheck.NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
))
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/buf/buf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appcmd/appcmdtesting"
Expand Down Expand Up @@ -1350,7 +1351,11 @@ func TestCheckLsBreakingRulesFromConfigExceptDeprecated(t *testing.T) {
// Do not need any custom lint/breaking plugins here.
client, err := bufcheck.NewClient(
slogtestext.NewLogger(t),
bufcheck.NewRunnerProvider(wasm.UnimplementedRuntime),
bufcheck.NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
)
require.NoError(t, err)
allRules, err := client.AllRules(context.Background(), check.RuleTypeBreaking, version)
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/buf/command/beta/lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/buf/buflsp"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/ioext"
Expand Down Expand Up @@ -115,7 +116,11 @@ func run(
}()
checkClient, err := bufcheck.NewClient(
container.Logger(),
bufcheck.NewRunnerProvider(wasmRuntime),
bufcheck.NewLocalRunnerProvider(
wasmRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/buf/command/breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/slicesext"
Expand Down Expand Up @@ -220,7 +221,11 @@ func run(
for i, imageWithConfig := range imageWithConfigs {
client, err := bufcheck.NewClient(
container.Logger(),
bufcheck.NewRunnerProvider(wasmRuntime),
bufcheck.NewLocalRunnerProvider(
wasmRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/buf/command/config/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/normalpath"
Expand Down Expand Up @@ -196,7 +197,11 @@ func lsRun(
}()
client, err := bufcheck.NewClient(
container.Logger(),
bufcheck.NewRunnerProvider(wasmRuntime),
bufcheck.NewLocalRunnerProvider(
wasmRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/buf/command/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/bufbuild/buf/private/buf/bufctl"
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/stringutil"
Expand Down Expand Up @@ -145,7 +146,11 @@ func run(
for _, imageWithConfig := range imageWithConfigs {
client, err := bufcheck.NewClient(
container.Logger(),
bufcheck.NewRunnerProvider(wasmRuntime),
bufcheck.NewLocalRunnerProvider(
wasmRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/buf/command/mod/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/slicesext"
Expand Down Expand Up @@ -175,7 +176,11 @@ func lsRun(
// BufYAMLFiles <=v1 never had plugins.
client, err := bufcheck.NewClient(
container.Logger(),
bufcheck.NewRunnerProvider(wasm.UnimplementedRuntime),
bufcheck.NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func upload(
var err error
plugin, err = bufplugin.NewLocalWasmPlugin(
pluginFullName,
nil, // args
func() ([]byte, error) {
wasmBinary, err := os.ReadFile(flags.Binary)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/protoc-gen-buf-breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/encoding"
"github.com/bufbuild/buf/private/pkg/protodescriptor"
"github.com/bufbuild/buf/private/pkg/protoencoding"
Expand Down Expand Up @@ -125,7 +126,11 @@ func handle(
// The protoc plugins do not support custom lint/breaking change plugins for now.
client, err := bufcheck.NewClient(
container.Logger(),
bufcheck.NewRunnerProvider(wasm.UnimplementedRuntime),
bufcheck.NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
bufcheck.ClientWithStderr(pluginEnv.Stderr),
)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/protoc-gen-buf-lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/encoding"
"github.com/bufbuild/buf/private/pkg/protodescriptor"
"github.com/bufbuild/buf/private/pkg/protoencoding"
Expand Down Expand Up @@ -100,7 +101,11 @@ func handle(
// The protoc plugins do not support custom lint/breaking change plugins for now.
client, err := bufcheck.NewClient(
container.Logger(),
bufcheck.NewRunnerProvider(wasm.UnimplementedRuntime),
bufcheck.NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
bufcheck.ClientWithStderr(pluginEnv.Stderr),
)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion private/bufpkg/bufcheck/breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/slogtestext"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
"github.com/bufbuild/buf/private/pkg/wasm"
Expand Down Expand Up @@ -1344,7 +1345,11 @@ func testBreaking(
require.NoError(t, err)
breakingConfig := workspace.GetBreakingConfigForOpaqueID(opaqueID)
require.NotNil(t, breakingConfig)
client, err := bufcheck.NewClient(logger, bufcheck.NewRunnerProvider(wasm.UnimplementedRuntime))
client, err := bufcheck.NewClient(logger, bufcheck.NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
))
require.NoError(t, err)
err = client.Breaking(
ctx,
Expand Down
10 changes: 8 additions & 2 deletions private/bufpkg/bufcheck/bufcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"buf.build/go/bufplugin/check"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/syserror"
"github.com/bufbuild/buf/private/pkg/wasm"
Expand Down Expand Up @@ -169,7 +170,7 @@ func (r RunnerProviderFunc) NewRunner(pluginConfig bufconfig.PluginConfig) (plug
return r(pluginConfig)
}

// NewRunnerProvider returns a new RunnerProvider for the wasm.Runtime.
// NewLocalRunnerProvider returns a new RunnerProvider for the wasm.Runtime.
//
// This implementation should only be used for local applications. It is safe to
// use concurrently.
Expand All @@ -178,13 +179,18 @@ func (r RunnerProviderFunc) NewRunner(pluginConfig bufconfig.PluginConfig) (plug
// The supported types are:
// - bufconfig.PluginConfigTypeLocal
// - bufconfig.PluginConfigTypeLocalWasm
// - bufconfig.PluginConfigTypeRemoteWasm
//
// If the PluginConfigType is not supported, an error is returned.
func NewRunnerProvider(
func NewLocalRunnerProvider(
wasmRuntime wasm.Runtime,
pluginKeyProvider bufplugin.PluginKeyProvider,
pluginDataProvider bufplugin.PluginDataProvider,
) RunnerProvider {
return newRunnerProvider(
wasmRuntime,
pluginKeyProvider,
pluginDataProvider,
)
}

Expand Down
7 changes: 6 additions & 1 deletion private/bufpkg/bufcheck/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/slogtestext"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
"github.com/bufbuild/buf/private/pkg/wasm"
Expand Down Expand Up @@ -1355,7 +1356,11 @@ func testLintWithOptions(
})
client, err := bufcheck.NewClient(
logger,
bufcheck.NewRunnerProvider(wasmRuntime),
bufcheck.NewLocalRunnerProvider(
wasmRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
)
require.NoError(t, err)
err = client.Lint(
Expand Down
17 changes: 13 additions & 4 deletions private/bufpkg/bufcheck/multi_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"buf.build/go/bufplugin/check/checkutil"
"buf.build/go/bufplugin/option"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/slogtestext"
"github.com/bufbuild/buf/private/pkg/stringutil"
Expand Down Expand Up @@ -182,13 +183,17 @@ func TestMultiClientCannotHaveOverlappingRulesWithBuiltIn(t *testing.T) {

client, err := newClient(
slogtestext.NewLogger(t),
NewRunnerProvider(wasm.UnimplementedRuntime),
NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
)
require.NoError(t, err)
duplicateBuiltInRulePluginConfig, err := bufconfig.NewLocalPluginConfig(
"buf-plugin-duplicate-rule",
nil,
[]string{"buf-plugin-duplicate-rule"},
nil,
)
require.NoError(t, err)
emptyOptions, err := option.NewOptions(nil)
Expand Down Expand Up @@ -275,13 +280,17 @@ func TestMultiClientCannotHaveOverlappingCategoriesWithBuiltIn(t *testing.T) {

client, err := newClient(
slogtestext.NewLogger(t),
NewRunnerProvider(wasm.UnimplementedRuntime),
NewLocalRunnerProvider(
wasm.UnimplementedRuntime,
bufplugin.NopPluginKeyProvider,
bufplugin.NopPluginDataProvider,
),
)
require.NoError(t, err)
duplicateBuiltInRulePluginConfig, err := bufconfig.NewLocalPluginConfig(
"buf-plugin-duplicate-category",
nil,
[]string{"buf-plugin-duplicate-category"},
nil,
)
require.NoError(t, err)
emptyOptions, err := option.NewOptions(nil)
Expand Down
Loading
Loading