blob: a77956bdeaf53db3cafec187a07388cdfdbcc803 [file] [log] [blame]
Joe Onorato63a84552023-06-29 14:34:18 -07001# Copyright (C) 2023 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15#
16# This file is included by build/make/core/Makefile, and contains the logic for
17# the combined flags files.
18#
19
20# TODO: Should we do all of the images in $(IMAGES_TO_BUILD)?
21_FLAG_PARTITIONS := product system system_ext vendor
22
23
24# -----------------------------------------------------------------
Joe Onorato63a84552023-06-29 14:34:18 -070025# Aconfig Flags
26
27# Create a summary file of build flags for each partition
Ted Bauer98bedd82023-09-14 15:28:12 +000028# $(1): built aconfig flags file (out)
29# $(2): installed aconfig flags file (out)
LaMont Jonesacbe15e2024-06-26 14:32:51 -070030# $(3): the partition (in)
31# $(4): input aconfig files for the partition (in)
Joe Onorato63a84552023-06-29 14:34:18 -070032define generate-partition-aconfig-flag-file
33$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
LaMont Jonesacbe15e2024-06-26 14:32:51 -070034$(eval $(strip $(1)): PRIVATE_IN := $(strip $(4)))
35$(strip $(1)): $(ACONFIG) $(strip $(4))
36 mkdir -p $$(dir $$(PRIVATE_OUT))
37 $$(if $$(PRIVATE_IN), \
38 $$(ACONFIG) dump --dedup --format protobuf --out $$(PRIVATE_OUT) \
39 --filter container:$$(strip $(3)) $$(addprefix --cache ,$$(PRIVATE_IN)), \
40 echo -n > $$(PRIVATE_OUT) \
41 )
42$(call copy-one-file, $(1), $(2))
43endef
44
45# Create a summary file of build flags for each partition
46# $(1): built aconfig flags file (out)
47# $(2): installed aconfig flags file (out)
48# $(3): input aconfig files for the partition (in)
49define generate-global-aconfig-flag-file
50$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
Joe Onorato63a84552023-06-29 14:34:18 -070051$(eval $(strip $(1)): PRIVATE_IN := $(strip $(3)))
Joe Onoratob2093492023-08-19 19:00:04 -070052$(strip $(1)): $(ACONFIG) $(strip $(3))
Joe Onorato63a84552023-06-29 14:34:18 -070053 mkdir -p $$(dir $$(PRIVATE_OUT))
54 $$(if $$(PRIVATE_IN), \
Colin Cross706b0c32023-12-05 16:39:20 -080055 $$(ACONFIG) dump --dedup --format protobuf --out $$(PRIVATE_OUT) \
Joe Onorato63a84552023-06-29 14:34:18 -070056 $$(addprefix --cache ,$$(PRIVATE_IN)), \
Ted Bauerc0d16592023-11-01 16:03:51 +000057 echo -n > $$(PRIVATE_OUT) \
Joe Onorato63a84552023-06-29 14:34:18 -070058 )
59$(call copy-one-file, $(1), $(2))
60endef
61
62
63$(foreach partition, $(_FLAG_PARTITIONS), \
Ted Bauer98bedd82023-09-14 15:28:12 +000064 $(eval aconfig_flag_summaries_protobuf.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/aconfig_flags.pb) \
Joe Onorato63a84552023-06-29 14:34:18 -070065 $(eval $(call generate-partition-aconfig-flag-file, \
Ted Bauer98bedd82023-09-14 15:28:12 +000066 $(TARGET_OUT_FLAGS)/$(partition)/aconfig_flags.pb, \
67 $(aconfig_flag_summaries_protobuf.$(partition)), \
LaMont Jonesacbe15e2024-06-26 14:32:51 -070068 $(partition), \
Ted Bauer98bedd82023-09-14 15:28:12 +000069 $(sort $(foreach m,$(call register-names-for-partition, $(partition)), \
70 $(ALL_MODULES.$(m).ACONFIG_FILES) \
71 )), \
Joe Onorato63a84552023-06-29 14:34:18 -070072 )) \
73)
74
LaMont Jones2e47c7b2024-01-26 18:23:47 +000075# Collect the on-device flags into a single file, similar to all_aconfig_declarations.
76required_aconfig_flags_files := \
77 $(sort $(foreach partition, $(filter $(IMAGES_TO_BUILD), $(_FLAG_PARTITIONS)), \
78 $(aconfig_flag_summaries_protobuf.$(partition)) \
79 ))
80
81.PHONY: device_aconfig_declarations
82device_aconfig_declarations: $(PRODUCT_OUT)/device_aconfig_declarations.pb
LaMont Jonesacbe15e2024-06-26 14:32:51 -070083$(eval $(call generate-global-aconfig-flag-file, \
LaMont Jones2e47c7b2024-01-26 18:23:47 +000084 $(TARGET_OUT_FLAGS)/device_aconfig_declarations.pb, \
85 $(PRODUCT_OUT)/device_aconfig_declarations.pb, \
86 $(sort $(required_aconfig_flags_files)) \
87)) \
88
Dennis Shenc39f3782024-01-12 16:38:04 +000089# Create a set of storage file for each partition
Dennis Shenf2d4c8d2024-01-23 20:50:54 +000090# $(1): built aconfig flags storage package map file (out)
91# $(2): built aconfig flags storage flag map file (out)
92# $(3): built aconfig flags storage flag val file (out)
93# $(4): installed aconfig flags storage package map file (out)
94# $(5): installed aconfig flags storage flag map file (out)
95# $(6): installed aconfig flags storage flag value file (out)
96# $(7): input aconfig files for the partition (in)
Dennis Shen34a21ca2024-03-25 19:56:33 +000097# $(8): partition name
Dennis Shenc39f3782024-01-12 16:38:04 +000098define generate-partition-aconfig-storage-file
Dennis Shenf2d4c8d2024-01-23 20:50:54 +000099$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
100$(eval $(strip $(1)): PRIVATE_IN := $(strip $(7)))
101$(strip $(1)): $(ACONFIG) $(strip $(7))
102 mkdir -p $$(dir $$(PRIVATE_OUT))
Dennis Shenc39f3782024-01-12 16:38:04 +0000103 $$(if $$(PRIVATE_IN), \
Dennis Shen34a21ca2024-03-25 19:56:33 +0000104 $$(ACONFIG) create-storage --container $(8) --file package_map --out $$(PRIVATE_OUT) \
Dennis Shenc39f3782024-01-12 16:38:04 +0000105 $$(addprefix --cache ,$$(PRIVATE_IN)), \
106 )
Dennis Shenf2d4c8d2024-01-23 20:50:54 +0000107 touch $$(PRIVATE_OUT)
108$(eval $(strip $(2)): PRIVATE_OUT := $(strip $(2)))
109$(eval $(strip $(2)): PRIVATE_IN := $(strip $(7)))
110$(strip $(2)): $(ACONFIG) $(strip $(7))
111 mkdir -p $$(dir $$(PRIVATE_OUT))
112 $$(if $$(PRIVATE_IN), \
Dennis Shen34a21ca2024-03-25 19:56:33 +0000113 $$(ACONFIG) create-storage --container $(8) --file flag_map --out $$(PRIVATE_OUT) \
Dennis Shenf2d4c8d2024-01-23 20:50:54 +0000114 $$(addprefix --cache ,$$(PRIVATE_IN)), \
115 )
116 touch $$(PRIVATE_OUT)
117$(eval $(strip $(3)): PRIVATE_OUT := $(strip $(3)))
118$(eval $(strip $(3)): PRIVATE_IN := $(strip $(7)))
119$(strip $(3)): $(ACONFIG) $(strip $(7))
120 mkdir -p $$(dir $$(PRIVATE_OUT))
121 $$(if $$(PRIVATE_IN), \
Dennis Shen34a21ca2024-03-25 19:56:33 +0000122 $$(ACONFIG) create-storage --container $(8) --file flag_val --out $$(PRIVATE_OUT) \
Dennis Shenf2d4c8d2024-01-23 20:50:54 +0000123 $$(addprefix --cache ,$$(PRIVATE_IN)), \
124 )
125 touch $$(PRIVATE_OUT)
126$(call copy-one-file, $(strip $(1)), $(4))
127$(call copy-one-file, $(strip $(2)), $(5))
128$(call copy-one-file, $(strip $(3)), $(6))
Dennis Shenc39f3782024-01-12 16:38:04 +0000129endef
130
131ifeq ($(RELEASE_CREATE_ACONFIG_STORAGE_FILE),true)
132$(foreach partition, $(_FLAG_PARTITIONS), \
Dennis Shenbebbf542024-02-28 15:26:28 +0000133 $(eval aconfig_storage_package_map.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/aconfig/package.map) \
134 $(eval aconfig_storage_flag_map.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/aconfig/flag.map) \
135 $(eval aconfig_storage_flag_val.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/aconfig/flag.val) \
Dennis Shenc39f3782024-01-12 16:38:04 +0000136 $(eval $(call generate-partition-aconfig-storage-file, \
Dennis Shenf2d4c8d2024-01-23 20:50:54 +0000137 $(TARGET_OUT_FLAGS)/$(partition)/package.map, \
138 $(TARGET_OUT_FLAGS)/$(partition)/flag.map, \
139 $(TARGET_OUT_FLAGS)/$(partition)/flag.val, \
Dennis Shenc39f3782024-01-12 16:38:04 +0000140 $(aconfig_storage_package_map.$(partition)), \
141 $(aconfig_storage_flag_map.$(partition)), \
142 $(aconfig_storage_flag_val.$(partition)), \
Zhi Doua4b29192024-07-03 19:41:27 +0000143 $(aconfig_flag_summaries_protobuf.$(partition)), \
Dennis Shen34a21ca2024-03-25 19:56:33 +0000144 $(partition), \
Dennis Shenc39f3782024-01-12 16:38:04 +0000145 )) \
146)
147endif
Joe Onorato63a84552023-06-29 14:34:18 -0700148
149# -----------------------------------------------------------------
150# Install the ones we need for the configured product
151required_flags_files := \
152 $(sort $(foreach partition, $(filter $(IMAGES_TO_BUILD), $(_FLAG_PARTITIONS)), \
153 $(build_flag_summaries.$(partition)) \
Ted Bauer98bedd82023-09-14 15:28:12 +0000154 $(aconfig_flag_summaries_protobuf.$(partition)) \
Dennis Shenc39f3782024-01-12 16:38:04 +0000155 $(aconfig_storage_package_map.$(partition)) \
156 $(aconfig_storage_flag_map.$(partition)) \
157 $(aconfig_storage_flag_val.$(partition)) \
Joe Onorato63a84552023-06-29 14:34:18 -0700158 ))
159
160ALL_DEFAULT_INSTALLED_MODULES += $(required_flags_files)
Wei Li9b4cf432023-08-08 17:26:49 -0700161ALL_FLAGS_FILES := $(required_flags_files)
Joe Onorato63a84552023-06-29 14:34:18 -0700162
163# TODO: Remove
164.PHONY: flag-files
165flag-files: $(required_flags_files)
166
167
168# Clean up
169required_flags_files:=
LaMont Jones2e47c7b2024-01-26 18:23:47 +0000170required_aconfig_flags_files:=
Joe Onorato63a84552023-06-29 14:34:18 -0700171$(foreach partition, $(_FLAG_PARTITIONS), \
172 $(eval build_flag_summaries.$(partition):=) \
Ted Bauer98bedd82023-09-14 15:28:12 +0000173 $(eval aconfig_flag_summaries_protobuf.$(partition):=) \
Dennis Shenc39f3782024-01-12 16:38:04 +0000174 $(eval aconfig_storage_package_map.$(partition):=) \
175 $(eval aconfig_storage_flag_map.$(partition):=) \
176 $(eval aconfig_storage_flag_val.$(partition):=) \
Joe Onorato63a84552023-06-29 14:34:18 -0700177)
178