Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 1 | # Copyright 2021 Google LLC |
| 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 | # https://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 | |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 15 | load(":build_id.rbc|init", _build_id_init = "init") |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 16 | |
| 17 | def _all_versions(): |
| 18 | """Returns all known versions.""" |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 19 | versions = ["OPR1", "OPD1", "OPD2", "OPM1", "OPM2", "PPR1", "PPD1", "PPD2", "PPM1", "PPM2", "QPR1"] |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 20 | for v in ("Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"): |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 21 | for e in ("P1A", "P1B", "P2A", "P2B", "D1A", "D1B", "D2A", "D2B", "Q1A", "Q1B", "Q2A", "Q2B", "Q3A", "Q3B"): |
| 22 | versions.append(v + e) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 23 | return versions |
| 24 | |
| 25 | def _allowed_versions(all_versions, min_version, max_version, default_version): |
| 26 | """Checks that version range and default versions is valid, returns all versions in range.""" |
| 27 | for v in (min_version, max_version, default_version): |
| 28 | if v not in all_versions: |
| 29 | fail("% is invalid" % v) |
| 30 | |
| 31 | min_i = all_versions.index(min_version) |
| 32 | max_i = all_versions.index(max_version) |
| 33 | def_i = all_versions.index(default_version) |
| 34 | if min_i > max_i: |
| 35 | fail("%s should come before %s in the version list" % (min_version, max_version)) |
| 36 | if def_i < min_i or def_i > max_i: |
| 37 | fail("%s should come between % and %s" % (default_version, min_version, max_version)) |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 38 | return all_versions[min_i:max_i + 1] |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 39 | |
| 40 | # This function is a manual conversion of the version_defaults.mk |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 41 | def _versions_default(g, all_versions, v): |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 42 | """Handle various build version information. |
| 43 | |
| 44 | Guarantees that the following are defined: |
| 45 | PLATFORM_VERSION |
| 46 | PLATFORM_SDK_VERSION |
| 47 | PLATFORM_VERSION_CODENAME |
| 48 | DEFAULT_APP_TARGET_SDK |
| 49 | BUILD_ID |
| 50 | BUILD_NUMBER |
| 51 | PLATFORM_SECURITY_PATCH |
| 52 | PLATFORM_VNDK_VERSION |
| 53 | PLATFORM_SYSTEMSDK_VERSIONS |
| 54 | """ |
| 55 | |
| 56 | # If build_id.rbc exists, it may override some of the defaults. |
| 57 | # Note that build.prop target also wants INTERNAL_BUILD_ID_MAKEFILE to be set if the file exists. |
| 58 | if _build_id_init != None: |
| 59 | _build_id_init(g) |
| 60 | g["INTERNAL_BUILD_ID_MAKEFILE"] = "build/make/core/build_id" |
| 61 | |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 62 | allowed_versions = _allowed_versions(all_versions, v.min_platform_version, v.max_platform_version, v.default_platform_version) |
| 63 | g.setdefault("TARGET_PLATFORM_VERSION", v.default_platform_version) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 64 | if g["TARGET_PLATFORM_VERSION"] not in allowed_versions: |
| 65 | fail("% is not valid, must be one of %s" % (g["TARGET_PLATFORM_VERSION"], allowed_versions)) |
| 66 | |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 67 | g["DEFAULT_PLATFORM_VERSION"] = v.default_platform_version |
| 68 | g["PLATFORM_VERSION_LAST_STABLE"] = v.platform_version_last_stable |
| 69 | target_platform_version = g["TARGET_PLATFORM_VERSION"] |
| 70 | if v.codenames[target_platform_version]: |
| 71 | g.setdefault("PLATFORM_VERSION_CODENAME", v.codenames[target_platform_version]) |
| 72 | else: |
| 73 | g.setdefault("PLATFORM_VERSION_CODENAME", target_platform_version) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 74 | # TODO(asmundak): set PLATFORM_VERSION_ALL_CODENAMES |
| 75 | |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 76 | g.setdefault("PLATFORM_SDK_VERSION", v.platform_sdk_version) |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 77 | version_codename = g["PLATFORM_VERSION_CODENAME"] |
| 78 | if version_codename == "REL": |
| 79 | g.setdefault("PLATFORM_VERSION", g["PLATFORM_VERSION_LAST_STABLE"]) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 80 | g["PLATFORM_PREVIEW_SDK_VERSION"] = 0 |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 81 | g.setdefault("DEFAULT_APP_TARGET_SDK", g["PLATFORM_SDK_VERSION"]) |
| 82 | g.setdefault("PLATFORM_VNDK_VERSION", g["PLATFORM_SDK_VERSION"]) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 83 | else: |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 84 | g.setdefault("PLATFORM_VERSION", version_codename) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 85 | g.setdefault("PLATFORM_PREVIEW_SDK_VERSION", 1) |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 86 | g.setdefault("DEFAULT_APP_TARGET_SDK", version_codename) |
| 87 | g.setdefault("PLATFORM_VNDK_VERSION", version_codename) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 88 | |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 89 | g.setdefault("PLATFORM_SYSTEMSDK_MIN_VERSION", 28) |
| 90 | versions = [str(i) for i in range(g["PLATFORM_SYSTEMSDK_MIN_VERSION"], g["PLATFORM_SDK_VERSION"] + 1)] |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 91 | versions.append(version_codename) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 92 | g["PLATFORM_SYSTEMSDK_VERSIONS"] = sorted(versions) |
| 93 | |
| 94 | # Used to indicate the security patch that has been applied to the device. |
| 95 | # It must signify that the build includes all security patches issued up through the designated Android Public Security Bulletin. |
| 96 | # It must be of the form "YYYY-MM-DD" on production devices. |
| 97 | # It must match one of the Android Security Patch Level strings of the Public Security Bulletins. |
| 98 | # If there is no $PLATFORM_SECURITY_PATCH set, keep it empty. |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 99 | |
| 100 | g.setdefault("PLATFORM_SECURITY_PATCH", v.platform_security_patch) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 101 | dt = 'TZ="GMT" %s' % g["PLATFORM_SECURITY_PATCH"] |
| 102 | g.setdefault("PLATFORM_SECURITY_PATCH_TIMESTAMP", rblf_shell("date -d '%s' +%%s" % dt)) |
| 103 | |
| 104 | # Used to indicate the base os applied to the device. Can be an arbitrary string, but must be a single word. |
| 105 | # If there is no $PLATFORM_BASE_OS set, keep it empty. |
| 106 | g.setdefault("PLATFORM_BASE_OS", "") |
| 107 | |
| 108 | # Used to signify special builds. E.g., branches and/or releases, like "M5-RC7". Can be an arbitrary string, but |
| 109 | # must be a single word and a valid file name. If there is no BUILD_ID set, make it obvious. |
| 110 | g.setdefault("BUILD_ID", "UNKNOWN") |
| 111 | |
| 112 | # BUILD_NUMBER should be set to the source control value that represents the current state of the source code. |
| 113 | # E.g., a perforce changelist number or a git hash. Can be an arbitrary string (to allow for source control that |
| 114 | # uses something other than numbers), but must be a single word and a valid file name. |
| 115 | # |
| 116 | # If no BUILD_NUMBER is set, create a useful "I am an engineering build from this date/time" value. Make it start |
| 117 | # with a non-digit so that anyone trying to parse it as an integer will probably get "0". |
| 118 | g.setdefault("BUILD_NUMBER", "eng.%s.%s" % (g["USER"], "TIMESTAMP")) |
| 119 | |
| 120 | # Used to set minimum supported target sdk version. Apps targeting SDK version lower than the set value will result |
| 121 | # in a warning being shown when any activity from the app is started. |
| 122 | g.setdefault("PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION", 23) |
| 123 | |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 124 | # This is the sdk extension version of this tree. |
| 125 | g["PLATFORM_SDK_EXTENSION_VERSION"] = v.platform_sdk_extension_version |
| 126 | # This is the sdk extension version that PLATFORM_SDK_VERSION ships with. |
| 127 | g["PLATFORM_BASE_SDK_EXTENSION_VERSION"] = v.platform_base_sdk_extension_version |
| 128 | |
| 129 | |
| 130 | def init(g, v): |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 131 | """Initializes globals. |
| 132 | |
| 133 | The code is the Starlark counterpart of the contents of the |
| 134 | envsetup.mk file. |
| 135 | Args: |
| 136 | g: globals dictionary |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 137 | v: version info struct |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 138 | """ |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 139 | all_versions = _all_versions() |
Sasha Smundak | b2220c2 | 2021-05-04 09:01:16 -0700 | [diff] [blame] | 140 | _versions_default(g, all_versions, v) |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 141 | for v in all_versions: |
| 142 | g["IS_AT_LEAST" + v] = True |
| 143 | if v == g["TARGET_PLATFORM_VERSION"]: |
| 144 | break |
| 145 | |
| 146 | # --------------------------------------------------------------- |
| 147 | # If you update the build system such that the environment setup or buildspec.mk need to be updated, |
| 148 | # increment this number, and people who haven't re-run those will have to do so before they can build. |
| 149 | # Make sure to also update the corresponding value in buildspec.mk.default and envsetup.sh. |
| 150 | g["CORRECT_BUILD_ENV_SEQUENCE_NUMBER"] = 13 |
| 151 | |
| 152 | g.setdefault("TARGET_PRODUCT", "aosp_arm") |
| 153 | g.setdefault("TARGET_BUILD_VARIANT", "eng") |
| 154 | |
| 155 | g.setdefault("TARGET_BUILD_APPS", []) |
| 156 | g["TARGET_BUILD_UNBUNDLED"] = (g["TARGET_BUILD_APPS"] != []) or (getattr(g, "TARGET_BUILD_UNBUNDLED_IMAGE", "") != "") |
| 157 | |
| 158 | # --------------------------------------------------------------- |
| 159 | # Set up configuration for host machine. We don't do cross-compiles except for arm, so the HOST |
| 160 | # is whatever we are running on. |
| 161 | host = rblf_shell("uname -sm") |
| 162 | if host.find("Linux") >= 0: |
| 163 | g["HOST_OS"] = "linux" |
| 164 | elif host.find("Darwin") >= 0: |
| 165 | g["HOST_OS"] = "darwin" |
| 166 | else: |
| 167 | fail("Cannot run on %s OS" % host) |
| 168 | |
| 169 | # TODO(asmundak): set g.HOST_OS_EXTRA |
| 170 | |
| 171 | g["BUILD_OS"] = g["HOST_OS"] |
| 172 | |
| 173 | # TODO(asmundak): check cross-OS build |
| 174 | |
| 175 | if host.find("x86_64") >= 0: |
| 176 | g["HOST_ARCH"] = "x86_64" |
| 177 | g["HOST_2ND_ARCH"] = "x86" |
| 178 | g["HOST_IS_64_BIT"] = True |
| 179 | elif host.find("i686") >= 0 or host.find("x86") >= 0: |
| 180 | fail("Building on a 32-bit x86 host is not supported: %s" % host) |
| 181 | elif g["HOST_OS"] == "darwin": |
| 182 | g["HOST_2ND_ARCH"] = "" |
| 183 | |
| 184 | g["HOST_2ND_ARCH_VAR_PREFIX"] = "2ND_" |
| 185 | g["HOST_2ND_ARCH_MODULE_SUFFIX"] = "_32" |
| 186 | g["HOST_CROSS_2ND_ARCH_VAR_PREFIX"] = "2ND_" |
| 187 | g["HOST_CROSS_2ND_ARCH_MODULE_SUFFIX"] = "_64" |
| 188 | g["TARGET_2ND_ARCH_VAR_PREFIX"] = "2ND_" |
| 189 | |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 190 | # TODO(asmundak): envsetup.mk lines 216-226: |
| 191 | # convert combo-related stuff from combo/select.mk |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 192 | |
| 193 | # on windows, the tools have .exe at the end, and we depend on the |
| 194 | # host config stuff being done first |
| 195 | g["BUILD_ARCH"] = g["HOST_ARCH"] |
| 196 | g["BUILD_2ND_ARCH"] = g["HOST_2ND_ARCH"] |
| 197 | |
| 198 | # the host build defaults to release, and it must be release or debug |
| 199 | g.setdefault("HOST_BUILD_TYPE", "release") |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 200 | if g["HOST_BUILD_TYPE"] not in ["release", "debug"]: |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 201 | fail("HOST_BUILD_TYPE must be either release or debug, not '%s'" % g["HOST_BUILD_TYPE"]) |
| 202 | |
Sasha Smundak | 412a0da | 2021-08-16 13:37:23 -0700 | [diff] [blame] | 203 | g.update([ |
| 204 | ("TARGET_COPY_OUT_VENDOR", "||VENDOR-PATH-PH||"), |
| 205 | ("TARGET_COPY_OUT_PRODUCT", "||PRODUCT-PATH-PH||"), |
| 206 | ("TARGET_COPY_OUT_PRODUCT_SERVICES", "||PRODUCT-PATH-PH||"), |
| 207 | ("TARGET_COPY_OUT_SYSTEM_EXT", "||SYSTEM_EXT-PATH-PH||"), |
| 208 | ("TARGET_COPY_OUT_ODM", "||ODM-PATH-PH||"), |
| 209 | ("TARGET_COPY_OUT_VENDOR_DLKM", "||VENDOR_DLKM-PATH-PH||"), |
| 210 | ("TARGET_COPY_OUT_ODM_DLKM", "||ODM_DLKM-PATH-PH||"), |
| 211 | ]) |
| 212 | |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 213 | # TODO(asmundak): there is more stuff in envsetup.mk lines 249-292, but |
| 214 | # it does not seem to affect product configuration. Revisit this. |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 215 | g["ART_APEX_JARS"] = [ |
| 216 | "com.android.art:core-oj", |
| 217 | "com.android.art:core-libart", |
| 218 | "com.android.art:okhttp", |
| 219 | "com.android.art:bouncycastle", |
Sasha Smundak | 357e37c | 2021-03-31 12:30:42 -0700 | [diff] [blame] | 220 | "com.android.art:apache-xml", |
Sasha Smundak | 5c8b09b | 2020-11-03 23:44:14 -0800 | [diff] [blame] | 221 | ] |
| 222 | |
| 223 | if g.get("TARGET_BUILD_TYPE", "") != "debug": |
| 224 | g["TARGET_BUILD_TYPE"] = "release" |