Joe Onorato | 964f401 | 2023-05-06 12:29:01 -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 | |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 15 | |
| 16 | # ----------------------------------------------------------------- |
LaMont Jones | 052282b | 2024-05-16 10:46:49 -0700 | [diff] [blame] | 17 | # Determine which pass this is. |
| 18 | # ----------------------------------------------------------------- |
| 19 | # On the first pass, we are asked for only PRODUCT_RELEASE_CONFIG_MAPS, |
| 20 | # on the second pass, we are asked for whatever else is wanted. |
| 21 | _final_product_config_pass:= |
| 22 | ifneq (PRODUCT_RELEASE_CONFIG_MAPS,$(DUMP_MANY_VARS)) |
| 23 | _final_product_config_pass:=true |
| 24 | endif |
| 25 | |
| 26 | # ----------------------------------------------------------------- |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 27 | # Choose the flag files |
| 28 | # ----------------------------------------------------------------- |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 29 | # Release configs are defined in reflease_config_map files, which map |
| 30 | # the short name (e.g. -next) used in lunch to the starlark files |
| 31 | # defining the build flag values. |
| 32 | # |
| 33 | # (If you're thinking about aconfig flags, there is one build flag, |
Joe Onorato | 6aa48f8 | 2023-06-21 15:17:42 -0700 | [diff] [blame] | 34 | # RELEASE_ACONFIG_VALUE_SETS, that sets which aconfig_value_set |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 35 | # module to use to set the aconfig flag values.) |
| 36 | # |
| 37 | # The short release config names *can* appear multiple times, to allow |
| 38 | # for AOSP and vendor specific flags under the same name, but the |
| 39 | # individual flag values must appear in exactly one config. Vendor |
| 40 | # does not override AOSP, or anything like that. This is because |
| 41 | # vendor code usually includes prebuilts, and having vendor compile |
| 42 | # with different flags from AOSP increases the likelihood of flag |
| 43 | # mismatch. |
| 44 | |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 45 | # Do this first, because we're going to unset TARGET_RELEASE before |
| 46 | # including anyone, so they don't start making conditionals based on it. |
| 47 | # This logic is in make because starlark doesn't understand optional |
| 48 | # vendor files. |
| 49 | |
| 50 | # If this is a google source tree, restrict it to only the one file |
| 51 | # which has OWNERS control. If it isn't let others define their own. |
| 52 | # TODO: Remove wildcard for build/release one when all branch manifests |
| 53 | # have updated. |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 54 | _must_protobuf := |
LaMont Jones | 91fa432 | 2024-03-29 14:50:50 -0700 | [diff] [blame] | 55 | config_map_files := $(wildcard build/release/release_config_map.mk) \ |
LaMont Jones | 318dafe | 2024-03-07 17:08:05 -0800 | [diff] [blame] | 56 | $(wildcard vendor/google_shared/build/release/release_config_map.mk) \ |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 57 | $(if $(wildcard vendor/google/release/release_config_map.mk), \ |
| 58 | vendor/google/release/release_config_map.mk, \ |
| 59 | $(sort \ |
| 60 | $(wildcard device/*/release/release_config_map.mk) \ |
| 61 | $(wildcard device/*/*/release/release_config_map.mk) \ |
| 62 | $(wildcard vendor/*/release/release_config_map.mk) \ |
| 63 | $(wildcard vendor/*/*/release/release_config_map.mk) \ |
| 64 | ) \ |
| 65 | ) |
| 66 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 67 | protobuf_map_files := $(wildcard build/release/release_config_map.textproto) \ |
| 68 | $(wildcard vendor/google_shared/build/release/release_config_map.textproto) \ |
| 69 | $(if $(wildcard vendor/google/release/release_config_map.textproto), \ |
| 70 | vendor/google/release/release_config_map.textproto, \ |
| 71 | $(sort \ |
| 72 | $(wildcard device/*/release/release_config_map.textproto) \ |
| 73 | $(wildcard device/*/*/release/release_config_map.textproto) \ |
| 74 | $(wildcard vendor/*/release/release_config_map.textproto) \ |
| 75 | $(wildcard vendor/*/*/release/release_config_map.textproto) \ |
| 76 | ) \ |
| 77 | ) |
| 78 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 79 | # PRODUCT_RELEASE_CONFIG_MAPS is set by Soong using an initial run of product |
| 80 | # config to capture only the list of config maps needed by the build. |
| 81 | # Keep them in the order provided, but remove duplicates. |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 82 | # Treat .mk and .textproto as equal for duplicate elimination, but force |
| 83 | # protobuf if any PRODUCT_RELEASE_CONFIG_MAPS specify .textproto. |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 84 | $(foreach map,$(PRODUCT_RELEASE_CONFIG_MAPS), \ |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 85 | $(if $(filter $(basename $(map)),$(basename $(config_map_files))),, \ |
| 86 | $(eval config_map_files += $(map))) \ |
| 87 | $(if $(filter $(basename $(map)).textproto,$(map)),$(eval _must_protobuf := true)) \ |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 88 | ) |
| 89 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 90 | |
| 91 | # If we are missing the textproto version of any of $(config_map_files), we cannot use protobuf. |
| 92 | _can_protobuf := true |
| 93 | $(foreach map,$(config_map_files), \ |
| 94 | $(if $(wildcard $(basename $(map)).textproto),,$(eval _can_protobuf :=)) \ |
| 95 | ) |
| 96 | # If we are missing the mk version of any of $(protobuf_map_files), we must use protobuf. |
| 97 | $(foreach map,$(protobuf_map_files), \ |
| 98 | $(if $(wildcard $(basename $(map)).mk),,$(eval _must_protobuf := true)) \ |
| 99 | ) |
| 100 | |
| 101 | ifneq (,$(_must_protobuf)) |
| 102 | ifeq (,$(_can_protobuf)) |
LaMont Jones | 052282b | 2024-05-16 10:46:49 -0700 | [diff] [blame] | 103 | # We must use protobuf, but we cannot use protobuf. |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 104 | $(error release config is a mixture of .scl and .textproto) |
| 105 | endif |
| 106 | endif |
| 107 | |
| 108 | _use_protobuf := |
| 109 | ifneq (,$(_must_protobuf)) |
| 110 | _use_protobuf := true |
| 111 | else |
| 112 | ifneq ($(_can_protobuf),) |
| 113 | # Determine the default |
| 114 | $(foreach map,$(config_map_files), \ |
| 115 | $(if $(wildcard $(dir $(map))/build_config/DEFAULT=proto),$(eval _use_protobuf := true)) \ |
| 116 | $(if $(wildcard $(dir $(map))/build_config/DEFAULT=make),$(eval _use_protobuf := )) \ |
| 117 | ) |
| 118 | # Update for this specific release config only (no inheritance). |
| 119 | $(foreach map,$(config_map_files), \ |
| 120 | $(if $(wildcard $(dir $(map))/build_config/$(TARGET_RELEASE)=proto),$(eval _use_protobuf := true)) \ |
| 121 | $(if $(wildcard $(dir $(map))/build_config/$(TARGET_RELEASE)=make),$(eval _use_protobuf := )) \ |
| 122 | ) |
| 123 | endif |
| 124 | endif |
| 125 | |
| 126 | ifneq (,$(_use_protobuf)) |
| 127 | # The .textproto files are the canonical source of truth. |
| 128 | _args := $(foreach map,$(config_map_files), --map $(map) ) |
| 129 | ifneq (,$(_must_protobuf)) |
| 130 | # Disable the build flag in release-config. |
| 131 | _args += --guard=false |
| 132 | endif |
LaMont Jones | 3b9a935 | 2024-05-22 14:40:11 -0700 | [diff] [blame] | 133 | _flags_dir:=$(OUT_DIR)/soong/release-config |
| 134 | _flags_file:=$(_flags_dir)/release_config-$(TARGET_PRODUCT)-$(TARGET_RELEASE).vars |
LaMont Jones | 052282b | 2024-05-16 10:46:49 -0700 | [diff] [blame] | 135 | # release-config generates $(_flags_varmk) |
| 136 | _flags_varmk:=$(_flags_file:.vars=.varmk) |
Cole Faust | 50dc47d | 2024-05-21 18:16:21 -0700 | [diff] [blame] | 137 | $(shell $(OUT_DIR)/release-config $(_args) >$(OUT_DIR)/release-config.out && touch -t 200001010000 $(_flags_varmk)) |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 138 | $(if $(filter-out 0,$(.SHELLSTATUS)),$(error release-config failed to run)) |
LaMont Jones | 052282b | 2024-05-16 10:46:49 -0700 | [diff] [blame] | 139 | ifneq (,$(_final_product_config_pass)) |
| 140 | # Save the final version of the config. |
| 141 | $(shell if ! cmp --quiet $(_flags_varmk) $(_flags_file); then cp $(_flags_varmk) $(_flags_file); fi) |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 142 | # This will also set ALL_RELEASE_CONFIGS_FOR_PRODUCT and _used_files for us. |
LaMont Jones | 052282b | 2024-05-16 10:46:49 -0700 | [diff] [blame] | 143 | $(eval include $(_flags_file)) |
| 144 | $(KATI_extra_file_deps $(OUT_DIR)/release-config $(protobuf_map_files) $(_flags_file)) |
| 145 | else |
| 146 | # This is the first pass of product config. |
| 147 | $(eval include $(_flags_varmk)) |
| 148 | endif |
| 149 | _used_files := |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 150 | ifeq (,$(_must_protobuf)$(RELEASE_BUILD_FLAGS_IN_PROTOBUF)) |
| 151 | _use_protobuf := |
LaMont Jones | 3b9a935 | 2024-05-22 14:40:11 -0700 | [diff] [blame] | 152 | else |
| 153 | _base_all_release := all_release_configs-$(TARGET_PRODUCT) |
| 154 | $(call dist-for-goals,droid,\ |
| 155 | $(_flags_dir)/$(_base_all_release).pb:build_flags/all_release_configs.pb \ |
| 156 | $(_flags_dir)/$(_base_all_release).textproto:build_flags/all_release_configs.textproto \ |
| 157 | $(_flags_dir)/$(_base_all_release).json:build_flags/all_release_configs.json \ |
| 158 | ) |
| 159 | # These are always created, add an empty rule for them to keep ninja happy. |
| 160 | $(_flags_dir)/$(_base_all_release).pb $(_flags_dir)/$(_base_all_release).textproto $(_flags_dir)/$(_base_all_release).json: |
| 161 | : created by $(OUT_DIR)/release-config |
| 162 | _base_all_release := |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 163 | endif |
LaMont Jones | 3b9a935 | 2024-05-22 14:40:11 -0700 | [diff] [blame] | 164 | _flags_dir:= |
| 165 | _flags_file:= |
| 166 | _flags_varmk:= |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 167 | endif |
| 168 | ifeq (,$(_use_protobuf)) |
| 169 | # The .mk files are the canonical source of truth. |
| 170 | |
| 171 | |
LaMont Jones | 61b0f79 | 2024-01-30 23:04:02 +0000 | [diff] [blame] | 172 | # Declare an alias release-config |
| 173 | # |
| 174 | # This should be used to declare a release as an alias of another, meaning no |
| 175 | # release config files should be present. |
| 176 | # |
| 177 | # $1 config name |
| 178 | # $2 release config for which it is an alias |
| 179 | define alias-release-config |
| 180 | $(call _declare-release-config,$(1),,$(2),true) |
| 181 | endef |
| 182 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 183 | # Declare or extend a release-config. |
| 184 | # |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 185 | # The order of processing is: |
| 186 | # 1. Recursively apply any overridden release configs. Only apply each config |
| 187 | # the first time we reach it. |
| 188 | # 2. Apply any files for this release config, in the order they were added to |
| 189 | # the declaration. |
| 190 | # |
| 191 | # Example: |
| 192 | # With these declarations: |
| 193 | # $(declare-release-config foo, foo.scl) |
| 194 | # $(declare-release-config bar, bar.scl, foo) |
| 195 | # $(declare-release-config baz, baz.scl, bar) |
| 196 | # $(declare-release-config bif, bif.scl, foo baz) |
| 197 | # $(declare-release-config bop, bop.scl, bar baz) |
| 198 | # |
| 199 | # TARGET_RELEASE: |
| 200 | # - bar will use: foo.scl bar.scl |
| 201 | # - baz will use: foo.scl bar.scl baz.scl |
| 202 | # - bif will use: foo.scl bar.scl baz.scl bif.scl |
| 203 | # - bop will use: foo.scl bar.scl baz.scl bop.scl |
| 204 | # |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 205 | # $1 config name |
| 206 | # $2 release config files |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 207 | # $3 overridden release config |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 208 | define declare-release-config |
LaMont Jones | 61b0f79 | 2024-01-30 23:04:02 +0000 | [diff] [blame] | 209 | $(call _declare-release-config,$(1),$(2),$(3),) |
| 210 | endef |
| 211 | |
| 212 | define _declare-release-config |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 213 | $(if $(strip $(2)$(3)),, \ |
| 214 | $(error declare-release-config: config $(strip $(1)) must have release config files, override another release config, or both) \ |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 215 | ) |
LaMont Jones | 61b0f79 | 2024-01-30 23:04:02 +0000 | [diff] [blame] | 216 | $(if $(strip $(4)),$(eval _all_release_configs.$(strip $(1)).ALIAS := true)) |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 217 | $(eval ALL_RELEASE_CONFIGS_FOR_PRODUCT := $(sort $(ALL_RELEASE_CONFIGS_FOR_PRODUCT) $(strip $(1)))) |
LaMont Jones | a6b6e67 | 2023-11-27 20:12:36 +0000 | [diff] [blame] | 218 | $(if $(strip $(3)), \ |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 219 | $(if $(filter $(ALL_RELEASE_CONFIGS_FOR_PRODUCT), $(strip $(3))), |
LaMont Jones | a6b6e67 | 2023-11-27 20:12:36 +0000 | [diff] [blame] | 220 | $(if $(filter $(_all_release_configs.$(strip $(1)).OVERRIDES),$(strip $(3))),, |
| 221 | $(eval _all_release_configs.$(strip $(1)).OVERRIDES := $(_all_release_configs.$(strip $(1)).OVERRIDES) $(strip $(3)))), \ |
| 222 | $(error No release config $(strip $(3))) \ |
| 223 | ) \ |
| 224 | ) |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 225 | $(eval _all_release_configs.$(strip $(1)).DECLARED_IN := $(_included) $(_all_release_configs.$(strip $(1)).DECLARED_IN)) |
| 226 | $(eval _all_release_configs.$(strip $(1)).FILES := $(_all_release_configs.$(strip $(1)).FILES) $(strip $(2))) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 227 | endef |
| 228 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 229 | # Include the config map files and populate _flag_declaration_files. |
LaMont Jones | 451abd6 | 2024-03-14 10:48:55 -0700 | [diff] [blame] | 230 | # If the file is found more than once, only include it the first time. |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 231 | _flag_declaration_files := |
LaMont Jones | 451abd6 | 2024-03-14 10:48:55 -0700 | [diff] [blame] | 232 | _included_config_map_files := |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 233 | $(foreach f, $(config_map_files), \ |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 234 | $(eval FLAG_DECLARATION_FILES:= ) \ |
LaMont Jones | 451abd6 | 2024-03-14 10:48:55 -0700 | [diff] [blame] | 235 | $(if $(filter $(_included_config_map_files),$(f)),,\ |
| 236 | $(eval _included := $(f)) \ |
| 237 | $(eval include $(f)) \ |
| 238 | $(eval _flag_declaration_files += $(FLAG_DECLARATION_FILES)) \ |
| 239 | $(eval _included_config_map_files += $(f)) \ |
| 240 | ) \ |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 241 | ) |
| 242 | FLAG_DECLARATION_FILES := |
| 243 | |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 244 | # Verify that all inherited/overridden release configs are declared. |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 245 | $(foreach config,$(ALL_RELEASE_CONFIGS_FOR_PRODUCT),\ |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 246 | $(foreach r,$(all_release_configs.$(r).OVERRIDES),\ |
| 247 | $(if $(strip $(_all_release_configs.$(r).FILES)$(_all_release_configs.$(r).OVERRIDES)),,\ |
| 248 | $(error Release config $(config) [declared in: $(_all_release_configs.$(r).DECLARED_IN)] inherits from non-existent $(r).)\ |
| 249 | ))) |
| 250 | # Verify that alias configs do not have config files. |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 251 | $(foreach r,$(ALL_RELEASE_CONFIGS_FOR_PRODUCT),\ |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 252 | $(if $(_all_release_configs.$(r).ALIAS),$(if $(_all_release_configs.$(r).FILES),\ |
| 253 | $(error Alias release config "$(r)" may not specify release config files $(_all_release_configs.$(r).FILES))\ |
| 254 | ))) |
| 255 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 256 | # Use makefiles |
| 257 | endif |
| 258 | |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 259 | ifeq ($(TARGET_RELEASE),) |
| 260 | # We allow some internal paths to explicitly set TARGET_RELEASE to the |
| 261 | # empty string. For the most part, 'make' treats unset and empty string as |
| 262 | # the same. But the following line differentiates, and will only assign |
| 263 | # if the variable was completely unset. |
| 264 | TARGET_RELEASE ?= was_unset |
| 265 | ifeq ($(TARGET_RELEASE),was_unset) |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 266 | $(error No release config set for target; please set TARGET_RELEASE, or if building on the command line use 'lunch <target>-<release>-<build_type>', where release is one of: $(ALL_RELEASE_CONFIGS_FOR_PRODUCT)) |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 267 | endif |
| 268 | # Instead of leaving this string empty, we want to default to a valid |
| 269 | # setting. Full builds coming through this path is a bug, but in case |
| 270 | # of such a bug, we want to at least get consistent, valid results. |
| 271 | TARGET_RELEASE = trunk_staging |
| 272 | endif |
| 273 | |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 274 | # During pass 1 of product config, using a non-existent release config is not an error. |
| 275 | # We can safely assume that we are doing pass 1 if DUMP_MANY_VARS=="PRODUCT_RELEASE_CONFIG_MAPS". |
LaMont Jones | 052282b | 2024-05-16 10:46:49 -0700 | [diff] [blame] | 276 | ifneq (,$(_final_product_config_pass)) |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 277 | ifeq ($(filter $(ALL_RELEASE_CONFIGS_FOR_PRODUCT), $(TARGET_RELEASE)),) |
| 278 | $(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE). Available releases are: $(ALL_RELEASE_CONFIGS_FOR_PRODUCT)) |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 279 | endif |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 280 | endif |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 281 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 282 | ifeq (,$(_use_protobuf)) |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 283 | # Choose flag files |
| 284 | # Don't sort this, use it in the order they gave us. |
| 285 | # Do allow duplicate entries, retaining only the first usage. |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 286 | flag_value_files := |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 287 | |
| 288 | # Apply overrides recursively |
| 289 | # |
| 290 | # $1 release config that we override |
| 291 | applied_releases := |
| 292 | define _apply-release-config-overrides |
| 293 | $(foreach r,$(1), \ |
| 294 | $(if $(filter $(r),$(applied_releases)),, \ |
| 295 | $(foreach o,$(_all_release_configs.$(r).OVERRIDES),$(call _apply-release-config-overrides,$(o)))\ |
| 296 | $(eval applied_releases += $(r))\ |
LaMont Jones | a6b6e67 | 2023-11-27 20:12:36 +0000 | [diff] [blame] | 297 | $(foreach f,$(_all_release_configs.$(r).FILES), \ |
| 298 | $(if $(filter $(f),$(flag_value_files)),,$(eval flag_value_files += $(f)))\ |
| 299 | )\ |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 300 | )\ |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 301 | ) |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 302 | endef |
| 303 | $(call _apply-release-config-overrides,$(TARGET_RELEASE)) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 304 | # Unset variables so they can't use them |
| 305 | define declare-release-config |
| 306 | $(error declare-release-config can only be called from inside release_config_map.mk files) |
| 307 | endef |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 308 | define _apply-release-config-overrides |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 309 | $(error invalid use of apply-release-config-overrides) |
| 310 | endef |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 311 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 312 | # use makefiles |
| 313 | endif |
| 314 | |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 315 | # TODO: Remove this check after enough people have sourced lunch that we don't |
| 316 | # need to worry about it trying to do get_build_vars TARGET_RELEASE. Maybe after ~9/2023 |
| 317 | ifneq ($(CALLED_FROM_SETUP),true) |
| 318 | define TARGET_RELEASE |
| 319 | $(error TARGET_RELEASE may not be accessed directly. Use individual flags.) |
| 320 | endef |
| 321 | else |
| 322 | TARGET_RELEASE:= |
| 323 | endif |
| 324 | .KATI_READONLY := TARGET_RELEASE |
| 325 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 326 | ifeq (,$(_use_protobuf)) |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 327 | $(foreach config, $(ALL_RELEASE_CONFIGS_FOR_PRODUCT), \ |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 328 | $(eval _all_release_configs.$(config).DECLARED_IN:= ) \ |
| 329 | $(eval _all_release_configs.$(config).FILES:= ) \ |
| 330 | ) |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 331 | applied_releases:= |
| 332 | # use makefiles |
| 333 | endif |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 334 | config_map_files:= |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 335 | protobuf_map_files:= |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 336 | |
| 337 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 338 | ifeq (,$(_use_protobuf)) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 339 | # ----------------------------------------------------------------- |
| 340 | # Flag declarations and values |
| 341 | # ----------------------------------------------------------------- |
| 342 | # This part is in starlark. We generate a root starlark file that loads |
| 343 | # all of the flags declaration files that we found, and the flag_value_files |
| 344 | # that we chose from the config map above. Then we run that, and load the |
| 345 | # results of that into the make environment. |
| 346 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 347 | # _flag_declaration_files is the combined list of FLAG_DECLARATION_FILES set by |
| 348 | # release_config_map.mk files above. |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 349 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 350 | # Because starlark can't find files with $(wildcard), write an entrypoint starlark script that |
| 351 | # contains the result of the above wildcards for the starlark code to use. |
| 352 | filename_to_starlark=$(subst /,_,$(subst .,_,$(1))) |
Cole Faust | 9a106f3 | 2023-11-08 09:51:04 -0800 | [diff] [blame] | 353 | _c:=load("//build/make/core/release_config.scl", "release_config") |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 354 | _c+=$(newline)def add(d, k, v): |
| 355 | _c+=$(newline)$(space)d = dict(d) |
| 356 | _c+=$(newline)$(space)d[k] = v |
| 357 | _c+=$(newline)$(space)return d |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 358 | _c+=$(foreach f,$(_flag_declaration_files),$(newline)load("$(f)", flags_$(call filename_to_starlark,$(f)) = "flags")) |
| 359 | _c+=$(newline)all_flags = [] $(foreach f,$(_flag_declaration_files),+ [add(x, "declared_in", "$(f)") for x in flags_$(call filename_to_starlark,$(f))]) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 360 | _c+=$(foreach f,$(flag_value_files),$(newline)load("//$(f)", values_$(call filename_to_starlark,$(f)) = "values")) |
| 361 | _c+=$(newline)all_values = [] $(foreach f,$(flag_value_files),+ [add(x, "set_in", "$(f)") for x in values_$(call filename_to_starlark,$(f))]) |
| 362 | _c+=$(newline)variables_to_export_to_make = release_config(all_flags, all_values) |
Cole Faust | 9a106f3 | 2023-11-08 09:51:04 -0800 | [diff] [blame] | 363 | $(file >$(OUT_DIR)/release_config_entrypoint.scl,$(_c)) |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 364 | _c:= |
| 365 | filename_to_starlark:= |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 366 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 367 | # Exclude the entrypoint file as a dependency (by passing it as the 2nd argument) so that we don't |
| 368 | # rerun kati every build. Kati will replay the $(file) command that generates it every build, |
| 369 | # updating its timestamp. |
| 370 | # |
| 371 | # We also need to pass --allow_external_entrypoint to rbcrun in case the OUT_DIR is set to something |
| 372 | # outside of the source tree. |
Cole Faust | 9a106f3 | 2023-11-08 09:51:04 -0800 | [diff] [blame] | 373 | $(call run-starlark,$(OUT_DIR)/release_config_entrypoint.scl,$(OUT_DIR)/release_config_entrypoint.scl,--allow_external_entrypoint) |
Joe Onorato | 7b578d3 | 2023-05-19 09:13:36 -0700 | [diff] [blame] | 374 | |
LaMont Jones | 20dd4c2 | 2024-05-01 11:24:08 -0700 | [diff] [blame] | 375 | # use makefiles |
| 376 | endif |
| 377 | _can_protobuf := |
| 378 | _must_protobuf := |
| 379 | _use_protobuf := |
Joe Onorato | 5f14162 | 2024-05-30 15:41:07 -0700 | [diff] [blame^] | 380 | |