8000 fix: ignore comment in BUILD (#2492) · googleapis/sdk-platform-java@1d2db48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d2db48

Browse files
JoeWang1127lqiu96
authored andcommitted
fix: ignore comment in BUILD (#2492)
In this PR: - Ignore comment (leading with `#`) when parsing BUILD.bazel - Add unit tests Context: There's a [BUILD](https://github.com/googleapis/googleapis/blob/master/google/cloud/resourcemanager/v3/BUILD.bazel#L52C10-L52C50) in googleapis has common_resources.proto comment out. We need to adjust the regex pattern to adjust this case.
1 parent ae27931 commit 1d2db48

13 files changed

+77
-33
lines changed

library_generation/model/gapic_inputs.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
(.*?)
3232
\)
3333
"""
34-
resource_pattern = r"//google/cloud:common_resources_proto"
35-
location_pattern = r"//google/cloud/location:location_proto"
36-
iam_pattern = r"//google/iam/v1:iam_policy_proto"
34+
# match a line which the first character is "#".
35+
comment_pattern = r"^\s*\#+"
36+
pattern_to_proto = {
37+
r"//google/cloud:common_resources_proto": "google/cloud/common_resources.proto",
38+
r"//google/cloud/location:location_proto": "google/cloud/location/locations.proto",
39+
r"//google/iam/v1:iam_policy_proto": "google/iam/v1/iam_policy.proto",
40+
}
3741
transport_pattern = r"transport = \"(.*?)\""
3842
rest_pattern = r"rest_numeric_enums = True"
3943
gapic_yaml_pattern = r"gapic_yaml = \"(.*?)\""
@@ -97,7 +101,9 @@ def parse(
97101
if len(assembly_target) > 0:
98102
include_samples = __parse_include_samples(assembly_target[0])
99103
if len(gapic_target) == 0:
100-
return GapicInputs(include_samples=include_samples)
104+
return GapicInputs(
105+
additional_protos=additional_protos, include_samples=include_samples
106+
)
101107

102108
transport = __parse_transport(gapic_target[0])
103109
rest_numeric_enum = __parse_rest_numeric_enums(gapic_target[0])
@@ -119,12 +125,16 @@ def parse(
119125

120126
def __parse_additional_protos(proto_library_target: str) -> str:
121127
res = [" "]
122-
if len(re.findall(resource_pattern, proto_library_target)) != 0:
123-
res.append("google/cloud/common_resources.proto")
124-
if len(re.findall(location_pattern, proto_library_target)) != 0:
125-
res.append("google/cloud/location/locations.proto")
126-
if len(re.findall(iam_pattern, proto_library_target)) != 0:
127-
res.append("google/iam/v1/iam_policy.proto")
128+
lines = proto_library_target.split("\n")
129+
for line in lines:
130+
if len(re.findall(comment_pattern, line)) != 0:
131+
# skip a line which the first charactor is "#" since it's
132+
# a comment.
133+
continue
134+
for pattern in pattern_to_proto:
135+
if len(re.findall(pattern, line)) == 0:
136+
continue
137+
res.append(pattern_to_proto[pattern])
128138
return " ".join(res)
129139

130140

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proto_library_with_info(
2+
deps = [< 8000 /div>
3+
#"//google/cloud:common_resources_proto",
4+
]
5+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proto_library_with_info(
2+
deps = [
3+
# "//google/iam/v1:iam_policy_proto",
4+
]
5+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proto_library_with_info(
2+
deps = [
3+
# "//google/cloud/location:location_proto",
4+
]
5+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proto_library_with_info(
2+
deps = [
3+
"//google/cloud:common_resources_proto",
4+
]
5+
)
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# this file is only used in testing `get_gapic_additional_protos_from_BUILD` in utilities.sh
2-
31
proto_library_with_info(
42
deps = [
5-
"//google/iam/v1:iam_policy_proto",
63
"//google/cloud/location:location_proto",
4+
"//google/iam/v1:iam_policy_proto",
75
]
86
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proto_library_with_info(
2+
deps = [
3+
"//google/iam/v1:iam_policy_proto",
4+
]
5+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proto_library_with_info(
2+
deps = [
3+
"//google/cloud/location:location_proto",
4+
]
5+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
proto_library_with_info(
2+
deps = [
3+
]
4+
)

library_generation/test/resources/search_additional_protos/BUILD_common_resources.bazel

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0