• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2008 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# ---------------------------------------------------------------
18# Generic functions
19# TODO: Move these to definitions.make once we're able to include
20# definitions.make before config.make.
21
22###########################################################
23## Return non-empty if $(1) is a C identifier; i.e., if it
24## matches /^[a-zA-Z_][a-zA-Z0-9_]*$/.  We do this by first
25## making sure that it isn't empty and doesn't start with
26## a digit, then by removing each valid character.  If the
27## final result is empty, then it was a valid C identifier.
28##
29## $(1): word to check
30###########################################################
31
32_ici_digits := 0 1 2 3 4 5 6 7 8 9
33_ici_alphaunderscore := \
34    a b c d e f g h i j k l m n o p q r s t u v w x y z \
35    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _
36define is-c-identifier
37$(strip \
38  $(if $(1), \
39    $(if $(filter $(addsuffix %,$(_ici_digits)),$(1)), \
40     , \
41      $(eval w := $(1)) \
42      $(foreach c,$(_ici_digits) $(_ici_alphaunderscore), \
43        $(eval w := $(subst $(c),,$(w))) \
44       ) \
45      $(if $(w),,TRUE) \
46      $(eval w :=) \
47     ) \
48   ) \
49 )
50endef
51
52# TODO: push this into the combo files; unfortunately, we don't even
53# know HOST_OS at this point.
54trysed := $(shell echo a | sed -E -e 's/a/b/' 2>/dev/null)
55ifeq ($(trysed),b)
56  SED_EXTENDED := sed -E
57else
58  trysed := $(shell echo c | sed -r -e 's/c/d/' 2>/dev/null)
59  ifeq ($(trysed),d)
60    SED_EXTENDED := sed -r
61  else
62    $(error Unknown sed version)
63  endif
64endif
65
66###########################################################
67## List all of the files in a subdirectory in a format
68## suitable for PRODUCT_COPY_FILES and
69## PRODUCT_SDK_ADDON_COPY_FILES
70##
71## $(1): Glob to match file name
72## $(2): Source directory
73## $(3): Target base directory
74###########################################################
75
76define find-copy-subdir-files
77$(shell find $(2) -name "$(1)" -type f | $(SED_EXTENDED) "s:($(2)/?(.*)):\\1\\:$(3)/\\2:" | sed "s://:/:g" | sort)
78endef
79
80#
81# Convert file file to the PRODUCT_COPY_FILES/PRODUCT_SDK_ADDON_COPY_FILES
82# format: for each file F return $(F):$(PREFIX)/$(notdir $(F))
83# $(1): files list
84# $(2): prefix
85
86define copy-files
87$(foreach f,$(1),$(f):$(2)/$(notdir $(f)))
88endef
89
90#
91# Convert the list of file names to the list of PRODUCT_COPY_FILES items
92# $(1): from pattern
93# $(2): to pattern
94# $(3): file names
95# E.g., calling product-copy-files-by-pattern with
96#   (from/%, to/%, a b)
97# returns
98#   from/a:to/a from/b:to/b
99define product-copy-files-by-pattern
100$(join $(patsubst %,$(1),$(3)),$(patsubst %,:$(2),$(3)))
101endef
102
103# Return empty unless the board matches
104define is-board-platform2
105$(filter $(1), $(TARGET_BOARD_PLATFORM))
106endef
107
108# Return empty unless the board is in the list
109define is-board-platform-in-list2
110$(filter $(1),$(TARGET_BOARD_PLATFORM))
111endef
112
113# Return empty unless the board is QCOM
114define is-vendor-board-qcom
115$(if $(strip $(TARGET_BOARD_PLATFORM) $(QCOM_BOARD_PLATFORMS)),$(filter $(TARGET_BOARD_PLATFORM),$(QCOM_BOARD_PLATFORMS)),\
116  $(error both TARGET_BOARD_PLATFORM=$(TARGET_BOARD_PLATFORM) and QCOM_BOARD_PLATFORMS=$(QCOM_BOARD_PLATFORMS)))
117endef
118
119# ---------------------------------------------------------------
120# Check for obsolete PRODUCT- and APP- goals
121ifeq ($(CALLED_FROM_SETUP),true)
122product_goals := $(strip $(filter PRODUCT-%,$(MAKECMDGOALS)))
123ifdef product_goals
124  $(error The PRODUCT-* goal is no longer supported. Use `TARGET_PRODUCT=<product> m droid` instead)
125endif
126unbundled_goals := $(strip $(filter APP-%,$(MAKECMDGOALS)))
127ifdef unbundled_goals
128  $(error The APP-* goal is no longer supported. Use `TARGET_BUILD_APPS="<app>" m droid` instead)
129endif # unbundled_goals
130endif
131
132# Default to building dalvikvm on hosts that support it...
133ifeq ($(HOST_OS),linux)
134# ... or if the if the option is already set
135ifeq ($(WITH_HOST_DALVIK),)
136  WITH_HOST_DALVIK := true
137endif
138endif
139
140# ---------------------------------------------------------------
141# Include the product definitions.
142# We need to do this to translate TARGET_PRODUCT into its
143# underlying TARGET_DEVICE before we start defining any rules.
144#
145include $(BUILD_SYSTEM)/node_fns.mk
146include $(BUILD_SYSTEM)/product.mk
147
148# Read all product definitions.
149#
150# Products are defined in AndroidProducts.mk files:
151android_products_makefiles := $(file <$(OUT_DIR)/.module_paths/AndroidProducts.mk.list) \
152  $(SRC_TARGET_DIR)/product/AndroidProducts.mk
153
154# An AndroidProduct.mk file sets the following variables:
155#   PRODUCT_MAKEFILES specifies product makefiles. Each item in this list
156#     is either a <product>:path/to/file.mk, or just path/to/<product.mk>
157#   COMMON_LUNCH_CHOICES specifies <product>-<variant> values to be shown
158#     in the `lunch` menu
159#   STARLARK_OPT_IN_PRODUCTS specifies products to use Starlark-based
160#     product configuration by default
161
162# Builds a list of first/second elements of each pair:
163#   $(call _first,a:A b:B,:) returns 'a b'
164#   $(call _second,a-A b-B,-) returns 'A B'
165_first=$(filter-out $(2)%,$(subst $(2),$(space)$(2),$(1)))
166_second=$(filter-out %$(2),$(subst $(2),$(2)$(space),$(1)))
167
168# Returns <product>:<path> pair from a PRODUCT_MAKEFILE item.
169# If an item is <product>:path/to/file.mk, return it as is,
170# otherwise assume that an item is path/to/<product>.mk and
171# return <product>:path/to/<product>.mk
172_product-spec=$(strip $(if $(findstring :,$(1)),$(1),$(basename $(notdir $(1))):$(1)))
173
174# Reads given AndroidProduct.mk file and sets the following variables:
175#  ap_product_paths -- the list of <product>:<path> pairs
176#  ap_common_lunch_choices -- the list of <product>-<build variant> items
177#  ap_products_using_starlark_config -- the list of products using starlark config
178# In addition, validates COMMON_LUNCH_CHOICES and STARLARK_OPT_IN_PRODUCTS values
179define _read-ap-file
180  $(eval PRODUCT_MAKEFILES :=) \
181  $(eval COMMON_LUNCH_CHOICES :=) \
182  $(eval STARLARK_OPT_IN_PRODUCTS := ) \
183  $(eval ap_product_paths :=) \
184  $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
185  $(eval include $(f)) \
186  $(foreach p, $(PRODUCT_MAKEFILES),$(eval ap_product_paths += $(call _product-spec,$(p)))) \
187  $(eval ap_common_lunch_choices  := $(COMMON_LUNCH_CHOICES)) \
188  $(eval ap_products_using_starlark_config := $(STARLARK_OPT_IN_PRODUCTS)) \
189  $(eval _products := $(call _first,$(ap_product_paths),:)) \
190  $(eval _bad := $(filter-out $(_products),$(call _first,$(ap_common_lunch_choices),-))) \
191  $(if $(_bad),$(error COMMON_LUNCH_CHOICES contains products(s) not defined in this file: $(_bad))) \
192  $(eval _bad := $(filter-out %-eng %-userdebug %-user,$(ap_common_lunch_choices))) \
193  $(if $(_bad),$(error invalid variant in COMMON_LUNCH_CHOICES: $(_bad)))
194  $(eval _bad := $(filter-out $(_products),$(ap_products_using_starlark_config))) \
195  $(if $(_bad),$(error STARLARK_OPT_IN_PRODUCTS contains product(s) not defined in this file: $(_bad)))
196endef
197
198# Build cumulative lists of all product specs/lunch choices/Starlark-based products.
199product_paths :=
200common_lunch_choices :=
201products_using_starlark_config :=
202$(foreach f,$(android_products_makefiles), \
203    $(call _read-ap-file,$(f)) \
204    $(eval product_paths += $(ap_product_paths)) \
205    $(eval common_lunch_choices += $(ap_common_lunch_choices)) \
206    $(eval products_using_starlark_config += $(ap_products_using_starlark_config)) \
207)
208
209# Dedup, extract product names, etc.
210product_paths := $(sort $(product_paths))
211all_named_products := $(sort $(call _first,$(product_paths),:))
212current_product_makefile := $(call _second,$(filter $(TARGET_PRODUCT):%,$(product_paths)),:)
213COMMON_LUNCH_CHOICES := $(sort $(common_lunch_choices))
214
215# Check that there are no duplicate product names
216$(foreach p,$(all_named_products), \
217  $(if $(filter 1,$(words $(filter $(p):%,$(product_paths)))),, \
218    $(error Product name must be unique, "$(p)" used by $(call _second,$(filter $(p):%,$(product_paths)),:))))
219
220ifneq ($(ALLOW_RULES_IN_PRODUCT_CONFIG),)
221_product_config_saved_KATI_ALLOW_RULES := $(.KATI_ALLOW_RULES)
222.KATI_ALLOW_RULES := $(ALLOW_RULES_IN_PRODUCT_CONFIG)
223endif
224
225ifeq (,$(current_product_makefile))
226  $(error Cannot locate config makefile for product "$(TARGET_PRODUCT)")
227endif
228
229ifneq (,$(filter $(TARGET_PRODUCT),$(products_using_starlark_config)))
230  RBC_PRODUCT_CONFIG := true
231endif
232
233ifndef RBC_PRODUCT_CONFIG
234$(call import-products, $(current_product_makefile))
235else
236  $(shell mkdir -p $(OUT_DIR)/rbc)
237  $(call dump-variables-rbc, $(OUT_DIR)/rbc/make_vars_pre_product_config.mk)
238
239  $(shell $(OUT_DIR)/mk2rbc \
240    --mode=write -r --outdir $(OUT_DIR)/rbc \
241    --launcher=$(OUT_DIR)/rbc/launcher.rbc \
242    --input_variables=$(OUT_DIR)/rbc/make_vars_pre_product_config.mk \
243    --makefile_list=$(OUT_DIR)/.module_paths/configuration.list \
244    $(current_product_makefile))
245  ifneq ($(.SHELLSTATUS),0)
246    $(error product configuration converter failed: $(.SHELLSTATUS))
247  endif
248
249  $(shell build/soong/scripts/update_out $(OUT_DIR)/rbc/rbc_product_config_results.mk \
250    $(OUT_DIR)/rbcrun --mode=rbc $(OUT_DIR)/rbc/launcher.rbc)
251  ifneq ($(.SHELLSTATUS),0)
252    $(error product configuration runner failed: $(.SHELLSTATUS))
253  endif
254
255  include $(OUT_DIR)/rbc/rbc_product_config_results.mk
256endif
257
258# This step was already handled in the RBC product configuration.
259ifeq ($(RBC_PRODUCT_CONFIG)$(SKIP_ARTIFACT_PATH_REQUIREMENT_PRODUCTS_CHECK),)
260# Import all the products that have made artifact path requirements, so that we can verify
261# the artifacts they produce. They might be intermediate makefiles instead of real products.
262$(foreach makefile,$(ARTIFACT_PATH_REQUIREMENT_PRODUCTS),\
263  $(if $(filter-out $(makefile),$(PRODUCTS)),$(eval $(call import-products,$(makefile))))\
264)
265endif
266
267INTERNAL_PRODUCT := $(current_product_makefile)
268# Strip and assign the PRODUCT_ variables.
269$(call strip-product-vars)
270
271# Quick check
272$(check-current-product)
273
274ifneq ($(ALLOW_RULES_IN_PRODUCT_CONFIG),)
275.KATI_ALLOW_RULES := $(_saved_KATI_ALLOW_RULES)
276_product_config_saved_KATI_ALLOW_RULES :=
277endif
278
279############################################################################
280
281current_product_makefile :=
282
283# AOSP and Google products currently share the same `apex_contributions` in next.
284# This causes issues when building <aosp_product>-next-userdebug in main.
285# Create a temporary allowlist to ignore the google apexes listed in `contents` of apex_contributions of `next`
286# *for aosp products*.
287# TODO(b/308187268): Remove this denylist mechanism
288# Use PRODUCT_PACKAGES to determine if this is an aosp product. aosp products do not use google signed apexes.
289ignore_apex_contributions :=
290ifeq (,$(findstring com.google.android.conscrypt,$(PRODUCT_PACKAGES))$(findstring com.google.android.go.conscrypt,$(PRODUCT_PACKAGES)))
291  ignore_apex_contributions := true
292endif
293ifeq (true,$(PRODUCT_MODULE_BUILD_FROM_SOURCE))
294  ignore_apex_contributions := true
295endif
296ifneq ($(EMMA_INSTRUMENT)$(EMMA_INSTRUMENT_STATIC)$(EMMA_INSTRUMENT_FRAMEWORK)$(CLANG_COVERAGE)$(NATIVE_COVERAGE_PATHS),)
297# Coverage builds for TARGET_RELEASE=foo should always build from source,
298# even if TARGET_RELEASE=foo uses prebuilt mainline modules.
299# This is necessary because the checked-in prebuilts were generated with
300# instrumentation turned off.
301  ignore_apex_contributions := true
302endif
303
304ifeq (true, $(ignore_apex_contributions))
305PRODUCT_BUILD_IGNORE_APEX_CONTRIBUTION_CONTENTS := true
306endif
307
308#############################################################################
309
310# Quick check and assign default values
311
312TARGET_DEVICE := $(PRODUCT_DEVICE)
313
314# Allow overriding PLATFORM_BASE_OS when PRODUCT_BASE_OS is defined
315ifdef PRODUCT_BASE_OS
316  PLATFORM_BASE_OS := $(PRODUCT_BASE_OS)
317else
318  PLATFORM_BASE_OS := $(PLATFORM_BASE_OS_ENV_INPUT)
319endif
320.KATI_READONLY := PLATFORM_BASE_OS
321
322# TODO: also keep track of things like "port", "land" in product files.
323
324# Figure out which resoure configuration options to use for this
325# product.
326# If CUSTOM_LOCALES contains any locales not already included
327# in PRODUCT_LOCALES, add them to PRODUCT_LOCALES.
328extra_locales := $(filter-out $(PRODUCT_LOCALES),$(CUSTOM_LOCALES))
329ifneq (,$(extra_locales))
330  ifneq ($(CALLED_FROM_SETUP),true)
331    # Don't spam stdout, because envsetup.sh may be scraping values from it.
332    $(info Adding CUSTOM_LOCALES [$(extra_locales)] to PRODUCT_LOCALES [$(PRODUCT_LOCALES)])
333  endif
334  PRODUCT_LOCALES += $(extra_locales)
335  extra_locales :=
336endif
337
338# Add PRODUCT_LOCALES to PRODUCT_AAPT_CONFIG
339PRODUCT_AAPT_CONFIG := $(PRODUCT_LOCALES) $(PRODUCT_AAPT_CONFIG)
340
341# Keep a copy of the space-separated config
342PRODUCT_AAPT_CONFIG_SP := $(PRODUCT_AAPT_CONFIG)
343PRODUCT_AAPT_CONFIG := $(subst $(space),$(comma),$(PRODUCT_AAPT_CONFIG))
344
345###########################################################
346## Add 'platform:' prefix to jars not in <apex>:<module> format.
347##
348## This makes sure that a jar corresponds to ConfigureJarList format of <apex> and <module> pairs
349## where needed.
350##
351## $(1): a list of jars either in <module> or <apex>:<module> format
352###########################################################
353
354define qualify-platform-jars
355  $(foreach jar,$(1),$(if $(findstring :,$(jar)),,platform:)$(jar))
356endef
357
358# Extra boot jars must be appended at the end after common boot jars.
359PRODUCT_BOOT_JARS += $(PRODUCT_BOOT_JARS_EXTRA)
360
361PRODUCT_BOOT_JARS := $(call qualify-platform-jars,$(PRODUCT_BOOT_JARS))
362
363# b/191127295: force core-icu4j onto boot image. It comes from a non-updatable APEX jar, but has
364# historically been part of the boot image; even though APEX jars are not meant to be part of the
365# boot image.
366# TODO(b/191686720): remove PRODUCT_APEX_BOOT_JARS to avoid a special handling of core-icu4j
367# in make rules.
368PRODUCT_APEX_BOOT_JARS := $(filter-out com.android.i18n:core-icu4j,$(PRODUCT_APEX_BOOT_JARS))
369# All APEX jars come after /system and /system_ext jars, so adding core-icu4j at the end of the list
370PRODUCT_BOOT_JARS += com.android.i18n:core-icu4j
371
372# The extra system server jars must be appended at the end after common system server jars.
373PRODUCT_SYSTEM_SERVER_JARS += $(PRODUCT_SYSTEM_SERVER_JARS_EXTRA)
374
375PRODUCT_SYSTEM_SERVER_JARS := $(call qualify-platform-jars,$(PRODUCT_SYSTEM_SERVER_JARS))
376
377# Sort APEX boot and system server jars. We use deterministic alphabetical order
378# when constructing BOOTCLASSPATH and SYSTEMSERVERCLASSPATH definition on device
379# after an update. Enforce it in the build system as well to avoid recompiling
380# everything after an update due a change in the order.
381PRODUCT_APEX_BOOT_JARS := $(sort $(PRODUCT_APEX_BOOT_JARS))
382PRODUCT_APEX_SYSTEM_SERVER_JARS := $(sort $(PRODUCT_APEX_SYSTEM_SERVER_JARS))
383
384PRODUCT_STANDALONE_SYSTEM_SERVER_JARS := \
385  $(call qualify-platform-jars,$(PRODUCT_STANDALONE_SYSTEM_SERVER_JARS))
386
387ifndef PRODUCT_SYSTEM_NAME
388  PRODUCT_SYSTEM_NAME := $(PRODUCT_NAME)
389endif
390ifndef PRODUCT_SYSTEM_DEVICE
391  PRODUCT_SYSTEM_DEVICE := $(PRODUCT_DEVICE)
392endif
393ifndef PRODUCT_SYSTEM_BRAND
394  PRODUCT_SYSTEM_BRAND := $(PRODUCT_BRAND)
395endif
396ifndef PRODUCT_MODEL
397  PRODUCT_MODEL := $(PRODUCT_NAME)
398endif
399ifndef PRODUCT_SYSTEM_MODEL
400  PRODUCT_SYSTEM_MODEL := $(PRODUCT_MODEL)
401endif
402
403ifndef PRODUCT_MANUFACTURER
404  PRODUCT_MANUFACTURER := unknown
405endif
406ifndef PRODUCT_SYSTEM_MANUFACTURER
407  PRODUCT_SYSTEM_MANUFACTURER := $(PRODUCT_MANUFACTURER)
408endif
409
410ifndef PRODUCT_CHARACTERISTICS
411  TARGET_AAPT_CHARACTERISTICS := default
412else
413  TARGET_AAPT_CHARACTERISTICS := $(PRODUCT_CHARACTERISTICS)
414endif
415
416ifndef PRODUCT_SHIPPING_API_LEVEL
417  PRODUCT_SHIPPING_API_LEVEL := 10000
418endif
419
420ifdef PRODUCT_DEFAULT_DEV_CERTIFICATE
421  ifneq (1,$(words $(PRODUCT_DEFAULT_DEV_CERTIFICATE)))
422    $(error PRODUCT_DEFAULT_DEV_CERTIFICATE='$(PRODUCT_DEFAULT_DEV_CERTIFICATE)', \
423      only 1 certificate is allowed.)
424  endif
425endif
426
427$(foreach apexpair,$(PRODUCT_APEX_BOOT_JARS), \
428  $(foreach platformpair,$(PRODUCT_BOOT_JARS), \
429    $(eval apexjar := $(call word-colon,2,$(apexpair))) \
430    $(eval platformjar := $(call word-colon,2,$(platformpair))) \
431    $(if $(filter $(apexjar), $(platformjar)), \
432      $(error A jar in PRODUCT_APEX_BOOT_JARS must not be in PRODUCT_BOOT_JARS, but $(apexjar) is))))
433
434ENFORCE_SYSTEM_CERTIFICATE := $(PRODUCT_ENFORCE_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT)
435ENFORCE_SYSTEM_CERTIFICATE_ALLOW_LIST := $(PRODUCT_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT_ALLOW_LIST)
436
437PRODUCT_OTA_PUBLIC_KEYS := $(sort $(PRODUCT_OTA_PUBLIC_KEYS))
438PRODUCT_EXTRA_OTA_KEYS := $(sort $(PRODUCT_EXTRA_OTA_KEYS))
439PRODUCT_EXTRA_RECOVERY_KEYS := $(sort $(PRODUCT_EXTRA_RECOVERY_KEYS))
440
441PRODUCT_VALIDATION_CHECKS := $(sort $(PRODUCT_VALIDATION_CHECKS))
442
443# Resolve and setup per-module dex-preopt configs.
444DEXPREOPT_DISABLED_MODULES :=
445# If a module has multiple setups, the first takes precedence.
446_pdpmc_modules :=
447$(foreach c,$(PRODUCT_DEX_PREOPT_MODULE_CONFIGS),\
448  $(eval m := $(firstword $(subst =,$(space),$(c))))\
449  $(if $(filter $(_pdpmc_modules),$(m)),,\
450    $(eval _pdpmc_modules += $(m))\
451    $(eval cf := $(patsubst $(m)=%,%,$(c)))\
452    $(eval cf := $(subst $(_PDPMC_SP_PLACE_HOLDER),$(space),$(cf)))\
453    $(if $(filter disable,$(cf)),\
454      $(eval DEXPREOPT_DISABLED_MODULES += $(m)),\
455      $(eval DEXPREOPT.$(TARGET_PRODUCT).$(m).CONFIG := $(cf)))))
456_pdpmc_modules :=
457
458
459# Resolve and setup per-module sanitizer configs.
460# If a module has multiple setups, the first takes precedence.
461_psmc_modules :=
462$(foreach c,$(PRODUCT_SANITIZER_MODULE_CONFIGS),\
463  $(eval m := $(firstword $(subst =,$(space),$(c))))\
464  $(if $(filter $(_psmc_modules),$(m)),,\
465    $(eval _psmc_modules += $(m))\
466    $(eval cf := $(patsubst $(m)=%,%,$(c)))\
467    $(eval cf := $(subst $(_PSMC_SP_PLACE_HOLDER),$(space),$(cf)))\
468    $(eval SANITIZER.$(TARGET_PRODUCT).$(m).CONFIG := $(cf))))
469_psmc_modules :=
470
471# Reset ADB keys. If RELEASE_BUILD_USE_VARIANT_FLAGS is set look for
472# the value of a dedicated flag. Otherwise check if build variant is
473# non-debuggable.
474ifneq (,$(RELEASE_BUILD_USE_VARIANT_FLAGS))
475ifneq (,$(RELEASE_BUILD_PURGE_PRODUCT_ADB_KEYS))
476  PRODUCT_ADB_KEYS :=
477endif
478else ifeq (,$(filter eng userdebug,$(TARGET_BUILD_VARIANT)))
479  PRODUCT_ADB_KEYS :=
480endif
481
482ifneq ($(filter-out 0 1,$(words $(PRODUCT_ADB_KEYS))),)
483  $(error Only one file may be in PRODUCT_ADB_KEYS: $(PRODUCT_ADB_KEYS))
484endif
485
486# Show a warning wall of text if non-compliance-GSI products set this option.
487ifdef PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT
488  ifeq (,$(filter gsi_arm gsi_arm64 gsi_x86 gsi_x86_64 gsi_car_arm64 gsi_car_x86_64 gsi_tv_arm gsi_tv_arm64 clockwork_gsi_google_arm,$(PRODUCT_NAME)))
489    $(warning PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT is set but \
490      PRODUCT_NAME ($(PRODUCT_NAME)) doesn't look like a GSI for compliance \
491      testing. This is a special configuration for compliance GSI, so do make \
492      sure you understand the security implications before setting this \
493      option. If you don't know what this option does, then you probably \
494      shouldn't set this.)
495  endif
496endif
497
498ifndef PRODUCT_USE_DYNAMIC_PARTITIONS
499  PRODUCT_USE_DYNAMIC_PARTITIONS := $(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)
500endif
501
502# All requirements of PRODUCT_USE_DYNAMIC_PARTITIONS falls back to
503# PRODUCT_USE_DYNAMIC_PARTITIONS if not defined.
504ifndef PRODUCT_USE_DYNAMIC_PARTITION_SIZE
505  PRODUCT_USE_DYNAMIC_PARTITION_SIZE := $(PRODUCT_USE_DYNAMIC_PARTITIONS)
506endif
507
508ifndef PRODUCT_BUILD_SUPER_PARTITION
509  PRODUCT_BUILD_SUPER_PARTITION := $(PRODUCT_USE_DYNAMIC_PARTITIONS)
510endif
511
512ifeq ($(PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS),)
513  ifdef PRODUCT_SHIPPING_API_LEVEL
514    ifeq (true,$(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),29))
515      PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS := true
516    endif
517  endif
518endif
519
520ifeq ($(PRODUCT_SET_DEBUGFS_RESTRICTIONS),)
521  ifdef PRODUCT_SHIPPING_API_LEVEL
522    ifeq (true,$(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),31))
523      PRODUCT_SET_DEBUGFS_RESTRICTIONS := true
524    endif
525  endif
526endif
527
528# If build command defines OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS,
529# override PRODUCT_EXTRA_VNDK_VERSIONS with it.
530ifdef OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS
531  PRODUCT_EXTRA_VNDK_VERSIONS := $(OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS)
532endif
533
534###########################################
535# APEXes are by default not compressed
536#
537# APEX compression can be forcibly enabled (resp. disabled) by
538# setting OVERRIDE_PRODUCT_COMPRESSED_APEX to true (resp. false), e.g. by
539# setting the OVERRIDE_PRODUCT_COMPRESSED_APEX environment variable.
540ifdef OVERRIDE_PRODUCT_COMPRESSED_APEX
541  PRODUCT_COMPRESSED_APEX := $(OVERRIDE_PRODUCT_COMPRESSED_APEX)
542endif
543
544ifdef OVERRIDE_PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE
545  PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE := $(OVERRIDE_PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE)
546else ifeq ($(PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE),)
547  # Use ext4 as a default payload fs type
548  PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE := ext4
549endif
550ifeq ($(filter ext4 erofs,$(PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE)),)
551  $(error PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE should be either erofs or ext4,\
552    not $(PRODUCT_DEFAULT_APEX_PAYLOAD_TYPE).)
553endif
554
555$(KATI_obsolete_var OVERRIDE_PRODUCT_EXTRA_VNDK_VERSIONS \
556    ,Use PRODUCT_EXTRA_VNDK_VERSIONS instead)
557
558# If build command defines OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE,
559# override PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE with it unless it is
560# defined as `false`. If the value is `false` clear
561# PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE
562# OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE can be used for
563# testing only.
564ifdef OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE
565  ifeq (false,$(OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE))
566    PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE :=
567  else
568    PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE := $(OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE)
569  endif
570else ifeq ($(PRODUCT_SHIPPING_API_LEVEL),)
571  # No shipping level defined. Enforce the product interface by default.
572  PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE := true
573else ifeq ($(call math_gt,$(PRODUCT_SHIPPING_API_LEVEL),29),true)
574  # Enforce product interface if PRODUCT_SHIPPING_API_LEVEL is greater than 29.
575  PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE := true
576endif
577
578$(KATI_obsolete_var OVERRIDE_PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE,Use PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE instead)
579
580# From Android V, Define PRODUCT_PRODUCT_VNDK_VERSION as current by default.
581# This is required to make all devices have product variants.
582ifndef PRODUCT_PRODUCT_VNDK_VERSION
583  PRODUCT_PRODUCT_VNDK_VERSION := current
584endif
585
586ifdef PRODUCT_ENFORCE_RRO_EXEMPTED_TARGETS
587    $(error PRODUCT_ENFORCE_RRO_EXEMPTED_TARGETS is deprecated, consider using RRO for \
588      $(PRODUCT_ENFORCE_RRO_EXEMPTED_TARGETS))
589endif
590
591# This table maps sdk version 35 to vendor api level 202404 and assumes yearly
592# release for the same month. If 10000 API level or more is used, which usually
593# represents 'current' or 'future' API levels, several zeros are added to
594# preserve ordering. Specifically API level 10,000 is converted to 10,000,000
595# which importantly is greater than 202404 = 202,404. This convention will break
596# in 100,000 CE, which is the closest multiple of 10 that doesn't break earlier
597# than 10,000 as an API level breaks.
598define sdk-to-vendor-api-level
599$(if $(call math_lt_or_eq,$(1),34),$(1),$(if $(call math_lt,$(1),10000),20$(call int_subtract,$(1),11)04,$(1)000))
600endef
601
602ifneq ($(call sdk-to-vendor-api-level,34),34)
603$(error sdk-to-vendor-api-level is broken for pre-Trunk-Stable SDKs)
604endif
605ifneq ($(call sdk-to-vendor-api-level,35),202404)
606$(error sdk-to-vendor-api-level is broken for post-Trunk-Stable SDKs)
607endif
608ifneq ($(call sdk-to-vendor-api-level,10000),10000000)
609$(error sdk-to-vendor-api-level is broken for current $(call sdk-to-vendor-api-level,10000))
610endif
611
612ifdef PRODUCT_SHIPPING_VENDOR_API_LEVEL
613# Follow the version that is set manually.
614  VSR_VENDOR_API_LEVEL := $(PRODUCT_SHIPPING_VENDOR_API_LEVEL)
615else
616  # VSR API level is the vendor api level of the product shipping API level.
617  VSR_VENDOR_API_LEVEL := $(call sdk-to-vendor-api-level,$(PLATFORM_SDK_VERSION))
618  ifdef PRODUCT_SHIPPING_API_LEVEL
619    VSR_VENDOR_API_LEVEL := $(call sdk-to-vendor-api-level,$(PRODUCT_SHIPPING_API_LEVEL))
620  endif
621  ifdef BOARD_SHIPPING_API_LEVEL
622    # Vendors with GRF must define BOARD_SHIPPING_API_LEVEL for the vendor API level.
623    # In this case, the VSR API level is the minimum of the PRODUCT_SHIPPING_API_LEVEL
624    # and RELEASE_BOARD_API_LEVEL
625    board_api_level := $(RELEASE_BOARD_API_LEVEL)
626    ifdef BOARD_API_LEVEL_PROP_OVERRIDE
627      board_api_level := $(BOARD_API_LEVEL_PROP_OVERRIDE)
628    endif
629    VSR_VENDOR_API_LEVEL := $(call math_min,$(VSR_VENDOR_API_LEVEL),$(board_api_level))
630    board_api_level :=
631  endif
632endif
633.KATI_READONLY := VSR_VENDOR_API_LEVEL
634
635# Boolean variable determining if vendor seapp contexts is enforced
636CHECK_VENDOR_SEAPP_VIOLATIONS := false
637ifneq ($(call math_gt,$(VSR_VENDOR_API_LEVEL),34),)
638  CHECK_VENDOR_SEAPP_VIOLATIONS := true
639else ifneq ($(PRODUCT_CHECK_VENDOR_SEAPP_VIOLATIONS),)
640  CHECK_VENDOR_SEAPP_VIOLATIONS := $(PRODUCT_CHECK_VENDOR_SEAPP_VIOLATIONS)
641endif
642.KATI_READONLY := CHECK_VENDOR_SEAPP_VIOLATIONS
643
644# Boolean variable determining if selinux labels of /dev are enforced
645CHECK_DEV_TYPE_VIOLATIONS := false
646ifneq ($(call math_gt,$(VSR_VENDOR_API_LEVEL),202404),)
647  CHECK_DEV_TYPE_VIOLATIONS := true
648else ifneq ($(PRODUCT_CHECK_DEV_TYPE_VIOLATIONS),)
649  CHECK_DEV_TYPE_VIOLATIONS := $(PRODUCT_CHECK_DEV_TYPE_VIOLATIONS)
650endif
651.KATI_READONLY := CHECK_DEV_TYPE_VIOLATIONS
652
653define product-overrides-config
654$$(foreach rule,$$(PRODUCT_$(1)_OVERRIDES),\
655    $$(if $$(filter 2,$$(words $$(subst :,$$(space),$$(rule)))),,\
656        $$(error Rule "$$(rule)" in PRODUCT_$(1)_OVERRIDE is not <module_name>:<new_value>)))
657endef
658
659$(foreach var, \
660    MANIFEST_PACKAGE_NAME \
661    PACKAGE_NAME \
662    CERTIFICATE, \
663  $(eval $(call product-overrides-config,$(var))))
664
665# Macro to use below. $(1) is the name of the partition
666define product-build-image-config
667ifneq ($$(filter-out true false,$$(PRODUCT_BUILD_$(1)_IMAGE)),)
668    $$(error Invalid PRODUCT_BUILD_$(1)_IMAGE: $$(PRODUCT_BUILD_$(1)_IMAGE) -- true false and empty are supported)
669endif
670endef
671
672ifndef PRODUCT_VIRTUAL_AB_COW_VERSION
673  PRODUCT_VIRTUAL_AB_COW_VERSION := 2
674  ifdef PRODUCT_SHIPPING_API_LEVEL
675    ifeq (true,$(call math_gt_or_eq,$(PRODUCT_SHIPPING_API_LEVEL),34))
676      PRODUCT_VIRTUAL_AB_COW_VERSION := 3
677    endif
678  endif
679endif
680
681# Copy and check the value of each PRODUCT_BUILD_*_IMAGE variable
682$(foreach image, \
683    PVMFW \
684    SYSTEM \
685    SYSTEM_OTHER \
686    VENDOR \
687    PRODUCT \
688    SYSTEM_EXT \
689    ODM \
690    VENDOR_DLKM \
691    ODM_DLKM \
692    SYSTEM_DLKM \
693    CACHE \
694    RAMDISK \
695    USERDATA \
696    BOOT \
697    RECOVERY, \
698  $(eval $(call product-build-image-config,$(image))))
699
700product-build-image-config :=
701
702ifdef PRODUCT_SOONG_ONLY
703  ifneq ($(PRODUCT_SOONG_ONLY),true)
704    ifneq ($(PRODUCT_SOONG_ONLY),false)
705      $(error PRODUCT_SOONG_ONLY can only be true, false or unset)
706    endif
707  endif
708endif
709
710$(call readonly-product-vars)
711