1 // Copyright (C) 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use std::path::PathBuf;
16 
17 use anyhow::Result;
18 use clap::Parser;
19 use crate_health::{
20     default_output_dir, default_repo_root, maybe_build_cargo_embargo, CrateCollection,
21     NameAndVersionMap, ReportEngine,
22 };
23 
24 /// Generate a health report for crates in external/rust/crates
25 #[derive(Parser, Debug)]
26 #[command(about, long_about = None)]
27 struct Args {
28     /// Path to the AOSP repo. Defaults to current working directory.
29     #[arg(long, default_value_os_t=default_repo_root().unwrap_or(PathBuf::from(".")))]
30     repo_root: PathBuf,
31 
32     /// Path the health report will be written to.
33     #[arg(long, default_value_os_t=default_output_dir("crate-health-report.html"))]
34     output_path: PathBuf,
35 }
36 
main() -> Result<()>37 fn main() -> Result<()> {
38     let args = Args::parse();
39 
40     maybe_build_cargo_embargo(&args.repo_root, false)?;
41 
42     let mut cc = CrateCollection::new(args.repo_root);
43     cc.add_from(&"external/rust/crates")?;
44     cc.map_field_mut().retain(|_nv, krate| krate.is_crates_io());
45 
46     cc.stage_crates()?;
47     cc.generate_android_bps()?;
48     cc.diff_android_bps()?;
49 
50     let re = ReportEngine::new()?;
51 
52     Ok(re.health_report(&cc, &args.output_path)?)
53 }
54