-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathattrs_validators.bzl
57 lines (49 loc) · 1.75 KB
/
attrs_validators.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
_ATTRS_VALIDATORS_NAME = "attrs_validators"
AttrsValidatorsInfo = provider(
fields = {
"func": typing.Callable[[AnalysisActions, Label, struct], dict[str, Artifact]],
},
)
def get_attrs_validation_specs(ctx: AnalysisContext) -> list[ValidationSpec]:
validators = getattr(ctx.attrs, _ATTRS_VALIDATORS_NAME, [])
if not validators:
return []
specs = []
for validator in validators:
for name, output in validator[AttrsValidatorsInfo].func(ctx.actions, ctx.label, ctx.attrs).items():
specs.append(ValidationSpec(name = name, validation_result = output))
return specs
def _attrs_validators_arg():
return {
_ATTRS_VALIDATORS_NAME: attrs.option(
attrs.list(attrs.dep(providers = [AttrsValidatorsInfo])),
default = None,
),
}
def _validation_specs_arg():
return {
"validation_specs": attrs.dict(
attrs.string(),
attrs.source(doc = """
An artifact pointing to a JSON file that will be used in ValidationSpec.
{
"version": 1,
"data": {
"message": "What goes in stderr",
"status": "success" | "failure",
}
}
"""),
default = {},
),
}
validation_common = struct(
attrs_validators_arg = _attrs_validators_arg,
validation_specs_arg = _validation_specs_arg,
)