1# 2# Copyright (C) 2020 The Android Open Source Project 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# http://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 17# sysprop.mk defines rules for generating <partition>/[etc/]build.prop files 18 19# ----------------------------------------------------------------- 20# property_overrides_split_enabled 21property_overrides_split_enabled := 22ifeq ($(BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED), true) 23 property_overrides_split_enabled := true 24endif 25 26BUILDINFO_SH := build/make/tools/buildinfo.sh 27POST_PROCESS_PROPS := $(HOST_OUT_EXECUTABLES)/post_process_props$(HOST_EXECUTABLE_SUFFIX) 28 29# Emits a set of sysprops common to all partitions to a file. 30# $(1): Partition name 31# $(2): Output file name 32define generate-common-build-props 33 echo "####################################" >> $(2);\ 34 echo "# from generate-common-build-props" >> $(2);\ 35 echo "# These properties identify this partition image." >> $(2);\ 36 echo "####################################" >> $(2);\ 37 $(if $(filter system,$(1)),\ 38 echo "ro.product.$(1).brand=$(PRODUCT_SYSTEM_BRAND)" >> $(2);\ 39 echo "ro.product.$(1).device=$(PRODUCT_SYSTEM_DEVICE)" >> $(2);\ 40 echo "ro.product.$(1).manufacturer=$(PRODUCT_SYSTEM_MANUFACTURER)" >> $(2);\ 41 echo "ro.product.$(1).model=$(PRODUCT_SYSTEM_MODEL)" >> $(2);\ 42 echo "ro.product.$(1).name=$(PRODUCT_SYSTEM_NAME)" >> $(2);\ 43 ,\ 44 echo "ro.product.$(1).brand=$(PRODUCT_BRAND)" >> $(2);\ 45 echo "ro.product.$(1).device=$(TARGET_DEVICE)" >> $(2);\ 46 echo "ro.product.$(1).manufacturer=$(PRODUCT_MANUFACTURER)" >> $(2);\ 47 echo "ro.product.$(1).model=$(PRODUCT_MODEL)" >> $(2);\ 48 echo "ro.product.$(1).name=$(TARGET_PRODUCT)" >> $(2);\ 49 )\ 50 echo "ro.$(1).build.date=`$(DATE_FROM_FILE)`" >> $(2);\ 51 echo "ro.$(1).build.date.utc=`$(DATE_FROM_FILE) +%s`" >> $(2);\ 52 echo "ro.$(1).build.fingerprint=$(BUILD_FINGERPRINT_FROM_FILE)" >> $(2);\ 53 echo "ro.$(1).build.id=$(BUILD_ID)" >> $(2);\ 54 echo "ro.$(1).build.tags=$(BUILD_VERSION_TAGS)" >> $(2);\ 55 echo "ro.$(1).build.type=$(TARGET_BUILD_VARIANT)" >> $(2);\ 56 echo "ro.$(1).build.version.incremental=$(BUILD_NUMBER_FROM_FILE)" >> $(2);\ 57 echo "ro.$(1).build.version.release=$(PLATFORM_VERSION)" >> $(2);\ 58 echo "ro.$(1).build.version.sdk=$(PLATFORM_SDK_VERSION)" >> $(2);\ 59 60endef 61 62# Rule for generating <partition>/[etc/]build.prop file 63# 64# $(1): partition name 65# $(2): path to the output 66# $(3): path to the input *.prop files. The contents of the files are directly 67# emitted to the output 68# $(4): list of variable names each of which contains name=value pairs 69# $(5): optional list of prop names to force remove from the output. Properties from both 70# $(3) and (4) are affected. 71define build-properties 72ALL_DEFAULT_INSTALLED_MODULES += $(2) 73 74$(eval # Properties can be assigned using `prop ?= value` or `prop = value` syntax.) 75$(eval # Eliminate spaces around the ?= and = separators.) 76$(foreach name,$(strip $(4)),\ 77 $(eval _temp := $$(call collapse-pairs,$$($(name)),?=))\ 78 $(eval _resolved_$(name) := $$(call collapse-pairs,$$(_temp),=))\ 79) 80 81$(eval # Implement the legacy behavior when BUILD_BROKEN_DUP_SYSPROP is on.) 82$(eval # Optional assignments are all converted to normal assignments and) 83$(eval # when their duplicates the first one wins) 84$(if $(filter true,$(BUILD_BROKEN_DUP_SYSPROP)),\ 85 $(foreach name,$(strip $(4)),\ 86 $(eval _temp := $$(subst ?=,=,$$(_resolved_$(name))))\ 87 $(eval _resolved_$(name) := $$(call uniq-pairs-by-first-component,$$(_resolved_$(name)),=))\ 88 )\ 89 $(eval _option := --allow-dup)\ 90) 91 92$(2): $(POST_PROCESS_PROPS) $(INTERNAL_BUILD_ID_MAKEFILE) $(API_FINGERPRINT) $(3) 93 $(hide) echo Building $$@ 94 $(hide) mkdir -p $$(dir $$@) 95 $(hide) rm -f $$@ && touch $$@ 96 $(hide) $$(call generate-common-build-props,$(call to-lower,$(strip $(1))),$$@) 97 $(hide) $(foreach file,$(strip $(3)),\ 98 if [ -f "$(file)" ]; then\ 99 echo "" >> $$@;\ 100 echo "####################################" >> $$@;\ 101 echo "# from $(file)" >> $$@;\ 102 echo "####################################" >> $$@;\ 103 cat $(file) >> $$@;\ 104 fi;) 105 $(hide) $(foreach name,$(strip $(4)),\ 106 echo "" >> $$@;\ 107 echo "####################################" >> $$@;\ 108 echo "# from variable $(name)" >> $$@;\ 109 echo "####################################" >> $$@;\ 110 $$(foreach line,$$(_resolved_$(name)),\ 111 echo "$$(line)" >> $$@;\ 112 )\ 113 ) 114 $(hide) $(POST_PROCESS_PROPS) $$(_option) $$@ $(5) 115 $(hide) echo "# end of file" >> $$@ 116endef 117 118# ----------------------------------------------------------------- 119# Define fingerprint, thumbprint, and version tags for the current build 120# 121# BUILD_VERSION_TAGS is a comma-separated list of tags chosen by the device 122# implementer that further distinguishes the build. It's basically defined 123# by the device implementer. Here, we are adding a mandatory tag that 124# identifies the signing config of the build. 125BUILD_VERSION_TAGS := $(BUILD_VERSION_TAGS) 126ifeq ($(TARGET_BUILD_TYPE),debug) 127 BUILD_VERSION_TAGS += debug 128endif 129# The "test-keys" tag marks builds signed with the old test keys, 130# which are available in the SDK. "dev-keys" marks builds signed with 131# non-default dev keys (usually private keys from a vendor directory). 132# Both of these tags will be removed and replaced with "release-keys" 133# when the target-files is signed in a post-build step. 134ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/make/target/product/security/testkey) 135BUILD_KEYS := test-keys 136else 137BUILD_KEYS := dev-keys 138endif 139BUILD_VERSION_TAGS += $(BUILD_KEYS) 140BUILD_VERSION_TAGS := $(subst $(space),$(comma),$(sort $(BUILD_VERSION_TAGS))) 141 142# BUILD_FINGERPRINT is used used to uniquely identify the combined build and 143# product; used by the OTA server. 144ifeq (,$(strip $(BUILD_FINGERPRINT))) 145 ifeq ($(strip $(HAS_BUILD_NUMBER)),false) 146 BF_BUILD_NUMBER := $(BUILD_USERNAME)$$($(DATE_FROM_FILE) +%m%d%H%M) 147 else 148 BF_BUILD_NUMBER := $(file <$(BUILD_NUMBER_FILE)) 149 endif 150 BUILD_FINGERPRINT := $(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS) 151endif 152# unset it for safety. 153BF_BUILD_NUMBER := 154 155BUILD_FINGERPRINT_FILE := $(PRODUCT_OUT)/build_fingerprint.txt 156ifneq (,$(shell mkdir -p $(PRODUCT_OUT) && echo $(BUILD_FINGERPRINT) >$(BUILD_FINGERPRINT_FILE) && grep " " $(BUILD_FINGERPRINT_FILE))) 157 $(error BUILD_FINGERPRINT cannot contain spaces: "$(file <$(BUILD_FINGERPRINT_FILE))") 158endif 159BUILD_FINGERPRINT_FROM_FILE := $$(cat $(BUILD_FINGERPRINT_FILE)) 160# unset it for safety. 161BUILD_FINGERPRINT := 162 163# BUILD_THUMBPRINT is used to uniquely identify the system build; used by the 164# OTA server. This purposefully excludes any product-specific variables. 165ifeq (,$(strip $(BUILD_THUMBPRINT))) 166 BUILD_THUMBPRINT := $(PLATFORM_VERSION)/$(BUILD_ID)/$(BUILD_NUMBER_FROM_FILE):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS) 167endif 168 169BUILD_THUMBPRINT_FILE := $(PRODUCT_OUT)/build_thumbprint.txt 170ifneq (,$(shell mkdir -p $(PRODUCT_OUT) && echo $(BUILD_THUMBPRINT) >$(BUILD_THUMBPRINT_FILE) && grep " " $(BUILD_THUMBPRINT_FILE))) 171 $(error BUILD_THUMBPRINT cannot contain spaces: "$(file <$(BUILD_THUMBPRINT_FILE))") 172endif 173BUILD_THUMBPRINT_FROM_FILE := $$(cat $(BUILD_THUMBPRINT_FILE)) 174# unset it for safety. 175BUILD_THUMBPRINT := 176 177# ----------------------------------------------------------------- 178# Define human readable strings that describe this build 179# 180 181# BUILD_ID: detail info; has the same info as the build fingerprint 182BUILD_DESC := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS) 183 184# BUILD_DISPLAY_ID is shown under Settings -> About Phone 185ifeq ($(TARGET_BUILD_VARIANT),user) 186 # User builds should show: 187 # release build number or branch.buld_number non-release builds 188 189 # Dev. branches should have DISPLAY_BUILD_NUMBER set 190 ifeq (true,$(DISPLAY_BUILD_NUMBER)) 191 BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER_FROM_FILE) $(BUILD_KEYS) 192 else 193 BUILD_DISPLAY_ID := $(BUILD_ID) $(BUILD_KEYS) 194 endif 195else 196 # Non-user builds should show detailed build information 197 BUILD_DISPLAY_ID := $(BUILD_DESC) 198endif 199 200# TARGET_BUILD_FLAVOR and ro.build.flavor are used only by the test 201# harness to distinguish builds. Only add _asan for a sanitized build 202# if it isn't already a part of the flavor (via a dedicated lunch 203# config for example). 204TARGET_BUILD_FLAVOR := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) 205ifneq (, $(filter address, $(SANITIZE_TARGET))) 206ifeq (,$(findstring _asan,$(TARGET_BUILD_FLAVOR))) 207TARGET_BUILD_FLAVOR := $(TARGET_BUILD_FLAVOR)_asan 208endif 209endif 210 211KNOWN_OEM_THUMBPRINT_PROPERTIES := \ 212 ro.product.brand \ 213 ro.product.name \ 214 ro.product.device 215OEM_THUMBPRINT_PROPERTIES := $(filter $(KNOWN_OEM_THUMBPRINT_PROPERTIES),\ 216 $(PRODUCT_OEM_PROPERTIES)) 217KNOWN_OEM_THUMBPRINT_PROPERTIES:= 218 219# ----------------------------------------------------------------- 220# system/build.prop 221# 222# Note: parts of this file that can't be generated by the build-properties 223# macro are manually created as separate files and then fed into the macro 224 225# Accepts a whitespace separated list of product locales such as 226# (en_US en_AU en_GB...) and returns the first locale in the list with 227# underscores replaced with hyphens. In the example above, this will 228# return "en-US". 229define get-default-product-locale 230$(strip $(subst _,-, $(firstword $(1)))) 231endef 232 233gen_from_buildinfo_sh := $(call intermediates-dir-for,PACKAGING,system_build_prop)/buildinfo.prop 234$(gen_from_buildinfo_sh): $(INTERNAL_BUILD_ID_MAKEFILE) $(API_FINGERPRINT) 235 $(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \ 236 TARGET_BUILD_FLAVOR="$(TARGET_BUILD_FLAVOR)" \ 237 TARGET_DEVICE="$(TARGET_DEVICE)" \ 238 PRODUCT_DEFAULT_LOCALE="$(call get-default-product-locale,$(PRODUCT_LOCALES))" \ 239 PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \ 240 PRIVATE_BUILD_DESC="$(BUILD_DESC)" \ 241 BUILD_ID="$(BUILD_ID)" \ 242 BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \ 243 DATE="$(DATE_FROM_FILE)" \ 244 BUILD_USERNAME="$(BUILD_USERNAME)" \ 245 BUILD_HOSTNAME="$(BUILD_HOSTNAME)" \ 246 BUILD_NUMBER="$(BUILD_NUMBER_FROM_FILE)" \ 247 BOARD_BUILD_SYSTEM_ROOT_IMAGE="$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)" \ 248 PLATFORM_VERSION="$(PLATFORM_VERSION)" \ 249 PLATFORM_VERSION_LAST_STABLE="$(PLATFORM_VERSION_LAST_STABLE)" \ 250 PLATFORM_SECURITY_PATCH="$(PLATFORM_SECURITY_PATCH)" \ 251 PLATFORM_BASE_OS="$(PLATFORM_BASE_OS)" \ 252 PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \ 253 PLATFORM_PREVIEW_SDK_VERSION="$(PLATFORM_PREVIEW_SDK_VERSION)" \ 254 PLATFORM_PREVIEW_SDK_FINGERPRINT="$$(cat $(API_FINGERPRINT))" \ 255 PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \ 256 PLATFORM_VERSION_ALL_CODENAMES="$(PLATFORM_VERSION_ALL_CODENAMES)" \ 257 PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION="$(PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION)" \ 258 BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \ 259 $(if $(OEM_THUMBPRINT_PROPERTIES),BUILD_THUMBPRINT="$(BUILD_THUMBPRINT_FROM_FILE)") \ 260 TARGET_CPU_ABI_LIST="$(TARGET_CPU_ABI_LIST)" \ 261 TARGET_CPU_ABI_LIST_32_BIT="$(TARGET_CPU_ABI_LIST_32_BIT)" \ 262 TARGET_CPU_ABI_LIST_64_BIT="$(TARGET_CPU_ABI_LIST_64_BIT)" \ 263 TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \ 264 TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \ 265 bash $(BUILDINFO_SH) > $@ 266 267ifneq ($(PRODUCT_OEM_PROPERTIES),) 268import_oem_prop := $(call intermediates-dir-for,ETC,system_build_prop)/oem.prop 269 270$(import_oem_prop): 271 $(hide) echo "#" >> $@; \ 272 echo "# PRODUCT_OEM_PROPERTIES" >> $@; \ 273 echo "#" >> $@; 274 $(hide) $(foreach prop,$(PRODUCT_OEM_PROPERTIES), \ 275 echo "import /oem/oem.prop $(prop)" >> $@;) 276else 277import_oem_prop := 278endif 279 280ifdef TARGET_SYSTEM_PROP 281system_prop_file := $(TARGET_SYSTEM_PROP) 282else 283system_prop_file := $(wildcard $(TARGET_DEVICE_DIR)/system.prop) 284endif 285 286_prop_files_ := \ 287 $(import_oem_prop) \ 288 $(gen_from_buildinfo_sh) \ 289 $(system_prop_file) 290 291# Order matters here. When there are duplicates, the last one wins. 292# TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter 293_prop_vars_ := \ 294 ADDITIONAL_SYSTEM_PROPERTIES \ 295 PRODUCT_SYSTEM_PROPERTIES 296 297# TODO(b/117892318): deprecate this 298_prop_vars_ += \ 299 PRODUCT_SYSTEM_DEFAULT_PROPERTIES 300 301ifndef property_overrides_split_enabled 302_prop_vars_ += \ 303 ADDITIONAL_VENDOR_PROPERTIES 304endif 305 306_blacklist_names_ := \ 307 $(PRODUCT_SYSTEM_PROPERTY_BLACKLIST) \ 308 ro.product.first_api_level 309 310INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop 311 312$(eval $(call build-properties,system,$(INSTALLED_BUILD_PROP_TARGET),\ 313$(_prop_files_),$(_prop_vars_),\ 314$(_blacklist_names_))) 315 316# ----------------------------------------------------------------- 317# vendor/build.prop 318# 319_prop_files_ := $(if $(TARGET_VENDOR_PROP),\ 320 $(TARGET_VENDOR_PROP),\ 321 $(wildcard $(TARGET_DEVICE_DIR)/vendor.prop)) 322 323android_info_prop := $(call intermediates-dir-for,ETC,android_info_prop)/android_info.prop 324$(android_info_prop): $(INSTALLED_ANDROID_INFO_TXT_TARGET) 325 cat $< | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' > $@ 326 327_prop_files_ += $(android_info_pro) 328 329ifdef property_overrides_split_enabled 330# Order matters here. When there are duplicates, the last one wins. 331# TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter 332_prop_vars_ := \ 333 ADDITIONAL_VENDOR_PROPERTIES \ 334 PRODUCT_VENDOR_PROPERTIES 335 336# TODO(b/117892318): deprecate this 337_prop_vars_ += \ 338 PRODUCT_DEFAULT_PROPERTY_OVERRIDES \ 339 PRODUCT_PROPERTY_OVERRIDES 340else 341_prop_vars_ := 342endif 343 344INSTALLED_VENDOR_BUILD_PROP_TARGET := $(TARGET_OUT_VENDOR)/build.prop 345$(eval $(call build-properties,\ 346 vendor,\ 347 $(INSTALLED_VENDOR_BUILD_PROP_TARGET),\ 348 $(_prop_files_),\ 349 $(_prop_vars_),\ 350 $(PRODUCT_VENDOR_PROPERTY_BLACKLIST))) 351 352# ----------------------------------------------------------------- 353# product/etc/build.prop 354# 355 356_prop_files_ := $(if $(TARGET_PRODUCT_PROP),\ 357 $(TARGET_PRODUCT_PROP),\ 358 $(wildcard $(TARGET_DEVICE_DIR)/product.prop)) 359 360# Order matters here. When there are duplicates, the last one wins. 361# TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter 362_prop_vars_ := \ 363 ADDITIONAL_PRODUCT_PROPERTIES \ 364 PRODUCT_PRODUCT_PROPERTIES 365 366INSTALLED_PRODUCT_BUILD_PROP_TARGET := $(TARGET_OUT_PRODUCT)/etc/build.prop 367$(eval $(call build-properties,\ 368 product,\ 369 $(INSTALLED_PRODUCT_BUILD_PROP_TARGET),\ 370 $(_prop_files_),\ 371 $(_prop_vars_),\ 372 $(empty))) 373 374# ---------------------------------------------------------------- 375# odm/etc/build.prop 376# 377_prop_files_ := $(if $(TARGET_ODM_PROP),\ 378 $(TARGET_ODM_PROP),\ 379 $(wildcard $(TARGET_DEVICE_DIR)/odm.prop)) 380 381# Order matters here. When there are duplicates, the last one wins. 382# TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter 383_prop_vars_ := \ 384 ADDITIONAL_ODM_PROPERTIES \ 385 PRODUCT_ODM_PROPERTIES 386 387INSTALLED_ODM_BUILD_PROP_TARGET := $(TARGET_OUT_ODM)/etc/build.prop 388$(eval $(call build-properties,\ 389 odm,\ 390 $(INSTALLED_ODM_BUILD_PROP_TARGET),\ 391 $(_prop_files),\ 392 $(_prop_vars_),\ 393 $(empty))) 394 395# ---------------------------------------------------------------- 396# vendor_dlkm/etc/build.prop 397# 398 399INSTALLED_VENDOR_DLKM_BUILD_PROP_TARGET := $(TARGET_OUT_VENDOR_DLKM)/etc/build.prop 400$(eval $(call build-properties,\ 401 vendor_dlkm,\ 402 $(INSTALLED_VENDOR_DLKM_BUILD_PROP_TARGET))) 403 404# ---------------------------------------------------------------- 405# odm_dlkm/etc/build.prop 406# 407 408INSTALLED_ODM_DLKM_BUILD_PROP_TARGET := $(TARGET_OUT_ODM_DLKM)/etc/build.prop 409$(eval $(call build-properties,\ 410 odm_dlkm,\ 411 $(INSTALLED_ODM_DLKM_BUILD_PROP_TARGET))) 412 413# ----------------------------------------------------------------- 414# system_ext/etc/build.prop 415# 416_prop_files_ := $(if $(TARGET_SYSTEM_EXT_PROP),\ 417 $(TARGET_SYSTEM_EXT_PROP),\ 418 $(wildcard $(TARGET_DEVICE_DIR)/system_ext.prop)) 419 420# Order matters here. When there are duplicates, the last one wins. 421# TODO(b/117892318): don't allow duplicates so that the ordering doesn't matter 422_prop_vars_ := PRODUCT_SYSTEM_EXT_PROPERTIES 423 424INSTALLED_SYSTEM_EXT_BUILD_PROP_TARGET := $(TARGET_OUT_SYSTEM_EXT)/etc/build.prop 425$(eval $(call build-properties,\ 426 system_ext,\ 427 $(INSTALLED_SYSTEM_EXT_BUILD_PROP_TARGET),\ 428 $(_prop_files_),\ 429 $(_prop_vars_),\ 430 $(empty))) 431