blob: c738d32238e3ae5a71556b6110dac4739eb64a99 [file] [log] [blame]
Greg Estren2323dfe2020-07-15 12:02:51 -07001# Copyright 2020 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""The core data types ctexplain manipulates."""
15
16from typing import Mapping
17from typing import Optional
18from typing import Tuple
19# Do not edit this line. Copybara replaces it with PY2 migration helper.
20from dataclasses import dataclass
21from dataclasses import field
22from frozendict import frozendict
23
24
25@dataclass(frozen=True)
26class Configuration():
27 """Stores a build configuration as a collection of fragments and options."""
Greg Estrenc1d70872020-08-25 07:17:08 -070028 # Mapping of each BuildConfiguration.Fragment in this configuration to the
29 # FragmentOptions it requires.
30 #
31 # All names are qualified up to the base file name, without package prefixes.
32 # For example, foo.bar.BazConfiguration appears as "BazConfiguration".
33 # foo.bar.BazConfiguration$Options appears as "BazeConfiguration$Options".
34 fragments: Mapping[str, Tuple[str, ...]]
Greg Estren2323dfe2020-07-15 12:02:51 -070035 # Mapping of FragmentOptions to option key/value pairs. For example:
36 # {"CoreOptions": {"action_env": "[]", "cpu": "x86", ...}, ...}.
37 #
38 # Option values are stored as strings of whatever "bazel config" outputs.
39 #
40 # Note that Fragment and FragmentOptions aren't the same thing.
Greg Estrenc1d70872020-08-25 07:17:08 -070041 options: Mapping[str, Mapping[str, str]]
Greg Estren2323dfe2020-07-15 12:02:51 -070042
43
44@dataclass(frozen=True)
45class ConfiguredTarget():
46 """Encapsulates a target + configuration + required fragments."""
47 # Label of the target this represents.
48 label: str
49 # Configuration this target is applied to. May be None.
50 config: Optional[Configuration]
51 # The hash of this configuration as reported by Bazel.
52 config_hash: str
53 # Fragments required by this configured target and its transitive
54 # dependencies. Stored as base names without packages. For example:
Greg Estrenc1d70872020-08-25 07:17:08 -070055 # "PlatformOptions" or "FooConfiguration$Options".
Greg Estren2323dfe2020-07-15 12:02:51 -070056 transitive_fragments: Tuple[str, ...]
57
58
59@dataclass(frozen=True)
60class HostConfiguration(Configuration):
61 """Special marker for the host configuration.
62
63 There's exactly one host configuration per build, so we shouldn't suggest
64 merging it with other configurations.
65
66 TODO(gregce): suggest host configuration trimming once we figure out the right
67 criteria. Even if Bazel's not technically equipped to do the trimming, it's
68 still theoretically valuable information. Note that moving from host to exec
69 configurations make this all a little less relevant, since exec configurations
70 aren't "special" compared to normal configurations.
71 """
72 # We don't currently read the host config's fragments or option values.
73 fragments: Tuple[str, ...] = ()
74 options: Mapping[str,
75 Mapping[str,
76 str]] = field(default_factory=lambda: frozendict({}))
77
78
79@dataclass(frozen=True)
80class NullConfiguration(Configuration):
81 """Special marker for the null configuration.
82
83 By definition this has no fragments or options.
84 """
85 fragments: Tuple[str, ...] = ()
86 options: Mapping[str,
87 Mapping[str,
88 str]] = field(default_factory=lambda: frozendict({}))