Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b27f2ce4 authored by Mårten Kongstad's avatar Mårten Kongstad
Browse files

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
parent cfc5f5e9
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -93,16 +93,16 @@ pub fn create_cache(
    Ok(builder.build())
    Ok(builder.build())
}
}


pub fn create_java_lib(cache: &Cache) -> Result<OutputFile> {
pub fn create_java_lib(cache: Cache) -> Result<OutputFile> {
    generate_java_code(cache)
    generate_java_code(&cache)
}
}


pub fn create_cpp_lib(cache: &Cache) -> Result<OutputFile> {
pub fn create_cpp_lib(cache: Cache) -> Result<OutputFile> {
    generate_cpp_code(cache)
    generate_cpp_code(&cache)
}
}


pub fn create_rust_lib(cache: &Cache) -> Result<OutputFile> {
pub fn create_rust_lib(cache: Cache) -> Result<OutputFile> {
    generate_rust_code(cache)
    generate_rust_code(&cache)
}
}


#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
+3 −3
Original line number Original line Diff line number Diff line
@@ -125,7 +125,7 @@ fn main() -> Result<()> {
            let file = fs::File::open(path)?;
            let file = fs::File::open(path)?;
            let cache = Cache::read_from_reader(file)?;
            let cache = Cache::read_from_reader(file)?;
            let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
            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)?;
            write_output_file_realtive_to_dir(&dir, &generated_file)?;
        }
        }
        Some(("create-cpp-lib", sub_matches)) => {
        Some(("create-cpp-lib", sub_matches)) => {
@@ -133,7 +133,7 @@ fn main() -> Result<()> {
            let file = fs::File::open(path)?;
            let file = fs::File::open(path)?;
            let cache = Cache::read_from_reader(file)?;
            let cache = Cache::read_from_reader(file)?;
            let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
            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)?;
            write_output_file_realtive_to_dir(&dir, &generated_file)?;
        }
        }
        Some(("create-rust-lib", sub_matches)) => {
        Some(("create-rust-lib", sub_matches)) => {
@@ -141,7 +141,7 @@ fn main() -> Result<()> {
            let file = fs::File::open(path)?;
            let file = fs::File::open(path)?;
            let cache = Cache::read_from_reader(file)?;
            let cache = Cache::read_from_reader(file)?;
            let dir = PathBuf::from(get_required_arg::<String>(sub_matches, "out")?);
            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)?;
            write_output_file_realtive_to_dir(&dir, &generated_file)?;
        }
        }
        Some(("dump", sub_matches)) => {
        Some(("dump", sub_matches)) => {