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

Commit f101d2b7 authored by Aditya Choudhary's avatar Aditya Choudhary
Browse files

Refactor metadata tool to support metadata generation for different rules.

Bug: 296873595
Test: Manual test (use go test inside tools/metadata/testdata)

Ignore-AOSP-First: CPing test_spec rule to udc-mainline-prod to support migration of test targets. Cherry pick of: aosp/2833290

Change-Id: I881fd76213ec78001f9e12ed2fbc860d1503a364
Merged-In: I881fd76213ec78001f9e12ed2fbc860d1503a364
parent 16291ef6
Loading
Loading
Loading
Loading

tools/metadata/OWNERS

0 → 100644
+4 −0
Original line number Diff line number Diff line
dariofreni@google.com
joeo@google.com
ronish@google.com
caditya@google.com
+28 −20
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ func readFileToString(filePath string) string {
	return string(data)
}

func processProtobuf(
func processTestSpecProtobuf(
	filePath string, ownershipMetadataMap *sync.Map, keyLocks *keyToLocksMap,
	errCh chan error, wg *sync.WaitGroup,
) {
@@ -130,10 +130,11 @@ func processProtobuf(
func main() {
	inputFile := flag.String("inputFile", "", "Input file path")
	outputFile := flag.String("outputFile", "", "Output file path")
	rule := flag.String("rule", "", "Metadata rule (Hint: test_spec or code_metadata)")
	flag.Parse()

	if *inputFile == "" || *outputFile == "" {
		fmt.Println("Usage: metadata -inputFile <input file path> -outputFile <output file path>")
	if *inputFile == "" || *outputFile == "" || *rule == "" {
		fmt.Println("Usage: metadata -rule <rule> -inputFile <input file path> -outputFile <output file path>")
		os.Exit(1)
	}

@@ -144,9 +145,11 @@ func main() {
	errCh := make(chan error, len(filePaths))
	var wg sync.WaitGroup

	switch *rule {
	case "test_spec":
		for _, filePath := range filePaths {
			wg.Add(1)
		go processProtobuf(filePath, ownershipMetadataMap, keyLocks, errCh, &wg)
			go processTestSpecProtobuf(filePath, ownershipMetadataMap, keyLocks, errCh, &wg)
		}

		wg.Wait()
@@ -166,4 +169,9 @@ func main() {
		}

		writeOutput(*outputFile, allMetadata)
		break
	case "code_metadata":
	default:
		log.Fatalf("No specific processing implemented for rule '%s'.\n", *rule)
	}
}
+2 −2
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ import (

func TestMetadata(t *testing.T) {
	cmd := exec.Command(
		"metadata", "-inputFile", "./inputFiles.txt", "-outputFile",
		"metadata", "-rule", "test_spec", "-inputFile", "./inputFiles.txt", "-outputFile",
		"./generatedOutputFile.txt",
	)
	stderr, err := cmd.CombinedOutput()
@@ -40,7 +40,7 @@ func TestMetadata(t *testing.T) {

func TestMetadataNegativeCase(t *testing.T) {
	cmd := exec.Command(
		"metadata", "-inputFile", "./inputFilesNegativeCase.txt", "-outputFile",
		"metadata", "-rule", "test_spec", "-inputFile", "./inputFilesNegativeCase.txt", "-outputFile",
		"./generatedOutputFileNegativeCase.txt",
	)
	stderr, err := cmd.CombinedOutput()