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 | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 15 | |
| 16 | # ----------------------------------------------------------------- |
| 17 | # Choose the flag files |
| 18 | # ----------------------------------------------------------------- |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 19 | # Release configs are defined in reflease_config_map files, which map |
| 20 | # the short name (e.g. -next) used in lunch to the starlark files |
| 21 | # defining the build flag values. |
| 22 | # |
| 23 | # (If you're thinking about aconfig flags, there is one build flag, |
Joe Onorato | 6aa48f8 | 2023-06-21 15:17:42 -0700 | [diff] [blame] | 24 | # RELEASE_ACONFIG_VALUE_SETS, that sets which aconfig_value_set |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 25 | # module to use to set the aconfig flag values.) |
| 26 | # |
| 27 | # The short release config names *can* appear multiple times, to allow |
| 28 | # for AOSP and vendor specific flags under the same name, but the |
| 29 | # individual flag values must appear in exactly one config. Vendor |
| 30 | # does not override AOSP, or anything like that. This is because |
| 31 | # vendor code usually includes prebuilts, and having vendor compile |
| 32 | # with different flags from AOSP increases the likelihood of flag |
| 33 | # mismatch. |
| 34 | |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 35 | # Do this first, because we're going to unset TARGET_RELEASE before |
| 36 | # including anyone, so they don't start making conditionals based on it. |
| 37 | # This logic is in make because starlark doesn't understand optional |
| 38 | # vendor files. |
| 39 | |
| 40 | # If this is a google source tree, restrict it to only the one file |
| 41 | # which has OWNERS control. If it isn't let others define their own. |
| 42 | # TODO: Remove wildcard for build/release one when all branch manifests |
| 43 | # have updated. |
| 44 | config_map_files := $(wildcard build/release/release_config_map.mk) \ |
| 45 | $(if $(wildcard vendor/google/release/release_config_map.mk), \ |
| 46 | vendor/google/release/release_config_map.mk, \ |
| 47 | $(sort \ |
| 48 | $(wildcard device/*/release/release_config_map.mk) \ |
| 49 | $(wildcard device/*/*/release/release_config_map.mk) \ |
| 50 | $(wildcard vendor/*/release/release_config_map.mk) \ |
| 51 | $(wildcard vendor/*/*/release/release_config_map.mk) \ |
| 52 | ) \ |
| 53 | ) |
| 54 | |
| 55 | # $1 config name |
| 56 | # $2 release config files |
| 57 | define declare-release-config |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 58 | $(if $(strip $(2)),, \ |
| 59 | $(error declare-release-config: config $(strip $(1)) must have release config files) \ |
| 60 | ) |
| 61 | $(eval _all_release_configs := $(sort $(_all_release_configs) $(strip $(1)))) |
Joe Onorato | 1f65551 | 2023-06-12 23:29:25 -0700 | [diff] [blame] | 62 | $(eval _all_release_configs.$(strip $(1)).DECLARED_IN := $(_included) $(_all_release_configs.$(strip $(1)).DECLARED_IN)) |
| 63 | $(eval _all_release_configs.$(strip $(1)).FILES := $(_all_release_configs.$(strip $(1)).FILES) $(strip $(2))) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 64 | endef |
| 65 | |
| 66 | # Include the config map files |
| 67 | $(foreach f, $(config_map_files), \ |
| 68 | $(eval _included := $(f)) \ |
| 69 | $(eval include $(f)) \ |
| 70 | ) |
| 71 | |
| 72 | # If TARGET_RELEASE is set, fail if there is no matching release config |
| 73 | # If it isn't set, no release config files will be included and all flags |
| 74 | # will get their default values. |
| 75 | ifneq ($(TARGET_RELEASE),) |
| 76 | ifeq ($(filter $(_all_release_configs), $(TARGET_RELEASE)),) |
| 77 | $(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE). Available releases are: $(_all_release_configs)) |
| 78 | else |
Greg Kaiser | f5eaf3c | 2023-08-10 12:37:05 +0000 | [diff] [blame] | 79 | # TODO(b/294161396): Remove this logic |
| 80 | ifeq ($(TARGET_RELEASE),next) |
| 81 | ifndef TESTING_TARGET_RELEASE_NEXT |
| 82 | $(error "next" releases are not supported yet. b/294161396) |
| 83 | endif |
| 84 | endif |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 85 | # Choose flag files |
| 86 | # Don't sort this, use it in the order they gave us. |
| 87 | flag_value_files := $(_all_release_configs.$(TARGET_RELEASE).FILES) |
| 88 | endif |
| 89 | else |
| 90 | # Useful for finding scripts etc that aren't passing or setting TARGET_RELEASE |
| 91 | ifneq ($(FAIL_IF_NO_RELEASE_CONFIG),) |
| 92 | $(error FAIL_IF_NO_RELEASE_CONFIG was set and TARGET_RELEASE was not) |
| 93 | endif |
| 94 | flag_value_files := |
| 95 | endif |
| 96 | |
| 97 | # Unset variables so they can't use them |
| 98 | define declare-release-config |
| 99 | $(error declare-release-config can only be called from inside release_config_map.mk files) |
| 100 | endef |
| 101 | |
| 102 | # TODO: Remove this check after enough people have sourced lunch that we don't |
| 103 | # need to worry about it trying to do get_build_vars TARGET_RELEASE. Maybe after ~9/2023 |
| 104 | ifneq ($(CALLED_FROM_SETUP),true) |
| 105 | define TARGET_RELEASE |
| 106 | $(error TARGET_RELEASE may not be accessed directly. Use individual flags.) |
| 107 | endef |
| 108 | else |
| 109 | TARGET_RELEASE:= |
| 110 | endif |
| 111 | .KATI_READONLY := TARGET_RELEASE |
| 112 | |
| 113 | |
| 114 | $(foreach config, $(_all_release_configs), \ |
| 115 | $(eval _all_release_configs.$(config).DECLARED_IN:= ) \ |
| 116 | $(eval _all_release_configs.$(config).FILES:= ) \ |
| 117 | ) |
| 118 | _all_release_configs:= |
| 119 | config_map_files:= |
| 120 | |
| 121 | |
| 122 | # ----------------------------------------------------------------- |
| 123 | # Flag declarations and values |
| 124 | # ----------------------------------------------------------------- |
| 125 | # This part is in starlark. We generate a root starlark file that loads |
| 126 | # all of the flags declaration files that we found, and the flag_value_files |
| 127 | # that we chose from the config map above. Then we run that, and load the |
| 128 | # results of that into the make environment. |
| 129 | |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 130 | # If this is a google source tree, restrict it to only the one file |
| 131 | # 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] | 132 | # TODO: Remove wildcard for build/release one when all branch manifests |
| 133 | # have updated. |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 134 | flag_declaration_files := $(wildcard build/release/build_flags.bzl) \ |
| 135 | $(if $(wildcard vendor/google/release/build_flags.bzl), \ |
| 136 | vendor/google/release/build_flags.bzl, \ |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 137 | $(sort \ |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 138 | $(wildcard device/*/release/build_flags.bzl) \ |
| 139 | $(wildcard device/*/*/release/build_flags.bzl) \ |
| 140 | $(wildcard vendor/*/release/build_flags.bzl) \ |
| 141 | $(wildcard vendor/*/*/release/build_flags.bzl) \ |
| 142 | ) \ |
| 143 | ) |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 144 | |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 145 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 146 | # Because starlark can't find files with $(wildcard), write an entrypoint starlark script that |
| 147 | # contains the result of the above wildcards for the starlark code to use. |
| 148 | filename_to_starlark=$(subst /,_,$(subst .,_,$(1))) |
| 149 | _c:=load("//build/make/core/release_config.bzl", "release_config") |
Joe Onorato | d6df20a | 2023-06-09 18:51:00 -0700 | [diff] [blame] | 150 | _c+=$(newline)def add(d, k, v): |
| 151 | _c+=$(newline)$(space)d = dict(d) |
| 152 | _c+=$(newline)$(space)d[k] = v |
| 153 | _c+=$(newline)$(space)return d |
| 154 | _c+=$(foreach f,$(flag_declaration_files),$(newline)load("$(f)", flags_$(call filename_to_starlark,$(f)) = "flags")) |
| 155 | _c+=$(newline)all_flags = [] $(foreach f,$(flag_declaration_files),+ [add(x, "declared_in", "$(f)") for x in flags_$(call filename_to_starlark,$(f))]) |
| 156 | _c+=$(foreach f,$(flag_value_files),$(newline)load("//$(f)", values_$(call filename_to_starlark,$(f)) = "values")) |
| 157 | _c+=$(newline)all_values = [] $(foreach f,$(flag_value_files),+ [add(x, "set_in", "$(f)") for x in values_$(call filename_to_starlark,$(f))]) |
| 158 | _c+=$(newline)variables_to_export_to_make = release_config(all_flags, all_values) |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 159 | $(file >$(OUT_DIR)/release_config_entrypoint.bzl,$(_c)) |
| 160 | _c:= |
| 161 | filename_to_starlark:= |
Joe Onorato | 964f401 | 2023-05-06 12:29:01 -0700 | [diff] [blame] | 162 | |
Cole Faust | 386b374 | 2023-06-06 16:55:58 -0700 | [diff] [blame] | 163 | # Exclude the entrypoint file as a dependency (by passing it as the 2nd argument) so that we don't |
| 164 | # rerun kati every build. Kati will replay the $(file) command that generates it every build, |
| 165 | # updating its timestamp. |
| 166 | # |
| 167 | # We also need to pass --allow_external_entrypoint to rbcrun in case the OUT_DIR is set to something |
| 168 | # outside of the source tree. |
| 169 | $(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] | 170 | |