Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12705d46 authored by Dennis Shen's avatar Dennis Shen
Browse files

aconfig: update aconfig_storage_file crate

Add android.bp target for the binary. Change the binary name to
aconfig-storage. And a number of small updates.

Bug: b/321077378
Test: m aconfig-stoarge; atest aconfig_storage_file.test
Change-Id: I9f560a031433407800ded1c2f4f2bdab459f5df7
parent 7254e18a
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ rust_defaults {
    name: "aconfig_storage_file.defaults",
    edition: "2021",
    lints: "none",
    srcs: ["src/lib.rs"],
    rustlibs: [
        "libanyhow",
        "libthiserror",
@@ -22,12 +21,21 @@ rust_library {
    crate_name: "aconfig_storage_file",
    host_supported: true,
    defaults: ["aconfig_storage_file.defaults"],
    srcs: ["src/lib.rs"],
}

rust_binary_host {
    name: "aconfig-storage",
    defaults: ["aconfig_storage_file.defaults"],
    srcs: ["src/main.rs"],
    rustlibs: ["libaconfig_storage_file"],
}

rust_test_host {
    name: "aconfig_storage_file.test",
    test_suites: ["general-tests"],
    defaults: ["aconfig_storage_file.defaults"],
    srcs: ["src/lib.rs"],
}

rust_protobuf {
+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@ tempfile = "3.9.0"
thiserror = "1.0.56"
clap = { version = "4.1.8", features = ["derive"] }

[[bin]]
name = "aconfig-storage"
path = "src/main.rs"

[build-dependencies]
protobuf-codegen = "3.2.0"
cxx-build = "1.0"
+3 −1
Original line number Diff line number Diff line
@@ -78,7 +78,9 @@ impl TryFrom<&str> for StorageFileSelection {
            "package_map" => Ok(Self::PackageMap),
            "flag_map" => Ok(Self::FlagMap),
            "flag_val" => Ok(Self::FlagVal),
            _ => Err(anyhow!("Invalid storage file to create")),
            _ => Err(anyhow!(
                "Invalid storage file type, valid types are package_map|flag_map|flag_val]"
            )),
        }
    }
}
+9 −9
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

//! `aconfig_storage` is a debugging tool to parse storage files
//! `aconfig-storage` is a debugging tool to parse storage files

use aconfig_storage_file::{
    list_flags, read_file_to_bytes, AconfigStorageError, FlagTable, FlagValueList, PackageTable,
@@ -24,7 +24,7 @@ use aconfig_storage_file::{
use clap::{builder::ArgAction, Arg, Command};

fn cli() -> Command {
    Command::new("aconfig_storage_file")
    Command::new("aconfig-storage")
        .subcommand_required(true)
        .subcommand(
            Command::new("print")
@@ -39,13 +39,13 @@ fn cli() -> Command {
        .subcommand(
            Command::new("list")
                .arg(
                    Arg::new("package_map")
                        .long("package_map")
                    Arg::new("package-map")
                        .long("package-map")
                        .required(true)
                        .action(ArgAction::Set),
                )
                .arg(Arg::new("flag_map").long("flag_map").required(true).action(ArgAction::Set))
                .arg(Arg::new("flag_val").long("flag_val").required(true).action(ArgAction::Set)),
                .arg(Arg::new("flag-map").long("flag-map").required(true).action(ArgAction::Set))
                .arg(Arg::new("flag-val").long("flag-val").required(true).action(ArgAction::Set)),
        )
}

@@ -80,9 +80,9 @@ fn main() -> Result<(), AconfigStorageError> {
            print_storage_file(file_path, file_type)?
        }
        Some(("list", sub_matches)) => {
            let package_map = sub_matches.get_one::<String>("package_map").unwrap();
            let flag_map = sub_matches.get_one::<String>("flag_map").unwrap();
            let flag_val = sub_matches.get_one::<String>("flag_val").unwrap();
            let package_map = sub_matches.get_one::<String>("package-map").unwrap();
            let flag_map = sub_matches.get_one::<String>("flag-map").unwrap();
            let flag_val = sub_matches.get_one::<String>("flag-val").unwrap();
            let flags = list_flags(package_map, flag_map, flag_val)?;
            for flag in flags.iter() {
                println!("{}: {}", flag.0, flag.1);