blob: ce57855aae4e7e6def2c560a1d52d830dc1ee3cc [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
Joe Onorato964f4012023-05-06 12:29:01 -070015# If this is a google source tree, restrict it to only the one file
16# which has OWNERS control. If it isn't let others define their own.
Joe Onorato0d1a9812023-05-07 13:40:25 -070017# TODO: Remove wildcard for build/release one when all branch manifests
18# have updated.
Cole Faust386b3742023-06-06 16:55:58 -070019flag_declaration_files := $(wildcard build/release/build_flags.bzl) \
20 $(if $(wildcard vendor/google/release/build_flags.bzl), \
21 vendor/google/release/build_flags.bzl, \
Joe Onorato964f4012023-05-06 12:29:01 -070022 $(sort \
Cole Faust386b3742023-06-06 16:55:58 -070023 $(wildcard device/*/release/build_flags.bzl) \
24 $(wildcard device/*/*/release/build_flags.bzl) \
25 $(wildcard vendor/*/release/build_flags.bzl) \
26 $(wildcard vendor/*/*/release/build_flags.bzl) \
27 ) \
28 )
29config_map_files := $(wildcard build/release/release_config_map.bzl) \
30 $(if $(wildcard vendor/google/release/release_config_map.bzl), \
31 vendor/google/release/release_config_map.bzl, \
32 $(sort \
33 $(wildcard device/*/release/release_config_map.bzl) \
34 $(wildcard device/*/*/release/release_config_map.bzl) \
35 $(wildcard vendor/*/release/release_config_map.bzl) \
36 $(wildcard vendor/*/*/release/release_config_map.bzl) \
Joe Onorato964f4012023-05-06 12:29:01 -070037 ) \
38 )
39
Cole Faust386b3742023-06-06 16:55:58 -070040# Because starlark can't find files with $(wildcard), write an entrypoint starlark script that
41# contains the result of the above wildcards for the starlark code to use.
42filename_to_starlark=$(subst /,_,$(subst .,_,$(1)))
43_c:=load("//build/make/core/release_config.bzl", "release_config")
44_c+=$(foreach f,$(flag_declaration_files),$(newline)load("//$(f)", flags_$(call filename_to_starlark,$(f)) = "flags"))
45_c+=$(foreach f,$(config_map_files),$(newline)load("//$(f)", config_maps_$(call filename_to_starlark,$(f)) = "config_maps"))
46_c+=$(newline)all_flags = [] $(foreach f,$(flag_declaration_files),+ flags_$(call filename_to_starlark,$(f)))
47_c+=$(newline)all_config_maps = [$(foreach f,$(config_map_files),config_maps_$(call filename_to_starlark,$(f))$(comma))]
48_c+=$(newline)target_release = "$(TARGET_RELEASE)"
49_c+=$(newline)fail_if_no_release_config = True if "$(FAIL_IF_NO_RELEASE_CONFIG)" else False
50_c+=$(newline)variables_to_export_to_make = release_config(target_release, all_flags, all_config_maps, fail_if_no_release_config)
51$(file >$(OUT_DIR)/release_config_entrypoint.bzl,$(_c))
52_c:=
53filename_to_starlark:=
Joe Onorato964f4012023-05-06 12:29:01 -070054
55# TODO: Remove this check after enough people have sourced lunch that we don't
56# need to worry about it trying to do get_build_vars TARGET_RELEASE. Maybe after ~9/2023
57ifneq ($(CALLED_FROM_SETUP),true)
58define TARGET_RELEASE
59$(error TARGET_RELEASE may not be accessed directly. Use individual flags.)
60endef
61else
62TARGET_RELEASE:=
63endif
64.KATI_READONLY := TARGET_RELEASE
65
Cole Faust386b3742023-06-06 16:55:58 -070066# Exclude the entrypoint file as a dependency (by passing it as the 2nd argument) so that we don't
67# rerun kati every build. Kati will replay the $(file) command that generates it every build,
68# updating its timestamp.
69#
70# We also need to pass --allow_external_entrypoint to rbcrun in case the OUT_DIR is set to something
71# outside of the source tree.
72$(call run-starlark,$(OUT_DIR)/release_config_entrypoint.bzl,$(OUT_DIR)/release_config_entrypoint.bzl,--allow_external_entrypoint)
Joe Onorato7b578d32023-05-19 09:13:36 -070073
74# Set the flag values, and don't allow any one to modify them.
75$(foreach flag, $(_ALL_RELEASE_FLAGS), \
76 $(eval $(flag) := $(_ALL_RELEASE_FLAGS.$(flag).VALUE)) \
77 $(eval .KATI_READONLY := $(flag)) \
78)
79