Merge "Export some make variables to soong.variables."
diff --git a/core/Makefile b/core/Makefile
index 7083f83..4f85b7d 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -3288,8 +3288,8 @@
endif # BUILDING_SYSTEM_IMAGE
-.PHONY: sync syncsys
-sync syncsys: $(INTERNAL_SYSTEMIMAGE_FILES)
+.PHONY: sync syncsys sync_system
+sync syncsys sync_system: $(INTERNAL_SYSTEMIMAGE_FILES)
# -----------------------------------------------------------------
# Old PDK fusion targets
@@ -3617,7 +3617,8 @@
vendorimage-nodeps vnod: | $(INTERNAL_USERIMAGES_DEPS)
$(build-vendorimage-target)
-sync: $(INTERNAL_VENDORIMAGE_FILES)
+.PHONY: sync_vendor
+sync sync_vendor: $(INTERNAL_VENDORIMAGE_FILES)
else ifdef BOARD_PREBUILT_VENDORIMAGE
INSTALLED_VENDORIMAGE_TARGET := $(PRODUCT_OUT)/vendor.img
@@ -3681,7 +3682,8 @@
productimage-nodeps pnod: | $(INTERNAL_USERIMAGES_DEPS)
$(build-productimage-target)
-sync: $(INTERNAL_PRODUCTIMAGE_FILES)
+.PHONY: sync_product
+sync sync_product: $(INTERNAL_PRODUCTIMAGE_FILES)
else ifdef BOARD_PREBUILT_PRODUCTIMAGE
INSTALLED_PRODUCTIMAGE_TARGET := $(PRODUCT_OUT)/product.img
@@ -3743,7 +3745,8 @@
systemextimage-nodeps senod: | $(INTERNAL_USERIMAGES_DEPS)
$(build-system_extimage-target)
-sync: $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
+.PHONY: sync_system_ext
+sync sync_system_ext: $(INTERNAL_SYSTEM_EXTIMAGE_FILES)
else ifdef BOARD_PREBUILT_SYSTEM_EXTIMAGE
INSTALLED_SYSTEM_EXTIMAGE_TARGET := $(PRODUCT_OUT)/system_ext.img
@@ -3824,7 +3827,8 @@
odmimage-nodeps onod: | $(INTERNAL_USERIMAGES_DEPS)
$(build-odmimage-target)
-sync: $(INTERNAL_ODMIMAGE_FILES)
+.PHONY: sync_odm
+sync sync_odm: $(INTERNAL_ODMIMAGE_FILES)
else ifdef BOARD_PREBUILT_ODMIMAGE
INSTALLED_ODMIMAGE_TARGET := $(PRODUCT_OUT)/odm.img
@@ -3885,7 +3889,8 @@
vendor_dlkmimage-nodeps vdnod: | $(INTERNAL_USERIMAGES_DEPS)
$(build-vendor_dlkmimage-target)
-sync: $(INTERNAL_VENDOR_DLKMIMAGE_FILES)
+.PHONY: sync_vendor_dlkm
+sync sync_vendor_dlkm: $(INTERNAL_VENDOR_DLKMIMAGE_FILES)
else ifdef BOARD_PREBUILT_VENDOR_DLKMIMAGE
INSTALLED_VENDOR_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/vendor_dlkm.img
@@ -3946,7 +3951,8 @@
odm_dlkmimage-nodeps odnod: | $(INTERNAL_USERIMAGES_DEPS)
$(build-odm_dlkmimage-target)
-sync: $(INTERNAL_ODM_DLKMIMAGE_FILES)
+.PHONY: sync_odm_dlkm
+sync sync_odm_dlkm: $(INTERNAL_ODM_DLKMIMAGE_FILES)
else ifdef BOARD_PREBUILT_ODM_DLKMIMAGE
INSTALLED_ODM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/odm_dlkm.img
@@ -4009,7 +4015,8 @@
system_dlkmimage-nodeps sdnod: | $(INTERNAL_USERIMAGES_DEPS)
$(build-system_dlkmimage-target)
-sync: $(INTERNAL_SYSTEM_DLKMIMAGE_FILES)
+.PHONY: sync_system_dlkm
+sync sync_system_dlkm: $(INTERNAL_SYSTEM_DLKMIMAGE_FILES)
else ifdef BOARD_PREBUILT_SYSTEM_DLKMIMAGE
INSTALLED_SYSTEM_DLKMIMAGE_TARGET := $(PRODUCT_OUT)/system_dlkm.img
@@ -5273,7 +5280,7 @@
# -----------------------------------------------------------------
# fastboot-info.txt
-FASTBOOT_INFO_VERSION = 1.0
+FASTBOOT_INFO_VERSION = 1
INSTALLED_FASTBOOT_INFO_TARGET := $(PRODUCT_OUT)/fastboot-info.txt
diff --git a/core/product_config.mk b/core/product_config.mk
index 9db881f..bf48539 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -236,14 +236,22 @@
$(shell mkdir -p $(OUT_DIR)/rbc)
$(call dump-variables-rbc, $(OUT_DIR)/rbc/make_vars_pre_product_config.mk)
- $(shell build/soong/scripts/update_out \
- $(OUT_DIR)/rbc/rbc_product_config_results.mk \
- build/soong/scripts/rbc-run \
- $(current_product_makefile) \
- $(OUT_DIR)/rbc/make_vars_pre_product_config.mk)
+ $(shell $(OUT_DIR)/mk2rbc \
+ --mode=write -r --outdir $(OUT_DIR)/rbc \
+ --launcher=$(OUT_DIR)/rbc/launcher.rbc \
+ --input_variables=$(OUT_DIR)/rbc/make_vars_pre_product_config.mk \
+ --makefile_list=$(OUT_DIR)/.module_paths/configuration.list \
+ $(current_product_makefile))
ifneq ($(.SHELLSTATUS),0)
$(error product configuration converter failed: $(.SHELLSTATUS))
endif
+
+ $(shell build/soong/scripts/update_out $(OUT_DIR)/rbc/rbc_product_config_results.mk \
+ $(OUT_DIR)/rbcrun RBC_OUT="make,global" $(OUT_DIR)/rbc/launcher.rbc)
+ ifneq ($(.SHELLSTATUS),0)
+ $(error product configuration runner failed: $(.SHELLSTATUS))
+ endif
+
include $(OUT_DIR)/rbc/rbc_product_config_results.mk
endif
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index 9e9e74b..f9175e45 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -104,7 +104,7 @@
# It must be of the form "YYYY-MM-DD" on production devices.
# It must match one of the Android Security Patch Level strings of the Public Security Bulletins.
# If there is no $PLATFORM_SECURITY_PATCH set, keep it empty.
- PLATFORM_SECURITY_PATCH := 2023-04-05
+ PLATFORM_SECURITY_PATCH := 2023-05-05
endif
include $(BUILD_SYSTEM)/version_util.mk
diff --git a/target/board/generic/BoardConfig.mk b/target/board/generic/BoardConfig.mk
index 87c16da..6720ddb 100644
--- a/target/board/generic/BoardConfig.mk
+++ b/target/board/generic/BoardConfig.mk
@@ -30,20 +30,3 @@
TARGET_CPU_ABI2 := armeabi
include build/make/target/board/BoardConfigGsiCommon.mk
-
-ifndef BUILDING_GSI
-include build/make/target/board/BoardConfigEmuCommon.mk
-
-BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
-
-# Wifi.
-BOARD_WLAN_DEVICE := emulator
-BOARD_HOSTAPD_DRIVER := NL80211
-BOARD_WPA_SUPPLICANT_DRIVER := NL80211
-BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_simulated
-BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_simulated
-WPA_SUPPLICANT_VERSION := VER_0_8_X
-WIFI_DRIVER_FW_PATH_PARAM := "/dev/null"
-WIFI_DRIVER_FW_PATH_STA := "/dev/null"
-WIFI_DRIVER_FW_PATH_AP := "/dev/null"
-endif
diff --git a/target/board/generic/device.mk b/target/board/generic/device.mk
index 76242c9..76edf6b 100644
--- a/target/board/generic/device.mk
+++ b/target/board/generic/device.mk
@@ -14,5 +14,3 @@
# limitations under the License.
#
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish # for libwifi-hal-emu
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish-opengl # for goldfish deps.
diff --git a/target/board/generic_64bitonly_x86_64/BoardConfig.mk b/target/board/generic_64bitonly_x86_64/BoardConfig.mk
index a240eab..a129ea0 100644
--- a/target/board/generic_64bitonly_x86_64/BoardConfig.mk
+++ b/target/board/generic_64bitonly_x86_64/BoardConfig.mk
@@ -28,23 +28,3 @@
TARGET_PRELINK_MODULE := false
include build/make/target/board/BoardConfigGsiCommon.mk
-
-ifndef BUILDING_GSI
-include build/make/target/board/BoardConfigEmuCommon.mk
-
-BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
-
-BOARD_SEPOLICY_DIRS += device/generic/goldfish/sepolicy/x86
-
-# Wifi.
-BOARD_WLAN_DEVICE := emulator
-BOARD_HOSTAPD_DRIVER := NL80211
-BOARD_WPA_SUPPLICANT_DRIVER := NL80211
-BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_simulated
-BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_simulated
-WPA_SUPPLICANT_VERSION := VER_0_8_X
-WIFI_DRIVER_FW_PATH_PARAM := "/dev/null"
-WIFI_DRIVER_FW_PATH_STA := "/dev/null"
-WIFI_DRIVER_FW_PATH_AP := "/dev/null"
-
-endif # !BUILDING_GSI
diff --git a/target/board/generic_x86/BoardConfig.mk b/target/board/generic_x86/BoardConfig.mk
index 47fd384..26bede8 100644
--- a/target/board/generic_x86/BoardConfig.mk
+++ b/target/board/generic_x86/BoardConfig.mk
@@ -19,23 +19,3 @@
TARGET_ARCH_VARIANT := x86
include build/make/target/board/BoardConfigGsiCommon.mk
-
-ifndef BUILDING_GSI
-include build/make/target/board/BoardConfigEmuCommon.mk
-
-# Resize to 4G to accomodate ASAN and CTS
-BOARD_USERDATAIMAGE_PARTITION_SIZE := 4294967296
-
-BOARD_SEPOLICY_DIRS += device/generic/goldfish/sepolicy/x86
-
-# Wifi.
-BOARD_WLAN_DEVICE := emulator
-BOARD_HOSTAPD_DRIVER := NL80211
-BOARD_WPA_SUPPLICANT_DRIVER := NL80211
-BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_simulated
-BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_simulated
-WPA_SUPPLICANT_VERSION := VER_0_8_X
-WIFI_DRIVER_FW_PATH_PARAM := "/dev/null"
-WIFI_DRIVER_FW_PATH_STA := "/dev/null"
-WIFI_DRIVER_FW_PATH_AP := "/dev/null"
-endif
diff --git a/target/board/generic_x86/device.mk b/target/board/generic_x86/device.mk
index 5ad008f..60f0cc3 100644
--- a/target/board/generic_x86/device.mk
+++ b/target/board/generic_x86/device.mk
@@ -14,9 +14,6 @@
# limitations under the License.
#
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish # for libwifi-hal-emu
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish-opengl # for goldfish deps.
-
ifdef NET_ETH0_STARTONBOOT
PRODUCT_VENDOR_PROPERTIES += net.eth0.startonboot=1
endif
diff --git a/target/board/generic_x86_64/BoardConfig.mk b/target/board/generic_x86_64/BoardConfig.mk
index e7f2ae0..2385579 100755
--- a/target/board/generic_x86_64/BoardConfig.mk
+++ b/target/board/generic_x86_64/BoardConfig.mk
@@ -26,23 +26,3 @@
TARGET_DYNAMIC_64_32_MEDIASERVER := true
include build/make/target/board/BoardConfigGsiCommon.mk
-
-ifndef BUILDING_GSI
-include build/make/target/board/BoardConfigEmuCommon.mk
-
-BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
-
-BOARD_SEPOLICY_DIRS += device/generic/goldfish/sepolicy/x86
-
-# Wifi.
-BOARD_WLAN_DEVICE := emulator
-BOARD_HOSTAPD_DRIVER := NL80211
-BOARD_WPA_SUPPLICANT_DRIVER := NL80211
-BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_simulated
-BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_simulated
-WPA_SUPPLICANT_VERSION := VER_0_8_X
-WIFI_DRIVER_FW_PATH_PARAM := "/dev/null"
-WIFI_DRIVER_FW_PATH_STA := "/dev/null"
-WIFI_DRIVER_FW_PATH_AP := "/dev/null"
-
-endif # !BUILDING_GSI
diff --git a/target/board/generic_x86_64_arm64/BoardConfig.mk b/target/board/generic_x86_64_arm64/BoardConfig.mk
index f528294..818ec44 100755
--- a/target/board/generic_x86_64_arm64/BoardConfig.mk
+++ b/target/board/generic_x86_64_arm64/BoardConfig.mk
@@ -13,7 +13,6 @@
# limitations under the License.
#
-# x86_64 emulator specific definitions
TARGET_CPU_ABI := x86_64
TARGET_ARCH := x86_64
TARGET_ARCH_VARIANT := x86_64
@@ -37,23 +36,9 @@
TARGET_PRELINK_MODULE := false
include build/make/target/board/BoardConfigMainlineCommon.mk
-include build/make/target/board/BoardConfigEmuCommon.mk
# the settings differ from BoardConfigMainlineCommon.mk
BOARD_USES_SYSTEM_OTHER_ODEX :=
# Resize to 4G to accommodate ASAN and CTS
BOARD_USERDATAIMAGE_PARTITION_SIZE := 4294967296
-
-BOARD_SEPOLICY_DIRS += device/generic/goldfish/sepolicy/x86
-
-# Wifi.
-BOARD_WLAN_DEVICE := emulator
-BOARD_HOSTAPD_DRIVER := NL80211
-BOARD_WPA_SUPPLICANT_DRIVER := NL80211
-BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_simulated
-BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_simulated
-WPA_SUPPLICANT_VERSION := VER_0_8_X
-WIFI_DRIVER_FW_PATH_PARAM := "/dev/null"
-WIFI_DRIVER_FW_PATH_STA := "/dev/null"
-WIFI_DRIVER_FW_PATH_AP := "/dev/null"
diff --git a/target/board/generic_x86_64_arm64/device.mk b/target/board/generic_x86_64_arm64/device.mk
index 76242c9..76edf6b 100755
--- a/target/board/generic_x86_64_arm64/device.mk
+++ b/target/board/generic_x86_64_arm64/device.mk
@@ -14,5 +14,3 @@
# limitations under the License.
#
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish # for libwifi-hal-emu
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish-opengl # for goldfish deps.
diff --git a/target/board/generic_x86_arm/BoardConfig.mk b/target/board/generic_x86_arm/BoardConfig.mk
index f6589b0..62bb5eb 100644
--- a/target/board/generic_x86_arm/BoardConfig.mk
+++ b/target/board/generic_x86_arm/BoardConfig.mk
@@ -13,7 +13,6 @@
# limitations under the License.
#
-# x86 emulator specific definitions
TARGET_CPU_ABI := x86
TARGET_ARCH := x86
TARGET_ARCH_VARIANT := x86
@@ -30,23 +29,9 @@
# The settings in latter makefiles overwrite those in the former.
#
include build/make/target/board/BoardConfigMainlineCommon.mk
-include build/make/target/board/BoardConfigEmuCommon.mk
# the settings differ from BoardConfigMainlineCommon.mk
BOARD_USES_SYSTEM_OTHER_ODEX :=
# Resize to 4G to accomodate ASAN and CTS
BOARD_USERDATAIMAGE_PARTITION_SIZE := 4294967296
-
-BOARD_SEPOLICY_DIRS += device/generic/goldfish/sepolicy/x86
-
-# Wifi.
-BOARD_WLAN_DEVICE := emulator
-BOARD_HOSTAPD_DRIVER := NL80211
-BOARD_WPA_SUPPLICANT_DRIVER := NL80211
-BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_simulated
-BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_simulated
-WPA_SUPPLICANT_VERSION := VER_0_8_X
-WIFI_DRIVER_FW_PATH_PARAM := "/dev/null"
-WIFI_DRIVER_FW_PATH_STA := "/dev/null"
-WIFI_DRIVER_FW_PATH_AP := "/dev/null"
diff --git a/target/board/generic_x86_arm/device.mk b/target/board/generic_x86_arm/device.mk
index 76242c9..76edf6b 100644
--- a/target/board/generic_x86_arm/device.mk
+++ b/target/board/generic_x86_arm/device.mk
@@ -14,5 +14,3 @@
# limitations under the License.
#
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish # for libwifi-hal-emu
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish-opengl # for goldfish deps.
diff --git a/target/product/aosp_64bitonly_x86_64.mk b/target/product/aosp_64bitonly_x86_64.mk
index 75fd3c8..cf812a2 100644
--- a/target/product/aosp_64bitonly_x86_64.mk
+++ b/target/product/aosp_64bitonly_x86_64.mk
@@ -51,7 +51,6 @@
#
# All components inherited here go to vendor image
#
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86_64/device.mk)
#
diff --git a/target/product/aosp_arm.mk b/target/product/aosp_arm.mk
index 61c1316..d9c362e 100644
--- a/target/product/aosp_arm.mk
+++ b/target/product/aosp_arm.mk
@@ -50,7 +50,6 @@
# All components inherited here go to vendor image
#
$(call inherit-product-if-exists, build/make/target/product/ramdisk_stub.mk)
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86/device.mk)
#
diff --git a/target/product/aosp_arm64.mk b/target/product/aosp_arm64.mk
index 6c907db..d3514a5 100644
--- a/target/product/aosp_arm64.mk
+++ b/target/product/aosp_arm64.mk
@@ -54,7 +54,6 @@
#
# All components inherited here go to vendor or vendor_boot image
#
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_arm64/device.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/non_ab_device.mk)
diff --git a/target/product/aosp_riscv64.mk b/target/product/aosp_riscv64.mk
index 270a989..fa503ff 100644
--- a/target/product/aosp_riscv64.mk
+++ b/target/product/aosp_riscv64.mk
@@ -46,7 +46,6 @@
#
# All components inherited here go to vendor image
#
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_riscv64/device.mk)
#
diff --git a/target/product/aosp_x86.mk b/target/product/aosp_x86.mk
index a2f0390..c26a8bf 100644
--- a/target/product/aosp_x86.mk
+++ b/target/product/aosp_x86.mk
@@ -47,7 +47,6 @@
#
# All components inherited here go to vendor image
#
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86/device.mk)
diff --git a/target/product/aosp_x86_64.mk b/target/product/aosp_x86_64.mk
index 535ee3f..3040dd3 100644
--- a/target/product/aosp_x86_64.mk
+++ b/target/product/aosp_x86_64.mk
@@ -56,7 +56,6 @@
#
# All components inherited here go to vendor image
#
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86_64/device.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/non_ab_device.mk)
diff --git a/target/product/aosp_x86_arm.mk b/target/product/aosp_x86_arm.mk
index 39ad0d8..a103b1a 100644
--- a/target/product/aosp_x86_arm.mk
+++ b/target/product/aosp_x86_arm.mk
@@ -45,7 +45,6 @@
#
# All components inherited here go to vendor image
#
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86_arm/device.mk)
diff --git a/target/product/full.manifest.xml b/target/product/full.manifest.xml
new file mode 100644
index 0000000..b8b0d37
--- /dev/null
+++ b/target/product/full.manifest.xml
@@ -0,0 +1,2 @@
+<manifest version="1.0" type="device" target-level="7">
+</manifest>
diff --git a/target/product/full.mk b/target/product/full.mk
index 945957f..da04f49 100644
--- a/target/product/full.mk
+++ b/target/product/full.mk
@@ -20,10 +20,11 @@
# entirely appropriate to inherit from for on-device configurations.
$(call inherit-product-if-exists, build/make/target/product/ramdisk_stub.mk)
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic/device.mk)
+DEVICE_MANIFEST_FILE += build/make/target/product/full.manifest.xml
+
# Enable dynamic partition size
PRODUCT_USE_DYNAMIC_PARTITION_SIZE := true
diff --git a/target/product/full_x86.mk b/target/product/full_x86.mk
index 0f3be91..07f6472 100644
--- a/target/product/full_x86.mk
+++ b/target/product/full_x86.mk
@@ -23,10 +23,11 @@
# that isn't a wifi connection. This will instruct init.rc to enable the
# network connection so that you can use it with ADB
-$(call inherit-product, $(SRC_TARGET_DIR)/product/emulator_vendor.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/board/generic_x86/device.mk)
+DEVICE_MANIFEST_FILE += build/make/target/product/full.manifest.xml
+
ifdef NET_ETH0_STARTONBOOT
PRODUCT_VENDOR_PROPERTIES += net.eth0.startonboot=1
endif
diff --git a/target/product/generic.mk b/target/product/generic.mk
index fb5b727..fd3b3fb 100644
--- a/target/product/generic.mk
+++ b/target/product/generic.mk
@@ -14,9 +14,6 @@
# limitations under the License.
#
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish # for libwifi-hal-emu
-PRODUCT_SOONG_NAMESPACES += device/generic/goldfish-opengl # for goldfish deps.
-
# This is a generic phone product that isn't specialized for a specific device.
# It includes the base Android platform.
diff --git a/tools/aconfig/.gitignore b/tools/aconfig/.gitignore
new file mode 100644
index 0000000..1b72444
--- /dev/null
+++ b/tools/aconfig/.gitignore
@@ -0,0 +1,2 @@
+/Cargo.lock
+/target
diff --git a/tools/aconfig/Android.bp b/tools/aconfig/Android.bp
index b3813bf..e762f33 100644
--- a/tools/aconfig/Android.bp
+++ b/tools/aconfig/Android.bp
@@ -18,7 +18,11 @@
srcs: ["src/main.rs"],
rustlibs: [
"libaconfig_protos",
+ "libanyhow",
+ "libclap",
"libprotobuf",
+ "libserde",
+ "libserde_json",
],
}
diff --git a/tools/aconfig/Cargo.toml b/tools/aconfig/Cargo.toml
new file mode 100644
index 0000000..b439858
--- /dev/null
+++ b/tools/aconfig/Cargo.toml
@@ -0,0 +1,19 @@
+[package]
+name = "aconfig"
+version = "0.1.0"
+edition = "2021"
+build = "build.rs"
+
+[features]
+default = ["cargo"]
+cargo = []
+
+[dependencies]
+anyhow = "1.0.69"
+clap = { version = "4.1.8", features = ["derive"] }
+protobuf = "3.2.0"
+serde = { version = "1.0.152", features = ["derive"] }
+serde_json = "1.0.93"
+
+[build-dependencies]
+protobuf-codegen = "3.2.0"
diff --git a/tools/aconfig/build.rs b/tools/aconfig/build.rs
new file mode 100644
index 0000000..5ef5b60
--- /dev/null
+++ b/tools/aconfig/build.rs
@@ -0,0 +1,17 @@
+use protobuf_codegen::Codegen;
+
+fn main() {
+ let proto_files = vec!["protos/aconfig.proto"];
+
+ // tell cargo to only re-run the build script if any of the proto files has changed
+ for path in &proto_files {
+ println!("cargo:rerun-if-changed={}", path);
+ }
+
+ Codegen::new()
+ .pure()
+ .include("protos")
+ .inputs(proto_files)
+ .cargo_out_dir("aconfig_proto")
+ .run_from_script();
+}
diff --git a/tools/aconfig/protos/aconfig.proto b/tools/aconfig/protos/aconfig.proto
index 989c398..65817ca 100644
--- a/tools/aconfig/protos/aconfig.proto
+++ b/tools/aconfig/protos/aconfig.proto
@@ -12,12 +12,34 @@
// See the License for the specific language governing permissions and
// limitations under the License
-// Placeholder proto file. Will be replaced by actual contents.
+// This is the schema definition for of Aconfig files. Modifications need to be
+// either backwards compatible, or include updates to all Aconfig files in the
+// Android tree.
-syntax = "proto3";
+syntax = "proto2";
package android.aconfig;
-message Placeholder {
- string name = 1;
+message value {
+ required bool value = 1;
+ optional uint32 since = 2;
}
+
+message flag {
+ required string id = 1;
+ required string description = 2;
+ repeated value value = 3;
+};
+
+message android_config {
+ repeated flag flag = 1;
+};
+
+message override {
+ required string id = 1;
+ required bool value = 2;
+};
+
+message override_config {
+ repeated override override = 1;
+};
diff --git a/tools/aconfig/src/aconfig.rs b/tools/aconfig/src/aconfig.rs
new file mode 100644
index 0000000..22fcb88
--- /dev/null
+++ b/tools/aconfig/src/aconfig.rs
@@ -0,0 +1,284 @@
+/*
+ * 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.
+ */
+
+use anyhow::{anyhow, Context, Error, Result};
+
+use crate::protos::{
+ ProtoAndroidConfig, ProtoFlag, ProtoOverride, ProtoOverrideConfig, ProtoValue,
+};
+
+#[derive(Debug, PartialEq, Eq)]
+pub struct Value {
+ value: bool,
+ since: Option<u32>,
+}
+
+#[allow(dead_code)] // only used in unit tests
+impl Value {
+ pub fn new(value: bool, since: u32) -> Value {
+ Value { value, since: Some(since) }
+ }
+
+ pub fn default(value: bool) -> Value {
+ Value { value, since: None }
+ }
+}
+
+impl TryFrom<ProtoValue> for Value {
+ type Error = Error;
+
+ fn try_from(proto: ProtoValue) -> Result<Self, Self::Error> {
+ let Some(value) = proto.value else {
+ return Err(anyhow!("missing 'value' field"));
+ };
+ Ok(Value { value, since: proto.since })
+ }
+}
+
+#[derive(Debug, PartialEq, Eq)]
+pub struct Flag {
+ pub id: String,
+ pub description: String,
+
+ // ordered by Value.since; guaranteed to contain at least one item (the default value, with
+ // since == None)
+ pub values: Vec<Value>,
+}
+
+impl Flag {
+ #[allow(dead_code)] // only used in unit tests
+ pub fn try_from_text_proto(text_proto: &str) -> Result<Flag> {
+ let proto: ProtoFlag = crate::protos::try_from_text_proto(text_proto)
+ .with_context(|| text_proto.to_owned())?;
+ proto.try_into()
+ }
+
+ pub fn try_from_text_proto_list(text_proto: &str) -> Result<Vec<Flag>> {
+ let proto: ProtoAndroidConfig = crate::protos::try_from_text_proto(text_proto)
+ .with_context(|| text_proto.to_owned())?;
+ proto.flag.into_iter().map(|proto_flag| proto_flag.try_into()).collect()
+ }
+
+ pub fn resolve_value(&self, build_id: u32) -> bool {
+ let mut value = self.values[0].value;
+ for candidate in self.values.iter().skip(1) {
+ let since = candidate.since.expect("invariant: non-defaults values have Some(since)");
+ if since <= build_id {
+ value = candidate.value;
+ }
+ }
+ value
+ }
+}
+
+impl TryFrom<ProtoFlag> for Flag {
+ type Error = Error;
+
+ fn try_from(proto: ProtoFlag) -> Result<Self, Self::Error> {
+ let Some(id) = proto.id else {
+ return Err(anyhow!("missing 'id' field"));
+ };
+ let Some(description) = proto.description else {
+ return Err(anyhow!("missing 'description' field"));
+ };
+ if proto.value.is_empty() {
+ return Err(anyhow!("missing 'value' field"));
+ }
+
+ let mut values: Vec<Value> = vec![];
+ for proto_value in proto.value.into_iter() {
+ let v: Value = proto_value.try_into()?;
+ if values.iter().any(|w| v.since == w.since) {
+ let msg = match v.since {
+ None => format!("flag {}: multiple default values", id),
+ Some(x) => format!("flag {}: multiple values for since={}", id, x),
+ };
+ return Err(anyhow!(msg));
+ }
+ values.push(v);
+ }
+ values.sort_by_key(|v| v.since);
+
+ Ok(Flag { id, description, values })
+ }
+}
+
+#[derive(Debug, PartialEq, Eq)]
+pub struct Override {
+ pub id: String,
+ pub value: bool,
+}
+
+impl Override {
+ #[allow(dead_code)] // only used in unit tests
+ pub fn try_from_text_proto(text_proto: &str) -> Result<Override> {
+ let proto: ProtoOverride = crate::protos::try_from_text_proto(text_proto)?;
+ proto.try_into()
+ }
+
+ pub fn try_from_text_proto_list(text_proto: &str) -> Result<Vec<Override>> {
+ let proto: ProtoOverrideConfig = crate::protos::try_from_text_proto(text_proto)?;
+ proto.override_.into_iter().map(|proto_flag| proto_flag.try_into()).collect()
+ }
+}
+
+impl TryFrom<ProtoOverride> for Override {
+ type Error = Error;
+
+ fn try_from(proto: ProtoOverride) -> Result<Self, Self::Error> {
+ let Some(id) = proto.id else {
+ return Err(anyhow!("missing 'id' field"));
+ };
+ let Some(value) = proto.value else {
+ return Err(anyhow!("missing 'value' field"));
+ };
+ Ok(Override { id, value })
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_flag_try_from_text_proto() {
+ let expected = Flag {
+ id: "1234".to_owned(),
+ description: "Description of the flag".to_owned(),
+ values: vec![Value::default(false), Value::new(true, 8)],
+ };
+
+ let s = r#"
+ id: "1234"
+ description: "Description of the flag"
+ value {
+ value: false
+ }
+ value {
+ value: true
+ since: 8
+ }
+ "#;
+ let actual = Flag::try_from_text_proto(s).unwrap();
+
+ assert_eq!(expected, actual);
+ }
+
+ #[test]
+ fn test_flag_try_from_text_proto_bad_input() {
+ let s = r#"
+ id: "a"
+ description: "Description of the flag"
+ "#;
+ let error = Flag::try_from_text_proto(s).unwrap_err();
+ assert_eq!(format!("{:?}", error), "missing 'value' field");
+
+ let s = r#"
+ description: "Description of the flag"
+ value {
+ value: true
+ }
+ "#;
+ let error = Flag::try_from_text_proto(s).unwrap_err();
+ assert!(format!("{:?}", error).contains("Message not initialized"));
+
+ let s = r#"
+ id: "a"
+ description: "Description of the flag"
+ value {
+ value: true
+ }
+ value {
+ value: true
+ }
+ "#;
+ let error = Flag::try_from_text_proto(s).unwrap_err();
+ assert_eq!(format!("{:?}", error), "flag a: multiple default values");
+ }
+
+ #[test]
+ fn test_flag_try_from_text_proto_list() {
+ let expected = vec![
+ Flag {
+ id: "a".to_owned(),
+ description: "A".to_owned(),
+ values: vec![Value::default(true)],
+ },
+ Flag {
+ id: "b".to_owned(),
+ description: "B".to_owned(),
+ values: vec![Value::default(false)],
+ },
+ ];
+
+ let s = r#"
+ flag {
+ id: "a"
+ description: "A"
+ value {
+ value: true
+ }
+ }
+ flag {
+ id: "b"
+ description: "B"
+ value {
+ value: false
+ }
+ }
+ "#;
+ let actual = Flag::try_from_text_proto_list(s).unwrap();
+
+ assert_eq!(expected, actual);
+ }
+
+ #[test]
+ fn test_override_try_from_text_proto_list() {
+ let expected = Override { id: "1234".to_owned(), value: true };
+
+ let s = r#"
+ id: "1234"
+ value: true
+ "#;
+ let actual = Override::try_from_text_proto(s).unwrap();
+
+ assert_eq!(expected, actual);
+ }
+
+ #[test]
+ fn test_resolve_value() {
+ let flag = Flag {
+ id: "a".to_owned(),
+ description: "A".to_owned(),
+ values: vec![
+ Value::default(true),
+ Value::new(false, 10),
+ Value::new(true, 20),
+ Value::new(false, 30),
+ ],
+ };
+ assert!(flag.resolve_value(0));
+ assert!(flag.resolve_value(9));
+ assert!(!flag.resolve_value(10));
+ assert!(!flag.resolve_value(11));
+ assert!(!flag.resolve_value(19));
+ assert!(flag.resolve_value(20));
+ assert!(flag.resolve_value(21));
+ assert!(flag.resolve_value(29));
+ assert!(!flag.resolve_value(30));
+ assert!(!flag.resolve_value(10_000));
+ }
+}
diff --git a/tools/aconfig/src/cache.rs b/tools/aconfig/src/cache.rs
new file mode 100644
index 0000000..d27459d
--- /dev/null
+++ b/tools/aconfig/src/cache.rs
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+
+use anyhow::{anyhow, Result};
+use serde::{Deserialize, Serialize};
+use std::io::{Read, Write};
+
+use crate::aconfig::{Flag, Override};
+use crate::commands::Source;
+
+#[derive(Serialize, Deserialize)]
+pub struct Item {
+ pub id: String,
+ pub description: String,
+ pub value: bool,
+ pub debug: Vec<String>,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct Cache {
+ build_id: u32,
+ items: Vec<Item>,
+}
+
+impl Cache {
+ pub fn new(build_id: u32) -> Cache {
+ Cache { build_id, items: vec![] }
+ }
+
+ pub fn read_from_reader(reader: impl Read) -> Result<Cache> {
+ serde_json::from_reader(reader).map_err(|e| e.into())
+ }
+
+ pub fn write_to_writer(&self, writer: impl Write) -> Result<()> {
+ serde_json::to_writer(writer, self).map_err(|e| e.into())
+ }
+
+ pub fn add_flag(&mut self, source: Source, flag: Flag) -> Result<()> {
+ if self.items.iter().any(|item| item.id == flag.id) {
+ return Err(anyhow!(
+ "failed to add flag {} from {}: flag already defined",
+ flag.id,
+ source,
+ ));
+ }
+ let value = flag.resolve_value(self.build_id);
+ self.items.push(Item {
+ id: flag.id.clone(),
+ description: flag.description,
+ value,
+ debug: vec![format!("{}:{}", source, value)],
+ });
+ Ok(())
+ }
+
+ pub fn add_override(&mut self, source: Source, override_: Override) -> Result<()> {
+ let Some(existing_item) = self.items.iter_mut().find(|item| item.id == override_.id) else {
+ return Err(anyhow!("failed to override flag {}: unknown flag", override_.id));
+ };
+ existing_item.value = override_.value;
+ existing_item.debug.push(format!("{}:{}", source, override_.value));
+ Ok(())
+ }
+
+ pub fn iter(&self) -> impl Iterator<Item = &Item> {
+ self.items.iter()
+ }
+}
+
+impl Item {}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::aconfig::Value;
+
+ #[test]
+ fn test_add_flag() {
+ let mut cache = Cache::new(1);
+ cache
+ .add_flag(
+ Source::File("first.txt".to_string()),
+ Flag {
+ id: "foo".to_string(),
+ description: "desc".to_string(),
+ values: vec![Value::default(true)],
+ },
+ )
+ .unwrap();
+ let error = cache
+ .add_flag(
+ Source::File("second.txt".to_string()),
+ Flag {
+ id: "foo".to_string(),
+ description: "desc".to_string(),
+ values: vec![Value::default(false)],
+ },
+ )
+ .unwrap_err();
+ assert_eq!(
+ &format!("{:?}", error),
+ "failed to add flag foo from second.txt: flag already defined"
+ );
+ }
+
+ #[test]
+ fn test_add_override() {
+ fn check_value(cache: &Cache, id: &str, expected: bool) -> bool {
+ cache.iter().find(|&item| item.id == id).unwrap().value == expected
+ }
+
+ let mut cache = Cache::new(1);
+ let error = cache
+ .add_override(Source::Memory, Override { id: "foo".to_string(), value: true })
+ .unwrap_err();
+ assert_eq!(&format!("{:?}", error), "failed to override flag foo: unknown flag");
+
+ cache
+ .add_flag(
+ Source::File("first.txt".to_string()),
+ Flag {
+ id: "foo".to_string(),
+ description: "desc".to_string(),
+ values: vec![Value::default(true)],
+ },
+ )
+ .unwrap();
+ assert!(check_value(&cache, "foo", true));
+
+ cache
+ .add_override(Source::Memory, Override { id: "foo".to_string(), value: false })
+ .unwrap();
+ assert!(check_value(&cache, "foo", false));
+
+ cache
+ .add_override(Source::Memory, Override { id: "foo".to_string(), value: true })
+ .unwrap();
+ assert!(check_value(&cache, "foo", true));
+ }
+}
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
new file mode 100644
index 0000000..76b853b
--- /dev/null
+++ b/tools/aconfig/src/commands.rs
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+use anyhow::{Context, Result};
+use clap::ValueEnum;
+use serde::{Deserialize, Serialize};
+use std::fmt;
+use std::io::Read;
+
+use crate::aconfig::{Flag, Override};
+use crate::cache::Cache;
+
+#[derive(Clone, Serialize, Deserialize)]
+pub enum Source {
+ #[allow(dead_code)] // only used in unit tests
+ Memory,
+ File(String),
+}
+
+impl fmt::Display for Source {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ Self::Memory => write!(f, "<memory>"),
+ Self::File(path) => write!(f, "{}", path),
+ }
+ }
+}
+
+pub struct Input {
+ pub source: Source,
+ pub reader: Box<dyn Read>,
+}
+
+pub fn create_cache(build_id: u32, aconfigs: Vec<Input>, overrides: Vec<Input>) -> Result<Cache> {
+ let mut cache = Cache::new(build_id);
+
+ for mut input in aconfigs {
+ let mut contents = String::new();
+ input.reader.read_to_string(&mut contents)?;
+ let flags = Flag::try_from_text_proto_list(&contents)
+ .with_context(|| format!("Failed to parse {}", input.source))?;
+ for flag in flags {
+ cache.add_flag(input.source.clone(), flag)?;
+ }
+ }
+
+ for mut input in overrides {
+ let mut contents = String::new();
+ input.reader.read_to_string(&mut contents)?;
+ let overrides = Override::try_from_text_proto_list(&contents)
+ .with_context(|| format!("Failed to parse {}", input.source))?;
+ for override_ in overrides {
+ cache.add_override(input.source.clone(), override_)?;
+ }
+ }
+
+ Ok(cache)
+}
+
+#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
+pub enum Format {
+ Text,
+ Debug,
+}
+
+pub fn dump_cache(cache: Cache, format: Format) -> Result<()> {
+ match format {
+ Format::Text => {
+ for item in cache.iter() {
+ println!("{}: {}", item.id, item.value);
+ }
+ }
+ Format::Debug => {
+ for item in cache.iter() {
+ println!("{}: {} ({:?})", item.id, item.value, item.debug);
+ }
+ }
+ }
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_create_cache() {
+ let s = r#"
+ flag {
+ id: "a"
+ description: "Description of a"
+ value {
+ value: true
+ }
+ }
+ "#;
+ let aconfigs = vec![Input { source: Source::Memory, reader: Box::new(s.as_bytes()) }];
+ let o = r#"
+ override {
+ id: "a"
+ value: false
+ }
+ "#;
+ let overrides = vec![Input { source: Source::Memory, reader: Box::new(o.as_bytes()) }];
+ let cache = create_cache(1, aconfigs, overrides).unwrap();
+ let value = cache.iter().find(|&item| item.id == "a").unwrap().value;
+ assert!(!value);
+ }
+}
diff --git a/tools/aconfig/src/main.rs b/tools/aconfig/src/main.rs
index 2f7255e..3ce9747 100644
--- a/tools/aconfig/src/main.rs
+++ b/tools/aconfig/src/main.rs
@@ -16,38 +16,75 @@
//! `aconfig` is a build time tool to manage build time configurations, such as feature flags.
-use aconfig_protos::aconfig::Placeholder;
-use protobuf::text_format::{parse_from_str, ParseError};
+use anyhow::Result;
+use clap::{builder::ArgAction, builder::EnumValueParser, Arg, Command};
+use std::fs;
-fn foo() -> Result<String, ParseError> {
- let placeholder = parse_from_str::<Placeholder>(r#"name: "aconfig""#)?;
- Ok(placeholder.name)
+mod aconfig;
+mod cache;
+mod commands;
+mod protos;
+
+use crate::cache::Cache;
+use commands::{Input, Source};
+
+fn cli() -> Command {
+ Command::new("aconfig")
+ .subcommand_required(true)
+ .subcommand(
+ Command::new("create-cache")
+ .arg(
+ Arg::new("build-id")
+ .long("build-id")
+ .value_parser(clap::value_parser!(u32))
+ .required(true),
+ )
+ .arg(Arg::new("aconfig").long("aconfig").action(ArgAction::Append))
+ .arg(Arg::new("override").long("override").action(ArgAction::Append))
+ .arg(Arg::new("cache").long("cache").required(true)),
+ )
+ .subcommand(
+ Command::new("dump").arg(Arg::new("cache").long("cache").required(true)).arg(
+ Arg::new("format")
+ .long("format")
+ .value_parser(EnumValueParser::<commands::Format>::new())
+ .default_value("text"),
+ ),
+ )
}
-fn main() {
- println!("{:?}", foo());
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_foo() {
- assert_eq!("aconfig", foo().unwrap());
+fn main() -> Result<()> {
+ let matches = cli().get_matches();
+ match matches.subcommand() {
+ Some(("create-cache", sub_matches)) => {
+ let mut aconfigs = vec![];
+ let build_id = *sub_matches.get_one::<u32>("build-id").unwrap();
+ for path in
+ sub_matches.get_many::<String>("aconfig").unwrap_or_default().collect::<Vec<_>>()
+ {
+ let file = Box::new(fs::File::open(path)?);
+ aconfigs.push(Input { source: Source::File(path.to_string()), reader: file });
+ }
+ let mut overrides = vec![];
+ for path in
+ sub_matches.get_many::<String>("override").unwrap_or_default().collect::<Vec<_>>()
+ {
+ let file = Box::new(fs::File::open(path)?);
+ overrides.push(Input { source: Source::File(path.to_string()), reader: file });
+ }
+ let cache = commands::create_cache(build_id, aconfigs, overrides)?;
+ let path = sub_matches.get_one::<String>("cache").unwrap();
+ let file = fs::File::create(path)?;
+ cache.write_to_writer(file)?;
+ }
+ Some(("dump", sub_matches)) => {
+ let path = sub_matches.get_one::<String>("cache").unwrap();
+ let file = fs::File::open(path)?;
+ let cache = Cache::read_from_reader(file)?;
+ let format = sub_matches.get_one("format").unwrap();
+ commands::dump_cache(cache, *format)?;
+ }
+ _ => unreachable!(),
}
-
- #[test]
- fn test_binary_protobuf() {
- use protobuf::Message;
- let mut buffer = Vec::new();
-
- let mut original = Placeholder::new();
- original.name = "test".to_owned();
- original.write_to_writer(&mut buffer).unwrap();
-
- let copy = Placeholder::parse_from_reader(&mut buffer.as_slice()).unwrap();
-
- assert_eq!(original, copy);
- }
+ Ok(())
}
diff --git a/tools/aconfig/src/protos.rs b/tools/aconfig/src/protos.rs
new file mode 100644
index 0000000..3c156b3
--- /dev/null
+++ b/tools/aconfig/src/protos.rs
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+// When building with the Android tool-chain
+//
+// - an external crate `aconfig_protos` will be generated
+// - the feature "cargo" will be disabled
+//
+// When building with cargo
+//
+// - a local sub-module will be generated in OUT_DIR and included in this file
+// - the feature "cargo" will be enabled
+//
+// This module hides these differences from the rest of aconfig.
+
+// ---- When building with the Android tool-chain ----
+#[cfg(not(feature = "cargo"))]
+pub use aconfig_protos::aconfig::Android_config as ProtoAndroidConfig;
+
+#[cfg(not(feature = "cargo"))]
+pub use aconfig_protos::aconfig::Value as ProtoValue;
+
+#[cfg(not(feature = "cargo"))]
+pub use aconfig_protos::aconfig::Flag as ProtoFlag;
+
+#[cfg(not(feature = "cargo"))]
+pub use aconfig_protos::aconfig::Override_config as ProtoOverrideConfig;
+
+#[cfg(not(feature = "cargo"))]
+pub use aconfig_protos::aconfig::Override as ProtoOverride;
+
+// ---- When building with cargo ----
+#[cfg(feature = "cargo")]
+include!(concat!(env!("OUT_DIR"), "/aconfig_proto/mod.rs"));
+
+#[cfg(feature = "cargo")]
+pub use aconfig::Android_config as ProtoAndroidConfig;
+
+#[cfg(feature = "cargo")]
+pub use aconfig::Value as ProtoValue;
+
+#[cfg(feature = "cargo")]
+pub use aconfig::Flag as ProtoFlag;
+
+#[cfg(feature = "cargo")]
+pub use aconfig::Override_config as ProtoOverrideConfig;
+
+#[cfg(feature = "cargo")]
+pub use aconfig::Override as ProtoOverride;
+
+// ---- Common for both the Android tool-chain and cargo ----
+use anyhow::Result;
+
+pub fn try_from_text_proto<T>(s: &str) -> Result<T>
+where
+ T: protobuf::MessageFull,
+{
+ // warning: parse_from_str does not check if required fields are set
+ protobuf::text_format::parse_from_str(s).map_err(|e| e.into())
+}