From 1af80b44fcdf7a1970f7a7a6b0849ae24cba557e Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Tue, 12 May 2020 11:03:20 +0200 Subject: [PATCH] abci: remove protoreplace script gogoproto is here to stay. --- abci/types/protoreplace/protoreplace.go | 55 ------------------------- 1 file changed, 55 deletions(-) delete mode 100644 abci/types/protoreplace/protoreplace.go diff --git a/abci/types/protoreplace/protoreplace.go b/abci/types/protoreplace/protoreplace.go deleted file mode 100644 index 7058a70fb..000000000 --- a/abci/types/protoreplace/protoreplace.go +++ /dev/null @@ -1,55 +0,0 @@ -// +build ignore - -package main - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - "os/exec" - "regexp" - "strings" -) - -// This script replaces most `[]byte` with `data.Bytes` in a `.pb.go` file. -// It was written before we realized we could use `gogo/protobuf` to achieve -// this more natively. So it's here for safe keeping in case we ever need to -// abandon `gogo/protobuf`. - -func main() { - bytePattern := regexp.MustCompile("[[][]]byte") - const oldPath = "types/types.pb.go" - const tmpPath = "types/types.pb.new" - content, err := ioutil.ReadFile(oldPath) - if err != nil { - panic("cannot read " + oldPath) - os.Exit(1) - } - lines := bytes.Split(content, []byte("\n")) - outFile, _ := os.Create(tmpPath) - wroteImport := false - for _, line_bytes := range lines { - line := string(line_bytes) - gotPackageLine := strings.HasPrefix(line, "package ") - writeImportTime := strings.HasPrefix(line, "import ") - containsDescriptor := strings.Contains(line, "Descriptor") - containsByteArray := strings.Contains(line, "[]byte") - if containsByteArray && !containsDescriptor { - line = string(bytePattern.ReplaceAll([]byte(line), []byte("data.Bytes"))) - } - if writeImportTime && !wroteImport { - wroteImport = true - fmt.Fprintf(outFile, "import \"github.com/tendermint/go-amino/data\"\n") - - } - if gotPackageLine { - fmt.Fprintf(outFile, "%s\n", "//nolint: gas") - } - fmt.Fprintf(outFile, "%s\n", line) - } - outFile.Close() - os.Remove(oldPath) - os.Rename(tmpPath, oldPath) - exec.Command("goimports", "-w", oldPath) -}