Merge "aconfig: move CodegenMode to codegen crate" into main am: 8351b78234
Original change: https://android-review.googlesource.com/c/platform/build/+/2883367 Change-Id: I0acf96005bc2202de62da31e639f138714a9316b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -20,7 +20,8 @@ use std::path::PathBuf;
|
|||||||
use tinytemplate::TinyTemplate;
|
use tinytemplate::TinyTemplate;
|
||||||
|
|
||||||
use crate::codegen;
|
use crate::codegen;
|
||||||
use crate::commands::{CodegenMode, OutputFile};
|
use crate::codegen::CodegenMode;
|
||||||
|
use crate::commands::OutputFile;
|
||||||
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
|
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
|
||||||
|
|
||||||
pub fn generate_cpp_code<I>(
|
pub fn generate_cpp_code<I>(
|
||||||
|
@@ -21,7 +21,8 @@ use std::path::PathBuf;
|
|||||||
use tinytemplate::TinyTemplate;
|
use tinytemplate::TinyTemplate;
|
||||||
|
|
||||||
use crate::codegen;
|
use crate::codegen;
|
||||||
use crate::commands::{CodegenMode, OutputFile};
|
use crate::codegen::CodegenMode;
|
||||||
|
use crate::commands::OutputFile;
|
||||||
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
|
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
|
||||||
|
|
||||||
pub fn generate_java_code<I>(
|
pub fn generate_java_code<I>(
|
||||||
|
@@ -19,6 +19,7 @@ pub mod java;
|
|||||||
pub mod rust;
|
pub mod rust;
|
||||||
|
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
|
use clap::ValueEnum;
|
||||||
|
|
||||||
pub fn is_valid_name_ident(s: &str) -> bool {
|
pub fn is_valid_name_ident(s: &str) -> bool {
|
||||||
// Identifiers must match [a-z][a-z0-9_]*, except consecutive underscores are not allowed
|
// 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))
|
Ok(format!("{}.{}", package, flag_name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
|
||||||
|
pub enum CodegenMode {
|
||||||
|
Production,
|
||||||
|
Test,
|
||||||
|
Exported,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@@ -19,7 +19,8 @@ use serde::Serialize;
|
|||||||
use tinytemplate::TinyTemplate;
|
use tinytemplate::TinyTemplate;
|
||||||
|
|
||||||
use crate::codegen;
|
use crate::codegen;
|
||||||
use crate::commands::{CodegenMode, OutputFile};
|
use crate::codegen::CodegenMode;
|
||||||
|
use crate::commands::OutputFile;
|
||||||
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
|
use crate::protos::{ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag};
|
||||||
|
|
||||||
pub fn generate_rust_code<I>(
|
pub fn generate_rust_code<I>(
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use anyhow::{bail, ensure, Context, Result};
|
use anyhow::{bail, ensure, Context, Result};
|
||||||
use clap::ValueEnum;
|
|
||||||
use protobuf::Message;
|
use protobuf::Message;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -23,6 +22,7 @@ use std::path::PathBuf;
|
|||||||
use crate::codegen::cpp::generate_cpp_code;
|
use crate::codegen::cpp::generate_cpp_code;
|
||||||
use crate::codegen::java::generate_java_code;
|
use crate::codegen::java::generate_java_code;
|
||||||
use crate::codegen::rust::generate_rust_code;
|
use crate::codegen::rust::generate_rust_code;
|
||||||
|
use crate::codegen::CodegenMode;
|
||||||
use crate::dump::{DumpFormat, DumpPredicate};
|
use crate::dump::{DumpFormat, DumpPredicate};
|
||||||
use crate::protos::{
|
use crate::protos::{
|
||||||
ParsedFlagExt, ProtoFlagMetadata, ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag,
|
ParsedFlagExt, ProtoFlagMetadata, ProtoFlagPermission, ProtoFlagState, ProtoParsedFlag,
|
||||||
@@ -188,13 +188,6 @@ pub fn parse_flags(
|
|||||||
Ok(output)
|
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>> {
|
pub fn create_java_lib(mut input: Input, codegen_mode: CodegenMode) -> Result<Vec<OutputFile>> {
|
||||||
let parsed_flags = input.try_parse_flags()?;
|
let parsed_flags = input.try_parse_flags()?;
|
||||||
let filtered_parsed_flags = filter_parsed_flags(parsed_flags, codegen_mode);
|
let filtered_parsed_flags = filter_parsed_flags(parsed_flags, codegen_mode);
|
||||||
|
@@ -30,12 +30,13 @@ mod dump;
|
|||||||
mod protos;
|
mod protos;
|
||||||
mod storage;
|
mod storage;
|
||||||
|
|
||||||
|
use codegen::CodegenMode;
|
||||||
use dump::DumpFormat;
|
use dump::DumpFormat;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
use commands::{CodegenMode, Input, OutputFile};
|
use commands::{Input, OutputFile};
|
||||||
|
|
||||||
const HELP_DUMP_FILTER: &str = r#"
|
const HELP_DUMP_FILTER: &str = r#"
|
||||||
Limit which flags to output. If multiple --filter arguments are provided, the output will be
|
Limit which flags to output. If multiple --filter arguments are provided, the output will be
|
||||||
@@ -69,7 +70,7 @@ fn cli() -> Command {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::new("mode")
|
Arg::new("mode")
|
||||||
.long("mode")
|
.long("mode")
|
||||||
.value_parser(EnumValueParser::<commands::CodegenMode>::new())
|
.value_parser(EnumValueParser::<CodegenMode>::new())
|
||||||
.default_value("production"),
|
.default_value("production"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -80,7 +81,7 @@ fn cli() -> Command {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::new("mode")
|
Arg::new("mode")
|
||||||
.long("mode")
|
.long("mode")
|
||||||
.value_parser(EnumValueParser::<commands::CodegenMode>::new())
|
.value_parser(EnumValueParser::<CodegenMode>::new())
|
||||||
.default_value("production"),
|
.default_value("production"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -91,7 +92,7 @@ fn cli() -> Command {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::new("mode")
|
Arg::new("mode")
|
||||||
.long("mode")
|
.long("mode")
|
||||||
.value_parser(EnumValueParser::<commands::CodegenMode>::new())
|
.value_parser(EnumValueParser::<CodegenMode>::new())
|
||||||
.default_value("production"),
|
.default_value("production"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -114,7 +115,12 @@ fn cli() -> Command {
|
|||||||
.value_parser(|s: &str| DumpFormat::try_from(s))
|
.value_parser(|s: &str| DumpFormat::try_from(s))
|
||||||
.default_value("text"),
|
.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("dedup").long("dedup").num_args(0).action(ArgAction::SetTrue))
|
||||||
.arg(Arg::new("out").long("out").default_value("-")),
|
.arg(Arg::new("out").long("out").default_value("-")),
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user