aconfig: give commands ownership of all arguments

Pass the Cache argument to command::create_<lang>_lib functions by value
instead of by reference, to align with other commands.

The intended ownership flow is as follows:

  - main creates objects based on command line arguments
  - main hands commands ownership of the objects
  - command processes the objects
  - command gives main ownership of any generated output
  - main writes the output to file

Rationale: commands.rs is a unit testable version of main, and to the
rest of aconfig, acts as the top level entry point; main.rs exists only
to parse command line arguments and perform I/O.

Bug: 283910447
Test: atest aconfig.test
Change-Id: I1e1dea7da8ecc2bb6e2f7ee4a6df64562c148959
This commit is contained in:
Mårten Kongstad
2023-06-02 11:43:21 +02:00
parent cfc5f5e9fd
commit b27f2ce436
2 changed files with 9 additions and 9 deletions

View File

@@ -93,16 +93,16 @@ pub fn create_cache(
Ok(builder.build())
}
pub fn create_java_lib(cache: &Cache) -> Result<OutputFile> {
generate_java_code(cache)
pub fn create_java_lib(cache: Cache) -> Result<OutputFile> {
generate_java_code(&cache)
}
pub fn create_cpp_lib(cache: &Cache) -> Result<OutputFile> {
generate_cpp_code(cache)
pub fn create_cpp_lib(cache: Cache) -> Result<OutputFile> {
generate_cpp_code(&cache)
}
pub fn create_rust_lib(cache: &Cache) -> Result<OutputFile> {
generate_rust_code(cache)
pub fn create_rust_lib(cache: Cache) -> Result<OutputFile> {
generate_rust_code(&cache)
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]

View File

@@ -125,7 +125,7 @@ fn main() -> Result<()> {
let file = fs::File::open(path)?;
let cache = Cache::read_from_reader(file)?;
let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
let generated_file = commands::create_java_lib(&cache)?;
let generated_file = commands::create_java_lib(cache)?;
write_output_file_realtive_to_dir(&dir, &generated_file)?;
}
Some(("create-cpp-lib", sub_matches)) => {
@@ -133,7 +133,7 @@ fn main() -> Result<()> {
let file = fs::File::open(path)?;
let cache = Cache::read_from_reader(file)?;
let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
let generated_file = commands::create_cpp_lib(&cache)?;
let generated_file = commands::create_cpp_lib(cache)?;
write_output_file_realtive_to_dir(&dir, &generated_file)?;
}
Some(("create-rust-lib", sub_matches)) => {
@@ -141,7 +141,7 @@ fn main() -> Result<()> {
let file = fs::File::open(path)?;
let cache = Cache::read_from_reader(file)?;
let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
let generated_file = commands::create_rust_lib(&cache)?;
let generated_file = commands::create_rust_lib(cache)?;
write_output_file_realtive_to_dir(&dir, &generated_file)?;
}
Some(("dump", sub_matches)) => {