Add aconfig rules

Test: treehugger
Change-Id: I456f87894926287a91d42e738016ca8052cd5039
diff --git a/core/release_config.mk b/core/release_config.mk
index 0ad87fc..fdfc6a0 100644
--- a/core/release_config.mk
+++ b/core/release_config.mk
@@ -15,7 +15,7 @@
 # Partitions that get build system flag summaries
 _FLAG_PARTITIONS := system vendor system_ext product
 
-# All possible release flags. Defined in the flags.mk files
+# All possible release flags. Defined in the build_flags.mk files
 # throughout the tree
 _ALL_RELEASE_FLAGS :=
 
@@ -26,7 +26,9 @@
 
 # If this is a google source tree, restrict it to only the one file
 # which has OWNERS control.  If it isn't let others define their own.
-config_map_files := build/make/release/release_config_map.mk \
+# TODO: Remove wildcard for build/release one when all branch manifests
+# have updated.
+config_map_files := $(wildcard build/release/release_config_map.mk) \
     $(if $(wildcard vendor/google/release/release_config_map.mk), \
         vendor/google/release/release_config_map.mk, \
         $(sort \
@@ -64,7 +66,7 @@
 # will get their default values.
 ifneq ($(TARGET_RELEASE),)
 ifeq ($(filter $(_all_release_configs), $(TARGET_RELEASE)),)
-    $(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE))
+    $(error No release config found for TARGET_RELEASE: $(TARGET_RELEASE). Available releases are: $(_all_release_configs))
 else
     # Choose flag files
     # Don't sort this, use it in the order they gave us.
@@ -135,14 +137,14 @@
 # Choose the files
 # If this is a google source tree, restrict it to only the one file
 # which has OWNERS control.  If it isn't let others define their own.
-flag_declaration_files := build/make/release/flags.mk \
-    $(if $(wildcard vendor/google/release/flags.mk), \
-        vendor/google/release/flags.mk, \
+flag_declaration_files := $(wildcard build/release/build_flags.mk) \
+    $(if $(wildcard vendor/google/release/build_flags.mk), \
+        vendor/google/release/build_flags.mk, \
         $(sort \
-            $(wildcard device/*/release/flags.mk) \
-            $(wildcard device/*/*/release/flags.mk) \
-            $(wildcard vendor/*/release/flags.mk) \
-            $(wildcard vendor/*/*/release/flags.mk) \
+            $(wildcard device/*/release/build_flags.mk) \
+            $(wildcard device/*/*/release/build_flags.mk) \
+            $(wildcard vendor/*/release/build_flags.mk) \
+            $(wildcard vendor/*/*/release/build_flags.mk) \
         ) \
     )
 
@@ -173,23 +175,45 @@
     $(eval _ALL_RELEASE_FLAGS.$(strip $(1)).SET_IN := $(_included))
 endef
 
+# This writes directly to a file so that the version never exists in make for
+# people to write conditionals upon.
+define set-release-version
+    $(eval _RELEASE_VERSION := $(strip $(1)))
+endef
+
 # Include the files (if there are any)
-$(foreach f, $(_release_config_files), \
-    $(eval _included := $(f)) \
-    $(eval include $(f)) \
-)
+ifneq ($(strip $(_release_config_files)),)
+    $(foreach f, $(_release_config_files), \
+        $(eval _included := $(f)) \
+        $(eval include $(f)) \
+    )
+else
+    # No TARGET_RELEASE means release version 0
+    $(call set-release-version, 0)
+endif
+
+
+ifeq ($(_RELEASE_VERSION)),)
+    $(error No release config file called set-release-version. Included files were: $(_release_config_files))
+endif
 
 # Don't let anyone declare build flags after here
 define set-build-flag
 $(error set-build-flag can only be called from inside release config files.)
 endef
 
+# Don't let anyone set the release version after here
+define set-release-version
+$(error set-release-version can only be called from inside release config files.)
+endef
+
 # Set the flag values, and don't allow any one to modify them.
 $(foreach flag, $(_ALL_RELEASE_FLAGS), \
     $(eval $(flag) := $(_ALL_RELEASE_FLAGS.$(flag).VALUE)) \
     $(eval .KATI_READONLY := $(flag)) \
 )
 
+
 # -----------------------------------------------------------------
 # Clear out vars
 flag_declaration_files:=
diff --git a/core/soong_config.mk b/core/soong_config.mk
index 034d044..8b9ba4f 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -319,6 +319,9 @@
 $(call add_json_str,  ProductBrand,        $(PRODUCT_BRAND))
 $(call add_json_list, BuildVersionTags,    $(BUILD_VERSION_TAGS))
 
+$(call add_json_str, ReleaseVersion,    $(_RELEASE_VERSION))
+$(call add_json_list, ReleaseDeviceConfigValueSets,    $(RELEASE_DEVICE_CONFIG_VALUE_SETS))
+
 $(call json_end)
 
 $(file >$(SOONG_VARIABLES).tmp,$(json_contents))
diff --git a/release/flags.mk b/release/flags.mk
deleted file mode 100644
index eb97dc1..0000000
--- a/release/flags.mk
+++ /dev/null
@@ -1,23 +0,0 @@
-# Copyright (C) 2023 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This file defines the build system flags that can be set based on the
-# release configuration.  If at all possible, use aconfig flags instead.
-# This is for things that must be decided at compile time.
-
-# Flag names should be alphabetical by flag name.
-
-$(call declare-build-flag, system, RELEASE_THE_FIRST_FLAG, true)
-$(call declare-build-flag, system, RELEASE_THE_SECOND_FLAG, true)
-
diff --git a/release/release_config_map.mk b/release/release_config_map.mk
deleted file mode 100644
index 190cb89..0000000
--- a/release/release_config_map.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-# Copyright (C) 2023 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# AOSP doesn't define any release configs yet.
-