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

Commit 76adff2a authored by Mårten Kongstad's avatar Mårten Kongstad
Browse files

aconfig: improve flag value tracing

Improve how the flag values (state, permission) are tracked when parsing
config and override files: migrate from a raw string to a proper struct,
as this will make it easier when aconfig will output this data in some
structured format for other tools to consume.

Also, rename Cache.debug to Cache.trace.

Bug: 279485059
Test: atest aconfig.test
Change-Id: Idad57c969515f697e9065429d8a44c38d8a512d2
parent 80bff11a
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -21,13 +21,20 @@ 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 debug: Vec<String>,
    pub trace: Vec<TracePoint>,
}

#[derive(Serialize, Deserialize, Debug)]
@@ -63,7 +70,7 @@ impl Cache {
            description: flag.description,
            state,
            permission,
            debug: vec![format!("{}:{:?} {:?}", source, state, permission)],
            trace: vec![TracePoint { source, state, permission }],
        });
        Ok(())
    }
@@ -74,9 +81,11 @@ impl Cache {
        };
        existing_item.state = override_.state;
        existing_item.permission = override_.permission;
        existing_item
            .debug
            .push(format!("{}:{:?} {:?}", source, override_.state, override_.permission));
        existing_item.trace.push(TracePoint {
            source,
            state: override_.state,
            permission: override_.permission,
        });
        Ok(())
    }

+2 −1
Original line number Diff line number Diff line
@@ -16,13 +16,14 @@

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)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum Source {
    #[allow(dead_code)] // only used in unit tests
    Memory,