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
diff --git a/tools/aconfig/src/main.rs b/tools/aconfig/src/main.rs
index 1d2ec95..c07bcf3 100644
--- a/tools/aconfig/src/main.rs
+++ b/tools/aconfig/src/main.rs
@@ -125,7 +125,7 @@
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 @@
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 @@
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)) => {