diff options
author | Jingwen Chen <jingwen@google.com> | 2023-02-16 11:22:14 +0000 |
---|---|---|
committer | Jingwen Chen <jingwen@google.com> | 2023-03-01 16:51:13 +0000 |
commit | 780df512e347118a9fcec5a3ae2830b2aaedaec7 (patch) | |
tree | bafc297d7c6cee85802df711be8b0aafe963c78a /rules/apex/sdk_versions.bzl | |
parent | d8a851a0b440ea76250415b766952b7a6ac12048 (diff) | |
download | bazel-780df512e347118a9fcec5a3ae2830b2aaedaec7.tar.gz |
Add support for APEX_GLOBAL_MIN_SDK_VERSION_OVERRIDE in apex.bzl.
Fixes: 268340414
Test: presubmits
Change-Id: Icee1e68b1278bdc5ba7f8fcba31a2fcde8dfa03b
Diffstat (limited to 'rules/apex/sdk_versions.bzl')
-rw-r--r-- | rules/apex/sdk_versions.bzl | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/rules/apex/sdk_versions.bzl b/rules/apex/sdk_versions.bzl new file mode 100644 index 00000000..acfad9e4 --- /dev/null +++ b/rules/apex/sdk_versions.bzl @@ -0,0 +1,40 @@ +""" +Copyright (C) 2023 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +load("//build/bazel/rules/common:api.bzl", api_levels = "api_levels_with_previews") + +# Override a min_sdk_version with another if higher. Normalize string codenames +# to API ints for direct comparisons. +# +# Function signature: string, string -> string +def maybe_override_min_sdk_version(min_sdk_version, override_min_sdk_version): + if min_sdk_version == "current": + min_sdk_version = "10000" + if not str(min_sdk_version).isdigit(): + fail("%s must only contain digits." % min_sdk_version) + + min_api_level = int(min_sdk_version) + + if str(override_min_sdk_version).isdigit(): + override_api_level = int(override_min_sdk_version) + else: + override_api_level = api_levels.get(override_min_sdk_version, -1) + + # Only override version numbers upwards. + if override_api_level > min_api_level: + min_api_level = override_api_level + + return str(min_api_level) |