Merge "Revert "(reland) Remove emulator dependencies on non emulator ta...""
diff --git a/core/Makefile b/core/Makefile
index 7083f83..3da1894 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
@@ -5308,13 +5315,13 @@
$(hide) echo "flash vendor_boot" >> $@
endif
ifneq (,$(strip $(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS)))
- $(hide) $(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS),\
- $(hide) echo "flash --apply-vbmeta vbmeta_$(partition)" >> $@;)
+ $(hide) $(foreach partition,$(BOARD_AVB_VBMETA_CUSTOM_PARTITIONS), \
+ echo "flash --apply-vbmeta vbmeta_$(partition)" >> $@;)
endif
endif # BOARD_AVB_ENABLE
$(hide) echo "reboot fastboot" >> $@
$(hide) echo "update-super" >> $@
- $(foreach partition,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
+ $(hide) $(foreach partition,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
echo "flash $(partition)" >> $@;)
ifdef BUILDING_SYSTEM_OTHER_IMAGE
$(hide) echo "flash --slot-other system system_other.img" >> $@
@@ -5763,6 +5770,8 @@
echo "virtual_ab_compression_method=$(PRODUCT_VIRTUAL_AB_COMPRESSION_METHOD)" >> $(1))
$(if $(filter true,$(PRODUCT_VIRTUAL_AB_OTA_RETROFIT)), \
echo "virtual_ab_retrofit=true" >> $(1))
+ $(if $(PRODUCT_VIRTUAL_AB_COW_VERSION), \
+ echo "virtual_ab_cow_version=$(PRODUCT_VIRTUAL_AB_COW_VERSION)" >> $(1))
endef
# By conditionally including the dependency of the target files package on the
diff --git a/core/product.mk b/core/product.mk
index e90e27b..818aac2 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -404,6 +404,10 @@
# supports it
_product_single_value_vars += PRODUCT_ENABLE_UFFD_GC
+# Specifies COW version to be used by update_engine and libsnapshot. If this value is not
+# specified we default to COW version 2 in update_engine for backwards compatibility
+_product_single_value_vars += PRODUCT_VIRTUAL_AB_COW_VERSION
+
_product_list_vars += PRODUCT_AFDO_PROFILES
.KATI_READONLY := _product_single_value_vars _product_list_vars
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/soong_config.mk b/core/soong_config.mk
index 90a2f75..034d044 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -315,6 +315,10 @@
$(call add_json_list, AfdoProfiles, $(ALL_AFDO_PROFILES))
+$(call add_json_str, ProductManufacturer, $(PRODUCT_MANUFACTURER))
+$(call add_json_str, ProductBrand, $(PRODUCT_BRAND))
+$(call add_json_list, BuildVersionTags, $(BUILD_VERSION_TAGS))
+
$(call json_end)
$(file >$(SOONG_VARIABLES).tmp,$(json_contents))
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/product/angle.mk b/target/product/angle_default.mk
similarity index 63%
copy from target/product/angle.mk
copy to target/product/angle_default.mk
index 0d7f8cb..bea0be6 100644
--- a/target/product/angle.mk
+++ b/target/product/angle_default.mk
@@ -14,13 +14,10 @@
# limitations under the License.
#
-# To include ANGLE drivers into the build, add
-# $(call inherit-product, $(SRC_TARGET_DIR)/product/angle.mk) to the Makefile.
+# To enable ANGLE as the default system GLES drivers, add
+# $(call inherit-product, $(SRC_TARGET_DIR)/product/angle_enabled.mk) to the Makefile.
-PRODUCT_PACKAGES := \
- libEGL_angle \
- libGLESv1_CM_angle \
- libGLESv2_angle
+$(call inherit-product, $(SRC_TARGET_DIR)/product/angle_supported.mk)
-# Set ro.gfx.angle.supported based on if ANGLE is installed in vendor partition
-PRODUCT_VENDOR_PROPERTIES := ro.gfx.angle.supported=true
+PRODUCT_VENDOR_PROPERTIES += \
+ persist.graphics.egl=angle
diff --git a/target/product/angle.mk b/target/product/angle_supported.mk
similarity index 71%
rename from target/product/angle.mk
rename to target/product/angle_supported.mk
index 0d7f8cb..c83ff5f 100644
--- a/target/product/angle.mk
+++ b/target/product/angle_supported.mk
@@ -14,13 +14,14 @@
# limitations under the License.
#
-# To include ANGLE drivers into the build, add
-# $(call inherit-product, $(SRC_TARGET_DIR)/product/angle.mk) to the Makefile.
+# To include ANGLE into the image build, add
+# $(call inherit-product, $(SRC_TARGET_DIR)/product/angle_supported.mk) to the Makefile.
+# By default, this will allow ANGLE binaries to coexist with native GLES drivers.
-PRODUCT_PACKAGES := \
+PRODUCT_PACKAGES += \
libEGL_angle \
libGLESv1_CM_angle \
libGLESv2_angle
# Set ro.gfx.angle.supported based on if ANGLE is installed in vendor partition
-PRODUCT_VENDOR_PROPERTIES := ro.gfx.angle.supported=true
+PRODUCT_VENDOR_PROPERTIES += ro.gfx.angle.supported=true
diff --git a/target/product/virtual_ab_ota/android_t_baseline.mk b/target/product/virtual_ab_ota/android_t_baseline.mk
index 418aaa4..f862485 100644
--- a/target/product/virtual_ab_ota/android_t_baseline.mk
+++ b/target/product/virtual_ab_ota/android_t_baseline.mk
@@ -20,3 +20,5 @@
#
# All U+ launching devices should instead use vabc_features.mk.
$(call inherit-product, $(SRC_TARGET_DIR)/product/virtual_ab_ota/vabc_features.mk)
+
+PRODUCT_VIRTUAL_AB_COW_VERSION := 2
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..6eac414 100644
--- a/tools/aconfig/protos/aconfig.proto
+++ b/tools/aconfig/protos/aconfig.proto
@@ -12,12 +12,46 @@
// 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;
+enum flag_state {
+ ENABLED = 1;
+ DISABLED = 2;
}
+
+enum permission {
+ READ_ONLY = 1;
+ READ_WRITE = 2;
+}
+
+message value {
+ required flag_state state = 1;
+ required permission permission = 2;
+ optional uint32 since = 3;
+}
+
+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 flag_state state = 2;
+ required permission permission = 3;
+};
+
+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..f10ca1f
--- /dev/null
+++ b/tools/aconfig/src/aconfig.rs
@@ -0,0 +1,352 @@
+/*
+ * 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 protobuf::{Enum, EnumOrUnknown};
+use serde::{Deserialize, Serialize};
+
+use crate::protos::{
+ ProtoAndroidConfig, ProtoFlag, ProtoFlagState, ProtoOverride, ProtoOverrideConfig,
+ ProtoPermission, ProtoValue,
+};
+
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
+pub enum FlagState {
+ Enabled,
+ Disabled,
+}
+
+impl TryFrom<EnumOrUnknown<ProtoFlagState>> for FlagState {
+ type Error = Error;
+
+ fn try_from(proto: EnumOrUnknown<ProtoFlagState>) -> Result<Self, Self::Error> {
+ match ProtoFlagState::from_i32(proto.value()) {
+ Some(ProtoFlagState::ENABLED) => Ok(FlagState::Enabled),
+ Some(ProtoFlagState::DISABLED) => Ok(FlagState::Disabled),
+ None => Err(anyhow!("unknown flag state enum value {}", proto.value())),
+ }
+ }
+}
+
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
+pub enum Permission {
+ ReadOnly,
+ ReadWrite,
+}
+
+impl TryFrom<EnumOrUnknown<ProtoPermission>> for Permission {
+ type Error = Error;
+
+ fn try_from(proto: EnumOrUnknown<ProtoPermission>) -> Result<Self, Self::Error> {
+ match ProtoPermission::from_i32(proto.value()) {
+ Some(ProtoPermission::READ_ONLY) => Ok(Permission::ReadOnly),
+ Some(ProtoPermission::READ_WRITE) => Ok(Permission::ReadWrite),
+ None => Err(anyhow!("unknown permission enum value {}", proto.value())),
+ }
+ }
+}
+
+#[derive(Debug, PartialEq, Eq)]
+pub struct Value {
+ state: FlagState,
+ permission: Permission,
+ since: Option<u32>,
+}
+
+#[allow(dead_code)] // only used in unit tests
+impl Value {
+ pub fn new(state: FlagState, permission: Permission, since: u32) -> Value {
+ Value { state, permission, since: Some(since) }
+ }
+
+ pub fn default(state: FlagState, permission: Permission) -> Value {
+ Value { state, permission, since: None }
+ }
+}
+
+impl TryFrom<ProtoValue> for Value {
+ type Error = Error;
+
+ fn try_from(proto: ProtoValue) -> Result<Self, Self::Error> {
+ let Some(proto_state) = proto.state else {
+ return Err(anyhow!("missing 'state' field"));
+ };
+ let state = proto_state.try_into()?;
+ let Some(proto_permission) = proto.permission else {
+ return Err(anyhow!("missing 'permission' field"));
+ };
+ let permission = proto_permission.try_into()?;
+ Ok(Value { state, permission, 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(&self, build_id: u32) -> (FlagState, Permission) {
+ let mut state = self.values[0].state;
+ let mut permission = self.values[0].permission;
+ for candidate in self.values.iter().skip(1) {
+ let since = candidate.since.expect("invariant: non-defaults values have Some(since)");
+ if since <= build_id {
+ state = candidate.state;
+ permission = candidate.permission;
+ }
+ }
+ (state, permission)
+ }
+}
+
+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 state: FlagState,
+ pub permission: Permission,
+}
+
+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(proto_state) = proto.state else {
+ return Err(anyhow!("missing 'state' field"));
+ };
+ let state = proto_state.try_into()?;
+ let Some(proto_permission) = proto.permission else {
+ return Err(anyhow!("missing 'permission' field"));
+ };
+ let permission = proto_permission.try_into()?;
+ Ok(Override { id, state, permission })
+ }
+}
+
+#[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(FlagState::Disabled, Permission::ReadOnly),
+ Value::new(FlagState::Enabled, Permission::ReadWrite, 8),
+ ],
+ };
+
+ let s = r#"
+ id: "1234"
+ description: "Description of the flag"
+ value {
+ state: DISABLED
+ permission: READ_ONLY
+ }
+ value {
+ state: ENABLED
+ permission: READ_WRITE
+ 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 {
+ state: ENABLED
+ permission: READ_ONLY
+ }
+ "#;
+ 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 {
+ state: ENABLED
+ permission: READ_ONLY
+ }
+ value {
+ state: ENABLED
+ permission: READ_ONLY
+ }
+ "#;
+ 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(FlagState::Enabled, Permission::ReadOnly)],
+ },
+ Flag {
+ id: "b".to_owned(),
+ description: "B".to_owned(),
+ values: vec![Value::default(FlagState::Disabled, Permission::ReadWrite)],
+ },
+ ];
+
+ let s = r#"
+ flag {
+ id: "a"
+ description: "A"
+ value {
+ state: ENABLED
+ permission: READ_ONLY
+ }
+ }
+ flag {
+ id: "b"
+ description: "B"
+ value {
+ state: DISABLED
+ permission: READ_WRITE
+ }
+ }
+ "#;
+ 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(),
+ state: FlagState::Enabled,
+ permission: Permission::ReadOnly,
+ };
+
+ let s = r#"
+ id: "1234"
+ state: ENABLED
+ permission: READ_ONLY
+ "#;
+ let actual = Override::try_from_text_proto(s).unwrap();
+
+ assert_eq!(expected, actual);
+ }
+
+ #[test]
+ fn test_flag_resolve() {
+ let flag = Flag {
+ id: "a".to_owned(),
+ description: "A".to_owned(),
+ values: vec![
+ Value::default(FlagState::Disabled, Permission::ReadOnly),
+ Value::new(FlagState::Disabled, Permission::ReadWrite, 10),
+ Value::new(FlagState::Enabled, Permission::ReadOnly, 20),
+ Value::new(FlagState::Enabled, Permission::ReadWrite, 30),
+ ],
+ };
+ assert_eq!((FlagState::Disabled, Permission::ReadOnly), flag.resolve(0));
+ assert_eq!((FlagState::Disabled, Permission::ReadOnly), flag.resolve(9));
+ assert_eq!((FlagState::Disabled, Permission::ReadWrite), flag.resolve(10));
+ assert_eq!((FlagState::Disabled, Permission::ReadWrite), flag.resolve(11));
+ assert_eq!((FlagState::Disabled, Permission::ReadWrite), flag.resolve(19));
+ assert_eq!((FlagState::Enabled, Permission::ReadOnly), flag.resolve(20));
+ assert_eq!((FlagState::Enabled, Permission::ReadOnly), flag.resolve(21));
+ assert_eq!((FlagState::Enabled, Permission::ReadOnly), flag.resolve(29));
+ assert_eq!((FlagState::Enabled, Permission::ReadWrite), flag.resolve(30));
+ assert_eq!((FlagState::Enabled, Permission::ReadWrite), flag.resolve(10_000));
+ }
+}
diff --git a/tools/aconfig/src/cache.rs b/tools/aconfig/src/cache.rs
new file mode 100644
index 0000000..94443d7
--- /dev/null
+++ b/tools/aconfig/src/cache.rs
@@ -0,0 +1,191 @@
+/*
+ * 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, FlagState, Override, Permission};
+use crate::commands::Source;
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct TracePoint {
+ pub source: Source,
+ pub state: FlagState,
+ pub permission: Permission,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct Item {
+ pub id: String,
+ pub description: String,
+ pub state: FlagState,
+ pub permission: Permission,
+ pub trace: Vec<TracePoint>,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+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 (state, permission) = flag.resolve(self.build_id);
+ self.items.push(Item {
+ id: flag.id.clone(),
+ description: flag.description,
+ state,
+ permission,
+ trace: vec![TracePoint { source, state, permission }],
+ });
+ 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.state = override_.state;
+ existing_item.permission = override_.permission;
+ existing_item.trace.push(TracePoint {
+ source,
+ state: override_.state,
+ permission: override_.permission,
+ });
+ Ok(())
+ }
+
+ pub fn iter(&self) -> impl Iterator<Item = &Item> {
+ self.items.iter()
+ }
+}
+
+impl Item {}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::aconfig::{FlagState, Permission, 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(FlagState::Enabled, Permission::ReadOnly)],
+ },
+ )
+ .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(FlagState::Disabled, Permission::ReadOnly)],
+ },
+ )
+ .unwrap_err();
+ assert_eq!(
+ &format!("{:?}", error),
+ "failed to add flag foo from second.txt: flag already defined"
+ );
+ }
+
+ #[test]
+ fn test_add_override() {
+ fn check(cache: &Cache, id: &str, expected: (FlagState, Permission)) -> bool {
+ let item = cache.iter().find(|&item| item.id == id).unwrap();
+ item.state == expected.0 && item.permission == expected.1
+ }
+
+ let mut cache = Cache::new(1);
+ let error = cache
+ .add_override(
+ Source::Memory,
+ Override {
+ id: "foo".to_string(),
+ state: FlagState::Enabled,
+ permission: Permission::ReadOnly,
+ },
+ )
+ .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(FlagState::Enabled, Permission::ReadOnly)],
+ },
+ )
+ .unwrap();
+ dbg!(&cache);
+ assert!(check(&cache, "foo", (FlagState::Enabled, Permission::ReadOnly)));
+
+ cache
+ .add_override(
+ Source::Memory,
+ Override {
+ id: "foo".to_string(),
+ state: FlagState::Disabled,
+ permission: Permission::ReadWrite,
+ },
+ )
+ .unwrap();
+ dbg!(&cache);
+ assert!(check(&cache, "foo", (FlagState::Disabled, Permission::ReadWrite)));
+
+ cache
+ .add_override(
+ Source::Memory,
+ Override {
+ id: "foo".to_string(),
+ state: FlagState::Enabled,
+ permission: Permission::ReadWrite,
+ },
+ )
+ .unwrap();
+ assert!(check(&cache, "foo", (FlagState::Enabled, Permission::ReadWrite)));
+ }
+}
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
new file mode 100644
index 0000000..73d3357
--- /dev/null
+++ b/tools/aconfig/src/commands.rs
@@ -0,0 +1,126 @@
+/*
+ * 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(Serialize, Deserialize, Clone, Debug)]
+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.state);
+ }
+ }
+ Format::Debug => {
+ for item in cache.iter() {
+ println!("{:?}", item);
+ }
+ }
+ }
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::aconfig::{FlagState, Permission};
+
+ #[test]
+ fn test_create_cache() {
+ let s = r#"
+ flag {
+ id: "a"
+ description: "Description of a"
+ value {
+ state: ENABLED
+ permission: READ_WRITE
+ }
+ }
+ "#;
+ let aconfigs = vec![Input { source: Source::Memory, reader: Box::new(s.as_bytes()) }];
+ let o = r#"
+ override {
+ id: "a"
+ state: DISABLED
+ permission: READ_ONLY
+ }
+ "#;
+ let overrides = vec![Input { source: Source::Memory, reader: Box::new(o.as_bytes()) }];
+ let cache = create_cache(1, aconfigs, overrides).unwrap();
+ let item = cache.iter().find(|&item| item.id == "a").unwrap();
+ assert_eq!(FlagState::Disabled, item.state);
+ assert_eq!(Permission::ReadOnly, item.permission);
+ }
+}
diff --git a/tools/aconfig/src/main.rs b/tools/aconfig/src/main.rs
index 2f7255e..62750ae 100644
--- a/tools/aconfig/src/main.rs
+++ b/tools/aconfig/src/main.rs
@@ -16,38 +16,72 @@
//! `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, ArgMatches, 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());
+fn open_zero_or_more_files(matches: &ArgMatches, arg_name: &str) -> Result<Vec<Input>> {
+ let mut opened_files = vec![];
+ for path in matches.get_many::<String>(arg_name).unwrap_or_default() {
+ let file = Box::new(fs::File::open(path)?);
+ opened_files.push(Input { source: Source::File(path.to_string()), reader: file });
+ }
+ Ok(opened_files)
}
-#[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 build_id = *sub_matches.get_one::<u32>("build-id").unwrap();
+ let aconfigs = open_zero_or_more_files(sub_matches, "aconfig")?;
+ let overrides = open_zero_or_more_files(sub_matches, "override")?;
+ 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..604eca4
--- /dev/null
+++ b/tools/aconfig/src/protos.rs
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+#[cfg(not(feature = "cargo"))]
+pub use aconfig_protos::aconfig::Permission as ProtoPermission;
+
+#[cfg(not(feature = "cargo"))]
+pub use aconfig_protos::aconfig::Flag_state as ProtoFlagState;
+
+// ---- 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;
+
+#[cfg(feature = "cargo")]
+pub use aconfig::Permission as ProtoPermission;
+
+#[cfg(feature = "cargo")]
+pub use aconfig::Flag_state as ProtoFlagState;
+
+// ---- 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())
+}
diff --git a/tools/finalization/environment.sh b/tools/finalization/environment.sh
index b0ed645..9714ac4 100755
--- a/tools/finalization/environment.sh
+++ b/tools/finalization/environment.sh
@@ -7,7 +7,6 @@
export FINAL_PLATFORM_CODENAME='VanillaIceCream'
export CURRENT_PLATFORM_CODENAME='VanillaIceCream'
export FINAL_PLATFORM_CODENAME_JAVA='VANILLA_ICE_CREAM'
-export FINAL_BUILD_PREFIX='VP1A'
export FINAL_PLATFORM_VERSION='15'
# Set arbitrary large values for CI.
diff --git a/tools/finalization/finalize-aidl-vndk-sdk-resources.sh b/tools/finalization/finalize-aidl-vndk-sdk-resources.sh
index d977a65..fa33986 100755
--- a/tools/finalization/finalize-aidl-vndk-sdk-resources.sh
+++ b/tools/finalization/finalize-aidl-vndk-sdk-resources.sh
@@ -4,13 +4,15 @@
function apply_droidstubs_hack() {
if ! grep -q 'STOPSHIP: RESTORE THIS LOGIC WHEN DECLARING "REL" BUILD' "$top/build/soong/java/droidstubs.go" ; then
- git -C "$top/build/soong" apply --allow-empty ../../build/make/tools/finalization/build_soong_java_droidstubs.go.apply_hack.diff
+ local build_soong_git_root="$(readlink -f $top/build/soong)"
+ git -C "$build_soong_git_root" apply --allow-empty ../../build/make/tools/finalization/build_soong_java_droidstubs.go.apply_hack.diff
fi
}
function apply_resources_sdk_int_fix() {
if ! grep -q 'public static final int RESOURCES_SDK_INT = SDK_INT;' "$top/frameworks/base/core/java/android/os/Build.java" ; then
- git -C "$top/frameworks/base" apply --allow-empty ../../build/make/tools/finalization/frameworks_base.apply_resource_sdk_int.diff
+ local base_git_root="$(readlink -f $top/frameworks/base)"
+ git -C "$base_git_root" apply --allow-empty ../../build/make/tools/finalization/frameworks_base.apply_resource_sdk_int.diff
fi
}
diff --git a/tools/finalization/finalize-sdk-rel.sh b/tools/finalization/finalize-sdk-rel.sh
index 84ad2a7..62e5ee5 100755
--- a/tools/finalization/finalize-sdk-rel.sh
+++ b/tools/finalization/finalize-sdk-rel.sh
@@ -34,7 +34,8 @@
revert_resources_sdk_int_fix
# build/make/core/version_defaults.mk
- sed -i -e "s/PLATFORM_VERSION_CODENAME.${FINAL_BUILD_PREFIX} := .*/PLATFORM_VERSION_CODENAME.${FINAL_BUILD_PREFIX} := REL/g" "$top/build/make/core/version_defaults.mk"
+ # Mark all versions "released".
+ sed -i 's/\(PLATFORM_VERSION_CODENAME\.[^[:space:]]*\) := [^[:space:]]*/\1 := REL/g' "$top/build/make/core/version_defaults.mk"
# cts
echo "$FINAL_PLATFORM_VERSION" > "$top/cts/tests/tests/os/assets/platform_versions.txt"
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 940ac1d..06de622 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -754,6 +754,33 @@
return ReadBytesFromInputFile(input_file, fn).decode()
+def WriteBytesToInputFile(input_file, fn, data):
+ """Write bytes |data| contents to fn of input zipfile or directory."""
+ if isinstance(input_file, zipfile.ZipFile):
+ with input_file.open(fn, "w") as entry_fp:
+ return entry_fp.write(data)
+ elif zipfile.is_zipfile(input_file):
+ with zipfile.ZipFile(input_file, "r", allowZip64=True) as zfp:
+ with zfp.open(fn, "w") as entry_fp:
+ return entry_fp.write(data)
+ else:
+ if not os.path.isdir(input_file):
+ raise ValueError(
+ "Invalid input_file, accepted inputs are ZipFile object, path to .zip file on disk, or path to extracted directory. Actual: " + input_file)
+ path = os.path.join(input_file, *fn.split("/"))
+ try:
+ with open(path, "wb") as f:
+ return f.write(data)
+ except IOError as e:
+ if e.errno == errno.ENOENT:
+ raise KeyError(fn)
+
+
+def WriteToInputFile(input_file, fn, str: str):
+ """Write str content to fn of input file or directory"""
+ return WriteBytesToInputFile(input_file, fn, str.encode())
+
+
def ExtractFromInputFile(input_file, fn):
"""Extracts the contents of fn from input zipfile or directory into a file."""
if isinstance(input_file, zipfile.ZipFile):
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index e40256c..1a4a895 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -270,7 +270,7 @@
import common
import ota_utils
from ota_utils import (UNZIP_PATTERN, FinalizeMetadata, GetPackageMetadata,
- PayloadGenerator, SECURITY_PATCH_LEVEL_PROP_NAME, CopyTargetFilesDir)
+ PayloadGenerator, SECURITY_PATCH_LEVEL_PROP_NAME, ExtractTargetFiles, CopyTargetFilesDir)
from common import DoesInputFileContain, IsSparseImage
import target_files_diff
from check_target_files_vintf import CheckVintfIfTrebleEnabled
@@ -519,15 +519,10 @@
Returns:
The filename of target-files.zip that doesn't contain postinstall config.
"""
- # We should only make a copy if postinstall_config entry exists.
- with zipfile.ZipFile(input_file, 'r', allowZip64=True) as input_zip:
- if POSTINSTALL_CONFIG not in input_zip.namelist():
- return input_file
-
- target_file = common.MakeTempFile(prefix="targetfiles-", suffix=".zip")
- shutil.copyfile(input_file, target_file)
- common.ZipDelete(target_file, POSTINSTALL_CONFIG)
- return target_file
+ config_path = os.path.join(input_file, POSTINSTALL_CONFIG)
+ if os.path.exists(config_path):
+ os.unlink(config_path)
+ return input_file
def ParseInfoDict(target_file_path):
@@ -544,6 +539,17 @@
Returns:
The path to modified target-files.zip
"""
+ if os.path.isdir(input_file):
+ dynamic_partition_info_path = os.path.join(
+ input_file, "META", "dynamic_partitions_info.txt")
+ with open(dynamic_partition_info_path, "r") as fp:
+ dynamic_partition_info = fp.read()
+ dynamic_partition_info = ModifyVABCCompressionParam(
+ dynamic_partition_info, vabc_compression_param)
+ with open(dynamic_partition_info_path, "w") as fp:
+ fp.write(dynamic_partition_info)
+ return input_file
+
target_file = common.MakeTempFile(prefix="targetfiles-", suffix=".zip")
shutil.copyfile(input_file, target_file)
common.ZipDelete(target_file, DYNAMIC_PARTITION_INFO)
@@ -571,23 +577,7 @@
The filename of target-files.zip used for partial ota update.
"""
- def AddImageForPartition(partition_name):
- """Add the archive name for a given partition to the copy list."""
- for prefix in ['IMAGES', 'RADIO']:
- image_path = '{}/{}.img'.format(prefix, partition_name)
- if image_path in namelist:
- copy_entries.append(image_path)
- map_path = '{}/{}.map'.format(prefix, partition_name)
- if map_path in namelist:
- copy_entries.append(map_path)
- return
-
- raise ValueError("Cannot find {} in input zipfile".format(partition_name))
-
- with zipfile.ZipFile(input_file, allowZip64=True) as input_zip:
- original_ab_partitions = input_zip.read(
- AB_PARTITIONS).decode().splitlines()
- namelist = input_zip.namelist()
+ original_ab_partitions = common.ReadFromInputFile(input_file, AB_PARTITIONS)
unrecognized_partitions = [partition for partition in ab_partitions if
partition not in original_ab_partitions]
@@ -596,50 +586,65 @@
unrecognized_partitions)
logger.info("Generating partial updates for %s", ab_partitions)
+ for subdir in ["IMAGES", "RADIO", "PREBUILT_IMAGES"]:
+ image_dir = os.path.join(subdir)
+ if not os.path.exists(image_dir):
+ continue
+ for filename in os.listdir(image_dir):
+ filepath = os.path.join(image_dir, filename)
+ if filename.endswith(".img"):
+ partition_name = filename.removesuffix(".img")
+ if partition_name not in ab_partitions:
+ os.unlink(filepath)
- copy_entries = ['META/update_engine_config.txt']
- for partition_name in ab_partitions:
- AddImageForPartition(partition_name)
+ common.WriteToInputFile(input_file, 'META/ab_partitions.txt',
+ '\n'.join(ab_partitions))
+ CARE_MAP_ENTRY = "META/care_map.pb"
+ if DoesInputFileContain(input_file, CARE_MAP_ENTRY):
+ caremap = care_map_pb2.CareMap()
+ caremap.ParseFromString(
+ common.ReadBytesFromInputFile(input_file, CARE_MAP_ENTRY))
+ filtered = [
+ part for part in caremap.partitions if part.name in ab_partitions]
+ del caremap.partitions[:]
+ caremap.partitions.extend(filtered)
+ common.WriteBytesToInputFile(input_file, CARE_MAP_ENTRY,
+ caremap.SerializeToString())
- # Use zip2zip to avoid extracting the zipfile.
- partial_target_file = common.MakeTempFile(suffix='.zip')
- cmd = ['zip2zip', '-i', input_file, '-o', partial_target_file]
- cmd.extend(['{}:{}'.format(name, name) for name in copy_entries])
- common.RunAndCheckOutput(cmd)
+ for info_file in ['META/misc_info.txt', DYNAMIC_PARTITION_INFO]:
+ if not DoesInputFileContain(input_file, info_file):
+ logger.warning('Cannot find %s in input zipfile', info_file)
+ continue
- partial_target_zip = zipfile.ZipFile(partial_target_file, 'a',
- allowZip64=True)
- with zipfile.ZipFile(input_file, allowZip64=True) as input_zip:
- common.ZipWriteStr(partial_target_zip, 'META/ab_partitions.txt',
- '\n'.join(ab_partitions))
- CARE_MAP_ENTRY = "META/care_map.pb"
- if CARE_MAP_ENTRY in input_zip.namelist():
- caremap = care_map_pb2.CareMap()
- caremap.ParseFromString(input_zip.read(CARE_MAP_ENTRY))
- filtered = [
- part for part in caremap.partitions if part.name in ab_partitions]
- del caremap.partitions[:]
- caremap.partitions.extend(filtered)
- common.ZipWriteStr(partial_target_zip, CARE_MAP_ENTRY,
- caremap.SerializeToString())
+ content = common.ReadFromInputFile(input_file, info_file)
+ modified_info = UpdatesInfoForSpecialUpdates(
+ content, lambda p: p in ab_partitions)
+ if OPTIONS.vabc_compression_param and info_file == DYNAMIC_PARTITION_INFO:
+ modified_info = ModifyVABCCompressionParam(
+ modified_info, OPTIONS.vabc_compression_param)
+ common.WriteToInputFile(input_file, info_file, modified_info)
- for info_file in ['META/misc_info.txt', DYNAMIC_PARTITION_INFO]:
- if info_file not in input_zip.namelist():
- logger.warning('Cannot find %s in input zipfile', info_file)
- continue
- content = input_zip.read(info_file).decode()
- modified_info = UpdatesInfoForSpecialUpdates(
- content, lambda p: p in ab_partitions)
- if OPTIONS.vabc_compression_param and info_file == DYNAMIC_PARTITION_INFO:
- modified_info = ModifyVABCCompressionParam(
- modified_info, OPTIONS.vabc_compression_param)
- common.ZipWriteStr(partial_target_zip, info_file, modified_info)
+ def IsInPartialList(postinstall_line: str):
+ idx = postinstall_line.find("=")
+ if idx < 0:
+ return False
+ key = postinstall_line[:idx]
+ logger.info("%s %s", key, ab_partitions)
+ for part in ab_partitions:
+ if key.endswith("_" + part):
+ return True
+ return False
- # TODO(xunchang) handle META/postinstall_config.txt'
+ postinstall_config = common.ReadFromInputFile(input_file, POSTINSTALL_CONFIG)
+ postinstall_config = [
+ line for line in postinstall_config.splitlines() if IsInPartialList(line)]
+ if postinstall_config:
+ postinstall_config = "\n".join(postinstall_config)
+ common.WriteToInputFile(input_file, POSTINSTALL_CONFIG, postinstall_config)
+ else:
+ os.unlink(os.path.join(input_file, POSTINSTALL_CONFIG))
- common.ZipClose(partial_target_zip)
-
- return partial_target_file
+ return input_file
def GetTargetFilesZipForRetrofitDynamicPartitions(input_file,
@@ -664,21 +669,12 @@
replace = {'OTA/super_{}.img'.format(dev): 'IMAGES/{}.img'.format(dev)
for dev in super_block_devices}
- target_file = common.MakeTempFile(prefix="targetfiles-", suffix=".zip")
- shutil.copyfile(input_file, target_file)
-
- with zipfile.ZipFile(input_file, allowZip64=True) as input_zip:
- namelist = input_zip.namelist()
-
- input_tmp = common.UnzipTemp(input_file, RETROFIT_DAP_UNZIP_PATTERN)
-
# Remove partitions from META/ab_partitions.txt that is in
# dynamic_partition_list but not in super_block_devices so that
# brillo_update_payload won't generate update for those logical partitions.
- ab_partitions_file = os.path.join(input_tmp, *AB_PARTITIONS.split('/'))
- with open(ab_partitions_file) as f:
- ab_partitions_lines = f.readlines()
- ab_partitions = [line.strip() for line in ab_partitions_lines]
+ ab_partitions_lines = common.ReadFromInputFile(
+ input_file, AB_PARTITIONS).split("\n")
+ ab_partitions = [line.strip() for line in ab_partitions_lines]
# Assert that all super_block_devices are in ab_partitions
super_device_not_updated = [partition for partition in super_block_devices
if partition not in ab_partitions]
@@ -686,15 +682,6 @@
"{} is in super_block_devices but not in {}".format(
super_device_not_updated, AB_PARTITIONS)
# ab_partitions -= (dynamic_partition_list - super_block_devices)
- new_ab_partitions = common.MakeTempFile(
- prefix="ab_partitions", suffix=".txt")
- with open(new_ab_partitions, 'w') as f:
- for partition in ab_partitions:
- if (partition in dynamic_partition_list and
- partition not in super_block_devices):
- logger.info("Dropping %s from ab_partitions.txt", partition)
- continue
- f.write(partition + "\n")
to_delete = [AB_PARTITIONS]
# Always skip postinstall for a retrofit update.
@@ -707,24 +694,28 @@
# Remove the existing partition images as well as the map files.
to_delete += list(replace.values())
to_delete += ['IMAGES/{}.map'.format(dev) for dev in super_block_devices]
-
- common.ZipDelete(target_file, to_delete)
-
- target_zip = zipfile.ZipFile(target_file, 'a', allowZip64=True)
+ for item in to_delete:
+ os.unlink(os.path.join(input_file, item))
# Write super_{foo}.img as {foo}.img.
for src, dst in replace.items():
- assert src in namelist, \
+ assert DoesInputFileContain(input_file, src), \
'Missing {} in {}; {} cannot be written'.format(src, input_file, dst)
- unzipped_file = os.path.join(input_tmp, *src.split('/'))
- common.ZipWrite(target_zip, unzipped_file, arcname=dst)
+ source_path = os.path.join(input_file, *src.split("/"))
+ target_path = os.path.join(input_file, *dst.split("/"))
+ os.rename(source_path, target_path)
# Write new ab_partitions.txt file
- common.ZipWrite(target_zip, new_ab_partitions, arcname=AB_PARTITIONS)
+ new_ab_partitions = os.paht.join(input_file, AB_PARTITIONS)
+ with open(new_ab_partitions, 'w') as f:
+ for partition in ab_partitions:
+ if (partition in dynamic_partition_list and
+ partition not in super_block_devices):
+ logger.info("Dropping %s from ab_partitions.txt", partition)
+ continue
+ f.write(partition + "\n")
- common.ZipClose(target_zip)
-
- return target_file
+ return input_file
def GetTargetFilesZipForCustomImagesUpdates(input_file, custom_images):
@@ -833,14 +824,20 @@
return pattern.search(output) is not None
+def ExtractOrCopyTargetFiles(target_file):
+ if os.path.isdir(target_file):
+ return CopyTargetFilesDir(target_file)
+ else:
+ return ExtractTargetFiles(target_file)
+
+
def GenerateAbOtaPackage(target_file, output_file, source_file=None):
"""Generates an Android OTA package that has A/B update payload."""
# If input target_files are directories, create a copy so that we can modify
# them directly
- if os.path.isdir(target_file):
- target_file = CopyTargetFilesDir(target_file)
- if source_file is not None and os.path.isdir(source_file):
- source_file = CopyTargetFilesDir(source_file)
+ target_file = ExtractOrCopyTargetFiles(target_file)
+ if source_file is not None:
+ source_file = ExtractOrCopyTargetFiles(source_file)
# Stage the output zip package for package signing.
if not OPTIONS.no_signing:
staging_file = common.MakeTempFile(suffix='.zip')
@@ -851,7 +848,7 @@
allowZip64=True)
if source_file is not None:
- source_file = ota_utils.ExtractTargetFiles(source_file)
+ source_file = ExtractTargetFiles(source_file)
assert "ab_partitions" in OPTIONS.source_info_dict, \
"META/ab_partitions.txt is required for ab_update."
assert "ab_partitions" in OPTIONS.target_info_dict, \
@@ -948,10 +945,10 @@
elif OPTIONS.partial:
target_file = GetTargetFilesZipForPartialUpdates(target_file,
OPTIONS.partial)
- elif OPTIONS.vabc_compression_param:
+ if OPTIONS.vabc_compression_param:
target_file = GetTargetFilesZipForCustomVABCCompression(
target_file, OPTIONS.vabc_compression_param)
- elif OPTIONS.skip_postinstall:
+ if OPTIONS.skip_postinstall:
target_file = GetTargetFilesZipWithoutPostinstallConfig(target_file)
# Target_file may have been modified, reparse ab_partitions
target_info.info_dict['ab_partitions'] = common.ReadFromInputFile(target_file,
diff --git a/tools/releasetools/ota_utils.py b/tools/releasetools/ota_utils.py
index 3291d56..9067e78 100644
--- a/tools/releasetools/ota_utils.py
+++ b/tools/releasetools/ota_utils.py
@@ -1047,10 +1047,15 @@
def CopyTargetFilesDir(input_dir):
output_dir = common.MakeTempDir("target_files")
- shutil.copytree(os.path.join(input_dir, "IMAGES"), os.path.join(
- output_dir, "IMAGES"), dirs_exist_ok=True)
+ IMAGES_DIR = ["IMAGES", "PREBUILT_IMAGES", "RADIO"]
+ for subdir in IMAGES_DIR:
+ if not os.path.exists(os.path.join(input_dir, subdir)):
+ continue
+ shutil.copytree(os.path.join(input_dir, subdir), os.path.join(
+ output_dir, subdir), dirs_exist_ok=True, copy_function=os.link)
shutil.copytree(os.path.join(input_dir, "META"), os.path.join(
output_dir, "META"), dirs_exist_ok=True)
+
for (dirpath, _, filenames) in os.walk(input_dir):
for filename in filenames:
path = os.path.join(dirpath, filename)