Skip to content

Commit

Permalink
Prepare databinding integration for moving the DatabindingV2Provider …
Browse files Browse the repository at this point in the history
…attributes class_infos and setter_stores from lists to depsets.

See
bazelbuild/bazel@876d48d
bazelbuild/bazel#11497 (comment)
bazelbuild/bazel#12780
  • Loading branch information
ahumesky committed Jul 29, 2021
1 parent 5c8bdd4 commit 5edebe5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
24 changes: 18 additions & 6 deletions rules/data_binding.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,27 @@ def _gen_sources(ctx, output_dir, java_package, deps, layout_info, data_binding_
args.add("-zipSourceOutput", "true")
args.add("-useAndroidX", "false")

class_infos = []
for info in deps:
class_infos.extend(info.class_infos)
if deps:
if type(deps[0].class_infos) == "depset":
class_infos = depset(transitive = [info.class_infos for info in deps])
inputs = depset(direct = [layout_info], transitive = [class_infos])
elif type(deps[0].class_infos) == "list":
class_infos = []
for info in deps:
class_infos.extend(info.class_infos)
inputs = class_infos + [layout_info]
else:
fail("Expected list or depset. Got %s" % type(deps[0].class_infos))
else:
class_infos = []
inputs = [layout_info]

args.add_all(class_infos, before_each = "-dependencyClassInfoList")

ctx.actions.run(
executable = data_binding_exec,
arguments = ["GEN_BASE_CLASSES", args],
inputs = class_infos + [layout_info],
inputs = inputs,
outputs = [class_info, srcjar],
mnemonic = "GenerateDataBindingBaseClasses",
progress_message = (
Expand All @@ -91,8 +103,8 @@ def _setup_dependent_lib_artifacts(ctx, output_dir, deps):
for info in deps:
# Yes, DataBinding requires depsets iterations.
for artifact in (info.transitive_br_files.to_list() +
info.setter_stores +
info.class_infos):
_utils.list_or_depset_to_list(info.setter_stores) +
_utils.list_or_depset_to_list(info.class_infos)):
# short_path might contain a parent directory reference if the
# databinding artifact is from an external repository (e.g. an aar
# from Maven). If that's the case, just remove the parent directory
Expand Down
9 changes: 9 additions & 0 deletions rules/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def _only(collection):
_error("Expected one element, has %s." % len(collection))
return _first(collection)

def _list_or_depset_to_list(list_or_depset):
if type(list_or_depset) == "list":
return list_or_depset
elif type(list_or_depset) == "depset":
return list_or_depset.to_list()
else:
return _error("Expected a list or a depset. Got %s" % type(list_or_depset))

def _copy_file(ctx, src, dest):
if src.is_directory or dest.is_directory:
fail("Cannot use copy_file with directories")
Expand Down Expand Up @@ -444,6 +452,7 @@ utils = struct(
sanitize_string = _sanitize_string,
sanitize_java_package = _sanitize_java_package,
hex = _hex,
list_or_depset_to_list = _list_or_depset_to_list,
)

log = struct(
Expand Down

0 comments on commit 5edebe5

Please sign in to comment.