Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2024 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | """A tool for generating buildinfo.prop""" |
| 18 | |
| 19 | import argparse |
| 20 | import contextlib |
Inseob Kim | 1d91482 | 2024-06-11 11:00:30 +0900 | [diff] [blame] | 21 | import json |
| 22 | import os |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 23 | import subprocess |
| 24 | |
Inseob Kim | 1d91482 | 2024-06-11 11:00:30 +0900 | [diff] [blame] | 25 | TEST_KEY_DIR = "build/make/target/product/security" |
| 26 | |
| 27 | def get_build_variant(product_config): |
| 28 | if product_config["Eng"]: |
| 29 | return "eng" |
| 30 | elif product_config["Debuggable"]: |
| 31 | return "userdebug" |
| 32 | else: |
| 33 | return "user" |
| 34 | |
| 35 | def get_build_flavor(product_config): |
| 36 | build_flavor = product_config["DeviceProduct"] + "-" + get_build_variant(product_config) |
| 37 | if "address" in product_config.get("SanitizeDevice", []) and "_asan" not in build_flavor: |
| 38 | build_flavor += "_asan" |
| 39 | return build_flavor |
| 40 | |
| 41 | def get_build_keys(product_config): |
| 42 | default_cert = product_config.get("DefaultAppCertificate", "") |
| 43 | if default_cert == "" or default_cert == os.path.join(TEST_KEY_DIR, "testKey"): |
| 44 | return "test-keys" |
| 45 | return "dev-keys" |
| 46 | |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 47 | def parse_args(): |
| 48 | """Parse commandline arguments.""" |
| 49 | parser = argparse.ArgumentParser() |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 50 | parser.add_argument('--build-hostname-file', required=True, type=argparse.FileType('r')), |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 51 | parser.add_argument('--build-number-file', required=True, type=argparse.FileType('r')) |
| 52 | parser.add_argument('--build-thumbprint-file', type=argparse.FileType('r')) |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 53 | parser.add_argument('--build-username', required=True) |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 54 | parser.add_argument('--date-file', required=True, type=argparse.FileType('r')) |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 55 | parser.add_argument('--platform-preview-sdk-fingerprint-file', |
| 56 | required=True, |
| 57 | type=argparse.FileType('r')) |
Inseob Kim | 1d91482 | 2024-06-11 11:00:30 +0900 | [diff] [blame] | 58 | parser.add_argument('--product-config', required=True, type=argparse.FileType('r')) |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 59 | parser.add_argument('--out', required=True, type=argparse.FileType('w')) |
| 60 | |
Inseob Kim | 1d91482 | 2024-06-11 11:00:30 +0900 | [diff] [blame] | 61 | option = parser.parse_args() |
| 62 | |
| 63 | product_config = json.load(option.product_config) |
| 64 | build_flags = product_config["BuildFlags"] |
| 65 | |
| 66 | option.build_flavor = get_build_flavor(product_config) |
| 67 | option.build_keys = get_build_keys(product_config) |
| 68 | option.build_id = product_config["BuildId"] |
| 69 | option.build_type = product_config["BuildType"] |
| 70 | option.build_variant = get_build_variant(product_config) |
Inseob Kim | 5a994c7 | 2024-06-25 19:09:12 +0900 | [diff] [blame] | 71 | option.build_version_tags = product_config["BuildVersionTags"] |
Inseob Kim | 1d91482 | 2024-06-11 11:00:30 +0900 | [diff] [blame] | 72 | option.cpu_abis = product_config["DeviceAbi"] |
| 73 | option.default_locale = None |
| 74 | if len(product_config.get("ProductLocales", [])) > 0: |
| 75 | option.default_locale = product_config["ProductLocales"][0] |
| 76 | option.default_wifi_channels = product_config.get("ProductDefaultWifiChannels", []) |
| 77 | option.device = product_config["DeviceName"] |
| 78 | option.display_build_number = product_config["DisplayBuildNumber"] |
| 79 | option.platform_base_os = product_config["Platform_base_os"] |
| 80 | option.platform_display_version = product_config["Platform_display_version_name"] |
| 81 | option.platform_min_supported_target_sdk_version = build_flags["RELEASE_PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION"] |
| 82 | option.platform_preview_sdk_version = product_config["Platform_preview_sdk_version"] |
| 83 | option.platform_sdk_version = product_config["Platform_sdk_version"] |
| 84 | option.platform_security_patch = product_config["Platform_security_patch"] |
| 85 | option.platform_version = product_config["Platform_version_name"] |
| 86 | option.platform_version_codename = product_config["Platform_sdk_codename"] |
| 87 | option.platform_version_all_codenames = product_config["Platform_version_active_codenames"] |
| 88 | option.platform_version_known_codenames = product_config["Platform_version_known_codenames"] |
| 89 | option.platform_version_last_stable = product_config["Platform_version_last_stable"] |
| 90 | option.product = product_config["DeviceProduct"] |
| 91 | option.use_vbmeta_digest_in_fingerprint = product_config["BoardUseVbmetaDigestInFingerprint"] |
| 92 | |
| 93 | return option |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 94 | |
| 95 | def main(): |
| 96 | option = parse_args() |
| 97 | |
| 98 | build_hostname = option.build_hostname_file.read().strip() |
| 99 | build_number = option.build_number_file.read().strip() |
Inseob Kim | 5a994c7 | 2024-06-25 19:09:12 +0900 | [diff] [blame] | 100 | build_version_tags_list = option.build_version_tags |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 101 | if option.build_type == "debug": |
Inseob Kim | 5a994c7 | 2024-06-25 19:09:12 +0900 | [diff] [blame] | 102 | build_version_tags_list.append("debug") |
| 103 | build_version_tags_list.append(option.build_keys) |
| 104 | build_version_tags = ",".join(sorted(set(build_version_tags_list))) |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 105 | |
| 106 | raw_date = option.date_file.read().strip() |
| 107 | date = subprocess.check_output(["date", "-d", f"@{raw_date}"], text=True).strip() |
| 108 | date_utc = subprocess.check_output(["date", "-d", f"@{raw_date}", "+%s"], text=True).strip() |
| 109 | |
| 110 | # build_desc is human readable strings that describe this build. This has the same info as the |
| 111 | # build fingerprint. |
| 112 | # e.g. "aosp_cf_x86_64_phone-userdebug VanillaIceCream MAIN eng.20240319.143939 test-keys" |
| 113 | build_desc = f"{option.product}-{option.build_variant} {option.platform_version} " \ |
| 114 | f"{option.build_id} {build_number} {build_version_tags}" |
| 115 | |
| 116 | platform_preview_sdk_fingerprint = option.platform_preview_sdk_fingerprint_file.read().strip() |
| 117 | |
| 118 | with contextlib.redirect_stdout(option.out): |
| 119 | print("# begin build properties") |
| 120 | print("# autogenerated by buildinfo.py") |
| 121 | |
| 122 | # The ro.build.id will be set dynamically by init, by appending the unique vbmeta digest. |
| 123 | if option.use_vbmeta_digest_in_fingerprint: |
| 124 | print(f"ro.build.legacy.id={option.build_id}") |
| 125 | else: |
| 126 | print(f"ro.build.id?={option.build_id}") |
| 127 | |
| 128 | # ro.build.display.id is shown under Settings -> About Phone |
| 129 | if option.build_variant == "user": |
| 130 | # User builds should show: |
| 131 | # release build number or branch.buld_number non-release builds |
| 132 | |
| 133 | # Dev. branches should have DISPLAY_BUILD_NUMBER set |
| 134 | if option.display_build_number: |
Inseob Kim | 51d3a6d | 2024-07-19 09:25:38 +0900 | [diff] [blame^] | 135 | print(f"ro.build.display.id?={option.build_id}.{build_number} {option.build_keys}") |
Inseob Kim | 8fa54da | 2024-03-19 16:48:59 +0900 | [diff] [blame] | 136 | else: |
| 137 | print(f"ro.build.display.id?={option.build_id} {option.build_keys}") |
| 138 | else: |
| 139 | # Non-user builds should show detailed build information (See build desc above) |
| 140 | print(f"ro.build.display.id?={build_desc}") |
| 141 | print(f"ro.build.version.incremental={build_number}") |
| 142 | print(f"ro.build.version.sdk={option.platform_sdk_version}") |
| 143 | print(f"ro.build.version.preview_sdk={option.platform_preview_sdk_version}") |
| 144 | print(f"ro.build.version.preview_sdk_fingerprint={platform_preview_sdk_fingerprint}") |
| 145 | print(f"ro.build.version.codename={option.platform_version_codename}") |
| 146 | print(f"ro.build.version.all_codenames={','.join(option.platform_version_all_codenames)}") |
| 147 | print(f"ro.build.version.known_codenames={option.platform_version_known_codenames}") |
| 148 | print(f"ro.build.version.release={option.platform_version_last_stable}") |
| 149 | print(f"ro.build.version.release_or_codename={option.platform_version}") |
| 150 | print(f"ro.build.version.release_or_preview_display={option.platform_display_version}") |
| 151 | print(f"ro.build.version.security_patch={option.platform_security_patch}") |
| 152 | print(f"ro.build.version.base_os={option.platform_base_os}") |
| 153 | print(f"ro.build.version.min_supported_target_sdk={option.platform_min_supported_target_sdk_version}") |
| 154 | print(f"ro.build.date={date}") |
| 155 | print(f"ro.build.date.utc={date_utc}") |
| 156 | print(f"ro.build.type={option.build_variant}") |
| 157 | print(f"ro.build.user={option.build_username}") |
| 158 | print(f"ro.build.host={build_hostname}") |
| 159 | # TODO: Remove any tag-related optional property declarations once the goals |
| 160 | # from go/arc-android-sigprop-changes have been achieved. |
| 161 | print(f"ro.build.tags?={build_version_tags}") |
| 162 | # ro.build.flavor are used only by the test harness to distinguish builds. |
| 163 | # Only add _asan for a sanitized build if it isn't already a part of the |
| 164 | # flavor (via a dedicated lunch config for example). |
| 165 | print(f"ro.build.flavor={option.build_flavor}") |
| 166 | |
| 167 | # These values are deprecated, use "ro.product.cpu.abilist" |
| 168 | # instead (see below). |
| 169 | print(f"# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,") |
| 170 | print(f"# use ro.product.cpu.abilist instead.") |
| 171 | print(f"ro.product.cpu.abi={option.cpu_abis[0]}") |
| 172 | if len(option.cpu_abis) > 1: |
| 173 | print(f"ro.product.cpu.abi2={option.cpu_abis[1]}") |
| 174 | |
| 175 | if option.default_locale: |
| 176 | print(f"ro.product.locale={option.default_locale}") |
| 177 | print(f"ro.wifi.channels={' '.join(option.default_wifi_channels)}") |
| 178 | |
| 179 | print(f"# ro.build.product is obsolete; use ro.product.device") |
| 180 | print(f"ro.build.product={option.device}") |
| 181 | |
| 182 | print(f"# Do not try to parse description or thumbprint") |
| 183 | print(f"ro.build.description?={build_desc}") |
| 184 | if option.build_thumbprint_file: |
| 185 | build_thumbprint = option.build_thumbprint_file.read().strip() |
| 186 | print(f"ro.build.thumbprint={build_thumbprint}") |
| 187 | |
| 188 | print(f"# end build properties") |
| 189 | |
| 190 | if __name__ == "__main__": |
| 191 | main() |