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