-
-
Notifications
You must be signed in to change notification settings - Fork 606
/
target_types.py
56 lines (40 loc) · 1.69 KB
/
target_types.py
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
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from pants.backend.codegen.protobuf.protoc import Protoc
from pants.engine.addresses import Address
from pants.engine.rules import register_rules, rule
from pants.engine.target import (
COMMON_TARGET_FIELDS,
Dependencies,
InjectDependenciesRequest,
InjectedDependencies,
Sources,
Target,
)
from pants.engine.unions import UnionRule
class ProtobufDependencies(Dependencies):
"""Addresses to other targets that this target depends on, e.g. `['protobuf/example:lib']`.
Pants will automatically inject any targets that you configure in the option `runtime_targets`
in the `[protoc]` scope. For example, if you set that option to include the Python runtime
library for Protobuf, every `protobuf_library` will automatically include that in its
`dependencies`.
"""
class ProtobufSources(Sources):
default = ("*.proto",)
expected_file_extensions = (".proto",)
class ProtobufLibrary(Target):
"""Protobuf files used to generate various languages.
See https://pants.readme.io/docs/protobuf.
"""
alias = "protobuf_library"
core_fields = (*COMMON_TARGET_FIELDS, ProtobufDependencies, ProtobufSources)
class InjectProtobufDependencies(InjectDependenciesRequest):
inject_for = ProtobufDependencies
@rule
def inject_dependencies(_: InjectProtobufDependencies, protoc: Protoc) -> InjectedDependencies:
return InjectedDependencies(Address.parse(addr) for addr in protoc.runtime_targets)
def rules():
return [
*register_rules(),
UnionRule(InjectDependenciesRequest, InjectProtobufDependencies),
]