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

chore(internal): stop generating Ads packages in genproto #3214

Merged
merged 2 commits into from
Nov 16, 2020
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
15 changes: 14 additions & 1 deletion internal/gapicgen/generator/genproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If skipPrefixes gets larger, it would be more efficient to preemptively remove strings that match the prefix from pkgFiles rather than checking it everytime in this for loop. Considering the size of skipPrefixes for now, I don't think it's a blocking optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on both counts. Going for simplicity for now.

continue
}
pk := pkg
Expand Down
65 changes: 65 additions & 0 deletions internal/gapicgen/generator/genproto_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}