From 07ea503ab395d8f781c46d924e1e185d76e6abfd Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 30 Sep 2021 16:11:16 -0700 Subject: [PATCH] Make mk2rbc accept either a makefile or product The current behavior of mk2rbc is that it can accept either a makefile to convert, or if it's also generating a launcher, it must accept a product name instead of a makefile. For board configuration, we need to convert a specific makefile, but we also want to generate a launcher. Change mk2rbc so that its non-flag arguments can be either makefiles or product names. Bug: 201700692 Test: ./build/bazel/ci/rbc_product_config.sh aosp_arm64-userdebug with board config changes patched in Change-Id: I521e31fe0bdc608b8f26c9aa803ca690dd1c538e --- mk2rbc/cmd/mk2rbc.go | 54 +++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/mk2rbc/cmd/mk2rbc.go b/mk2rbc/cmd/mk2rbc.go index 7b5f298e2..9d0f0c1b0 100644 --- a/mk2rbc/cmd/mk2rbc.go +++ b/mk2rbc/cmd/mk2rbc.go @@ -154,47 +154,49 @@ func main() { } // Convert! - ok := true - if *launcher != "" { - if len(flag.Args()) != 1 { - quit(fmt.Errorf("a launcher can be generated only for a single product")) + files := flag.Args() + productConfigMap := buildProductConfigMap() + if *allInSource { + for _, path := range productConfigMap { + files = append(files, path) } - product := flag.Args()[0] - productConfigMap := buildProductConfigMap() - path, found := productConfigMap[product] - if !found { - quit(fmt.Errorf("cannot generate configuration launcher for %s, it is not a known product", - product)) + } + for i, file := range files { + if _, err := os.Stat(file); os.IsNotExist(err) { + temp, ok := productConfigMap[file] + if ok { + files[i] = temp + } else { + quit(fmt.Errorf("%s is neither a product makefile nor a product name", file)) + } + } + } + ok := true + for _, mkFile := range files { + ok = convertOne(mkFile) && ok + } + + if *launcher != "" { + if len(files) != 1 { + quit(fmt.Errorf("a launcher can be generated only for a single product")) } versionDefaults, err := generateVersionDefaults() if err != nil { quit(err) } - ok = convertOne(path) && ok versionDefaultsPath := outputFilePath(versionDefaultsMk) err = writeGenerated(versionDefaultsPath, versionDefaults) if err != nil { - fmt.Fprintf(os.Stderr, "%s:%s", path, err) + fmt.Fprintf(os.Stderr, "%s:%s", files[0], err) ok = false } - err = writeGenerated(*launcher, mk2rbc.Launcher(outputFilePath(path), versionDefaultsPath, - mk2rbc.MakePath2ModuleName(path))) + err = writeGenerated(*launcher, mk2rbc.Launcher(outputFilePath(files[0]), versionDefaultsPath, + mk2rbc.MakePath2ModuleName(files[0]))) if err != nil { - fmt.Fprintf(os.Stderr, "%s:%s", path, err) + fmt.Fprintf(os.Stderr, "%s:%s", files[0], err) ok = false } - } else { - files := flag.Args() - if *allInSource { - productConfigMap := buildProductConfigMap() - for _, path := range productConfigMap { - files = append(files, path) - } - } - for _, mkFile := range files { - ok = convertOne(mkFile) && ok - } } printStats()