Skip to content

Commit

Permalink
Add proto_info.bzl and use it
Browse files Browse the repository at this point in the history
This prepares destination for Starlarkified ProtoInfo

PiperOrigin-RevId: 498579863
Change-Id: If43bd504a836a67dc6dbf690cd07aad0801911c6
  • Loading branch information
comius authored and copybara-github committed Dec 30, 2022
1 parent e7be4b1 commit abe26b8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

"""Starlark implementation of cc_proto_library"""

load(":common/proto/proto_info.bzl", "ProtoInfo")
load(":common/cc/cc_helper.bzl", "cc_helper")
load(":common/proto/proto_common.bzl", "ProtoLangToolchainInfo", proto_common = "proto_common_do_not_use")

ProtoInfo = _builtins.toplevel.ProtoInfo
CcInfo = _builtins.toplevel.CcInfo
cc_common = _builtins.toplevel.cc_common

Expand Down
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/java/java_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ load(":common/java/java_semantics.bzl", "semantics")
load(":common/rule_util.bzl", "merge_attrs")
load(":common/cc/cc_helper.bzl", "cc_helper")
load(":common/cc/semantics.bzl", cc_semantics = "semantics")
load(":common/proto/proto_info.bzl", "ProtoInfo")

CcInfo = _builtins.toplevel.CcInfo
CcLauncherInfo = _builtins.internal.cc_internal.launcher_provider
JavaInfo = _builtins.toplevel.JavaInfo
JavaPluginInfo = _builtins.toplevel.JavaPluginInfo
ProtoInfo = _builtins.toplevel.ProtoInfo
java_common = _builtins.toplevel.java_common

InternalDeployJarInfo = provider(
Expand Down
1 change: 0 additions & 1 deletion src/main/starlark/builtins_bzl/common/java/java_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ coverage_common = _builtins.toplevel.coverage_common

JavaInfo = _builtins.toplevel.JavaInfo
JavaPluginInfo = _builtins.toplevel.JavaPluginInfo
ProtoInfo = _builtins.toplevel.ProtoInfo
CcInfo = _builtins.toplevel.CcInfo

def _filter_srcs(srcs, ext):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

"""A Starlark implementation of the java_lite_proto_library rule."""

load(":common/proto/proto_info.bzl", "ProtoInfo")
load(":common/java/java_semantics.bzl", "semantics")
load(":common/proto/proto_common.bzl", "ProtoLangToolchainInfo", proto_common = "proto_common_do_not_use")
load(":common/java/proto/java_proto_library.bzl", "JavaProtoAspectInfo", "bazel_java_proto_library_rule", "java_compile_for_protos")

PROTO_TOOLCHAIN_ATTR = "_aspect_proto_toolchain_for_javalite"

java_common = _builtins.toplevel.java_common
ProtoInfo = _builtins.toplevel.ProtoInfo
JavaInfo = _builtins.toplevel.JavaInfo
ProguardSpecProvider = _builtins.toplevel.ProguardSpecProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

load(":common/java/java_semantics.bzl", "semantics")
load(":common/proto/proto_common.bzl", "ProtoLangToolchainInfo", proto_common = "proto_common_do_not_use")
load(":common/proto/proto_info.bzl", "ProtoInfo")

java_common = _builtins.toplevel.java_common
JavaInfo = _builtins.toplevel.JavaInfo
ProtoInfo = _builtins.toplevel.ProtoInfo

# The provider is used to collect source and runtime jars in the `proto_library` dependency graph.
JavaProtoAspectInfo = provider("JavaProtoAspectInfo", fields = ["jars"])
Expand Down
19 changes: 19 additions & 0 deletions src/main/starlark/builtins_bzl/common/proto/proto_info.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# 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.

"""
Definition of ProtoInfo provider.
"""

ProtoInfo = _builtins.toplevel.ProtoInfo
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

"""A Starlark implementation of the proto_lang_toolchain rule."""

load(":common/proto/proto_info.bzl", "ProtoInfo")
load(":common/proto/proto_common.bzl", "ProtoLangToolchainInfo")
load(":common/proto/proto_semantics.bzl", "semantics")

ProtoInfo = _builtins.toplevel.ProtoInfo

def _rule_impl(ctx):
provided_proto_sources = depset(transitive = [bp[ProtoInfo].transitive_proto_sources() for bp in ctx.attr.blacklisted_protos]).to_list()

Expand Down
10 changes: 4 additions & 6 deletions src/main/starlark/builtins_bzl/common/proto/proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ Definition of proto_library rule.

load(":common/proto/proto_semantics.bzl", "semantics")
load(":common/proto/proto_common.bzl", proto_common = "proto_common_do_not_use")
load(":common/proto/proto_info.bzl", "ProtoInfo")
load(":common/paths.bzl", "paths")

ProtoInfo = _builtins.toplevel.ProtoInfo
native_proto_common = _builtins.toplevel.proto_common

def _check_srcs_package(target_package, srcs):
"""Check that .proto files in sources are from the same package.
Expand Down Expand Up @@ -114,7 +112,7 @@ def _create_proto_sources(ctx, srcs, import_prefix, strip_import_prefix):
else:
# source_root == ''|'bazel-out/foo/k8-fastbuild/bin' / 'external/repo'
source_root = _join(src.root.path, ctx.label.workspace_root)
direct_sources.append(native_proto_common.ProtoSource(src, src, source_root))
direct_sources.append(_builtins.toplevel.proto_common.ProtoSource(src, src, source_root))

return ctx.label.workspace_root if ctx.label.workspace_root else ".", direct_sources

Expand Down Expand Up @@ -157,7 +155,7 @@ def _symlink_to_virtual_imports(ctx, srcs, import_prefix, strip_import_prefix):
target_file = src,
progress_message = "Symlinking virtual .proto sources for %{label}",
)
direct_sources.append(native_proto_common.ProtoSource(virtual_src, src, proto_path))
direct_sources.append(_builtins.toplevel.proto_common.ProtoSource(virtual_src, src, proto_path))
return proto_path, direct_sources

def _create_proto_info(ctx, direct_sources, deps, exports, proto_path, descriptor_set):
Expand Down Expand Up @@ -194,7 +192,7 @@ def _create_proto_info(ctx, direct_sources, deps, exports, proto_path, descripto
else:
exported_sources = depset(transitive = [dep.exported_sources() for dep in deps])

return native_proto_common.ProtoInfo(
return _builtins.toplevel.proto_common.ProtoInfo(
direct_sources,
proto_path,
transitive_sources,
Expand Down

0 comments on commit abe26b8

Please sign in to comment.