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

Disable proto rule generation by default in vendor #78

Merged
merged 1 commit into from
Jan 8, 2018
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
8 changes: 7 additions & 1 deletion internal/config/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package config

import (
"log"
"path"
"regexp"
"strings"

Expand Down Expand Up @@ -129,7 +130,7 @@ func ApplyDirectives(c *Config, directives []Directive, rel string) *Config {
// legacy go_proto_library.bzl is loaded, or if this is the Well Known Types
// repository, legacy mode is used. If go_proto_library is loaded from another
// file, proto rule generation is disabled.
func InferProtoMode(c *Config, f *bf.File, directives []Directive) *Config {
func InferProtoMode(c *Config, rel string, f *bf.File, directives []Directive) *Config {
if c.ProtoMode != DefaultProtoMode {
return c
}
Expand All @@ -148,6 +149,11 @@ func InferProtoMode(c *Config, f *bf.File, directives []Directive) *Config {
modified.ProtoMode = LegacyProtoMode
return &modified
}
if path.Base(rel) == "vendor" {
modified := *c
modified.ProtoMode = DisableProtoMode
return &modified
}
if f == nil {
return c
}
Expand Down
7 changes: 6 additions & 1 deletion internal/config/directives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestInferProtoMode(t *testing.T) {
for _, tc := range []struct {
desc, content string
c Config
rel string
want ProtoMode
}{
{
Expand All @@ -119,6 +120,10 @@ func TestInferProtoMode(t *testing.T) {
load("@io_bazel_rules_go//proto:go_proto_library.bzl", "go_proto_library")
`,
want: DefaultProtoMode,
}, {
desc: "vendor",
rel: "vendor",
want: DisableProtoMode,
}, {
desc: "legacy",
content: `load("@io_bazel_rules_go//proto:go_proto_library.bzl", "go_proto_library")`,
Expand Down Expand Up @@ -154,7 +159,7 @@ load("@io_bazel_rules_go//proto:go_proto_library.bzl", "go_proto_library")
directives = ParseDirectives(f)
}

got := InferProtoMode(&tc.c, f, directives)
got := InferProtoMode(&tc.c, tc.rel, f, directives)
if got.ProtoMode != tc.want {
t.Errorf("got proto mode %v ; want %v", got.ProtoMode, tc.want)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/packages/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func Walk(c *config.Config, root string, f WalkFunc) {
directives = config.ParseDirectives(oldFile)
c = config.ApplyDirectives(c, directives, rel)
}
c = config.InferProtoMode(c, oldFile, directives)
c = config.InferProtoMode(c, rel, oldFile, directives)

var ignore bool
for _, d := range directives {
Expand Down