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

Commit 07ea503a authored by Cole Faust's avatar Cole Faust
Browse files

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
parent 6a779a4b
Loading
Loading
Loading
Loading
+26 −24
Original line number Diff line number Diff line
@@ -154,47 +154,49 @@ func main() {
	}

	// Convert!
	files := flag.Args()
	productConfigMap := buildProductConfigMap()
	if *allInSource {
		for _, path := range productConfigMap {
			files = append(files, path)
		}
	}
	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(flag.Args()) != 1 {
		if len(files) != 1 {
			quit(fmt.Errorf("a launcher can be generated only for a single product"))
		}
		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))
		}
		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()