Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Sep 30, 2024
1 parent a17f1c1 commit 58c9e6f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
7 changes: 1 addition & 6 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ GO_TEST_BINS := $(GO_TEST_BINS) \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-category \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-rule
GO_TEST_WASM_BINS := $(GO_TEST_WASM_BINS) \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-panic \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-protovalidate-ext \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-rpc-ext \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-category \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-rule
private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix
GO_MOD_VERSION := 1.22
DOCKER_BINS := $(DOCKER_BINS) buf
FILE_IGNORES := $(FILE_IGNORES) \
Expand Down
5 changes: 0 additions & 5 deletions private/buf/bufprotopluginexec/bufprotopluginexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ func newHandlerOptions() *handlerOptions {
return &handlerOptions{}
}

// FindPluginPath returns the path to the specific plugin specified by pluginName.
func FindPluginPath(pluginName string) (string, error) {
return unsafeLookPath(pluginName)
}

// unsafeLookPath is a wrapper around exec.LookPath that restores the original
// pre-Go 1.19 behavior of resolving queries that would use relative PATH
// entries. We consider it acceptable for the use case of locating plugins.
Expand Down
18 changes: 16 additions & 2 deletions private/bufpkg/bufcheck/runner_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ package bufcheck

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"sync"

"github.com/bufbuild/buf/private/buf/bufprotopluginexec"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufwasm"
"github.com/bufbuild/buf/private/pkg/command"
Expand Down Expand Up @@ -131,7 +132,7 @@ func (r *wasmRunner) loadPlugin(ctx context.Context) (bufwasm.Plugin, error) {
path = r.programName
} else {
var err error
path, err = bufprotopluginexec.FindPluginPath(r.programName)
path, err = unsafeLookPath(r.programName)
if err != nil {
return nil, fmt.Errorf("could not find plugin %q in PATH: %v", r.programName, err)
}
Expand All @@ -150,3 +151,16 @@ func (r *wasmRunner) loadPlugin(ctx context.Context) (bufwasm.Plugin, error) {
// runner is limited to the CLI.
return plugin, nil
}

// unsafeLookPath is a wrapper around exec.LookPath that restores the original
// pre-Go 1.19 behavior of resolving queries that would use relative PATH
// entries. We consider it acceptable for the use case of locating plugins.
//
// https://pkg.go.dev/os/exec#hdr-Executables_in_the_current_directory
func unsafeLookPath(file string) (string, error) {
path, err := exec.LookPath(file)
if errors.Is(err, exec.ErrDot) {
err = nil
}
return path, err
}
2 changes: 2 additions & 0 deletions windows/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ go install ./cmd/buf \
./private/bufpkg/bufcheck/internal/cmd/buf-plugin-rpc-ext \
./private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-category \
./private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-rule
GOOS=wasip1 GOARCH=wasm go install -o $(GOBIN)/buf-plugin-suffix.wasm \
./private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix
go test ./...

0 comments on commit 58c9e6f

Please sign in to comment.