blob: 3b0bde8900d31c11b312ed098bb4e96318ea0a1b [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# -----------------------------------------------------------------
25# Release Config Flags
26
27# Create a summary file of build flags for each partition
28# $(1): built build flags json file
29# $(2): installed build flags json file
30# $(3): flag names
31define generate-partition-build-flag-file
32$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
33$(eval $(strip $(1)): PRIVATE_FLAG_NAMES := $(strip $(3)))
34$(strip $(1)):
35 mkdir -p $$(dir $$(PRIVATE_OUT))
36 echo '{' > $$(PRIVATE_OUT)
37 echo '"flags": [' >> $$(PRIVATE_OUT)
38 $$(foreach flag, $$(PRIVATE_FLAG_NAMES), \
39 ( \
40 printf ' { "name": "%s", "value": "%s", ' \
41 '$$(flag)' \
42 '$$(_ALL_RELEASE_FLAGS.$$(flag).VALUE)' \
43 ; \
44 printf '"set": "%s", "default": "%s", "declared": "%s" }' \
45 '$$(_ALL_RELEASE_FLAGS.$$(flag).SET_IN)' \
46 '$$(_ALL_RELEASE_FLAGS.$$(flag).DEFAULT)' \
47 '$$(_ALL_RELEASE_FLAGS.$$(flag).DECLARED_IN)' \
48 ; \
49 printf '$$(if $$(filter $$(lastword $$(PRIVATE_FLAG_NAMES)),$$(flag)),,$$(comma))\n' ; \
50 ) >> $$(PRIVATE_OUT) ; \
51 )
52 echo "]" >> $$(PRIVATE_OUT)
53 echo "}" >> $$(PRIVATE_OUT)
54$(call copy-one-file, $(1), $(2))
55endef
56
57$(foreach partition, $(_FLAG_PARTITIONS), \
58 $(eval build_flag_summaries.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/build_flags.json) \
59 $(eval $(call generate-partition-build-flag-file, \
60 $(TARGET_OUT_FLAGS)/$(partition)/build_flags.json, \
61 $(build_flag_summaries.$(partition)), \
62 $(_ALL_RELEASE_FLAGS.PARTITIONS.$(partition)) \
63 ) \
64 ) \
65)
66
67
68# -----------------------------------------------------------------
69# Aconfig Flags
70
71# Create a summary file of build flags for each partition
Ted Bauer98bedd82023-09-14 15:28:12 +000072# $(1): built aconfig flags file (out)
73# $(2): installed aconfig flags file (out)
Joe Onorato63a84552023-06-29 14:34:18 -070074# $(3): input aconfig files for the partition (in)
Ted Bauer49fbb312023-10-25 15:51:05 +000075# $(4): file format, passed to `aconfig dump` (in)
76# $(5): text placed in aconfig file when no flags present (out)
Joe Onorato63a84552023-06-29 14:34:18 -070077define generate-partition-aconfig-flag-file
78$(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1)))
79$(eval $(strip $(1)): PRIVATE_IN := $(strip $(3)))
Joe Onoratob2093492023-08-19 19:00:04 -070080$(strip $(1)): $(ACONFIG) $(strip $(3))
Joe Onorato63a84552023-06-29 14:34:18 -070081 mkdir -p $$(dir $$(PRIVATE_OUT))
82 $$(if $$(PRIVATE_IN), \
Ted Bauer49fbb312023-10-25 15:51:05 +000083 $$(ACONFIG) dump --format $(4) --out $$(PRIVATE_OUT) \
Joe Onorato63a84552023-06-29 14:34:18 -070084 $$(addprefix --cache ,$$(PRIVATE_IN)), \
Ted Bauer49fbb312023-10-25 15:51:05 +000085 echo -n "$(5)" > $$(PRIVATE_OUT) \
Joe Onorato63a84552023-06-29 14:34:18 -070086 )
87$(call copy-one-file, $(1), $(2))
88endef
89
90
91$(foreach partition, $(_FLAG_PARTITIONS), \
Ted Bauer49fbb312023-10-25 15:51:05 +000092 $(eval aconfig_flag_summaries_textproto.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/aconfig_flags.textproto) \
Ted Bauer98bedd82023-09-14 15:28:12 +000093 $(eval aconfig_flag_summaries_protobuf.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/aconfig_flags.pb) \
Joe Onorato63a84552023-06-29 14:34:18 -070094 $(eval $(call generate-partition-aconfig-flag-file, \
Ted Bauer49fbb312023-10-25 15:51:05 +000095 $(TARGET_OUT_FLAGS)/$(partition)/aconfig_flags.textproto, \
96 $(aconfig_flag_summaries_textproto.$(partition)), \
97 $(sort $(foreach m,$(call register-names-for-partition, $(partition)), \
98 $(ALL_MODULES.$(m).ACONFIG_FILES) \
99 )), \
100 textproto, \
101 "# No aconfig flags" \
102 )) \
103 $(eval $(call generate-partition-aconfig-flag-file, \
Ted Bauer98bedd82023-09-14 15:28:12 +0000104 $(TARGET_OUT_FLAGS)/$(partition)/aconfig_flags.pb, \
105 $(aconfig_flag_summaries_protobuf.$(partition)), \
106 $(sort $(foreach m,$(call register-names-for-partition, $(partition)), \
107 $(ALL_MODULES.$(m).ACONFIG_FILES) \
108 )), \
Ted Bauer49fbb312023-10-25 15:51:05 +0000109 protobuf, \
110 "" \
Joe Onorato63a84552023-06-29 14:34:18 -0700111 )) \
112)
113
114
115# -----------------------------------------------------------------
116# Install the ones we need for the configured product
117required_flags_files := \
118 $(sort $(foreach partition, $(filter $(IMAGES_TO_BUILD), $(_FLAG_PARTITIONS)), \
119 $(build_flag_summaries.$(partition)) \
Ted Bauer49fbb312023-10-25 15:51:05 +0000120 $(aconfig_flag_summaries_textproto.$(partition)) \
Ted Bauer98bedd82023-09-14 15:28:12 +0000121 $(aconfig_flag_summaries_protobuf.$(partition)) \
Joe Onorato63a84552023-06-29 14:34:18 -0700122 ))
123
124ALL_DEFAULT_INSTALLED_MODULES += $(required_flags_files)
Wei Li9b4cf432023-08-08 17:26:49 -0700125ALL_FLAGS_FILES := $(required_flags_files)
Joe Onorato63a84552023-06-29 14:34:18 -0700126
127# TODO: Remove
128.PHONY: flag-files
129flag-files: $(required_flags_files)
130
131
132# Clean up
133required_flags_files:=
134$(foreach partition, $(_FLAG_PARTITIONS), \
135 $(eval build_flag_summaries.$(partition):=) \
Ted Bauer49fbb312023-10-25 15:51:05 +0000136 $(eval aconfig_flag_summaries_textproto.$(partition):=) \
Ted Bauer98bedd82023-09-14 15:28:12 +0000137 $(eval aconfig_flag_summaries_protobuf.$(partition):=) \
Joe Onorato63a84552023-06-29 14:34:18 -0700138)
139