1# Copyright (C) 2023 The Android Open Source Project
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
15load(":cc_constants.bzl", "transition_constants")
16
17# This logic checks for the enablement of sanitizers to update the relevant
18# config_setting for the purpose of controlling the addition of sanitizer
19# blocklists.
20# TODO: b/294868620 - This whole file can be removed when completing the bug
21def apply_sanitizer_enablement_transition(features):
22    if "android_cfi" in features and "-android_cfi" not in features:
23        return True
24    for feature in features:
25        if feature.startswith("ubsan_"):
26            return True
27    return False
28
29def _drop_sanitizer_enablement_transition_impl(_, __):
30    return {
31        transition_constants.sanitizers_enabled_key: False,
32    }
33
34drop_sanitizer_enablement_transition = transition(
35    implementation = _drop_sanitizer_enablement_transition_impl,
36    inputs = [],
37    outputs = [transition_constants.sanitizers_enabled_key],
38)
39