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