diff --git a/internal/gapicgen/generator/genproto.go b/internal/gapicgen/generator/genproto.go index 2c28a7ab8610..0d0e597a2d49 100644 --- a/internal/gapicgen/generator/genproto.go +++ b/internal/gapicgen/generator/genproto.go @@ -42,6 +42,19 @@ var denylist = map[string]bool{ "google.golang.org/genproto/googleapis/devtools/containeranalysis/v1": true, } +var skipPrefixes = []string{ + "google.golang.org/genproto/googleapis/ads", +} + +func hasPrefix(s string, prefixes []string) bool { + for _, prefix := range prefixes { + if strings.HasPrefix(s, prefix) { + return true + } + } + return false +} + // regenGenproto regenerates the genproto repository. // // regenGenproto recursively walks through each directory named by given @@ -110,7 +123,7 @@ func regenGenproto(ctx context.Context, genprotoDir, googleapisDir, protoDir str // Run protoc on all protos of all packages. grp, _ := errgroup.WithContext(ctx) for pkg, fnames := range pkgFiles { - if !strings.HasPrefix(pkg, "google.golang.org/genproto") || denylist[pkg] { + if !strings.HasPrefix(pkg, "google.golang.org/genproto") || denylist[pkg] || hasPrefix(pkg, skipPrefixes) { continue } pk := pkg diff --git a/internal/gapicgen/generator/genproto_test.go b/internal/gapicgen/generator/genproto_test.go new file mode 100644 index 000000000000..23120e815d6e --- /dev/null +++ b/internal/gapicgen/generator/genproto_test.go @@ -0,0 +1,65 @@ +// Copyright 2020 Google LLC +// +// 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. + +package generator + +import "testing" + +func TestHasPrefix(t *testing.T) { + tests := []struct { + s string + prefixes []string + want bool + }{ + { + s: "abc", + prefixes: []string{"a"}, + want: true, + }, + { + s: "abc", + prefixes: []string{"ab"}, + want: true, + }, + { + s: "abc", + prefixes: []string{"abc"}, + want: true, + }, + { + s: "google.golang.org/genproto/googleapis/ads/googleads/v1/common", + prefixes: []string{"google.golang.org/genproto/googleapis/ads"}, + want: true, + }, + { + s: "abc", + prefixes: []string{"zzz"}, + want: false, + }, + { + s: "", + prefixes: []string{"zzz"}, + want: false, + }, + { + s: "abc", + want: false, + }, + } + for _, test := range tests { + if got := hasPrefix(test.s, test.prefixes); got != test.want { + t.Errorf("hasPrefix(%q, %q) got %v, want %v", test.s, test.prefixes, got, test.want) + } + } +}