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 | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 15 | # 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 Onorato | 0d1a981 | 2023-05-07 13:40:25 -0700 | [diff] [blame] | 17 | # TODO: Remove wildcard for build/release one when all branch manifests |
| 18 | # have updated. |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 19 | flag_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 Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 22 | $(sort \ |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 23 | $(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 | ) |
| 29 | config_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 Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 37 | ) \ |
| 38 | ) |
| 39 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 40 | # 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. |
| 42 | filename_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:= |
| 53 | filename_to_starlark:= |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 54 | |
| 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 |
| 57 | ifneq ($(CALLED_FROM_SETUP),true) |
| 58 | define TARGET_RELEASE |
| 59 | $(error TARGET_RELEASE may not be accessed directly. Use individual flags.) |
| 60 | endef |
| 61 | else |
| 62 | TARGET_RELEASE:= |
| 63 | endif |
| 64 | .KATI_READONLY := TARGET_RELEASE |
| 65 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 66 | # 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 Onorato | 7b578d3 | 2023-05-19 09:13:36 -0700 | [diff] [blame] | 73 | |
| 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 | |