| 91 | + ), |
| 92 | + providers = [PackageSpecificationInfo], |
| 93 | + ), |
| 94 | +} |
| 95 | + |
| 96 | +# Attributes common to all rules. |
| 97 | +COMMON_ATTRS = union_attrs( |
| 98 | + DATA_ATTRS, |
| 99 | + NATIVE_RULES_ALLOWLIST_ATTRS, |
| 100 | + { |
| 101 | + # NOTE: This attribute is deprecated and slated for removal. |
| 102 | + "distribs": attr.string_list(), |
| 103 | + # TODO(b/148103851): This attribute is deprecated and slated for |
| 104 | + # removal. |
| 105 | + # NOTE: The license attribute is missing in some Java integration tests, |
| 106 | + # so fallback to a regular string_list for that case. |
| 107 | + # buildifier: disable=attr-license |
| 108 | + "licenses": attr.license() if hasattr(attr, "license") else attr.string_list(), |
| 109 | + }, |
| 110 | + allow_none = True, |
| 111 | +) |
| 112 | + |
| 113 | +# Attributes common to rules accepting Python sources and deps. |
| 114 | +PY_SRCS_ATTRS = union_attrs( |
| 115 | + { |
| 116 | + "deps": attr.label_list( |
| 117 | + providers = [[PyInfo], [_CcInfo]], |
| 118 | + # TODO(b/228692666): Google-specific; remove these allowances once |
| 119 | + # the depot is cleaned up. |
| 120 | + allow_rules = DEPS_ATTR_ALLOW_RULES, |
| 121 | + ), |
| 122 | + # Required attribute, but details vary by rule. |
| 123 | + # Use create_srcs_attr to create one. |
| 124 | + "srcs": None, |
| 125 | + # NOTE: In Google, this attribute is deprecated, and can only |
| 126 | + # effectively be PY3 or PY3ONLY. Externally, with Bazel, this attribute |
| 127 | + # has a separate story. |
| 128 | + # Required attribute, but the details vary by rule. |
| 129 | + # Use create_srcs_version_attr to create one. |
| 130 | + "srcs_version": None, |
| 131 | + }, |
| 132 | + allow_none = True, |
| 133 | +) |
| 134 | + |
| 135 | +# Attributes specific to Python executable-equivalent rules. Such rules may not |
| 136 | +# accept Python sources (e.g. some packaged-version of a py_test/py_binary), but |
| 137 | +# still accept Python source-agnostic settings. |
| 138 | +AGNOSTIC_EXECUTABLE_ATTRS = union_attrs( |
| 139 | + DATA_ATTRS, |
| 140 | + { |
| 141 | + "env": attr.string_dict( |
| 142 | + doc = """\ |
| 143 | +Dictionary of strings; optional; values are subject to `$(location)` and "Make |
| 144 | +variable" substitution. |
| 145 | +
|
| 146 | +Specifies additional environment variables to set when the target is executed by |
| 147 | +`test` or `run`. |
| 148 | +""", |
| 149 | + ), |
| 150 | + # The value is required, but varies by rule and/or rule type. Use |
| 151 | + # create_stamp_attr to create one. |
| 152 | + "stamp": None, |
| 153 | + }, |
| 154 | + allow_none = True, |
| 155 | +) |
| 156 | + |
| 157 | +# Attributes specific to Python test-equivalent executable rules. Such rules may |
| 158 | +# not accept Python sources (e.g. some packaged-version of a py_test/py_binary), |
| 159 | +# but still accept Python source-agnostic settings. |
| 160 | +AGNOSTIC_TEST_ATTRS = union_attrs( |
| 161 | + AGNOSTIC_EXECUTABLE_ATTRS, |
| 162 | + # Tests have stamping disabled by default. |
| 163 | + create_stamp_attr(default = 0), |
| 164 | + { |
| 165 | + "env_inherit": attr.string_list( |
| 166 | + doc = """\ |
| 167 | +List of strings; optional |
| 168 | +
|
| 169 | +Specifies additional environment variables to inherit from the external |
| 170 | +environment when the test is executed by bazel test. |
| 171 | +""", |
| 172 | + ), |
| 173 | + # TODO(b/176993122): Remove when Bazel automatically knows to run on darwin. |
| 174 | + "_apple_constraints": attr.label_list( |
| 175 | + default = [ |
| 176 | + PLATFORMS_LOCATION + "/os:ios", |
| 177 | + PLATFORMS_LOCATION + "/os:macos", |
| 178 | + PLATFORMS_LOCATION + "/os:tvos", |
| 179 | + PLATFORMS_LOCATION + "/os:visionos", |
| 180 | + PLATFORMS_LOCATION + "/os:watchos", |
| 181 | + ], |
| 182 | + ), |
| 183 | + }, |
|
F41A
184 | +) |
| 185 | + |
| 186 | +# Attributes specific to Python binary-equivalent executable rules. Such rules may |
| 187 | +# not accept Python sources (e.g. some packaged-version of a py_test/py_binary), |
| 188 | +# but still accept Python source-agnostic settings. |
| 189 | +AGNOSTIC_BINARY_ATTRS = union_attrs( |
| 190 | + AGNOSTIC_EXECUTABLE_ATTRS, |
| 191 | + create_stamp_attr(default = -1), |
| 192 | +) |
| 193 | + |
| 194 | +# Attribute names common to all Python rules |
| 195 | +COMMON_ATTR_NAMES = [ |
| 196 | + "compatible_with", |
| 197 | + "deprecation", |
| 198 | + "distribs", # NOTE: Currently common to all rules, but slated for removal |
| 199 | + "exec_compatible_with", |
| 200 | + "exec_properties", |
| 201 | + "features", |
| 202 | + "restricted_to", |
| 203 | + "tags", |
| 204 | + "target_compatible_with", |
| 205 | + # NOTE: The testonly attribute requires careful handling: None/unset means |
| 206 | + # to use the `package(default_testonly`) value, which isn't observable |
| 207 | + # during the loading phase. |
| 208 | + "testonly", |
| 209 | + "toolchains", |
| 210 | + "visibility", |
| 211 | +] + COMMON_ATTRS.keys() |
| 212 | + |
| 213 | +# Attribute names common to all test=True rules |
| 214 | +TEST_ATTR_NAMES = COMMON_ATTR_NAMES + [ |
| 215 | + "args", |
| 216 | + "size", |
| 217 | + "timeout", |
| 218 | + "flaky", |
| 219 | + "shard_count", |
| 220 | + "local", |
| 221 | +] + AGNOSTIC_TEST_ATTRS.keys() |
| 222 | + |
| 223 | +# Attribute names common to all executable=True rules |
| 224 | +BINARY_ATTR_NAMES = COMMON_ATTR_NAMES + [ |
| 225 | + "args", |
| 226 | + "output_licenses", # NOTE: Common to all rules, but slated for removal |
| 227 | +] + AGNOSTIC_BINARY_ATTRS.keys() |
0 commit comments