• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2025 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 //! convert_finalized_flags is a build time tool used to convert the finalized
17 //! flags text files under prebuilts/sdk into structured data (FinalizedFlag
18 //! struct).
19 //! This binary is intended to run as part of a genrule to create a json file
20 //! which is provided to the aconfig binary that creates the codegen.
21 //! Usage:
22 //! cargo run -- --flag-files-path path/to/prebuilts/sdk/finalized-flags.txt file2.txt etc
23 use anyhow::Result;
24 use clap::Parser;
25 
26 use convert_finalized_flags::{
27     read_extend_file_to_map_using_path, read_files_to_map_using_path, EXTENDED_FLAGS_35_APILEVEL,
28 };
29 
30 const ABOUT_TEXT: &str = "Tool for processing finalized-flags.txt files.
31 
32 These files contain the list of qualified flag names that have been finalized,
33 each on a newline. The directory of the flag file is the finalized API level.
34 
35 The output is a json map of API level to set of FinalizedFlag objects. The only
36 supported use case for this tool is via a genrule at build time for aconfig
37 codegen.
38 
39 Args:
40 * `flag-files-path`: Space-separated list of absolute paths for the finalized
41 flags files.
42 ";
43 
44 #[derive(Parser, Debug)]
45 #[clap(long_about=ABOUT_TEXT, bin_name="convert-finalized-flags")]
46 struct Cli {
47     /// Flags files.
48     #[arg(long = "flag_file_path")]
49     flag_file_path: Vec<String>,
50 
51     #[arg(long)]
52     extended_flag_file_path: String,
53 }
54 
main() -> Result<()>55 fn main() -> Result<()> {
56     let cli = Cli::parse();
57     let mut finalized_flags_map = read_files_to_map_using_path(cli.flag_file_path)?;
58     let extended_flag_set = read_extend_file_to_map_using_path(cli.extended_flag_file_path)?;
59     for flag in extended_flag_set {
60         finalized_flags_map.insert_if_new(EXTENDED_FLAGS_35_APILEVEL, flag);
61     }
62 
63     let json_str = serde_json::to_string(&finalized_flags_map)?;
64     println!("{}", json_str);
65     Ok(())
66 }
67