Skip to content

Commit

Permalink
Sync from internal (bufbuild#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev authored Aug 26, 2021
1 parent c4b5ca4 commit e35f422
Show file tree
Hide file tree
Showing 49 changed files with 1,231 additions and 37 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclient/protoc-gen-go-apiclien
private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclientgrpc/protoc-gen-go-apiclientgrpc
private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclienttwirp/protoc-gen-go-apiclienttwirp
private/bufpkg/buftesting/cache/
private/pkg/bandeps/cmd/bandeps/bandeps
private/pkg/git/cmd/git-ls-files-unstaged/git-ls-files-unstaged
private/pkg/licenseheader/cmd/license-header/license-header
private/pkg/spdx/cmd/spdx-go-data/spdx-go-data
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclientgrpc/protoc-gen-go-apiclientgrpc
/private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclienttwirp/protoc-gen-go-apiclienttwirp
/private/bufpkg/buftesting/cache/
/private/pkg/bandeps/cmd/bandeps/bandeps
/private/pkg/git/cmd/git-ls-files-unstaged/git-ls-files-unstaged
/private/pkg/licenseheader/cmd/license-header/license-header
/private/pkg/spdx/cmd/spdx-go-data/spdx-go-data
Expand Down
30 changes: 30 additions & 0 deletions data/bandeps/bandeps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
bans:
- packages:
use:
- ./private/...
deps:
use:
- ./internal/...
except:
- ./internal/privateusage/...
note: Packages in private cannot depend on internal.
- packages:
use:
- ./...
except:
- ./cmd/...
- ./internal/buf/cmd/...
deps:
use:
- ./internal/buf/cmd/...
note: Packages in internal/buf/cmd should be self-contained.
- packages:
use:
- ./internal/...
except:
- ./internal/buf/bufcli/...
- ./internal/buf/cmd/...
deps:
use:
- ./internal/buf/bufcli/...
note: Package bufcli can only be depended on by cmd packages.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
go.opencensus.io v0.23.0
go.uber.org/multierr v1.7.0
go.uber.org/zap v1.19.0
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
golang.org/x/text v0.3.7 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210825183410-e898025ed96a h1:bRuuGXV8wwSdGTB+CtJf+FjgO1APK1CoO39T4BN/XBw=
golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
4 changes: 0 additions & 4 deletions internal/buf/cmd/buf/command/protoc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ func newRecursiveReferenceError(flagFilePath string) error {
return fmt.Errorf("%s recursively referenced", flagFilePath)
}

func newOutMultipleColonsError(pluginName string, out string) error {
return fmt.Errorf("invalid value for --%s_out=%s (multiple colons)", pluginName, out)
}

func newDuplicateOutError(pluginName string) error {
return fmt.Errorf("duplicate --%s_out", pluginName)
}
Expand Down
19 changes: 10 additions & 9 deletions internal/buf/cmd/buf/command/protoc/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/bufbuild/buf/internal/buf/buffetch"
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/pkg/normalpath"
"github.com/bufbuild/buf/private/pkg/stringutil"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -276,7 +277,7 @@ func (f *flagsBuilder) buildRec(
if arg[0] != '@' {
filePaths = append(filePaths, arg)
} else {
flagFilePath := arg[1:]
flagFilePath := normalpath.Unnormalize(arg[1:])
if _, ok := seenFlagFilePaths[flagFilePath]; ok {
return nil, newRecursiveReferenceError(flagFilePath)
}
Expand Down Expand Up @@ -359,14 +360,14 @@ func (f *flagsBuilder) parsePluginNameToPluginInfo(pluginNameToPluginInfo map[st
case 1:
out := f.pluginFake[pluginValue.OutIndexes[0]]
var opt string
split := strings.Split(out, ":")
switch len(split) {
case 1:
case 2:
out = split[1]
opt = split[0]
default:
return newOutMultipleColonsError(pluginName, out)
if isOutNotAFullPath(out) {
split := strings.SplitN(out, ":", 2)
switch len(split) {
case 1:
case 2:
out = split[1]
opt = split[0]
}
}
pluginInfo, ok := pluginNameToPluginInfo[pluginName]
if !ok {
Expand Down
57 changes: 57 additions & 0 deletions internal/buf/cmd/buf/command/protoc/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
)

func TestParseFlags(t *testing.T) {
absFilePath, err := filepath.Abs("out")
require.NoError(t, err)
testCases := []struct {
Args []string
Expected *env
Expand Down Expand Up @@ -528,6 +530,61 @@ func TestParseFlags(t *testing.T) {
},
},
},
{
Args: []string{
"-I",
"proto",
"foo.proto",
fmt.Sprintf("--go_out=%s", absFilePath),
},
Expected: &env{
flags: flags{
IncludeDirPaths: []string{
"proto",
},
ErrorFormat: "gcc",
},
PluginNamesSortedByOutIndex: []string{
"go",
},
PluginNameToPluginInfo: map[string]*pluginInfo{
"go": {
Out: absFilePath,
},
},
FilePaths: []string{
"foo.proto",
},
},
},
{
Args: []string{
"-I",
"proto",
"foo.proto",
fmt.Sprintf("--go_out=opt:%s", absFilePath),
},
Expected: &env{
flags: flags{
IncludeDirPaths: []string{
"proto",
},
ErrorFormat: "gcc",
},
PluginNamesSortedByOutIndex: []string{
"go",
},
PluginNameToPluginInfo: map[string]*pluginInfo{
"go": {
Out: absFilePath,
Opt: []string{"opt"},
},
},
FilePaths: []string{
"foo.proto",
},
},
},
}
for i, testCase := range testCases {
name := fmt.Sprintf("%d", i)
Expand Down
36 changes: 36 additions & 0 deletions internal/buf/cmd/buf/command/protoc/flags_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2020-2021 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris

package protoc

// isOutNotAFullPath checks if we need to consider the path to be a full path.
//
// This is always true in unix, and is true if the path is not absolute in windows.
// This is needed because i.e.:
//
// # unix
// --go_out=opt:foo/bar
// --go_out=foo/bar
// # windows
// --go_out=opt:C:\foo\bar
// --go_out=C:\foo\bar
//
// protoc uses : in both unix and windows to separate the opt and out, but in windows,
// if a full path is given, then we don't want it interpreted as something we should split.
func isOutNotAFullPath(path string) bool {
return true
}
40 changes: 40 additions & 0 deletions internal/buf/cmd/buf/command/protoc/flags_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2020-2021 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build windows
// +build windows

package protoc

import (
"path/filepath"
)

// isOutNotAFullPath checks if we need to consider the path to be a full path.
//
// This is always true in unix, and is true if the path is not absolute in windows.
// This is needed because i.e.:
//
// # unix
// --go_out=opt:foo/bar
// --go_out=foo/bar
// # windows
// --go_out=opt:C:\foo\bar
// --go_out=C:\foo\bar
//
// protoc uses : in both unix and windows to separate the opt and out, but in windows,
// if a full path is given, then we don't want it interpreted as something we should split.
func isOutNotAFullPath(path string) bool {
return !filepath.IsAbs(path)
}
25 changes: 22 additions & 3 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GO_BINS := $(GO_BINS) \
private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclient \
private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclientgrpc \
private/bufpkg/bufprotoplugin/cmd/protoc-gen-go-apiclienttwirp \
private/pkg/bandeps/cmd/bandeps \
private/pkg/git/cmd/git-ls-files-unstaged \
private/pkg/storage/cmd/ddiff \
private/pkg/storage/cmd/storage-go-data \
Expand Down Expand Up @@ -50,6 +51,12 @@ include make/go/buf.mk

installtest:: $(PROTOC) $(PROTOC_GEN_GO)

.PHONY: bandeps
bandeps: installbandeps
bandeps -f data/bandeps/bandeps.yaml

postlonglint:: bandeps

.PHONY: godata
godata: installspdx-go-data installstorage-go-data $(PROTOC)
rm -rf private/gen/data
Expand All @@ -62,7 +69,12 @@ prepostgenerate:: godata

.PHONY: licenseheader
licenseheader: installlicense-header installgit-ls-files-unstaged
license-header \
@echo license-header \
--license-type "$(LICENSE_HEADER_LICENSE_TYPE)" \
--copyright-holder "$(LICENSE_HEADER_COPYRIGHT_HOLDER)" \
--year-range "$(LICENSE_HEADER_YEAR_RANGE)" \
ALL_FILES
@license-header \
--license-type "$(LICENSE_HEADER_LICENSE_TYPE)" \
--copyright-holder "$(LICENSE_HEADER_COPYRIGHT_HOLDER)" \
--year-range "$(LICENSE_HEADER_YEAR_RANGE)" \
Expand Down Expand Up @@ -91,11 +103,11 @@ bufgenerateclean:: bufgeneratecleango

.PHONY: bufgenerateprotogo
bufgenerateprotogo:
buf generate proto --template data/buf/template/buf.go.gen.yaml
buf generate proto --template data/template/buf.go.gen.yaml

.PHONY: bufgenerateprotogoclient
bufgenerateprotogoclient:
buf generate proto --template data/buf/template/buf.go-client.gen.yaml
buf generate proto --template data/template/buf.go-client.gen.yaml

bufgeneratesteps:: \
bufgenerateprotogo \
Expand All @@ -105,6 +117,13 @@ bufgeneratesteps:: \
bufrelease:
DOCKER_IMAGE=golang:1.17.0-buster bash make/buf/scripts/release.bash

# We have to manually set the Homebrew version on the Homebrew badge as there
# is no badge on shields.io for Homebrew packages outside of homebrew-core

.PHONY: updatehomebrewbadge
updatehomebrewbadge:
$(SED_I) "s/HOMEBREW_VERSION/v$(shell bash make/buf/scripts/homebrewversion.bash)/g" README.md

.PHONY: gofuzz
gofuzz: $(GO_FUZZ)
@rm -rf $(TMP)/gofuzz
Expand Down
8 changes: 8 additions & 0 deletions make/buf/scripts/homebrewversion.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -euo pipefail

curl -sSL "https://raw.githubusercontent.com/bufbuild/homebrew-buf/main/Formula/buf.rb" \
| grep 'version "' \
| sed 's/.*version "//' \
| sed 's/"//'
7 changes: 7 additions & 0 deletions make/go/base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ ifeq ($(UNAME_OS),Linux)
OPEN_CMD := xdg-open
endif

ifeq ($(UNAME_OS),Darwin)
SED_I := sed -i ''
endif
ifeq ($(UNAME_OS),Linux)
SED_I := sed -i
endif

# Runtime ALL

# All variables exported here must also be added to env.sh
Expand Down
3 changes: 2 additions & 1 deletion make/go/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ godeps: deps

.PHONY: gofmtmodtidy
gofmtmodtidy:
gofmt -s -w $(shell find . -name '*.go')
@echo gofmt -s -w ALL_GO_FILES
@gofmt -s -w $(shell find . -name '*.go')
go mod tidy -v

postgenerate:: gofmtmodtidy
Expand Down
Loading

0 comments on commit e35f422

Please sign in to comment.