• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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?
21_FLAG_PARTITIONS := product system system_ext vendor
22
23# -----------------------------------------------------------------
24# Aconfig Flags
25
26# Create a summary file of build flags for a single partition
27# $(1): built aconfig flags file (out)
28# $(2): installed aconfig flags file (out)
29# $(3): the partition (in)
30# $(4): input aconfig files for the partition (in)
31define generate-partition-aconfig-flag-file
32$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
33$(eval $(strip $(1)): PRIVATE_IN := $(strip $(4)))
34$(strip $(1)): $(ACONFIG) $(strip $(4))
35	mkdir -p $$(dir $$(PRIVATE_OUT))
36	$$(if $$(PRIVATE_IN), \
37		$$(ACONFIG) dump --dedup --format protobuf --out $$(PRIVATE_OUT) \
38			--filter container:$(strip $(3))+state:ENABLED \
39			--filter container:$(strip $(3))+permission:READ_WRITE \
40			$$(addprefix --cache ,$$(PRIVATE_IN)), \
41		echo -n > $$(PRIVATE_OUT) \
42	)
43$(call copy-one-file, $(1), $(2))
44endef
45
46
47# Create a summary file of build flags for each partition
48# $(1): built aconfig flags file (out)
49# $(2): installed aconfig flags file (out)
50# $(3): input aconfig files for the partition (in)
51define generate-global-aconfig-flag-file
52$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
53$(eval $(strip $(1)): PRIVATE_IN := $(strip $(3)))
54$(strip $(1)): $(ACONFIG) $(strip $(3))
55	mkdir -p $$(dir $$(PRIVATE_OUT))
56	$$(if $$(PRIVATE_IN), \
57		$$(ACONFIG) dump --dedup --format protobuf --out $$(PRIVATE_OUT) \
58			$$(addprefix --cache ,$$(PRIVATE_IN)), \
59		echo -n > $$(PRIVATE_OUT) \
60	)
61$(call copy-one-file, $(1), $(2))
62endef
63
64define out-dir-for-partition
65$(TARGET_COPY_OUT_$(call to-upper,$(1)))
66endef
67
68# Get the module names suitable for ALL_MODULES.* variables that are installed
69# for a given container
70# $(1): container
71define register-names-for-container
72$(sort $(foreach m,$(product_MODULES),\
73	$(if $(filter $(PRODUCT_OUT)/$(call out-dir-for-partition,$(strip $(1)))/%, $(ALL_MODULES.$(m).INSTALLED)), \
74		$(m)
75	) \
76))
77endef
78
79$(foreach partition, $(_FLAG_PARTITIONS), \
80	$(eval aconfig_flag_summaries_protobuf.$(partition) := $(PRODUCT_OUT)/$(call out-dir-for-partition,$(partition))/etc/aconfig_flags.pb) \
81	$(eval $(call generate-partition-aconfig-flag-file, \
82			$(TARGET_OUT_FLAGS)/$(partition)/aconfig_flags.pb, \
83			$(aconfig_flag_summaries_protobuf.$(partition)), \
84			$(partition), \
85			$(sort \
86				$(foreach m, $(call register-names-for-container, $(partition)), \
87					$(ALL_MODULES.$(m).ACONFIG_FILES) \
88				) \
89			) \
90	)) \
91)
92
93# Collect the on-device flags into a single file, similar to all_aconfig_declarations.
94required_aconfig_flags_files := \
95		$(sort $(foreach partition, $(_FLAG_PARTITIONS), \
96			$(aconfig_flag_summaries_protobuf.$(partition)) \
97		))
98
99.PHONY: device_aconfig_declarations
100device_aconfig_declarations: $(PRODUCT_OUT)/device_aconfig_declarations.pb
101$(eval $(call generate-global-aconfig-flag-file, \
102			$(TARGET_OUT_FLAGS)/device_aconfig_declarations.pb, \
103			$(PRODUCT_OUT)/device_aconfig_declarations.pb, \
104			$(sort $(required_aconfig_flags_files)) \
105)) \
106
107# Create a set of storage file for each partition
108# $(1): built aconfig flags storage package map file (out)
109# $(2): built aconfig flags storage flag map file (out)
110# $(3): built aconfig flags storage flag val file (out)
111# $(4): built aconfig flags storage flag info file (out)
112# $(5): installed aconfig flags storage package map file (out)
113# $(6): installed aconfig flags storage flag map file (out)
114# $(7): installed aconfig flags storage flag value file (out)
115# $(8): installed aconfig flags storage flag info file (out)
116# $(9): input aconfig files for the partition (in)
117# $(10): partition name
118define generate-partition-aconfig-storage-file
119$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
120$(eval $(strip $(1)): PRIVATE_IN := $(strip $(9)))
121
122ifneq (,$(RELEASE_FINGERPRINT_ACONFIG_PACKAGES))
123STORAGE_FILE_VERSION := 2
124else
125STORAGE_FILE_VERSION := 1
126endif
127
128$(strip $(1)): $(ACONFIG) $(strip $(9))
129	mkdir -p $$(dir $$(PRIVATE_OUT))
130	$$(if $$(PRIVATE_IN), \
131		$$(ACONFIG) create-storage --container $(10) --file package_map --out $$(PRIVATE_OUT) --version $$(STORAGE_FILE_VERSION) \
132			$$(addprefix --cache ,$$(PRIVATE_IN)), \
133	)
134	touch $$(PRIVATE_OUT)
135$(eval $(strip $(2)): PRIVATE_OUT := $(strip $(2)))
136$(eval $(strip $(2)): PRIVATE_IN := $(strip $(9)))
137$(strip $(2)): $(ACONFIG) $(strip $(9))
138	mkdir -p $$(dir $$(PRIVATE_OUT))
139	$$(if $$(PRIVATE_IN), \
140		$$(ACONFIG) create-storage --container $(10) --file flag_map --out $$(PRIVATE_OUT) --version $$(STORAGE_FILE_VERSION) \
141			$$(addprefix --cache ,$$(PRIVATE_IN)), \
142	)
143	touch $$(PRIVATE_OUT)
144$(eval $(strip $(3)): PRIVATE_OUT := $(strip $(3)))
145$(eval $(strip $(3)): PRIVATE_IN := $(strip $(9)))
146$(strip $(3)): $(ACONFIG) $(strip $(9))
147	mkdir -p $$(dir $$(PRIVATE_OUT))
148	$$(if $$(PRIVATE_IN), \
149		$$(ACONFIG) create-storage --container $(10) --file flag_val --out $$(PRIVATE_OUT) --version $$(STORAGE_FILE_VERSION) \
150		$$(addprefix --cache ,$$(PRIVATE_IN)), \
151	)
152	touch $$(PRIVATE_OUT)
153$(eval $(strip $(4)): PRIVATE_OUT := $(strip $(4)))
154$(eval $(strip $(4)): PRIVATE_IN := $(strip $(9)))
155$(strip $(4)): $(ACONFIG) $(strip $(9))
156	mkdir -p $$(dir $$(PRIVATE_OUT))
157	$$(if $$(PRIVATE_IN), \
158		$$(ACONFIG) create-storage --container $(10) --file flag_info --out $$(PRIVATE_OUT) --version $$(STORAGE_FILE_VERSION) \
159		$$(addprefix --cache ,$$(PRIVATE_IN)), \
160	)
161	touch $$(PRIVATE_OUT)
162$(call copy-one-file, $(strip $(1)), $(5))
163$(call copy-one-file, $(strip $(2)), $(6))
164$(call copy-one-file, $(strip $(3)), $(7))
165$(call copy-one-file, $(strip $(4)), $(8))
166endef
167
168ifeq ($(RELEASE_CREATE_ACONFIG_STORAGE_FILE),true)
169$(foreach partition, $(_FLAG_PARTITIONS), \
170	$(eval aconfig_storage_package_map.$(partition) := $(PRODUCT_OUT)/$(call out-dir-for-partition,$(partition))/etc/aconfig/package.map) \
171	$(eval aconfig_storage_flag_map.$(partition) := $(PRODUCT_OUT)/$(call out-dir-for-partition,$(partition))/etc/aconfig/flag.map) \
172	$(eval aconfig_storage_flag_val.$(partition) := $(PRODUCT_OUT)/$(call out-dir-for-partition,$(partition))/etc/aconfig/flag.val) \
173	$(eval aconfig_storage_flag_info.$(partition) := $(PRODUCT_OUT)/$(call out-dir-for-partition,$(partition))/etc/aconfig/flag.info) \
174	$(eval $(call generate-partition-aconfig-storage-file, \
175				$(TARGET_OUT_FLAGS)/$(partition)/package.map, \
176				$(TARGET_OUT_FLAGS)/$(partition)/flag.map, \
177				$(TARGET_OUT_FLAGS)/$(partition)/flag.val, \
178				$(TARGET_OUT_FLAGS)/$(partition)/flag.info, \
179				$(aconfig_storage_package_map.$(partition)), \
180				$(aconfig_storage_flag_map.$(partition)), \
181				$(aconfig_storage_flag_val.$(partition)), \
182				$(aconfig_storage_flag_info.$(partition)), \
183				$(aconfig_flag_summaries_protobuf.$(partition)), \
184				$(partition), \
185	)) \
186)
187endif
188
189# -----------------------------------------------------------------
190# Install the ones we need for the configured product
191required_flags_files := \
192		$(sort $(foreach partition, $(_FLAG_PARTITIONS), \
193			$(build_flag_summaries.$(partition)) \
194			$(aconfig_flag_summaries_protobuf.$(partition)) \
195			$(aconfig_storage_package_map.$(partition)) \
196			$(aconfig_storage_flag_map.$(partition)) \
197			$(aconfig_storage_flag_val.$(partition)) \
198			$(aconfig_storage_flag_info.$(partition)) \
199		))
200
201ALL_DEFAULT_INSTALLED_MODULES += $(required_flags_files)
202ALL_FLAGS_FILES := $(required_flags_files)
203
204# TODO: Remove
205.PHONY: flag-files
206flag-files: $(required_flags_files)
207
208
209# Clean up
210out-dir-for-partition:=
211register-names-for-container:=
212required_flags_files:=
213required_aconfig_flags_files:=
214$(foreach partition, $(_FLAG_PARTITIONS), \
215	$(eval build_flag_summaries.$(partition):=) \
216	$(eval aconfig_flag_summaries_protobuf.$(partition):=) \
217	$(eval aconfig_storage_package_map.$(partition):=) \
218	$(eval aconfig_storage_flag_map.$(partition):=) \
219	$(eval aconfig_storage_flag_val.$(partition):=) \
220	$(eval aconfig_storage_flag_info.$(partition):=) \
221)
222