Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 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 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 |
| 31 | define 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)) |
| 55 | endef |
| 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 Bauer | 98bedd8 | 2023-09-14 15:28:12 +0000 | [diff] [blame] | 72 | # $(1): built aconfig flags file (out) |
| 73 | # $(2): installed aconfig flags file (out) |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 74 | # $(3): input aconfig files for the partition (in) |
| 75 | define generate-partition-aconfig-flag-file |
| 76 | $(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1))) |
| 77 | $(eval $(strip $(1)): PRIVATE_IN := $(strip $(3))) |
Joe Onorato | b209349 | 2023-08-19 19:00:04 -0700 | [diff] [blame] | 78 | $(strip $(1)): $(ACONFIG) $(strip $(3)) |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 79 | mkdir -p $$(dir $$(PRIVATE_OUT)) |
| 80 | $$(if $$(PRIVATE_IN), \ |
Colin Cross | 706b0c3 | 2023-12-05 16:39:20 -0800 | [diff] [blame] | 81 | $$(ACONFIG) dump --dedup --format protobuf --out $$(PRIVATE_OUT) \ |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 82 | $$(addprefix --cache ,$$(PRIVATE_IN)), \ |
Ted Bauer | c0d1659 | 2023-11-01 16:03:51 +0000 | [diff] [blame] | 83 | echo -n > $$(PRIVATE_OUT) \ |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 84 | ) |
| 85 | $(call copy-one-file, $(1), $(2)) |
| 86 | endef |
| 87 | |
| 88 | |
| 89 | $(foreach partition, $(_FLAG_PARTITIONS), \ |
Ted Bauer | 98bedd8 | 2023-09-14 15:28:12 +0000 | [diff] [blame] | 90 | $(eval aconfig_flag_summaries_protobuf.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/aconfig_flags.pb) \ |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 91 | $(eval $(call generate-partition-aconfig-flag-file, \ |
Ted Bauer | 98bedd8 | 2023-09-14 15:28:12 +0000 | [diff] [blame] | 92 | $(TARGET_OUT_FLAGS)/$(partition)/aconfig_flags.pb, \ |
| 93 | $(aconfig_flag_summaries_protobuf.$(partition)), \ |
| 94 | $(sort $(foreach m,$(call register-names-for-partition, $(partition)), \ |
| 95 | $(ALL_MODULES.$(m).ACONFIG_FILES) \ |
| 96 | )), \ |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 97 | )) \ |
| 98 | ) |
| 99 | |
LaMont Jones | 2e47c7b | 2024-01-26 18:23:47 +0000 | [diff] [blame^] | 100 | # Collect the on-device flags into a single file, similar to all_aconfig_declarations. |
| 101 | required_aconfig_flags_files := \ |
| 102 | $(sort $(foreach partition, $(filter $(IMAGES_TO_BUILD), $(_FLAG_PARTITIONS)), \ |
| 103 | $(aconfig_flag_summaries_protobuf.$(partition)) \ |
| 104 | )) |
| 105 | |
| 106 | .PHONY: device_aconfig_declarations |
| 107 | device_aconfig_declarations: $(PRODUCT_OUT)/device_aconfig_declarations.pb |
| 108 | $(eval $(call generate-partition-aconfig-flag-file, \ |
| 109 | $(TARGET_OUT_FLAGS)/device_aconfig_declarations.pb, \ |
| 110 | $(PRODUCT_OUT)/device_aconfig_declarations.pb, \ |
| 111 | $(sort $(required_aconfig_flags_files)) \ |
| 112 | )) \ |
| 113 | |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 114 | # Create a set of storage file for each partition |
Dennis Shen | f2d4c8d | 2024-01-23 20:50:54 +0000 | [diff] [blame] | 115 | # $(1): built aconfig flags storage package map file (out) |
| 116 | # $(2): built aconfig flags storage flag map file (out) |
| 117 | # $(3): built aconfig flags storage flag val file (out) |
| 118 | # $(4): installed aconfig flags storage package map file (out) |
| 119 | # $(5): installed aconfig flags storage flag map file (out) |
| 120 | # $(6): installed aconfig flags storage flag value file (out) |
| 121 | # $(7): input aconfig files for the partition (in) |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 122 | define generate-partition-aconfig-storage-file |
Dennis Shen | f2d4c8d | 2024-01-23 20:50:54 +0000 | [diff] [blame] | 123 | $(eval $(strip $(1)): PRIVATE_OUT := $(strip $(1))) |
| 124 | $(eval $(strip $(1)): PRIVATE_IN := $(strip $(7))) |
| 125 | $(strip $(1)): $(ACONFIG) $(strip $(7)) |
| 126 | mkdir -p $$(dir $$(PRIVATE_OUT)) |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 127 | $$(if $$(PRIVATE_IN), \ |
Dennis Shen | f2d4c8d | 2024-01-23 20:50:54 +0000 | [diff] [blame] | 128 | $$(ACONFIG) create-storage --container "" --file package_map --out $$(PRIVATE_OUT) \ |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 129 | $$(addprefix --cache ,$$(PRIVATE_IN)), \ |
| 130 | ) |
Dennis Shen | f2d4c8d | 2024-01-23 20:50:54 +0000 | [diff] [blame] | 131 | touch $$(PRIVATE_OUT) |
| 132 | $(eval $(strip $(2)): PRIVATE_OUT := $(strip $(2))) |
| 133 | $(eval $(strip $(2)): PRIVATE_IN := $(strip $(7))) |
| 134 | $(strip $(2)): $(ACONFIG) $(strip $(7)) |
| 135 | mkdir -p $$(dir $$(PRIVATE_OUT)) |
| 136 | $$(if $$(PRIVATE_IN), \ |
| 137 | $$(ACONFIG) create-storage --container "" --file flag_map --out $$(PRIVATE_OUT) \ |
| 138 | $$(addprefix --cache ,$$(PRIVATE_IN)), \ |
| 139 | ) |
| 140 | touch $$(PRIVATE_OUT) |
| 141 | $(eval $(strip $(3)): PRIVATE_OUT := $(strip $(3))) |
| 142 | $(eval $(strip $(3)): PRIVATE_IN := $(strip $(7))) |
| 143 | $(strip $(3)): $(ACONFIG) $(strip $(7)) |
| 144 | mkdir -p $$(dir $$(PRIVATE_OUT)) |
| 145 | $$(if $$(PRIVATE_IN), \ |
| 146 | $$(ACONFIG) create-storage --container "" --file flag_val --out $$(PRIVATE_OUT) \ |
| 147 | $$(addprefix --cache ,$$(PRIVATE_IN)), \ |
| 148 | ) |
| 149 | touch $$(PRIVATE_OUT) |
| 150 | $(call copy-one-file, $(strip $(1)), $(4)) |
| 151 | $(call copy-one-file, $(strip $(2)), $(5)) |
| 152 | $(call copy-one-file, $(strip $(3)), $(6)) |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 153 | endef |
| 154 | |
| 155 | ifeq ($(RELEASE_CREATE_ACONFIG_STORAGE_FILE),true) |
| 156 | $(foreach partition, $(_FLAG_PARTITIONS), \ |
| 157 | $(eval aconfig_storage_package_map.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/package.map) \ |
| 158 | $(eval aconfig_storage_flag_map.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/flag.map) \ |
Dennis Shen | f2d4c8d | 2024-01-23 20:50:54 +0000 | [diff] [blame] | 159 | $(eval aconfig_storage_flag_val.$(partition) := $(PRODUCT_OUT)/$(partition)/etc/flag.val) \ |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 160 | $(eval $(call generate-partition-aconfig-storage-file, \ |
Dennis Shen | f2d4c8d | 2024-01-23 20:50:54 +0000 | [diff] [blame] | 161 | $(TARGET_OUT_FLAGS)/$(partition)/package.map, \ |
| 162 | $(TARGET_OUT_FLAGS)/$(partition)/flag.map, \ |
| 163 | $(TARGET_OUT_FLAGS)/$(partition)/flag.val, \ |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 164 | $(aconfig_storage_package_map.$(partition)), \ |
| 165 | $(aconfig_storage_flag_map.$(partition)), \ |
| 166 | $(aconfig_storage_flag_val.$(partition)), \ |
| 167 | $(sort $(foreach m,$(call register-names-for-partition, $(partition)), \ |
| 168 | $(ALL_MODULES.$(m).ACONFIG_FILES) \ |
| 169 | )), \ |
| 170 | )) \ |
| 171 | ) |
| 172 | endif |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 173 | |
| 174 | # ----------------------------------------------------------------- |
| 175 | # Install the ones we need for the configured product |
| 176 | required_flags_files := \ |
| 177 | $(sort $(foreach partition, $(filter $(IMAGES_TO_BUILD), $(_FLAG_PARTITIONS)), \ |
| 178 | $(build_flag_summaries.$(partition)) \ |
Ted Bauer | 98bedd8 | 2023-09-14 15:28:12 +0000 | [diff] [blame] | 179 | $(aconfig_flag_summaries_protobuf.$(partition)) \ |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 180 | $(aconfig_storage_package_map.$(partition)) \ |
| 181 | $(aconfig_storage_flag_map.$(partition)) \ |
| 182 | $(aconfig_storage_flag_val.$(partition)) \ |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 183 | )) |
| 184 | |
| 185 | ALL_DEFAULT_INSTALLED_MODULES += $(required_flags_files) |
Wei Li | 9b4cf43 | 2023-08-08 17:26:49 -0700 | [diff] [blame] | 186 | ALL_FLAGS_FILES := $(required_flags_files) |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 187 | |
| 188 | # TODO: Remove |
| 189 | .PHONY: flag-files |
| 190 | flag-files: $(required_flags_files) |
| 191 | |
| 192 | |
| 193 | # Clean up |
| 194 | required_flags_files:= |
LaMont Jones | 2e47c7b | 2024-01-26 18:23:47 +0000 | [diff] [blame^] | 195 | required_aconfig_flags_files:= |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 196 | $(foreach partition, $(_FLAG_PARTITIONS), \ |
| 197 | $(eval build_flag_summaries.$(partition):=) \ |
Ted Bauer | 98bedd8 | 2023-09-14 15:28:12 +0000 | [diff] [blame] | 198 | $(eval aconfig_flag_summaries_protobuf.$(partition):=) \ |
Dennis Shen | c39f378 | 2024-01-12 16:38:04 +0000 | [diff] [blame] | 199 | $(eval aconfig_storage_package_map.$(partition):=) \ |
| 200 | $(eval aconfig_storage_flag_map.$(partition):=) \ |
| 201 | $(eval aconfig_storage_flag_val.$(partition):=) \ |
Joe Onorato | 63a8455 | 2023-06-29 14:34:18 -0700 | [diff] [blame] | 202 | ) |
| 203 | |