-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Closed
Labels
P2We'll consider working on this in future. (Assignee optional)We'll consider working on this in future. (Assignee optional)team-Rules-APIAPI for writing rules/aspects: providers, runfiles, actions, artifactsAPI for writing rules/aspects: providers, runfiles, actions, artifactstype: process
Description
Flag: --incompatible_disallow_struct_provider_syntax
Available since: 0.23 (February 2019 release)
Motivation
The motivation for this change is described in #6241
Migration
Rule implementation functions should return a collection of provider instances instead of a struct
# Before
def _rule_impl(ctx):
return struct(
foo_info = struct(foo = ‘foo’),
bar_info = struct(bar = ‘bar’),
)
my_rule = rule(implementation = _rule_impl)
# After
FooInfo = provider()
BarInfo = provider()
def _rule_impl(ctx):
return [FooInfo(foo = ‘foo’), BarInfo(bar = ‘bar’)]
my_rule = rule(implementation = _rule_impl)One corner case to note is specifying files for coverage. This used
to be done with the hardcoded struct field instrumented_files, but should
now be done by using coverage_common.instrumented_files_info(). For example:
# Before
def rule_impl(ctx):
return struct(
instrumented_files = struct(
source_attributes = ["srcs"],
dependency_attributes = ["deps", "image"],
extensions = ["js"],
),
)
my_rule = rule(implementation = _rule_impl)
# After
def rule_impl(ctx):
my_coverage_info = coverage_common.instrumented_files_info(
ctx,
source_attributes = ["srcs"],
dependency_attributes = ["deps", "image"],
extensions = ["js"])
return [my_coverage_info]
my_rule = rule(implementation = _rule_impl)Globegitter
Metadata
Metadata
Assignees
Labels
P2We'll consider working on this in future. (Assignee optional)We'll consider working on this in future. (Assignee optional)team-Rules-APIAPI for writing rules/aspects: providers, runfiles, actions, artifactsAPI for writing rules/aspects: providers, runfiles, actions, artifactstype: process