Skip to content

Commit c519916

Browse files
comiuscopybara-github
authored andcommitted
Make Google proto_library and extension of Bazel proto_library
PiperOrigin-RevId: 580146223 Change-Id: I13ac76086d56cd26ae0c661d1c36c45a2ee270d1
1 parent 41a1fbc commit c519916

File tree

9 files changed

+14
-49
lines changed

9 files changed

+14
-49
lines changed

src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ public static StarlarkRuleFunction createRule(
519519
}
520520

521521
// Verify the child against parent's allowlist
522-
if (parent != null && parent.getExtendableAllowlist() != null) {
522+
if (parent != null
523+
&& parent.getExtendableAllowlist() != null
524+
&& !bzlFile.getRepository().getNameWithAt().equals("@_builtins")) {
523525
builder.addAllowlistChecker(EXTEND_RULE_ALLOWLIST_CHECKER);
524526
Attribute.Builder<Label> allowlistAttr =
525527
attr("$allowlist_extend_rule", LABEL)

src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public boolean isDefaultExecutableCreated() {
455455
*/
456456
public void close() {
457457
// Check super was called
458-
if (ruleClassUnderEvaluation.getStarlarkParent() != null && !superCalled) {
458+
if (ruleClassUnderEvaluation.getStarlarkParent() != null && !superCalled && !isForAspect()) {
459459
ruleContext.ruleError("'super' was not called.");
460460
}
461461

@@ -585,7 +585,7 @@ public Object callParent(StarlarkThread thread) throws EvalException, Interrupte
585585
BuiltinRestriction.failIfCalledOutsideAllowlist(thread, ALLOWLIST_RULE_EXTENSION_API);
586586
}
587587
checkMutable("super()");
588-
if (aspectDescriptor != null) {
588+
if (isForAspect()) {
589589
throw Starlark.errorf("Can't use 'super' call in an aspect.");
590590
}
591591
if (ruleClassUnderEvaluation.getStarlarkParent() == null) {

src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilder.java

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

src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class ProtoConstants {
4343
* it with the .proto file that violates strict proto deps.
4444
*/
4545
static final String STRICT_PROTO_DEPS_VIOLATION_MESSAGE =
46-
"%%s is imported, but %1$s doesn't directly depend on a proto_library that 'srcs' it.";
46+
"--direct_dependencies_violation_msg=%%s is imported, but %1$s doesn't directly depend on a proto_library that 'srcs' it.";
4747

4848
private ProtoConstants() {}
4949
}

src/main/starlark/builtins_bzl/bazel/exports.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ load("@_builtins//:common/java/java_import.bzl", "java_import")
1919
load("@_builtins//:common/java/java_library.bzl", "JAVA_LIBRARY_ATTRS", "bazel_java_library_rule", "java_library", "make_sharded_java_library")
2020
load("@_builtins//:common/java/java_plugin.bzl", "java_plugin")
2121
load("@_builtins//:common/java/proto/java_proto_library.bzl", "java_proto_library")
22+
load("@_builtins//:common/proto/proto_library.bzl", "proto_library")
2223
load("@_builtins//:common/python/py_binary_macro.bzl", "py_binary")
2324
load("@_builtins//:common/python/py_internal.bzl", "py_internal")
2425
load("@_builtins//:common/python/py_library_macro.bzl", "py_library")
@@ -38,6 +39,7 @@ exported_toplevels = {
3839
"py_internal": py_internal,
3940
}
4041
exported_rules = {
42+
"proto_library": proto_library,
4143
"java_library": java_library,
4244
"java_plugin": java_plugin,
4345
"java_import": java_import,

src/main/starlark/builtins_bzl/common/exports.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ load("@_builtins//:common/objc/objc_library.bzl", "objc_library")
3535
load("@_builtins//:common/proto/proto_common.bzl", "proto_common_do_not_use")
3636
load("@_builtins//:common/proto/proto_info.bzl", "ProtoInfo")
3737
load("@_builtins//:common/proto/proto_lang_toolchain.bzl", "proto_lang_toolchain")
38-
load("@_builtins//:common/proto/proto_library.bzl", "proto_library")
3938
load("@_builtins//:common/python/providers.bzl", "PyCcLinkParamsProvider", "PyInfo", "PyRuntimeInfo")
4039
load("@_builtins//:common/python/py_runtime_macro.bzl", "py_runtime")
4140
load(":common/java/java_binary_deploy_jar.bzl", get_java_build_info = "get_build_info")
@@ -76,7 +75,6 @@ exported_rules = {
7675
"objc_import": objc_import,
7776
"objc_library": objc_library,
7877
"j2objc_library": j2objc_library,
79-
"proto_library": proto_library,
8078
"cc_shared_library": cc_shared_library,
8179
"cc_binary": cc_binary,
8280
"cc_test": cc_test,

src/main/starlark/builtins_bzl/common/proto/proto_library.bzl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _check_srcs_package(target_package, srcs):
3636
def _get_import_prefix(ctx):
3737
"""Gets and verifies import_prefix attribute if it is declared."""
3838

39-
import_prefix = ctx.attr.import_prefix if hasattr(ctx.attr, "import_prefix") else ""
39+
import_prefix = ctx.attr.import_prefix
4040

4141
if not paths.is_normalized(import_prefix):
4242
fail("should be normalized (without uplevel references or '.' path segments)", attr = "import_prefix")
@@ -61,8 +61,6 @@ def _get_strip_import_prefix(ctx):
6161
return strip_import_prefix.removesuffix("/")
6262

6363
def _proto_library_impl(ctx):
64-
semantics.preprocess(ctx)
65-
6664
# Verifies attributes.
6765
_check_srcs_package(ctx.label.package, ctx.attr.srcs)
6866
srcs = ctx.files.srcs
@@ -247,6 +245,7 @@ proto_library = rule(
247245
providers = [ProtoInfo],
248246
),
249247
"strip_import_prefix": attr.string(default = "/"),
248+
"import_prefix": attr.string(),
250249
"allow_exports": attr.label(
251250
cfg = "exec",
252251
providers = [PackageSpecificationInfo],
@@ -263,9 +262,8 @@ proto_library = rule(
263262
allow_files = True,
264263
default = configuration_field("proto", "proto_compiler"),
265264
),
266-
}) | semantics.EXTRA_ATTRIBUTES,
267-
fragments = ["proto"] + semantics.EXTRA_FRAGMENTS,
265+
}),
266+
fragments = ["proto"],
268267
provides = [ProtoInfo],
269-
exec_groups = semantics.EXEC_GROUPS,
270268
toolchains = toolchains.use_toolchain(semantics.PROTO_TOOLCHAIN),
271269
)

src/main/starlark/builtins_bzl/common/proto/proto_semantics.bzl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,8 @@
1616
Proto Semantics
1717
"""
1818

19-
def _preprocess(ctx):
20-
pass
21-
2219
semantics = struct(
2320
PROTO_TOOLCHAIN = "@rules_proto//proto:toolchain_type",
24-
PROTO_COMPILER_LABEL = "@bazel_tools//tools/proto:protoc",
25-
EXTRA_ATTRIBUTES = {
26-
"import_prefix": attr.string(),
27-
},
28-
EXTRA_FRAGMENTS = [],
29-
preprocess = _preprocess,
3021
# This constant is used in ProtoCompileActionBuilder to generate an error message that's
3122
# displayed when a strict proto deps violation occurs.
3223
#
@@ -37,6 +28,5 @@ semantics = struct(
3728
"--direct_dependencies_violation_msg=" +
3829
"%%s is imported, but %s doesn't directly depend on a proto_library that 'srcs' it."
3930
),
40-
EXEC_GROUPS = {},
4131
allowlist_different_package = None,
4232
)

src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void testDescriptorSetOutput_strictDeps() throws Exception {
225225
.containsAtLeast("--direct_dependencies", "x/nodeps.proto")
226226
.inOrder();
227227
assertThat(getGeneratingSpawnAction(getDescriptorOutput("//x:nodeps")).getRemainingArguments())
228-
.contains(String.format(ProtoCompileActionBuilder.STRICT_DEPS_FLAG_TEMPLATE, "//x:nodeps"));
228+
.contains(String.format(ProtoConstants.STRICT_PROTO_DEPS_VIOLATION_MESSAGE, "//x:nodeps"));
229229

230230
assertThat(
231231
getGeneratingSpawnAction(getDescriptorOutput("//x:withdeps")).getRemainingArguments())
@@ -275,7 +275,7 @@ public void testDescriptorSetOutput_strictDeps_disabled() throws Exception {
275275
assertThat(arg).doesNotContain("--direct_dependencies=");
276276
assertThat(arg)
277277
.doesNotContain(
278-
String.format(ProtoCompileActionBuilder.STRICT_DEPS_FLAG_TEMPLATE, "//x:foo_proto"));
278+
String.format(ProtoConstants.STRICT_PROTO_DEPS_VIOLATION_MESSAGE, "//x:foo_proto"));
279279
}
280280
}
281281

0 commit comments

Comments
 (0)