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
This commit is contained in:
4
tools/metadata/OWNERS
Normal file
4
tools/metadata/OWNERS
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dariofreni@google.com
|
||||||
|
joeo@google.com
|
||||||
|
ronish@google.com
|
||||||
|
caditya@google.com
|
@@ -73,7 +73,7 @@ func readFileToString(filePath string) string {
|
|||||||
return string(data)
|
return string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processProtobuf(
|
func processTestSpecProtobuf(
|
||||||
filePath string, ownershipMetadataMap *sync.Map, keyLocks *keyToLocksMap,
|
filePath string, ownershipMetadataMap *sync.Map, keyLocks *keyToLocksMap,
|
||||||
errCh chan error, wg *sync.WaitGroup,
|
errCh chan error, wg *sync.WaitGroup,
|
||||||
) {
|
) {
|
||||||
@@ -130,10 +130,11 @@ func processProtobuf(
|
|||||||
func main() {
|
func main() {
|
||||||
inputFile := flag.String("inputFile", "", "Input file path")
|
inputFile := flag.String("inputFile", "", "Input file path")
|
||||||
outputFile := flag.String("outputFile", "", "Output file path")
|
outputFile := flag.String("outputFile", "", "Output file path")
|
||||||
|
rule := flag.String("rule", "", "Metadata rule (Hint: test_spec or code_metadata)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *inputFile == "" || *outputFile == "" {
|
if *inputFile == "" || *outputFile == "" || *rule == "" {
|
||||||
fmt.Println("Usage: metadata -inputFile <input file path> -outputFile <output file path>")
|
fmt.Println("Usage: metadata -rule <rule> -inputFile <input file path> -outputFile <output file path>")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,26 +145,33 @@ func main() {
|
|||||||
errCh := make(chan error, len(filePaths))
|
errCh := make(chan error, len(filePaths))
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for _, filePath := range filePaths {
|
switch *rule {
|
||||||
wg.Add(1)
|
case "test_spec":
|
||||||
go processProtobuf(filePath, ownershipMetadataMap, keyLocks, errCh, &wg)
|
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)
|
|
||||||
}
|
}
|
||||||
|
4
tools/metadata/testdata/metadata_test.go
vendored
4
tools/metadata/testdata/metadata_test.go
vendored
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func TestMetadata(t *testing.T) {
|
func TestMetadata(t *testing.T) {
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"metadata", "-inputFile", "./inputFiles.txt", "-outputFile",
|
"metadata", "-rule", "test_spec", "-inputFile", "./inputFiles.txt", "-outputFile",
|
||||||
"./generatedOutputFile.txt",
|
"./generatedOutputFile.txt",
|
||||||
)
|
)
|
||||||
stderr, err := cmd.CombinedOutput()
|
stderr, err := cmd.CombinedOutput()
|
||||||
@@ -40,7 +40,7 @@ func TestMetadata(t *testing.T) {
|
|||||||
|
|
||||||
func TestMetadataNegativeCase(t *testing.T) {
|
func TestMetadataNegativeCase(t *testing.T) {
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"metadata", "-inputFile", "./inputFilesNegativeCase.txt", "-outputFile",
|
"metadata", "-rule", "test_spec", "-inputFile", "./inputFilesNegativeCase.txt", "-outputFile",
|
||||||
"./generatedOutputFileNegativeCase.txt",
|
"./generatedOutputFileNegativeCase.txt",
|
||||||
)
|
)
|
||||||
stderr, err := cmd.CombinedOutput()
|
stderr, err := cmd.CombinedOutput()
|
||||||
|
Reference in New Issue
Block a user