• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2007 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# Functions for including AndroidProducts.mk files
19# PRODUCT_MAKEFILES is set up in AndroidProducts.mks.
20# Format of PRODUCT_MAKEFILES:
21# <product_name>:<path_to_the_product_makefile>
22# If the <product_name> is the same as the base file name (without dir
23# and the .mk suffix) of the product makefile, "<product_name>:" can be
24# omitted.
25
26#
27# Returns the list of all AndroidProducts.mk files.
28# $(call ) isn't necessary.
29#
30define _find-android-products-files
31$(file <$(OUT_DIR)/.module_paths/AndroidProducts.mk.list) \
32  $(SRC_TARGET_DIR)/product/AndroidProducts.mk
33endef
34
35#
36# For entries returned by get-product-makefiles, decode an entry to a short
37# product name. These either may be in the form of <name>:path/to/file.mk or
38# path/to/<name>.mk
39# $(1): The entry to decode
40#
41# Returns two words:
42#   <name> <file>
43#
44define _decode-product-name
45$(strip \
46  $(eval _cpm_words := $(subst :,$(space),$(1))) \
47  $(if $(word 2,$(_cpm_words)), \
48    $(wordlist 1,2,$(_cpm_words)), \
49    $(basename $(notdir $(1))) $(1)))
50endef
51
52#
53# Validates the new common lunch choices -- ensures that they're in an
54# appropriate form, and are paired with definitions of their products.
55# $(1): The new list of COMMON_LUNCH_CHOICES
56# $(2): The new list of PRODUCT_MAKEFILES
57#
58define _validate-common-lunch-choices
59$(strip $(foreach choice,$(1),\
60  $(eval _parts := $(subst -,$(space),$(choice))) \
61  $(if $(call math_lt,$(words $(_parts)),2), \
62    $(error $(LOCAL_DIR): $(choice): Invalid lunch choice)) \
63  $(if $(call math_gt_or_eq,$(words $(_parts)),4), \
64    $(error $(LOCAL_DIR): $(choice): Invalid lunch choice)) \
65  $(if $(filter-out eng userdebug user,$(word 2,$(_parts))), \
66    $(error $(LOCAL_DIR): $(choice): Invalid variant: $(word 2,$(_parts)))) \
67  $(if $(filter-out $(foreach p,$(2),$(call _decode-product-name,$(p))),$(word 1,$(_parts))), \
68    $(error $(LOCAL_DIR): $(word 1,$(_parts)): Product not defined in this file)) \
69  ))
70endef
71
72#
73# Returns the sorted concatenation of PRODUCT_MAKEFILES
74# variables set in the given AndroidProducts.mk files.
75# $(1): the list of AndroidProducts.mk files.
76#
77# As a side-effect, COMMON_LUNCH_CHOICES will be set to a
78# union of all of the COMMON_LUNCH_CHOICES definitions within
79# each AndroidProducts.mk file.
80#
81define get-product-makefiles
82$(sort \
83  $(eval _COMMON_LUNCH_CHOICES :=) \
84  $(foreach f,$(1), \
85    $(eval PRODUCT_MAKEFILES :=) \
86    $(eval COMMON_LUNCH_CHOICES :=) \
87    $(eval LOCAL_DIR := $(patsubst %/,%,$(dir $(f)))) \
88    $(eval include $(f)) \
89    $(call _validate-common-lunch-choices,$(COMMON_LUNCH_CHOICES),$(PRODUCT_MAKEFILES)) \
90    $(eval _COMMON_LUNCH_CHOICES += $(COMMON_LUNCH_CHOICES)) \
91    $(PRODUCT_MAKEFILES) \
92   ) \
93  $(eval PRODUCT_MAKEFILES :=) \
94  $(eval LOCAL_DIR :=) \
95  $(eval COMMON_LUNCH_CHOICES := $(sort $(_COMMON_LUNCH_CHOICES))) \
96  $(eval _COMMON_LUNCH_CHOICES :=) \
97 )
98endef
99
100#
101# Returns the sorted concatenation of all PRODUCT_MAKEFILES
102# variables set in all AndroidProducts.mk files.
103# $(call ) isn't necessary.
104#
105define get-all-product-makefiles
106$(call get-product-makefiles,$(_find-android-products-files))
107endef
108
109# Variables that are meant to hold only a single value.
110# - The value set in the current makefile takes precedence over inherited values
111# - If multiple inherited makefiles set the var, the first-inherited value wins
112_product_single_value_vars :=
113
114# Variables that are lists of values.
115_product_list_vars :=
116
117_product_single_value_vars += PRODUCT_NAME
118_product_single_value_vars += PRODUCT_MODEL
119
120# The resoure configuration options to use for this product.
121_product_list_vars += PRODUCT_LOCALES
122_product_list_vars += PRODUCT_AAPT_CONFIG
123_product_single_value_vars += PRODUCT_AAPT_PREF_CONFIG
124_product_list_vars += PRODUCT_AAPT_PREBUILT_DPI
125_product_list_vars += PRODUCT_HOST_PACKAGES
126_product_list_vars += PRODUCT_PACKAGES
127_product_list_vars += PRODUCT_PACKAGES_DEBUG
128_product_list_vars += PRODUCT_PACKAGES_DEBUG_ASAN
129# Packages included only for eng/userdebug builds, when building with EMMA_INSTRUMENT=true
130_product_list_vars += PRODUCT_PACKAGES_DEBUG_JAVA_COVERAGE
131_product_list_vars += PRODUCT_PACKAGES_ENG
132_product_list_vars += PRODUCT_PACKAGES_TESTS
133
134# The device that this product maps to.
135_product_single_value_vars += PRODUCT_DEVICE
136_product_single_value_vars += PRODUCT_MANUFACTURER
137_product_single_value_vars += PRODUCT_BRAND
138
139# These PRODUCT_SYSTEM_* flags, if defined, are used in place of the
140# corresponding PRODUCT_* flags for the sysprops on /system.
141_product_single_value_vars += \
142    PRODUCT_SYSTEM_NAME \
143    PRODUCT_SYSTEM_MODEL \
144    PRODUCT_SYSTEM_DEVICE \
145    PRODUCT_SYSTEM_BRAND \
146    PRODUCT_SYSTEM_MANUFACTURER \
147
148# PRODUCT_<PARTITION>_PROPERTIES are lists of property assignments
149# that go to <partition>/build.prop. Each property assignment is
150# "key = value" with zero or more whitespace characters on either
151# side of the '='.
152_product_list_vars += \
153    PRODUCT_SYSTEM_PROPERTIES \
154    PRODUCT_SYSTEM_EXT_PROPERTIES \
155    PRODUCT_VENDOR_PROPERTIES \
156    PRODUCT_ODM_PROPERTIES \
157    PRODUCT_PRODUCT_PROPERTIES
158
159# TODO(b/117892318) deprecate these:
160# ... in favor or PRODUCT_SYSTEM_PROPERTIES
161_product_list_vars += PRODUCT_SYSTEM_DEFAULT_PROPERTIES
162# ... in favor of PRODUCT_VENDOR_PROPERTIES
163_product_list_vars += PRODUCT_PROPERTY_OVERRIDES
164_product_list_vars += PRODUCT_DEFAULT_PROPERTY_OVERRIDES
165
166# TODO(b/117892318) consider deprecating these too
167_product_list_vars += PRODUCT_SYSTEM_PROPERTY_BLACKLIST
168_product_list_vars += PRODUCT_VENDOR_PROPERTY_BLACKLIST
169
170# The characteristics of the product, which among other things is passed to aapt
171_product_single_value_vars += PRODUCT_CHARACTERISTICS
172
173# A list of words like <source path>:<destination path>[:<owner>].
174# The file at the source path should be copied to the destination path
175# when building  this product.  <destination path> is relative to
176# $(PRODUCT_OUT), so it should look like, e.g., "system/etc/file.xml".
177# The rules for these copy steps are defined in build/make/core/Makefile.
178# The optional :<owner> is used to indicate the owner of a vendor file.
179_product_list_vars += PRODUCT_COPY_FILES
180
181# The OTA key(s) specified by the product config, if any.  The names
182# of these keys are stored in the target-files zip so that post-build
183# signing tools can substitute them for the test key embedded by
184# default.
185_product_list_vars += PRODUCT_OTA_PUBLIC_KEYS
186_product_list_vars += PRODUCT_EXTRA_RECOVERY_KEYS
187
188# Should we use the default resources or add any product specific overlays
189_product_list_vars += PRODUCT_PACKAGE_OVERLAYS
190_product_list_vars += DEVICE_PACKAGE_OVERLAYS
191
192# Resource overlay list which must be excluded from enforcing RRO.
193_product_list_vars += PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS
194
195# Package list to apply enforcing RRO.
196_product_list_vars += PRODUCT_ENFORCE_RRO_TARGETS
197
198_product_list_vars += PRODUCT_SDK_ATREE_FILES
199_product_list_vars += PRODUCT_SDK_ADDON_NAME
200_product_list_vars += PRODUCT_SDK_ADDON_COPY_FILES
201_product_list_vars += PRODUCT_SDK_ADDON_COPY_MODULES
202_product_list_vars += PRODUCT_SDK_ADDON_DOC_MODULES
203_product_list_vars += PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP
204
205# which Soong namespaces to export to Make
206_product_list_vars += PRODUCT_SOONG_NAMESPACES
207
208_product_list_vars += PRODUCT_DEFAULT_WIFI_CHANNELS
209_product_single_value_vars += PRODUCT_DEFAULT_DEV_CERTIFICATE
210_product_list_vars += PRODUCT_MAINLINE_SEPOLICY_DEV_CERTIFICATES
211_product_list_vars += PRODUCT_RESTRICT_VENDOR_FILES
212
213# The list of product-specific kernel header dirs
214_product_list_vars += PRODUCT_VENDOR_KERNEL_HEADERS
215
216# A list of module names of BOOTCLASSPATH (jar files)
217_product_list_vars += PRODUCT_BOOT_JARS
218
219# A list of extra BOOTCLASSPATH jars (to be appended after common jars).
220# Products that include device-specific makefiles before AOSP makefiles should use this
221# instead of PRODUCT_BOOT_JARS, so that device-specific jars go after common jars.
222_product_list_vars += PRODUCT_BOOT_JARS_EXTRA
223
224_product_single_value_vars += PRODUCT_SUPPORTS_BOOT_SIGNER
225_product_single_value_vars += PRODUCT_SUPPORTS_VBOOT
226_product_single_value_vars += PRODUCT_SUPPORTS_VERITY
227_product_single_value_vars += PRODUCT_SUPPORTS_VERITY_FEC
228_product_list_vars += PRODUCT_SYSTEM_SERVER_APPS
229_product_list_vars += PRODUCT_SYSTEM_SERVER_JARS
230# List of system_server jars delivered via apex. Format = <apex name>:<jar name>.
231_product_list_vars += PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS
232# If true, then suboptimal order of system server jars does not cause an error.
233_product_single_value_vars += PRODUCT_BROKEN_SUBOPTIMAL_ORDER_OF_SYSTEM_SERVER_JARS
234
235# Additional system server jars to be appended at the end of the common list.
236# This is necessary to avoid jars reordering due to makefile inheritance order.
237_product_list_vars += PRODUCT_SYSTEM_SERVER_JARS_EXTRA
238
239# Set to true to disable <uses-library> checks for a product.
240_product_list_vars += PRODUCT_BROKEN_VERIFY_USES_LIBRARIES
241
242# All of the apps that we force preopt, this overrides WITH_DEXPREOPT.
243_product_list_vars += PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK
244_product_list_vars += PRODUCT_DEXPREOPT_SPEED_APPS
245_product_list_vars += PRODUCT_LOADED_BY_PRIVILEGED_MODULES
246_product_single_value_vars += PRODUCT_VBOOT_SIGNING_KEY
247_product_single_value_vars += PRODUCT_VBOOT_SIGNING_SUBKEY
248_product_single_value_vars += PRODUCT_VERITY_SIGNING_KEY
249_product_single_value_vars += PRODUCT_SYSTEM_VERITY_PARTITION
250_product_single_value_vars += PRODUCT_VENDOR_VERITY_PARTITION
251_product_single_value_vars += PRODUCT_PRODUCT_VERITY_PARTITION
252_product_single_value_vars += PRODUCT_SYSTEM_EXT_VERITY_PARTITION
253_product_single_value_vars += PRODUCT_ODM_VERITY_PARTITION
254_product_single_value_vars += PRODUCT_VENDOR_DLKM_VERITY_PARTITION
255_product_single_value_vars += PRODUCT_ODM_DLKM_VERITY_PARTITION
256_product_single_value_vars += PRODUCT_SYSTEM_SERVER_DEBUG_INFO
257_product_single_value_vars += PRODUCT_OTHER_JAVA_DEBUG_INFO
258
259# Per-module dex-preopt configs.
260_product_list_vars += PRODUCT_DEX_PREOPT_MODULE_CONFIGS
261_product_single_value_vars += PRODUCT_DEX_PREOPT_DEFAULT_COMPILER_FILTER
262_product_list_vars += PRODUCT_DEX_PREOPT_DEFAULT_FLAGS
263_product_single_value_vars += PRODUCT_DEX_PREOPT_BOOT_FLAGS
264_product_single_value_vars += PRODUCT_DEX_PREOPT_PROFILE_DIR
265_product_single_value_vars += PRODUCT_DEX_PREOPT_GENERATE_DM_FILES
266_product_single_value_vars += PRODUCT_DEX_PREOPT_NEVER_ALLOW_STRIPPING
267_product_single_value_vars += PRODUCT_DEX_PREOPT_RESOLVE_STARTUP_STRINGS
268
269# Boot image options.
270_product_single_value_vars += \
271    PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE \
272    PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION \
273    PRODUCT_USES_DEFAULT_ART_CONFIG \
274
275_product_single_value_vars += PRODUCT_SYSTEM_SERVER_COMPILER_FILTER
276# Per-module sanitizer configs
277_product_list_vars += PRODUCT_SANITIZER_MODULE_CONFIGS
278_product_single_value_vars += PRODUCT_SYSTEM_BASE_FS_PATH
279_product_single_value_vars += PRODUCT_VENDOR_BASE_FS_PATH
280_product_single_value_vars += PRODUCT_PRODUCT_BASE_FS_PATH
281_product_single_value_vars += PRODUCT_SYSTEM_EXT_BASE_FS_PATH
282_product_single_value_vars += PRODUCT_ODM_BASE_FS_PATH
283_product_single_value_vars += PRODUCT_VENDOR_DLKM_BASE_FS_PATH
284_product_single_value_vars += PRODUCT_ODM_DLKM_BASE_FS_PATH
285
286# The first API level this product shipped with
287_product_single_value_vars += PRODUCT_SHIPPING_API_LEVEL
288
289_product_list_vars += VENDOR_PRODUCT_RESTRICT_VENDOR_FILES
290_product_list_vars += VENDOR_EXCEPTION_MODULES
291_product_list_vars += VENDOR_EXCEPTION_PATHS
292# Whether the product wants to ship libartd. For rules and meaning, see art/Android.mk.
293_product_single_value_vars += PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD
294
295# Make this art variable visible to soong_config.mk.
296_product_single_value_vars += PRODUCT_ART_USE_READ_BARRIER
297
298# Add reserved headroom to a system image.
299_product_single_value_vars += PRODUCT_SYSTEM_HEADROOM
300
301# Whether to save disk space by minimizing java debug info
302_product_single_value_vars += PRODUCT_MINIMIZE_JAVA_DEBUG_INFO
303
304# Whether any paths are excluded from sanitization when SANITIZE_TARGET=integer_overflow
305_product_list_vars += PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS
306
307_product_single_value_vars += PRODUCT_ADB_KEYS
308
309# Whether any paths should have CFI enabled for components
310_product_list_vars += PRODUCT_CFI_INCLUDE_PATHS
311
312# Whether any paths are excluded from sanitization when SANITIZE_TARGET=cfi
313_product_list_vars += PRODUCT_CFI_EXCLUDE_PATHS
314
315# Whether the Scudo hardened allocator is disabled platform-wide
316_product_single_value_vars += PRODUCT_DISABLE_SCUDO
317
318# List of extra VNDK versions to be included
319_product_list_vars += PRODUCT_EXTRA_VNDK_VERSIONS
320
321# Whether APEX should be compressed or not
322_product_single_value_vars += PRODUCT_COMPRESSED_APEX
323
324# VNDK version of product partition. It can be 'current' if the product
325# partitions uses PLATFORM_VNDK_VERSION.
326_product_single_value_vars += PRODUCT_PRODUCT_VNDK_VERSION
327
328_product_single_value_vars += PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS
329_product_single_value_vars += PRODUCT_ENFORCE_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT
330_product_list_vars += PRODUCT_ARTIFACT_SYSTEM_CERTIFICATE_REQUIREMENT_ALLOW_LIST
331_product_list_vars += PRODUCT_ARTIFACT_PATH_REQUIREMENT_HINT
332_product_list_vars += PRODUCT_ARTIFACT_PATH_REQUIREMENT_ALLOWED_LIST
333
334# List of modules that should be forcefully unmarked from being LOCAL_PRODUCT_MODULE, and hence
335# installed on /system directory by default.
336_product_list_vars += PRODUCT_FORCE_PRODUCT_MODULES_TO_SYSTEM_PARTITION
337
338# When this is true, dynamic partitions is retrofitted on a device that has
339# already been launched without dynamic partitions. Otherwise, the device
340# is launched with dynamic partitions.
341# This flag implies PRODUCT_USE_DYNAMIC_PARTITIONS.
342_product_single_value_vars += PRODUCT_RETROFIT_DYNAMIC_PARTITIONS
343
344# When this is true, various build time as well as runtime debugfs restrictions are enabled.
345_product_single_value_vars += PRODUCT_SET_DEBUGFS_RESTRICTIONS
346
347# Other dynamic partition feature flags.PRODUCT_USE_DYNAMIC_PARTITION_SIZE and
348# PRODUCT_BUILD_SUPER_PARTITION default to the value of PRODUCT_USE_DYNAMIC_PARTITIONS.
349_product_single_value_vars += \
350    PRODUCT_USE_DYNAMIC_PARTITIONS \
351    PRODUCT_USE_DYNAMIC_PARTITION_SIZE \
352    PRODUCT_BUILD_SUPER_PARTITION \
353
354# If set, kernel configuration requirements are present in OTA package (and will be enforced
355# during OTA). Otherwise, kernel configuration requirements are enforced in VTS.
356# Devices that checks the running kernel (instead of the kernel in OTA package) should not
357# set this variable to prevent OTA failures.
358_product_list_vars += PRODUCT_OTA_ENFORCE_VINTF_KERNEL_REQUIREMENTS
359
360# If set to true, this product builds a generic OTA package, which installs generic system images
361# onto matching devices. The product may only build a subset of system images (e.g. only
362# system.img), so devices need to install the package in a system-only OTA manner.
363_product_single_value_vars += PRODUCT_BUILD_GENERIC_OTA_PACKAGE
364
365_product_list_vars += PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
366_product_list_vars += PRODUCT_PACKAGE_NAME_OVERRIDES
367_product_list_vars += PRODUCT_CERTIFICATE_OVERRIDES
368
369# A list of <overridden-apex>:<override-apex> pairs that specifies APEX module
370# overrides to be applied to the APEX names in the boot jar variables
371# (PRODUCT_BOOT_JARS, PRODUCT_UPDATABLE_BOOT_JARS etc).
372_product_list_vars += PRODUCT_BOOT_JAR_MODULE_OVERRIDES
373
374# Controls for whether different partitions are built for the current product.
375_product_single_value_vars += PRODUCT_BUILD_SYSTEM_IMAGE
376_product_single_value_vars += PRODUCT_BUILD_SYSTEM_OTHER_IMAGE
377_product_single_value_vars += PRODUCT_BUILD_VENDOR_IMAGE
378_product_single_value_vars += PRODUCT_BUILD_PRODUCT_IMAGE
379_product_single_value_vars += PRODUCT_BUILD_SYSTEM_EXT_IMAGE
380_product_single_value_vars += PRODUCT_BUILD_ODM_IMAGE
381_product_single_value_vars += PRODUCT_BUILD_VENDOR_DLKM_IMAGE
382_product_single_value_vars += PRODUCT_BUILD_ODM_DLKM_IMAGE
383_product_single_value_vars += PRODUCT_BUILD_CACHE_IMAGE
384_product_single_value_vars += PRODUCT_BUILD_RAMDISK_IMAGE
385_product_single_value_vars += PRODUCT_BUILD_USERDATA_IMAGE
386_product_single_value_vars += PRODUCT_BUILD_RECOVERY_IMAGE
387_product_single_value_vars += PRODUCT_BUILD_BOOT_IMAGE
388_product_single_value_vars += PRODUCT_BUILD_DEBUG_BOOT_IMAGE
389_product_single_value_vars += PRODUCT_BUILD_VENDOR_BOOT_IMAGE
390_product_single_value_vars += PRODUCT_BUILD_DEBUG_VENDOR_BOOT_IMAGE
391_product_single_value_vars += PRODUCT_BUILD_VBMETA_IMAGE
392_product_single_value_vars += PRODUCT_BUILD_SUPER_EMPTY_IMAGE
393
394# List of boot jars delivered via apex
395_product_list_vars += PRODUCT_UPDATABLE_BOOT_JARS
396
397# If set, device uses virtual A/B.
398_product_single_value_vars += PRODUCT_VIRTUAL_AB_OTA
399
400# If set, device uses virtual A/B Compression.
401_product_single_value_vars += PRODUCT_VIRTUAL_AB_COMPRESSION
402
403# If set, device retrofits virtual A/B.
404_product_single_value_vars += PRODUCT_VIRTUAL_AB_OTA_RETROFIT
405
406# If set, forcefully generate a non-A/B update package.
407# Note: A device configuration should inherit from virtual_ab_ota_plus_non_ab.mk
408# instead of setting this variable directly.
409# Note: Use TARGET_OTA_ALLOW_NON_AB in the build system because
410# TARGET_OTA_ALLOW_NON_AB takes the value of AB_OTA_UPDATER into account.
411_product_single_value_vars += PRODUCT_OTA_FORCE_NON_AB_PACKAGE
412
413# If set, Java module in product partition cannot use hidden APIs.
414_product_single_value_vars += PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE
415
416# If set, only java_sdk_library can be used at inter-partition dependency.
417# Note: Build error if BOARD_VNDK_VERSION is not set while
418#       PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY is true, because
419#       PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY has no meaning if
420#       BOARD_VNDK_VERSION is not set.
421# Note: When PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is not set, there are
422#       no restrictions at dependency between system and product partition.
423_product_single_value_vars += PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY
424
425# Allowlist for PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY option.
426# Listed modules are allowed at inter-partition dependency even if it isn't
427# a java_sdk_library module.
428_product_list_vars += PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST
429
430_product_single_value_vars += PRODUCT_INSTALL_EXTRA_FLATTENED_APEXES
431
432# Install a copy of the debug policy to the system_ext partition, and allow
433# init-second-stage to load debug policy from system_ext.
434# This option is only meant to be set by GSI products.
435_product_single_value_vars += PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT
436
437.KATI_READONLY := _product_single_value_vars _product_list_vars
438_product_var_list :=$= $(_product_single_value_vars) $(_product_list_vars)
439
440define dump-product
441$(warning ==== $(1) ====)\
442$(foreach v,$(_product_var_list),\
443$(warning PRODUCTS.$(1).$(v) := $(call get-product-var,$(1),$(v))))\
444$(warning --------)
445endef
446
447define dump-products
448$(foreach p,$(PRODUCTS),$(call dump-product,$(p)))
449endef
450
451#
452# Functions for including product makefiles
453#
454
455#
456# $(1): product to inherit
457#
458# To be called from product makefiles, and is later evaluated during the import-nodes
459# call below. It does three things:
460#  1. Inherits all of the variables from $1.
461#  2. Records the inheritance in the .INHERITS_FROM variable
462#  3. Records the calling makefile in PARENT_PRODUCT_FILES
463#
464# (2) and (3) can be used together to reconstruct the include hierarchy
465# See e.g. product-graph.mk for an example of this.
466#
467define inherit-product
468  $(if $(findstring ../,$(1)),\
469    $(eval np := $(call normalize-paths,$(1))),\
470    $(eval np := $(strip $(1))))\
471  $(foreach v,$(_product_var_list), \
472      $(eval $(v) := $($(v)) $(INHERIT_TAG)$(np))) \
473  $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
474  $(eval inherit_var := PRODUCTS.$(current_mk).INHERITS_FROM) \
475  $(eval $(inherit_var) := $(sort $($(inherit_var)) $(np))) \
476  $(eval PARENT_PRODUCT_FILES := $(sort $(PARENT_PRODUCT_FILES) $(current_mk))) \
477  $(call dump-inherit,$(strip $(word 1,$(_include_stack))),$(1)) \
478  $(call dump-config-vals,$(current_mk),inherit)
479endef
480
481# Specifies a number of path prefixes, relative to PRODUCT_OUT, where the
482# product makefile hierarchy rooted in the current node places its artifacts.
483# Creating artifacts outside the specified paths will cause a build-time error.
484define require-artifacts-in-path
485  $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
486  $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_REQUIREMENTS := $(strip $(1))) \
487  $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_ALLOWED_LIST := $(strip $(2))) \
488  $(eval ARTIFACT_PATH_REQUIREMENT_PRODUCTS := \
489    $(sort $(ARTIFACT_PATH_REQUIREMENT_PRODUCTS) $(current_mk)))
490endef
491
492# Like require-artifacts-in-path, but does not require all allow-list entries to
493# have an effect.
494define require-artifacts-in-path-relaxed
495  $(require-artifacts-in-path) \
496  $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_REQUIREMENT_IS_RELAXED := true)
497endef
498
499# Makes including non-existent modules in PRODUCT_PACKAGES an error.
500# $(1): list of non-existent modules to allow.
501define enforce-product-packages-exist
502  $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
503  $(eval PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST := true) \
504  $(eval PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST_ALLOW_LIST := $(1)) \
505  $(eval .KATI_READONLY := PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST) \
506  $(eval .KATI_READONLY := PRODUCTS.$(current_mk).PRODUCT_ENFORCE_PACKAGES_EXIST_ALLOW_LIST)
507endef
508
509#
510# Do inherit-product only if $(1) exists
511#
512define inherit-product-if-exists
513  $(if $(wildcard $(1)),$(call inherit-product,$(1)),)
514endef
515
516#
517# $(1): product makefile list
518#
519#TODO: check to make sure that products have all the necessary vars defined
520define import-products
521$(call import-nodes,PRODUCTS,$(1),$(_product_var_list),$(_product_single_value_vars))
522endef
523
524
525#
526# Does various consistency checks on all of the known products.
527# Takes no parameters, so $(call ) is not necessary.
528#
529define check-all-products
530$(if ,, \
531  $(eval _cap_names :=) \
532  $(foreach p,$(PRODUCTS), \
533    $(eval pn := $(strip $(PRODUCTS.$(p).PRODUCT_NAME))) \
534    $(if $(pn),,$(error $(p): PRODUCT_NAME must be defined.)) \
535    $(if $(filter $(pn),$(_cap_names)), \
536      $(error $(p): PRODUCT_NAME must be unique; "$(pn)" already used by $(strip \
537          $(foreach \
538            pp,$(PRODUCTS),
539              $(if $(filter $(pn),$(PRODUCTS.$(pp).PRODUCT_NAME)), \
540                $(pp) \
541               ))) \
542       ) \
543     ) \
544    $(eval _cap_names += $(pn)) \
545    $(if $(call is-c-identifier,$(pn)),, \
546      $(error $(p): PRODUCT_NAME must be a valid C identifier, not "$(pn)") \
547     ) \
548    $(eval pb := $(strip $(PRODUCTS.$(p).PRODUCT_BRAND))) \
549    $(if $(pb),,$(error $(p): PRODUCT_BRAND must be defined.)) \
550    $(foreach cf,$(strip $(PRODUCTS.$(p).PRODUCT_COPY_FILES)), \
551      $(if $(filter 2 3,$(words $(subst :,$(space),$(cf)))),, \
552        $(error $(p): malformed COPY_FILE "$(cf)") \
553       ) \
554     ) \
555   ) \
556)
557endef
558
559
560#
561# Returns the product makefile path for the product with the provided name
562#
563# $(1): short product name like "generic"
564#
565define _resolve-short-product-name
566  $(eval pn := $(strip $(1)))
567  $(eval p := \
568      $(foreach p,$(PRODUCTS), \
569          $(if $(filter $(pn),$(PRODUCTS.$(p).PRODUCT_NAME)), \
570            $(p) \
571       )) \
572   )
573  $(eval p := $(sort $(p)))
574  $(if $(filter 1,$(words $(p))), \
575    $(p), \
576    $(if $(filter 0,$(words $(p))), \
577      $(error No matches for product "$(pn)"), \
578      $(error Product "$(pn)" ambiguous: matches $(p)) \
579    ) \
580  )
581endef
582define resolve-short-product-name
583$(strip $(call _resolve-short-product-name,$(1)))
584endef
585
586# BoardConfig variables that are also inherited in product mks. Should ideally
587# be cleaned up to not be product variables.
588_readonly_late_variables := \
589  DEVICE_PACKAGE_OVERLAYS \
590  WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY \
591
592# Modified internally in the build system
593_readonly_late_variables += \
594  PRODUCT_COPY_FILES \
595  PRODUCT_DEX_PREOPT_NEVER_ALLOW_STRIPPING \
596  PRODUCT_DEX_PREOPT_BOOT_FLAGS \
597
598_readonly_early_variables := $(filter-out $(_readonly_late_variables),$(_product_var_list))
599
600#
601# Mark the variables in _product_stash_var_list as readonly
602#
603define readonly-variables
604$(foreach v,$(1), \
605  $(eval $(v) ?=) \
606  $(eval .KATI_READONLY := $(v)) \
607 )
608endef
609define readonly-product-vars
610$(call readonly-variables,$(_readonly_early_variables))
611endef
612
613define readonly-final-product-vars
614$(call readonly-variables,$(_readonly_late_variables))
615endef
616
617# Macro re-defined inside strip-product-vars.
618get-product-var = $(PRODUCTS.$(strip $(1)).$(2))
619#
620# Strip the variables in _product_var_list and a few build-system
621# internal variables, and assign the ones for the current product
622# to a shorthand that is more convenient to read from elsewhere.
623#
624define strip-product-vars
625$(call dump-phase-start,PRODUCT-EXPAND,,$(_product_var_list),$(_product_single_value_vars), \
626		build/make/core/product.mk) \
627$(foreach v,\
628  $(_product_var_list) \
629    PRODUCT_ENFORCE_PACKAGES_EXIST \
630    PRODUCT_ENFORCE_PACKAGES_EXIST_ALLOW_LIST, \
631  $(eval $(v) := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).$(v)))) \
632  $(eval get-product-var = $$(if $$(filter $$(1),$$(INTERNAL_PRODUCT)),$$($$(2)),$$(PRODUCTS.$$(strip $$(1)).$$(2)))) \
633  $(KATI_obsolete_var PRODUCTS.$(INTERNAL_PRODUCT).$(v),Use $(v) instead) \
634) \
635$(call dump-phase-end,build/make/core/product.mk)
636endef
637
638define add-to-product-copy-files-if-exists
639$(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1))
640endef
641
642# whitespace placeholder when we record module's dex-preopt config.
643_PDPMC_SP_PLACE_HOLDER := |@SP@|
644# Set up dex-preopt config for a module.
645# $(1) list of module names
646# $(2) the modules' dex-preopt config
647define add-product-dex-preopt-module-config
648$(eval _c := $(subst $(space),$(_PDPMC_SP_PLACE_HOLDER),$(strip $(2))))\
649$(eval PRODUCT_DEX_PREOPT_MODULE_CONFIGS += \
650  $(foreach m,$(1),$(m)=$(_c)))
651endef
652
653# whitespace placeholder when we record module's sanitizer config.
654_PSMC_SP_PLACE_HOLDER := |@SP@|
655# Set up sanitizer config for a module.
656# $(1) list of module names
657# $(2) the modules' sanitizer config
658define add-product-sanitizer-module-config
659$(eval _c := $(subst $(space),$(_PSMC_SP_PLACE_HOLDER),$(strip $(2))))\
660$(eval PRODUCT_SANITIZER_MODULE_CONFIGS += \
661  $(foreach m,$(1),$(m)=$(_c)))
662endef
663