Merge "aconfig: create one file at each create-storage command invocation" into main
This commit is contained in:
@@ -30,7 +30,8 @@ use crate::protos::{
|
|||||||
ParsedFlagExt, ProtoFlagMetadata, ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag,
|
ParsedFlagExt, ProtoFlagMetadata, ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag,
|
||||||
ProtoParsedFlags, ProtoTracepoint,
|
ProtoParsedFlags, ProtoTracepoint,
|
||||||
};
|
};
|
||||||
use crate::storage::generate_storage_files;
|
use crate::storage::generate_storage_file;
|
||||||
|
use crate::storage::StorageFileSelection;
|
||||||
|
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
pub source: String,
|
pub source: String,
|
||||||
@@ -223,7 +224,7 @@ pub fn create_rust_lib(mut input: Input, codegen_mode: CodegenMode) -> Result<Ou
|
|||||||
generate_rust_code(&package, modified_parsed_flags.into_iter(), codegen_mode)
|
generate_rust_code(&package, modified_parsed_flags.into_iter(), codegen_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_storage(caches: Vec<Input>, container: &str) -> Result<Vec<OutputFile>> {
|
pub fn create_storage(caches: Vec<Input>, container: &str, file: &StorageFileSelection) -> Result<Vec<u8>> {
|
||||||
let parsed_flags_vec: Vec<ProtoParsedFlags> = caches
|
let parsed_flags_vec: Vec<ProtoParsedFlags> = caches
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|mut input| input.try_parse_flags())
|
.map(|mut input| input.try_parse_flags())
|
||||||
@@ -231,7 +232,7 @@ pub fn create_storage(caches: Vec<Input>, container: &str) -> Result<Vec<OutputF
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|pfs| find_unique_container(pfs) == Some(container))
|
.filter(|pfs| find_unique_container(pfs) == Some(container))
|
||||||
.collect();
|
.collect();
|
||||||
generate_storage_files(container, parsed_flags_vec.iter())
|
generate_storage_file(container, parsed_flags_vec.iter(), file)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_device_config_defaults(mut input: Input) -> Result<Vec<u8>> {
|
pub fn create_device_config_defaults(mut input: Input) -> Result<Vec<u8>> {
|
||||||
|
@@ -32,6 +32,7 @@ mod storage;
|
|||||||
|
|
||||||
use codegen::CodegenMode;
|
use codegen::CodegenMode;
|
||||||
use dump::DumpFormat;
|
use dump::DumpFormat;
|
||||||
|
use storage::StorageFileSelection;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
@@ -135,6 +136,11 @@ fn cli() -> Command {
|
|||||||
.required(true)
|
.required(true)
|
||||||
.help("The target container for the generated storage file."),
|
.help("The target container for the generated storage file."),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("file")
|
||||||
|
.long("file")
|
||||||
|
.value_parser(|s: &str| StorageFileSelection::try_from(s)),
|
||||||
|
)
|
||||||
.arg(Arg::new("cache").long("cache").action(ArgAction::Append).required(true))
|
.arg(Arg::new("cache").long("cache").action(ArgAction::Append).required(true))
|
||||||
.arg(Arg::new("out").long("out").required(true)),
|
.arg(Arg::new("out").long("out").required(true)),
|
||||||
)
|
)
|
||||||
@@ -278,14 +284,14 @@ fn main() -> Result<()> {
|
|||||||
write_output_to_file_or_stdout(path, &output)?;
|
write_output_to_file_or_stdout(path, &output)?;
|
||||||
}
|
}
|
||||||
Some(("create-storage", sub_matches)) => {
|
Some(("create-storage", sub_matches)) => {
|
||||||
|
let file = get_required_arg::<StorageFileSelection>(sub_matches, "file")
|
||||||
|
.context("Invalid storage file selection")?;
|
||||||
let cache = open_zero_or_more_files(sub_matches, "cache")?;
|
let cache = open_zero_or_more_files(sub_matches, "cache")?;
|
||||||
let container = get_required_arg::<String>(sub_matches, "container")?;
|
let container = get_required_arg::<String>(sub_matches, "container")?;
|
||||||
let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
|
let path = get_required_arg::<String>(sub_matches, "out")?;
|
||||||
let generated_files = commands::create_storage(cache, container)
|
let output = commands::create_storage(cache, container, file)
|
||||||
.context("failed to create storage files")?;
|
.context("failed to create storage files")?;
|
||||||
generated_files
|
write_output_to_file_or_stdout(path, &output)?;
|
||||||
.iter()
|
|
||||||
.try_for_each(|file| write_output_file_realtive_to_dir(&dir, file))?;
|
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
@@ -21,14 +21,32 @@ pub mod package_table;
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use std::collections::{hash_map::DefaultHasher, HashMap, HashSet};
|
use std::collections::{hash_map::DefaultHasher, HashMap, HashSet};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use crate::commands::OutputFile;
|
|
||||||
use crate::protos::{ProtoParsedFlag, ProtoParsedFlags};
|
use crate::protos::{ProtoParsedFlag, ProtoParsedFlags};
|
||||||
use crate::storage::{
|
use crate::storage::{
|
||||||
flag_table::FlagTable, flag_value::FlagValueList, package_table::PackageTable,
|
flag_table::FlagTable, flag_value::FlagValueList, package_table::PackageTable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub enum StorageFileSelection {
|
||||||
|
PackageMap,
|
||||||
|
FlagMap,
|
||||||
|
FlagVal,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&str> for StorageFileSelection {
|
||||||
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
|
fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
|
||||||
|
match value {
|
||||||
|
"package_map" => Ok(Self::PackageMap),
|
||||||
|
"flag_map" => Ok(Self::FlagMap),
|
||||||
|
"flag_val" => Ok(Self::FlagVal),
|
||||||
|
_ => Err(anyhow!("Invalid storage file to create")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub const FILE_VERSION: u32 = 1;
|
pub const FILE_VERSION: u32 = 1;
|
||||||
|
|
||||||
pub const HASH_PRIMES: [u32; 29] = [
|
pub const HASH_PRIMES: [u32; 29] = [
|
||||||
@@ -110,34 +128,30 @@ where
|
|||||||
packages
|
packages
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_storage_files<'a, I>(
|
pub fn generate_storage_file<'a, I>(
|
||||||
container: &str,
|
container: &str,
|
||||||
parsed_flags_vec_iter: I,
|
parsed_flags_vec_iter: I,
|
||||||
) -> Result<Vec<OutputFile>>
|
file: &StorageFileSelection,
|
||||||
|
) -> Result<Vec<u8>>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = &'a ProtoParsedFlags>,
|
I: Iterator<Item = &'a ProtoParsedFlags>,
|
||||||
{
|
{
|
||||||
let packages = group_flags_by_package(parsed_flags_vec_iter);
|
let packages = group_flags_by_package(parsed_flags_vec_iter);
|
||||||
|
|
||||||
// create and serialize package map
|
match file {
|
||||||
|
StorageFileSelection::PackageMap => {
|
||||||
let package_table = PackageTable::new(container, &packages)?;
|
let package_table = PackageTable::new(container, &packages)?;
|
||||||
let package_table_file_path = PathBuf::from("package.map");
|
Ok(package_table.as_bytes())
|
||||||
let package_table_file =
|
}
|
||||||
OutputFile { contents: package_table.as_bytes(), path: package_table_file_path };
|
StorageFileSelection::FlagMap => {
|
||||||
|
|
||||||
// create and serialize flag map
|
|
||||||
let flag_table = FlagTable::new(container, &packages)?;
|
let flag_table = FlagTable::new(container, &packages)?;
|
||||||
let flag_table_file_path = PathBuf::from("flag.map");
|
Ok(flag_table.as_bytes())
|
||||||
let flag_table_file =
|
}
|
||||||
OutputFile { contents: flag_table.as_bytes(), path: flag_table_file_path };
|
StorageFileSelection::FlagVal => {
|
||||||
|
|
||||||
// create and serialize flag value
|
|
||||||
let flag_value = FlagValueList::new(container, &packages)?;
|
let flag_value = FlagValueList::new(container, &packages)?;
|
||||||
let flag_value_file_path = PathBuf::from("flag.val");
|
Ok(flag_value.as_bytes())
|
||||||
let flag_value_file =
|
}
|
||||||
OutputFile { contents: flag_value.as_bytes(), path: flag_value_file_path };
|
}
|
||||||
|
|
||||||
Ok(vec![package_table_file, flag_table_file, flag_value_file])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Reference in New Issue
Block a user