Skip to content

Commit

Permalink
Forward new provider for python in filter_layer (#697)
Browse files Browse the repository at this point in the history
* Forward correct provider for python in filter_layer
  • Loading branch information
aaliddell authored and xingao267 committed Mar 5, 2019
1 parent 16b7fcc commit eb986a1
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions lang/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,30 @@ def _filter_layer_rule_impl(ctx):
if str(dep.target.label).startswith(ctx.attr.filter) and str(dep.target.label) != str(ctx.attr.dep.label):
runfiles = runfiles.merge(dep.target.default_runfiles)
filtered_depsets.append(dep.target_deps)
return struct(
providers = [
FilterLayerInfo(
runfiles = runfiles,
filtered_depset = depset(transitive = filtered_depsets),
),
],
# Also forward builtin providers so that the filter_layer() can be used as a normal
# dependency to native targets (e.g. py_library(deps = [<filter_layer>])).
py = ctx.attr.dep.py if hasattr(ctx.attr.dep, "py") else None,
)

# Forward correct provider, depending on availability, so that the filter_layer() can be
# used as a normal dependency to native targets (e.g. py_library(deps = [<filter_layer>])).
if hasattr(ctx.attr.dep, "py"):
# Forward legacy builtin provider and PyInfo provider
return struct(
providers = [
FilterLayerInfo(
runfiles = runfiles,
filtered_depset = depset(transitive = filtered_depsets),
),
] + ([ctx.attr.dep[PyInfo]] if PyInfo in ctx.attr.dep else []),
py = ctx.attr.dep.py if hasattr(ctx.attr.dep, "py") else None,
)
else:
# Forward the PyInfo provider only
return struct(
providers = [
FilterLayerInfo(
runfiles = runfiles,
filtered_depset = depset(transitive = filtered_depsets),
),
] + ([ctx.attr.dep[PyInfo]] if PyInfo in ctx.attr.dep else []),
)

# A rule that allows selecting a subset of transitive dependencies, and using
# them as a layer in an image.
Expand Down

0 comments on commit eb986a1

Please sign in to comment.