blob: fdfc6a06f17e82483ebc5b3efdfd409aed89095b [file] [log] [blame]
Joe Onorato964f4012023-05-06 12:29:01 -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# Partitions that get build system flag summaries
16_FLAG_PARTITIONS := system vendor system_ext product
17
Joe Onorato0d1a9812023-05-07 13:40:25 -070018# All possible release flags. Defined in the build_flags.mk files
Joe Onorato964f4012023-05-06 12:29:01 -070019# 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 Onorato0d1a9812023-05-07 13:40:25 -070029# TODO: Remove wildcard for build/release one when all branch manifests
30# have updated.
31config_map_files := $(wildcard build/release/release_config_map.mk) \
Joe Onorato964f4012023-05-06 12:29:01 -070032 $(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
44define 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)))
56endef
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.
67ifneq ($(TARGET_RELEASE),)
68ifeq ($(filter $(_all_release_configs), $(TARGET_RELEASE)),)
Joe Onorato0d1a9812023-05-07 13:40:25 -070069 $(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE). Available releases are: $(_all_release_configs))
Joe Onorato964f4012023-05-06 12:29:01 -070070else
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)
74endif
75else
76# Useful for finding scripts etc that aren't passing or setting TARGET_RELEASE
77ifneq ($(FAIL_IF_NO_RELEASE_CONFIG),)
78 $(error FAIL_IF_NO_RELEASE_CONFIG was set and TARGET_RELEASE was not)
79endif
80_release_config_files :=
81endif
82
83# Unset variables so they can't use it
84define declare-release-config
85$(error declare-release-config can only be called from inside release_config_map.mk files)
86endef
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
90ifneq ($(CALLED_FROM_SETUP),true)
91define TARGET_RELEASE
92$(error TARGET_RELEASE may not be accessed directly. Use individual flags.)
93endef
94else
95TARGET_RELEASE:=
96endif
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:=
104config_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
112define 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:=)
134endef
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 Onorato0d1a9812023-05-07 13:40:25 -0700140flag_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 Onorato964f4012023-05-06 12:29:01 -0700143 $(sort \
Joe Onorato0d1a9812023-05-07 13:40:25 -0700144 $(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 Onorato964f4012023-05-06 12:29:01 -0700148 ) \
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
158define declare-build-flag
159$(error declare-build-flag can only be called from inside flag definition files.)
160endef
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
170define 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))
176endef
177
Joe Onorato0d1a9812023-05-07 13:40:25 -0700178# This writes directly to a file so that the version never exists in make for
179# people to write conditionals upon.
180define set-release-version
181 $(eval _RELEASE_VERSION := $(strip $(1)))
182endef
183
Joe Onorato964f4012023-05-06 12:29:01 -0700184# Include the files (if there are any)
Joe Onorato0d1a9812023-05-07 13:40:25 -0700185ifneq ($(strip $(_release_config_files)),)
186 $(foreach f, $(_release_config_files), \
187 $(eval _included := $(f)) \
188 $(eval include $(f)) \
189 )
190else
191 # No TARGET_RELEASE means release version 0
192 $(call set-release-version, 0)
193endif
194
195
196ifeq ($(_RELEASE_VERSION)),)
197 $(error No release config file called set-release-version. Included files were: $(_release_config_files))
198endif
Joe Onorato964f4012023-05-06 12:29:01 -0700199
200# Don't let anyone declare build flags after here
201define set-build-flag
202$(error set-build-flag can only be called from inside release config files.)
203endef
204
Joe Onorato0d1a9812023-05-07 13:40:25 -0700205# Don't let anyone set the release version after here
206define set-release-version
207$(error set-release-version can only be called from inside release config files.)
208endef
209
Joe Onorato964f4012023-05-06 12:29:01 -0700210# 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 Onorato0d1a9812023-05-07 13:40:25 -0700216
Joe Onorato964f4012023-05-06 12:29:01 -0700217# -----------------------------------------------------------------
218# Clear out vars
219flag_declaration_files:=
220flag_files:=
221_included:=
222_release_config_files:=