to_json/to_proto methods on structs are deprecated and will be removed (#295)

This commit is contained in:
Alexandre Rostovtsev 2021-05-03 12:27:40 -04:00 committed by GitHub
parent 398f312289
commit 7b859037a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 16 deletions

View File

@ -5,13 +5,15 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
http_archive( http_archive(
name = "rules_pkg", name = "rules_pkg",
sha256 = "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a",
urls = [ urls = [
"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz",
], ],
sha256 = "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a",
) )
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies() rules_pkg_dependencies()
maybe( maybe(

View File

@ -138,6 +138,7 @@ def _is_instance(v):
Returns: Returns:
True if v was created by `make`, False otherwise. True if v was created by `make`, False otherwise.
""" """
# Note that in bazel 3.7.0 and earlier, type(v.function) is the same # Note that in bazel 3.7.0 and earlier, type(v.function) is the same
# as the type of a function even if v.function is a rule. But we # as the type of a function even if v.function is a rule. But we
# cannot rely on this in later bazels due to breaking change # cannot rely on this in later bazels due to breaking change
@ -145,10 +146,10 @@ def _is_instance(v):
# #
# Since this check is heuristic anyway, we simply check for the # Since this check is heuristic anyway, we simply check for the
# presence of a "function" attribute without checking its type. # presence of a "function" attribute without checking its type.
return type(v) == _a_struct_type \ return type(v) == _a_struct_type and \
and hasattr(v, "function") \ hasattr(v, "function") and \
and hasattr(v, "args") and type(v.args) == _a_tuple_type \ hasattr(v, "args") and type(v.args) == _a_tuple_type and \
and hasattr(v, "kwargs") and type(v.kwargs) == _a_dict_type hasattr(v, "kwargs") and type(v.kwargs) == _a_dict_type
partial = struct( partial = struct(
make = _make, make = _make,

View File

@ -25,10 +25,14 @@ def _to_dict(s):
transformation is only applied to the struct's fields and not to any transformation is only applied to the struct's fields and not to any
nested values. nested values.
""" """
attributes = dir(s)
attributes.remove("to_json") # to_json()/to_proto() are disabled by --incompatible_struct_has_no_methods
attributes.remove("to_proto") # and will be removed entirely in a future Bazel release.
return {key: getattr(s, key) for key in attributes} return {
key: getattr(s, key)
for key in dir(s)
if key != "to_json" and key != "to_proto"
}
structs = struct( structs = struct(
to_dict = _to_dict, to_dict = _to_dict,

View File

@ -65,8 +65,7 @@ def _copy_file_impl(ctx):
target_file = ctx.file.src, target_file = ctx.file.src,
is_executable = ctx.attr.is_executable, is_executable = ctx.attr.is_executable,
) )
else: elif ctx.attr.is_windows:
if ctx.attr.is_windows:
copy_cmd(ctx, ctx.file.src, ctx.outputs.out) copy_cmd(ctx, ctx.file.src, ctx.outputs.out)
else: else:
copy_bash(ctx, ctx.file.src, ctx.outputs.out) copy_bash(ctx, ctx.file.src, ctx.outputs.out)

View File

@ -80,8 +80,8 @@ genrule(
output_to_bindir = 1, output_to_bindir = 1,
tools = [ tools = [
":bin_gen", ":bin_gen",
":bin_src",
":bin_gen_symlink", ":bin_gen_symlink",
":bin_src",
":bin_src_symlink", ":bin_src_symlink",
], ],
) )
@ -147,8 +147,8 @@ copy_file(
name = "copy_xsrc_symlink", name = "copy_xsrc_symlink",
src = "a_with_exec_bit.txt", src = "a_with_exec_bit.txt",
out = "xout/a-out-symlink.sh", out = "xout/a-out-symlink.sh",
is_executable = True,
allow_symlink = True, allow_symlink = True,
is_executable = True,
) )
copy_file( copy_file(
@ -162,8 +162,8 @@ copy_file(
name = "copy_xgen_symlink", name = "copy_xgen_symlink",
src = ":gen", src = ":gen",
out = "xout/gen-out-symlink.sh", out = "xout/gen-out-symlink.sh",
is_executable = True,
allow_symlink = True, allow_symlink = True,
is_executable = True,
) )
genrule( genrule(