blob: 9e7b3b641cb85ceaa03fc1eef5661484b8b7ded1 [file] [log] [blame]
Jingwen Chen164e0862021-02-19 00:48:40 -05001package bp2build
2
3import (
4 "android/soong/android"
5 "fmt"
Liz Kammer6eff3232021-08-26 08:37:59 -04006 "strings"
Jingwen Chen164e0862021-02-19 00:48:40 -05007)
8
9// Simple metrics struct to collect information about a Blueprint to BUILD
10// conversion process.
11type CodegenMetrics struct {
12 // Total number of Soong/Blueprint modules
13 TotalModuleCount int
14
15 // Counts of generated Bazel targets per Bazel rule class
16 RuleClassCount map[string]int
Liz Kammerba3ea162021-02-17 13:22:03 -050017
18 // Total number of handcrafted targets
19 handCraftedTargetCount int
Liz Kammer6eff3232021-08-26 08:37:59 -040020
21 moduleWithUnconvertedDepsMsgs []string
Jingwen Chen61174502021-09-17 08:40:45 +000022
23 convertedModules []string
Jingwen Chen164e0862021-02-19 00:48:40 -050024}
25
26// Print the codegen metrics to stdout.
Jingwen Chenafb84bd2021-09-20 10:31:46 +000027func (metrics *CodegenMetrics) Print() {
Jingwen Chen164e0862021-02-19 00:48:40 -050028 generatedTargetCount := 0
29 for _, ruleClass := range android.SortedStringKeys(metrics.RuleClassCount) {
30 count := metrics.RuleClassCount[ruleClass]
31 fmt.Printf("[bp2build] %s: %d targets\n", ruleClass, count)
32 generatedTargetCount += count
33 }
34 fmt.Printf(
Liz Kammer6eff3232021-08-26 08:37:59 -040035 "[bp2build] Generated %d total BUILD targets and included %d handcrafted BUILD targets from %d Android.bp modules.\n With %d modules with unconverted deps \n\t%s",
Jingwen Chen164e0862021-02-19 00:48:40 -050036 generatedTargetCount,
Liz Kammerba3ea162021-02-17 13:22:03 -050037 metrics.handCraftedTargetCount,
Liz Kammer6eff3232021-08-26 08:37:59 -040038 metrics.TotalModuleCount,
39 len(metrics.moduleWithUnconvertedDepsMsgs),
40 strings.Join(metrics.moduleWithUnconvertedDepsMsgs, "\n\t"))
Jingwen Chen164e0862021-02-19 00:48:40 -050041}
Jingwen Chen61174502021-09-17 08:40:45 +000042
Jingwen Chenafb84bd2021-09-20 10:31:46 +000043func (metrics *CodegenMetrics) AddConvertedModule(moduleName string) {
Jingwen Chen61174502021-09-17 08:40:45 +000044 // Undo prebuilt_ module name prefix modifications
45 moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
46 metrics.convertedModules = append(metrics.convertedModules, moduleName)
47}