From 92cf0ec2325e0740a9d07c0a1db72d660d569203 Mon Sep 17 00:00:00 2001 From: Zhi Dou Date: Wed, 19 Jul 2023 19:29:22 +0000 Subject: [PATCH] Aconfig: sort the parsed flag order in create-cache This change will sorted the parsed flags from the declarations. Without this change the code will expect the passed in declarations sorted. After this change the code will still guarantee the parsed flags in the cache is sorted, but it won't expect the passed in declarations are sorted Test: atest aconfig.test Bug: 291926035 Change-Id: I5f0637fe770003224b128591890e04277bc09345 --- tools/aconfig/src/commands.rs | 2 ++ tools/aconfig/src/protos.rs | 4 ++++ tools/aconfig/tests/test.aconfig | 38 ++++++++++++++++---------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs index 0ac84b24a2..bf4592175c 100644 --- a/tools/aconfig/src/commands.rs +++ b/tools/aconfig/src/commands.rs @@ -127,6 +127,8 @@ pub fn parse_flags(package: &str, declarations: Vec, values: Vec) } } + // Create a sorted parsed_flags + crate::protos::parsed_flags::sort_parsed_flags(&mut parsed_flags); crate::protos::parsed_flags::verify_fields(&parsed_flags)?; let mut output = Vec::new(); parsed_flags.write_to_vec(&mut output)?; diff --git a/tools/aconfig/src/protos.rs b/tools/aconfig/src/protos.rs index a621b87c34..4ddada7994 100644 --- a/tools/aconfig/src/protos.rs +++ b/tools/aconfig/src/protos.rs @@ -255,6 +255,10 @@ pub mod parsed_flags { Ok(merged) } + pub fn sort_parsed_flags(pf: &mut ProtoParsedFlags) { + pf.parsed_flag.sort_by_key(create_sorting_key); + } + fn create_sorting_key(pf: &ProtoParsedFlag) -> String { format!("{}.{}", pf.package(), pf.name()) } diff --git a/tools/aconfig/tests/test.aconfig b/tools/aconfig/tests/test.aconfig index a8f665223d..d7ac919a60 100644 --- a/tools/aconfig/tests/test.aconfig +++ b/tools/aconfig/tests/test.aconfig @@ -1,24 +1,5 @@ package: "com.android.aconfig.test" -# This flag's final value is calculated from: -# - test.aconfig: DISABLED + READ_WRITE (default) -# - first.values: DISABLED + READ_ONLY -flag { - name: "disabled_ro" - namespace: "aconfig_test" - description: "This flag is DISABLED + READ_ONLY" - bug: "123" -} - -# This flag's final value is calculated from: -# - test.aconfig: DISABLED + READ_WRITE (default) -flag { - name: "disabled_rw" - namespace: "aconfig_test" - description: "This flag is DISABLED + READ_WRITE" - bug: "456" -} - # This flag's final value is calculated from: # - test.aconfig: DISABLED + READ_WRITE (default) # - first.values: DISABLED + READ_WRITE @@ -40,3 +21,22 @@ flag { description: "This flag is ENABLED + READ_WRITE" # no bug field: bug is not mandatory } + +# This flag's final value is calculated from: +# - test.aconfig: DISABLED + READ_WRITE (default) +# - first.values: DISABLED + READ_ONLY +flag { + name: "disabled_ro" + namespace: "aconfig_test" + description: "This flag is DISABLED + READ_ONLY" + bug: "123" +} + +# This flag's final value is calculated from: +# - test.aconfig: DISABLED + READ_WRITE (default) +flag { + name: "disabled_rw" + namespace: "aconfig_test" + description: "This flag is DISABLED + READ_WRITE" + bug: "456" +}