Skip to content

Commit 370f4c3

Browse files
authored
chore(tool/cmd/migrate): parse metadata from BUILD.bazel (#4296)
Parse metadata from `BUILD.bazel`. For #3618
1 parent c9868e4 commit 370f4c3

3 files changed

Lines changed: 148 additions & 0 deletions

File tree

tool/cmd/migrate/legacylibrarian.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
type goGAPICInfo struct {
3838
ClientPackageName string
3939
ImportPath string
40+
NoMetadata bool
4041
NoRESTNumericEnums bool
4142
}
4243

@@ -292,6 +293,7 @@ func buildGoLibraries(input *MigrationInput) ([]*config.Library, error) {
292293
}
293294
goAPI.ClientPackage = info.ClientPackageName
294295
goAPI.ImportPath = info.ImportPath
296+
goAPI.NoMetadata = info.NoMetadata
295297
goAPI.NoRESTNumericEnums = info.NoRESTNumericEnums
296298
if library.Go == nil {
297299
library.Go = &config.GoModule{}
@@ -343,6 +345,7 @@ func isEmptyGoModule(mod *config.GoModule) bool {
343345

344346
func isEmptyGoGAPICInfo(info *goGAPICInfo) bool {
345347
return reflect.DeepEqual(info, &goGAPICInfo{
348+
NoMetadata: false,
346349
NoRESTNumericEnums: false,
347350
})
348351
}
@@ -396,6 +399,7 @@ func parseBazel(googleapisDir, dir string) (*goGAPICInfo, error) {
396399
importPath, clientPkg := parseImportPathFromBuild(rule.AttrString("importpath"))
397400
defaultImportPath, defaultClientPkg := defaultImportPathFromAPI(dir)
398401
info := &goGAPICInfo{
402+
NoMetadata: rule.AttrLiteral("metadata") != "True",
399403
NoRESTNumericEnums: rule.AttrLiteral("rest_numeric_enums") == "False",
400404
}
401405
if importPath != defaultImportPath {

tool/cmd/migrate/legacylibrarian_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,42 @@ func TestBuildGoLibraries(t *testing.T) {
707707
},
708708
},
709709
},
710+
{
711+
name: "parse metadata from BUILD.bazel",
712+
input: &MigrationInput{
713+
librarianState: &legacyconfig.LibrarianState{
714+
Libraries: []*legacyconfig.LibraryState{
715+
{
716+
ID: "asset",
717+
APIs: []*legacyconfig.API{
718+
{
719+
Path: "google/cloud/asset/v1",
720+
},
721+
},
722+
},
723+
},
724+
},
725+
librarianConfig: &legacyconfig.LibrarianConfig{},
726+
repoPath: "testdata/google-cloud-go",
727+
googleapisDir: "testdata/googleapis",
728+
},
729+
want: []*config.Library{
730+
{
731+
Name: "asset",
732+
APIs: []*config.API{
733+
{Path: "google/cloud/asset/v1"},
734+
},
735+
Go: &config.GoModule{
736+
GoAPIs: []*config.GoAPI{
737+
{
738+
NoMetadata: true,
739+
Path: "google/cloud/asset/v1",
740+
},
741+
},
742+
},
743+
},
744+
},
745+
},
710746
} {
711747
t.Run(test.name, func(t *testing.T) {
712748
got, err := buildGoLibraries(test.input)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
# This file was automatically generated by BuildFileGenerator
3+
4+
# This is an API workspace, having public visibility by default makes perfect sense.
5+
package(default_visibility = ["//visibility:public"])
6+
7+
##############################################################################
8+
# Common
9+
##############################################################################
10+
load("@rules_proto//proto:defs.bzl", "proto_library")
11+
load("@com_google_googleapis_imports//:imports.bzl", "proto_library_with_info")
12+
13+
proto_library(
14+
name = "asset_proto",
15+
srcs = [
16+
"asset_enrichment_resourceowners.proto",
17+
"asset_service.proto",
18+
"assets.proto",
19+
],
20+
deps = [
21+
"//google/api:annotations_proto",
22+
"//google/api:client_proto",
23+
"//google/api:field_behavior_proto",
24+
"//google/api:resource_proto",
25+
"//google/cloud/orgpolicy/v1:orgpolicy_proto",
26+
"//google/cloud/osconfig/v1:osconfig_proto",
27+
"//google/iam/v1:policy_proto",
28+
"//google/identity/accesscontextmanager/type:type_proto",
29+
"//google/identity/accesscontextmanager/v1:accesscontextmanager_proto",
30+
"//google/longrunning:operations_proto",
31+
"//google/rpc:code_proto",
32+
"//google/rpc:status_proto",
33+
"//google/type:expr_proto",
34+
"@com_google_protobuf//:any_proto",
35+
"@com_google_protobuf//:duration_proto",
36+
"@com_google_protobuf//:empty_proto",
37+
"@com_google_protobuf//:field_mask_proto",
38+
"@com_google_protobuf//:struct_proto",
39+
"@com_google_protobuf//:timestamp_proto",
40+
],
41+
)
42+
43+
proto_library_with_info(
44+
name = "asset_proto_with_info",
45+
deps = [
46+
":asset_proto",
47+
"//google/cloud:common_resources_proto",
48+
],
49+
)
50+
51+
##############################################################################
52+
# Go
53+
##############################################################################
54+
load(
55+
"@com_google_googleapis_imports//:imports.bzl",
56+
"go_gapic_assembly_pkg",
57+
"go_gapic_library",
58+
"go_grpc_library",
59+
)
60+
61+
go_grpc_library(
62+
name = "asset_go_proto",
63+
importpath = "cloud.google.com/go/asset/apiv1/assetpb",
64+
protos = [":asset_proto"],
65+
deps = [
66+
"//google/api:annotations_go_proto",
67+
"//google/cloud/orgpolicy/v1:orgpolicy_go_proto",
68+
"//google/cloud/osconfig/v1:osconfig_go_proto",
69+
"//google/iam/v1:iam_go_proto",
70+
"//google/identity/accesscontextmanager/v1:accesscontextmanager_go_proto",
71+
"//google/longrunning:longrunning_go_proto",
72+
"//google/rpc:code_go_proto",
73+
"//google/rpc:status_go_proto",
74+
"//google/type:expr_go_proto",
75+
],
76+
)
77+
78+
go_gapic_library(
79+
name = "asset_go_gapic",
80+
srcs = [":asset_proto_with_info"],
81+
grpc_service_config = "cloudasset_grpc_service_config.json",
82+
importpath = "cloud.google.com/go/asset/apiv1;asset",
83+
release_level = "ga",
84+
rest_numeric_enums = True,
85+
service_yaml = "cloudasset_v1.yaml",
86+
transport = "grpc+rest",
87+
deps = [
88+
":asset_go_proto",
89+
"//google/iam/v1:iam_go_proto",
90+
"//google/longrunning:longrunning_go_proto",
91+
"@com_google_cloud_go_longrunning//:go_default_library",
92+
"@com_google_cloud_go_longrunning//autogen:go_default_library",
93+
"@io_bazel_rules_go//proto/wkt:any_go_proto",
94+
"@io_bazel_rules_go//proto/wkt:duration_go_proto",
95+
"@io_bazel_rules_go//proto/wkt:struct_go_proto",
96+
],
97+
)
98+
99+
# Open Source Packages
100+
go_gapic_assembly_pkg(
101+
name = "gapi-cloud-asset-v1-go",
102+
deps = [
103+
":asset_go_gapic",
104+
":asset_go_gapic_srcjar-snippets.srcjar",
105+
":asset_go_gapic_srcjar-test.srcjar",
106+
":asset_go_proto",
107+
],
108+
)

0 commit comments

Comments
 (0)