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 | # ----------------------------------------------------------------- |
| 17 | # Choose the flag files |
| 18 | # ----------------------------------------------------------------- |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 19 | # Release configs are defined in reflease_config_map files, which map |
| 20 | # the short name (e.g. -next) used in lunch to the starlark files |
| 21 | # defining the build flag values. |
| 22 | # |
| 23 | # (If you're thinking about aconfig flags, there is one build flag, |
Joe Onorato | 6aa48f8 | 2023-06-21 15:17:42 -0700 | [diff] [blame] | 24 | # RELEASE_ACONFIG_VALUE_SETS, that sets which aconfig_value_set |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 25 | # module to use to set the aconfig flag values.) |
| 26 | # |
| 27 | # The short release config names *can* appear multiple times, to allow |
| 28 | # for AOSP and vendor specific flags under the same name, but the |
| 29 | # individual flag values must appear in exactly one config. Vendor |
| 30 | # does not override AOSP, or anything like that. This is because |
| 31 | # vendor code usually includes prebuilts, and having vendor compile |
| 32 | # with different flags from AOSP increases the likelihood of flag |
| 33 | # mismatch. |
| 34 | |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 35 | # Do this first, because we're going to unset TARGET_RELEASE before |
| 36 | # including anyone, so they don't start making conditionals based on it. |
| 37 | # This logic is in make because starlark doesn't understand optional |
| 38 | # vendor files. |
| 39 | |
| 40 | # If this is a google source tree, restrict it to only the one file |
| 41 | # which has OWNERS control. If it isn't let others define their own. |
| 42 | # TODO: Remove wildcard for build/release one when all branch manifests |
| 43 | # have updated. |
LaMont Jones | 318dafe | 2024-03-07 17:08:05 -0800 | [diff] [blame] | 44 | config_map_files := $(wildcard build/trunk_release/release_config_map.mk) \ |
| 45 | $(wildcard build/release/release_config_map.mk) \ |
| 46 | $(wildcard vendor/google_shared/build/release/release_config_map.mk) \ |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 47 | $(if $(wildcard vendor/google/release/release_config_map.mk), \ |
| 48 | vendor/google/release/release_config_map.mk, \ |
| 49 | $(sort \ |
| 50 | $(wildcard device/*/release/release_config_map.mk) \ |
| 51 | $(wildcard device/*/*/release/release_config_map.mk) \ |
| 52 | $(wildcard vendor/*/release/release_config_map.mk) \ |
| 53 | $(wildcard vendor/*/*/release/release_config_map.mk) \ |
| 54 | ) \ |
| 55 | ) |
| 56 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 57 | # PRODUCT_RELEASE_CONFIG_MAPS is set by Soong using an initial run of product |
| 58 | # config to capture only the list of config maps needed by the build. |
| 59 | # Keep them in the order provided, but remove duplicates. |
| 60 | $(foreach map,$(PRODUCT_RELEASE_CONFIG_MAPS), \ |
| 61 | $(if $(filter $(map),$(config_map_files)),,$(eval config_map_files += $(map))) \ |
| 62 | ) |
| 63 | |
LaMont Jones | 61b0f79 | 2024-01-30 23:04:02 +0000 | [diff] [blame] | 64 | # Declare an alias release-config |
| 65 | # |
| 66 | # This should be used to declare a release as an alias of another, meaning no |
| 67 | # release config files should be present. |
| 68 | # |
| 69 | # $1 config name |
| 70 | # $2 release config for which it is an alias |
| 71 | define alias-release-config |
| 72 | $(call _declare-release-config,$(1),,$(2),true) |
| 73 | endef |
| 74 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 75 | # Declare or extend a release-config. |
| 76 | # |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 77 | # The order of processing is: |
| 78 | # 1. Recursively apply any overridden release configs. Only apply each config |
| 79 | # the first time we reach it. |
| 80 | # 2. Apply any files for this release config, in the order they were added to |
| 81 | # the declaration. |
| 82 | # |
| 83 | # Example: |
| 84 | # With these declarations: |
| 85 | # $(declare-release-config foo, foo.scl) |
| 86 | # $(declare-release-config bar, bar.scl, foo) |
| 87 | # $(declare-release-config baz, baz.scl, bar) |
| 88 | # $(declare-release-config bif, bif.scl, foo baz) |
| 89 | # $(declare-release-config bop, bop.scl, bar baz) |
| 90 | # |
| 91 | # TARGET_RELEASE: |
| 92 | # - bar will use: foo.scl bar.scl |
| 93 | # - baz will use: foo.scl bar.scl baz.scl |
| 94 | # - bif will use: foo.scl bar.scl baz.scl bif.scl |
| 95 | # - bop will use: foo.scl bar.scl baz.scl bop.scl |
| 96 | # |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 97 | # $1 config name |
| 98 | # $2 release config files |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 99 | # $3 overridden release config |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 100 | define declare-release-config |
LaMont Jones | 61b0f79 | 2024-01-30 23:04:02 +0000 | [diff] [blame] | 101 | $(call _declare-release-config,$(1),$(2),$(3),) |
| 102 | endef |
| 103 | |
| 104 | define _declare-release-config |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 105 | $(if $(strip $(2)$(3)),, \ |
| 106 | $(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] | 107 | ) |
LaMont Jones | 61b0f79 | 2024-01-30 23:04:02 +0000 | [diff] [blame] | 108 | $(if $(strip $(4)),$(eval _all_release_configs.$(strip $(1)).ALIAS := true)) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 109 | $(eval _all_release_configs := $(sort $(_all_release_configs) $(strip $(1)))) |
LaMont Jones | a6b6e67 | 2023-11-27 20:12:36 +0000 | [diff] [blame] | 110 | $(if $(strip $(3)), \ |
| 111 | $(if $(filter $(_all_release_configs), $(strip $(3))), |
| 112 | $(if $(filter $(_all_release_configs.$(strip $(1)).OVERRIDES),$(strip $(3))),, |
| 113 | $(eval _all_release_configs.$(strip $(1)).OVERRIDES := $(_all_release_configs.$(strip $(1)).OVERRIDES) $(strip $(3)))), \ |
| 114 | $(error No release config $(strip $(3))) \ |
| 115 | ) \ |
| 116 | ) |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 117 | $(eval _all_release_configs.$(strip $(1)).DECLARED_IN := $(_included) $(_all_release_configs.$(strip $(1)).DECLARED_IN)) |
| 118 | $(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] | 119 | endef |
| 120 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 121 | # Include the config map files and populate _flag_declaration_files. |
LaMont Jones | 451abd6 | 2024-03-14 10:48:55 -0700 | [diff] [blame] | 122 | # 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] | 123 | _flag_declaration_files := |
LaMont Jones | 451abd6 | 2024-03-14 10:48:55 -0700 | [diff] [blame] | 124 | _included_config_map_files := |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 125 | $(foreach f, $(config_map_files), \ |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 126 | $(eval FLAG_DECLARATION_FILES:= ) \ |
LaMont Jones | 451abd6 | 2024-03-14 10:48:55 -0700 | [diff] [blame] | 127 | $(if $(filter $(_included_config_map_files),$(f)),,\ |
| 128 | $(eval _included := $(f)) \ |
| 129 | $(eval include $(f)) \ |
| 130 | $(eval _flag_declaration_files += $(FLAG_DECLARATION_FILES)) \ |
| 131 | $(eval _included_config_map_files += $(f)) \ |
| 132 | ) \ |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 133 | ) |
| 134 | FLAG_DECLARATION_FILES := |
| 135 | |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 136 | # Verify that all inherited/overridden release configs are declared. |
| 137 | $(foreach config,$(_all_release_configs),\ |
| 138 | $(foreach r,$(all_release_configs.$(r).OVERRIDES),\ |
| 139 | $(if $(strip $(_all_release_configs.$(r).FILES)$(_all_release_configs.$(r).OVERRIDES)),,\ |
| 140 | $(error Release config $(config) [declared in: $(_all_release_configs.$(r).DECLARED_IN)] inherits from non-existent $(r).)\ |
| 141 | ))) |
| 142 | # Verify that alias configs do not have config files. |
| 143 | $(foreach r,$(_all_release_configs),\ |
| 144 | $(if $(_all_release_configs.$(r).ALIAS),$(if $(_all_release_configs.$(r).FILES),\ |
| 145 | $(error Alias release config "$(r)" may not specify release config files $(_all_release_configs.$(r).FILES))\ |
| 146 | ))) |
| 147 | |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 148 | ifeq ($(TARGET_RELEASE),) |
| 149 | # We allow some internal paths to explicitly set TARGET_RELEASE to the |
| 150 | # empty string. For the most part, 'make' treats unset and empty string as |
| 151 | # the same. But the following line differentiates, and will only assign |
| 152 | # if the variable was completely unset. |
| 153 | TARGET_RELEASE ?= was_unset |
| 154 | ifeq ($(TARGET_RELEASE),was_unset) |
| 155 | $(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)) |
| 156 | endif |
| 157 | # Instead of leaving this string empty, we want to default to a valid |
| 158 | # setting. Full builds coming through this path is a bug, but in case |
| 159 | # of such a bug, we want to at least get consistent, valid results. |
| 160 | TARGET_RELEASE = trunk_staging |
| 161 | endif |
| 162 | |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 163 | # During pass 1 of product config, using a non-existent release config is not an error. |
| 164 | # We can safely assume that we are doing pass 1 if DUMP_MANY_VARS=="PRODUCT_RELEASE_CONFIG_MAPS". |
| 165 | ifneq (PRODUCT_RELEASE_CONFIG_MAPS,$(DUMP_MANY_VARS)) |
| 166 | ifeq ($(filter $(_all_release_configs), $(TARGET_RELEASE)),) |
| 167 | $(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE). Available releases are: $(_all_release_configs)) |
| 168 | endif |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 169 | endif |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 170 | |
| 171 | # Choose flag files |
| 172 | # Don't sort this, use it in the order they gave us. |
| 173 | # Do allow duplicate entries, retaining only the first usage. |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 174 | flag_value_files := |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 175 | |
| 176 | # Apply overrides recursively |
| 177 | # |
| 178 | # $1 release config that we override |
| 179 | applied_releases := |
| 180 | define _apply-release-config-overrides |
| 181 | $(foreach r,$(1), \ |
| 182 | $(if $(filter $(r),$(applied_releases)),, \ |
| 183 | $(foreach o,$(_all_release_configs.$(r).OVERRIDES),$(call _apply-release-config-overrides,$(o)))\ |
| 184 | $(eval applied_releases += $(r))\ |
LaMont Jones | a6b6e67 | 2023-11-27 20:12:36 +0000 | [diff] [blame] | 185 | $(foreach f,$(_all_release_configs.$(r).FILES), \ |
| 186 | $(if $(filter $(f),$(flag_value_files)),,$(eval flag_value_files += $(f)))\ |
| 187 | )\ |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 188 | )\ |
Greg Kaiser | 0229ecf | 2023-11-09 20:28:55 +0000 | [diff] [blame] | 189 | ) |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 190 | endef |
| 191 | $(call _apply-release-config-overrides,$(TARGET_RELEASE)) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 192 | # Unset variables so they can't use them |
| 193 | define declare-release-config |
| 194 | $(error declare-release-config can only be called from inside release_config_map.mk files) |
| 195 | endef |
LaMont Jones | 76452d8 | 2024-03-20 12:24:21 -0700 | [diff] [blame] | 196 | define _apply-release-config-overrides |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 197 | $(error invalid use of apply-release-config-overrides) |
| 198 | endef |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 199 | |
| 200 | # TODO: Remove this check after enough people have sourced lunch that we don't |
| 201 | # need to worry about it trying to do get_build_vars TARGET_RELEASE. Maybe after ~9/2023 |
| 202 | ifneq ($(CALLED_FROM_SETUP),true) |
| 203 | define TARGET_RELEASE |
| 204 | $(error TARGET_RELEASE may not be accessed directly. Use individual flags.) |
| 205 | endef |
| 206 | else |
| 207 | TARGET_RELEASE:= |
| 208 | endif |
| 209 | .KATI_READONLY := TARGET_RELEASE |
| 210 | |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 211 | $(foreach config, $(_all_release_configs), \ |
| 212 | $(eval _all_release_configs.$(config).DECLARED_IN:= ) \ |
| 213 | $(eval _all_release_configs.$(config).FILES:= ) \ |
| 214 | ) |
| 215 | _all_release_configs:= |
| 216 | config_map_files:= |
LaMont Jones | 55d5fc5 | 2024-01-23 19:15:49 +0000 | [diff] [blame] | 217 | applied_releases:= |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 218 | |
| 219 | |
| 220 | # ----------------------------------------------------------------- |
| 221 | # Flag declarations and values |
| 222 | # ----------------------------------------------------------------- |
| 223 | # This part is in starlark. We generate a root starlark file that loads |
| 224 | # all of the flags declaration files that we found, and the flag_value_files |
| 225 | # that we chose from the config map above. Then we run that, and load the |
| 226 | # results of that into the make environment. |
| 227 | |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 228 | # _flag_declaration_files is the combined list of FLAG_DECLARATION_FILES set by |
| 229 | # release_config_map.mk files above. |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 230 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 231 | # Because starlark can't find files with $(wildcard), write an entrypoint starlark script that |
| 232 | # contains the result of the above wildcards for the starlark code to use. |
| 233 | filename_to_starlark=$(subst /,_,$(subst .,_,$(1))) |
Cole Faust | 9a106f3 | 2023-11-08 09:51:04 -0800 | [diff] [blame] | 234 | _c:=load("//build/make/core/release_config.scl", "release_config") |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 235 | _c+=$(newline)def add(d, k, v): |
| 236 | _c+=$(newline)$(space)d = dict(d) |
| 237 | _c+=$(newline)$(space)d[k] = v |
| 238 | _c+=$(newline)$(space)return d |
LaMont Jones | 38b195e | 2023-11-06 22:14:51 +0000 | [diff] [blame] | 239 | _c+=$(foreach f,$(_flag_declaration_files),$(newline)load("$(f)", flags_$(call filename_to_starlark,$(f)) = "flags")) |
| 240 | _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] | 241 | _c+=$(foreach f,$(flag_value_files),$(newline)load("//$(f)", values_$(call filename_to_starlark,$(f)) = "values")) |
| 242 | _c+=$(newline)all_values = [] $(foreach f,$(flag_value_files),+ [add(x, "set_in", "$(f)") for x in values_$(call filename_to_starlark,$(f))]) |
| 243 | _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] | 244 | $(file >$(OUT_DIR)/release_config_entrypoint.scl,$(_c)) |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 245 | _c:= |
| 246 | filename_to_starlark:= |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 247 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 248 | # Exclude the entrypoint file as a dependency (by passing it as the 2nd argument) so that we don't |
| 249 | # rerun kati every build. Kati will replay the $(file) command that generates it every build, |
| 250 | # updating its timestamp. |
| 251 | # |
| 252 | # We also need to pass --allow_external_entrypoint to rbcrun in case the OUT_DIR is set to something |
| 253 | # outside of the source tree. |
Cole Faust | 9a106f3 | 2023-11-08 09:51:04 -0800 | [diff] [blame] | 254 | $(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] | 255 | |