aconfig: move CodegenMode to codegen crate

This change moves CodegenMode to codegen crate.

Bug: 311152507
Test: ateset aconfig.test
Change-Id: I4f64cdbdc3d1b419412012560bfe03344b2b8faf
This commit is contained in:
Zhi Dou 2023-12-19 18:59:26 +00:00
parent 0f1b9da4d9
commit dcfa0400c9
6 changed files with 26 additions and 16 deletions

View file

@ -20,7 +20,8 @@ use std::path::PathBuf;
use tinytemplate::TinyTemplate;
use crate::codegen;
use crate::commands::{CodegenMode, OutputFile};
use crate::codegen::CodegenMode;
use crate::commands::OutputFile;
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
pub fn generate_cpp_code<I>(

View file

@ -21,7 +21,8 @@ use std::path::PathBuf;
use tinytemplate::TinyTemplate;
use crate::codegen;
use crate::commands::{CodegenMode, OutputFile};
use crate::codegen::CodegenMode;
use crate::commands::OutputFile;
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
pub fn generate_java_code<I>(

View file

@ -19,6 +19,7 @@ pub mod java;
pub mod rust;
use anyhow::{ensure, Result};
use clap::ValueEnum;
pub fn is_valid_name_ident(s: &str) -> bool {
// Identifiers must match [a-z][a-z0-9_]*, except consecutive underscores are not allowed
@ -52,6 +53,13 @@ pub fn create_device_config_ident(package: &str, flag_name: &str) -> Result<Stri
Ok(format!("{}.{}", package, flag_name))
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum CodegenMode {
Production,
Test,
Exported,
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -19,7 +19,8 @@ use serde::Serialize;
use tinytemplate::TinyTemplate;
use crate::codegen;
use crate::commands::{CodegenMode, OutputFile};
use crate::codegen::CodegenMode;
use crate::commands::OutputFile;
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
pub fn generate_rust_code<I>(

View file

@ -15,7 +15,6 @@
*/
use anyhow::{bail, ensure, Context, Result};
use clap::ValueEnum;
use protobuf::Message;
use std::io::Read;
use std::path::PathBuf;
@ -23,6 +22,7 @@ use std::path::PathBuf;
use crate::codegen::cpp::generate_cpp_code;
use crate::codegen::java::generate_java_code;
use crate::codegen::rust::generate_rust_code;
use crate::codegen::CodegenMode;
use crate::dump::{DumpFormat, DumpPredicate};
use crate::protos::{
ParsedFlagExt, ProtoFlagMetadata, ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag,
@ -188,13 +188,6 @@ pub fn parse_flags(
Ok(output)
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum CodegenMode {
Production,
Test,
Exported,
}
pub fn create_java_lib(mut input: Input, codegen_mode: CodegenMode) -> Result<Vec<OutputFile>> {
let parsed_flags = input.try_parse_flags()?;
let filtered_parsed_flags = filter_parsed_flags(parsed_flags, codegen_mode);

View file

@ -30,12 +30,13 @@ mod dump;
mod protos;
mod storage;
use codegen::CodegenMode;
use dump::DumpFormat;
#[cfg(test)]
mod test;
use commands::{CodegenMode, Input, OutputFile};
use commands::{Input, OutputFile};
const HELP_DUMP_FILTER: &str = r#"
Limit which flags to output. If multiple --filter arguments are provided, the output will be
@ -69,7 +70,7 @@ fn cli() -> Command {
.arg(
Arg::new("mode")
.long("mode")
.value_parser(EnumValueParser::<commands::CodegenMode>::new())
.value_parser(EnumValueParser::<CodegenMode>::new())
.default_value("production"),
),
)
@ -80,7 +81,7 @@ fn cli() -> Command {
.arg(
Arg::new("mode")
.long("mode")
.value_parser(EnumValueParser::<commands::CodegenMode>::new())
.value_parser(EnumValueParser::<CodegenMode>::new())
.default_value("production"),
),
)
@ -91,7 +92,7 @@ fn cli() -> Command {
.arg(
Arg::new("mode")
.long("mode")
.value_parser(EnumValueParser::<commands::CodegenMode>::new())
.value_parser(EnumValueParser::<CodegenMode>::new())
.default_value("production"),
),
)
@ -114,7 +115,12 @@ fn cli() -> Command {
.value_parser(|s: &str| DumpFormat::try_from(s))
.default_value("text"),
)
.arg(Arg::new("filter").long("filter").action(ArgAction::Append).help(HELP_DUMP_FILTER.trim()))
.arg(
Arg::new("filter")
.long("filter")
.action(ArgAction::Append)
.help(HELP_DUMP_FILTER.trim()),
)
.arg(Arg::new("dedup").long("dedup").num_args(0).action(ArgAction::SetTrue))
.arg(Arg::new("out").long("out").default_value("-")),
)