Refactor metadata tool to support metadata generation for different rules.
Bug: 296873595
Test: Manual test (use go test inside tools/metadata/testdata)
Change-Id: I881fd76213ec78001f9e12ed2fbc860d1503a364
diff --git a/tools/metadata/generator.go b/tools/metadata/generator.go
index 8e82f7f..eb87755 100644
--- a/tools/metadata/generator.go
+++ b/tools/metadata/generator.go
@@ -73,7 +73,7 @@
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 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,26 +145,33 @@
errCh := make(chan error, len(filePaths))
var wg sync.WaitGroup
- for _, filePath := range filePaths {
- wg.Add(1)
- go processProtobuf(filePath, ownershipMetadataMap, keyLocks, errCh, &wg)
+ switch *rule {
+ case "test_spec":
+ for _, filePath := range filePaths {
+ wg.Add(1)
+ go processTestSpecProtobuf(filePath, ownershipMetadataMap, keyLocks, errCh, &wg)
+ }
+
+ wg.Wait()
+ close(errCh)
+
+ for err := range errCh {
+ log.Fatal(err)
+ }
+
+ allKeys := getSortedKeys(ownershipMetadataMap)
+ var allMetadata []*test_spec_proto.TestSpec_OwnershipMetadata
+
+ for _, key := range allKeys {
+ value, _ := ownershipMetadataMap.Load(key)
+ metadataList := value.([]*test_spec_proto.TestSpec_OwnershipMetadata)
+ allMetadata = append(allMetadata, metadataList...)
+ }
+
+ writeOutput(*outputFile, allMetadata)
+ break
+ case "code_metadata":
+ default:
+ log.Fatalf("No specific processing implemented for rule '%s'.\n", *rule)
}
-
- wg.Wait()
- close(errCh)
-
- for err := range errCh {
- log.Fatal(err)
- }
-
- allKeys := getSortedKeys(ownershipMetadataMap)
- var allMetadata []*test_spec_proto.TestSpec_OwnershipMetadata
-
- for _, key := range allKeys {
- value, _ := ownershipMetadataMap.Load(key)
- metadataList := value.([]*test_spec_proto.TestSpec_OwnershipMetadata)
- allMetadata = append(allMetadata, metadataList...)
- }
-
- writeOutput(*outputFile, allMetadata)
}