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 | |
| 15 | # Partitions that get build system flag summaries |
| 16 | _FLAG_PARTITIONS := system vendor system_ext product |
| 17 | |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 18 | # All possible release flags. Defined in the build_flags.mk files |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 19 | # throughout the tree |
| 20 | _ALL_RELEASE_FLAGS := |
| 21 | |
| 22 | # ----------------------------------------------------------------- |
| 23 | # Choose the flag files |
| 24 | # Do this first, because we're going to unset TARGET_RELEASE before |
| 25 | # including anyone, so they don't start making conditionals based on it. |
| 26 | |
| 27 | # If this is a google source tree, restrict it to only the one file |
| 28 | # which has OWNERS control. If it isn't let others define their own. |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 29 | # TODO: Remove wildcard for build/release one when all branch manifests |
| 30 | # have updated. |
| 31 | config_map_files := $(wildcard build/release/release_config_map.mk) \ |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 32 | $(if $(wildcard vendor/google/release/release_config_map.mk), \ |
| 33 | vendor/google/release/release_config_map.mk, \ |
| 34 | $(sort \ |
| 35 | $(wildcard device/*/release/release_config_map.mk) \ |
| 36 | $(wildcard device/*/*/release/release_config_map.mk) \ |
| 37 | $(wildcard vendor/*/release/release_config_map.mk) \ |
| 38 | $(wildcard vendor/*/*/release/release_config_map.mk) \ |
| 39 | ) \ |
| 40 | ) |
| 41 | |
| 42 | # $1 config name |
| 43 | # $2 release config files |
| 44 | define declare-release-config |
| 45 | $(eval # No duplicates) |
| 46 | $(if $(filter $(_all_release_configs), $(strip $(1))), \ |
| 47 | $(error declare-release-config: config $(strip $(1)) declared in: $(_included) Previously declared here: $(_all_release_configs.$(strip $(1)).DECLARED_IN)) \ |
| 48 | ) |
| 49 | $(eval # Must have release config files) |
| 50 | $(if $(strip $(2)),, \ |
| 51 | $(error declare-release-config: config $(strip $(1)) must have release config files) \ |
| 52 | ) |
| 53 | $(eval _all_release_configs := $(sort $(_all_release_configs) $(strip $(1)))) |
| 54 | $(eval _all_release_configs.$(strip $(1)).DECLARED_IN := $(_included)) |
| 55 | $(eval _all_release_configs.$(strip $(1)).FILES := $(strip $(2))) |
| 56 | endef |
| 57 | |
| 58 | # Include the config map files |
| 59 | $(foreach f, $(config_map_files), \ |
| 60 | $(eval _included := $(f)) \ |
| 61 | $(eval include $(f)) \ |
| 62 | ) |
| 63 | |
| 64 | # If TARGET_RELEASE is set, fail if there is no matching release config |
| 65 | # If it isn't set, no release config files will be included and all flags |
| 66 | # will get their default values. |
| 67 | ifneq ($(TARGET_RELEASE),) |
| 68 | ifeq ($(filter $(_all_release_configs), $(TARGET_RELEASE)),) |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 69 | $(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE). Available releases are: $(_all_release_configs)) |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 70 | else |
| 71 | # Choose flag files |
| 72 | # Don't sort this, use it in the order they gave us. |
| 73 | _release_config_files := $(_all_release_configs.$(TARGET_RELEASE).FILES) |
| 74 | endif |
| 75 | else |
| 76 | # Useful for finding scripts etc that aren't passing or setting TARGET_RELEASE |
| 77 | ifneq ($(FAIL_IF_NO_RELEASE_CONFIG),) |
| 78 | $(error FAIL_IF_NO_RELEASE_CONFIG was set and TARGET_RELEASE was not) |
| 79 | endif |
| 80 | _release_config_files := |
| 81 | endif |
| 82 | |
| 83 | # Unset variables so they can't use it |
| 84 | define declare-release-config |
| 85 | $(error declare-release-config can only be called from inside release_config_map.mk files) |
| 86 | endef |
| 87 | |
| 88 | # TODO: Remove this check after enough people have sourced lunch that we don't |
| 89 | # need to worry about it trying to do get_build_vars TARGET_RELEASE. Maybe after ~9/2023 |
| 90 | ifneq ($(CALLED_FROM_SETUP),true) |
| 91 | define TARGET_RELEASE |
| 92 | $(error TARGET_RELEASE may not be accessed directly. Use individual flags.) |
| 93 | endef |
| 94 | else |
| 95 | TARGET_RELEASE:= |
| 96 | endif |
| 97 | .KATI_READONLY := TARGET_RELEASE |
| 98 | |
| 99 | $(foreach config, $(_all_release_configs), \ |
| 100 | $(eval _all_release_configs.$(config).DECLARED_IN:= ) \ |
| 101 | $(eval _all_release_configs.$(config).FILES:= ) \ |
| 102 | ) |
| 103 | _all_release_configs:= |
| 104 | config_map_files:= |
| 105 | |
| 106 | # ----------------------------------------------------------------- |
| 107 | # Declare the flags |
| 108 | |
| 109 | # $1 partition(s) |
| 110 | # $2 flag name. Must start with RELEASE_ |
| 111 | # $3 default. True or false |
| 112 | define declare-build-flag |
| 113 | $(if $(filter-out all $(_FLAG_PARTITIONS), $(strip $(1))), \ |
| 114 | $(error declare-build-flag: invalid partitions: $(strip $(1))) \ |
| 115 | ) |
| 116 | $(if $(and $(filter all,$(strip $(1))),$(filter-out all, $(strip $(1)))), \ |
| 117 | $(error declare-build-flag: "all" can't be combined with other partitions: $(strip $(1))), \ |
| 118 | $(eval declare-build-flag.partition := $(_FLAG_PARTITIONS)) \ |
| 119 | ) |
| 120 | $(if $(filter-out RELEASE_%, $(strip $(2))), \ |
| 121 | $(error declare-build-flag: Release flag names must start with RELEASE_: $(strip $(2))) \ |
| 122 | ) |
| 123 | $(eval _ALL_RELEASE_FLAGS += $(strip $(2))) |
| 124 | $(foreach partition, $(declare-build-flag.partition), \ |
| 125 | $(eval _ALL_RELEASE_FLAGS.PARTITIONS.$(partition) := $(sort \ |
| 126 | $(_ALL_RELEASE_FLAGS.PARTITIONS.$(partition)) $(strip $(2)))) \ |
| 127 | ) |
| 128 | $(eval _ALL_RELEASE_FLAGS.$(strip $(2)).PARTITIONS := $(declare-build-flag.partition)) |
| 129 | $(eval _ALL_RELEASE_FLAGS.$(strip $(2)).DEFAULT := $(strip $(3))) |
| 130 | $(eval _ALL_RELEASE_FLAGS.$(strip $(2)).DECLARED_IN := $(_included)) |
| 131 | $(eval _ALL_RELEASE_FLAGS.$(strip $(2)).VALUE := $(strip $(3))) |
| 132 | $(eval _ALL_RELEASE_FLAGS.$(strip $(2)).SET_IN := $(_included)) |
| 133 | $(eval declare-build-flag.partition:=) |
| 134 | endef |
| 135 | |
| 136 | |
| 137 | # Choose the files |
| 138 | # If this is a google source tree, restrict it to only the one file |
| 139 | # which has OWNERS control. If it isn't let others define their own. |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 140 | flag_declaration_files := $(wildcard build/release/build_flags.mk) \ |
| 141 | $(if $(wildcard vendor/google/release/build_flags.mk), \ |
| 142 | vendor/google/release/build_flags.mk, \ |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 143 | $(sort \ |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 144 | $(wildcard device/*/release/build_flags.mk) \ |
| 145 | $(wildcard device/*/*/release/build_flags.mk) \ |
| 146 | $(wildcard vendor/*/release/build_flags.mk) \ |
| 147 | $(wildcard vendor/*/*/release/build_flags.mk) \ |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 148 | ) \ |
| 149 | ) |
| 150 | |
| 151 | # Include the files |
| 152 | $(foreach f, $(flag_declaration_files), \ |
| 153 | $(eval _included := $(f)) \ |
| 154 | $(eval include $(f)) \ |
| 155 | ) |
| 156 | |
| 157 | # Don't let anyone declare build flags after here |
| 158 | define declare-build-flag |
| 159 | $(error declare-build-flag can only be called from inside flag definition files.) |
| 160 | endef |
| 161 | |
| 162 | # No more flags from here on |
| 163 | .KATI_READONLY := _ALL_RELEASE_FLAGS |
| 164 | |
| 165 | # ----------------------------------------------------------------- |
| 166 | # Set the flags |
| 167 | |
| 168 | # $(1): Flag name. Must start with RELEASE_ and have been defined by declare-build-flag |
| 169 | # $(2): Value. True or false |
| 170 | define set-build-flag |
| 171 | $(if $(filter-out $(_ALL_RELEASE_FLAGS), $(strip $(1))), \ |
| 172 | $(error set-build-flag: Undeclared build flag: $(strip $(1))) \ |
| 173 | ) |
| 174 | $(eval _ALL_RELEASE_FLAGS.$(strip $(1)).VALUE := $(strip $(2))) |
| 175 | $(eval _ALL_RELEASE_FLAGS.$(strip $(1)).SET_IN := $(_included)) |
| 176 | endef |
| 177 | |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 178 | # This writes directly to a file so that the version never exists in make for |
| 179 | # people to write conditionals upon. |
| 180 | define set-release-version |
| 181 | $(eval _RELEASE_VERSION := $(strip $(1))) |
| 182 | endef |
| 183 | |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 184 | # Include the files (if there are any) |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 185 | ifneq ($(strip $(_release_config_files)),) |
| 186 | $(foreach f, $(_release_config_files), \ |
| 187 | $(eval _included := $(f)) \ |
| 188 | $(eval include $(f)) \ |
| 189 | ) |
| 190 | else |
| 191 | # No TARGET_RELEASE means release version 0 |
| 192 | $(call set-release-version, 0) |
| 193 | endif |
| 194 | |
| 195 | |
| 196 | ifeq ($(_RELEASE_VERSION)),) |
| 197 | $(error No release config file called set-release-version. Included files were: $(_release_config_files)) |
| 198 | endif |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 199 | |
| 200 | # Don't let anyone declare build flags after here |
| 201 | define set-build-flag |
| 202 | $(error set-build-flag can only be called from inside release config files.) |
| 203 | endef |
| 204 | |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 205 | # Don't let anyone set the release version after here |
| 206 | define set-release-version |
| 207 | $(error set-release-version can only be called from inside release config files.) |
| 208 | endef |
| 209 | |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 210 | # Set the flag values, and don't allow any one to modify them. |
| 211 | $(foreach flag, $(_ALL_RELEASE_FLAGS), \ |
| 212 | $(eval $(flag) := $(_ALL_RELEASE_FLAGS.$(flag).VALUE)) \ |
| 213 | $(eval .KATI_READONLY := $(flag)) \ |
| 214 | ) |
| 215 | |
Joe Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame^] | 216 | |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 217 | # ----------------------------------------------------------------- |
| 218 | # Clear out vars |
| 219 | flag_declaration_files:= |
| 220 | flag_files:= |
| 221 | _included:= |
| 222 | _release_config_files:= |