Skip to content

Commit

Permalink
bump vitess and tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Feb 10, 2023
1 parent 2cc34d7 commit c0e8b75
Show file tree
Hide file tree
Showing 174 changed files with 10,241 additions and 12,874 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ $(BIN)/protoc-gen-go: Makefile | $(BIN)
$(TOOL_INSTALL) google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1

$(BIN)/protoc-gen-go-vtproto: Makefile | $(BIN)
$(TOOL_INSTALL) github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@v0.3.0
$(TOOL_INSTALL) github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@v0.4.0

$(BIN)/protoc-gen-connect-go: Makefile | $(BIN)
$(TOOL_INSTALL) github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@v1.0.0
$(TOOL_INSTALL) github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@v1.5.1

$(BIN)/gofumpt: Makefile | $(BIN)
$(TOOL_INSTALL) mvdan.cc/gofumpt@v0.4.0

$(BIN)/buf: Makefile | $(BIN)
$(TOOL_INSTALL) github.com/bufbuild/buf/cmd/buf@v1.8.0
$(TOOL_INSTALL) github.com/bufbuild/buf/cmd/buf@v1.14.0

$(BIN)/yq: Makefile | $(BIN)
$(TOOL_INSTALL) github.com/mikefarah/yq/v4@v4.28.1
$(TOOL_INSTALL) github.com/mikefarah/yq/v4@v4.30.8

PROTO_TOOLS := $(BIN)/protoc-gen-go $(BIN)/protoc-gen-connect-go $(BIN)/protoc-gen-go-vtproto $(BIN)/buf
tools: $(PROTO_TOOLS) $(BIN)/gofumpt $(BIN)/staticcheck $(BIN)/govulncheck $(BIN)/yq

$(VERSIONS): $(PROTO_TOOLS)
$(BIN)/buf generate -v --debug $@ --template $@/buf.gen.yaml
$(BIN)/buf generate -v --debug $@ --template $@/gen.yaml

download:
go run download.go
Expand Down
77 changes: 49 additions & 28 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
maybePanic(err)

templates := template.Must(template.ParseFiles(
filepath.Join(".", "src", "vitess", "buf.gen.yaml.tmpl"),
filepath.Join(".", "src", "vitess", "gen.yaml.tmpl"),
))

if len(os.Args) > 1 {
Expand Down Expand Up @@ -92,48 +92,59 @@ func download(templates *template.Template, version, ref string) {
r, err := zip.NewReader(bytes.NewReader(b.Bytes()), int64(b.Len()))
maybePanic(err)

os.MkdirAll(dst, 0o755)

// extract the files we care about
for _, f := range r.File {
if !f.FileInfo().Mode().IsRegular() {
continue
}
bits := strings.SplitN(f.Name, "/", 3)[1:]
if len(bits) != 2 {
continue
}
folder, path := bits[0], bits[1]
if folder != "proto" {
continue
}
if filepath.Ext(path) != ".proto" {
continue
if isLicense(f.Name) {
fp, err := f.Open()
maybePanic(err)
fdst, err := os.Create(filepath.Join(dst, "LICENSE"))
maybePanic(err)
io.Copy(fdst, fp)
fdst.Close()
fp.Close()
} else {
bits := strings.SplitN(f.Name, "/", 3)[1:]
if len(bits) != 2 {
continue
}
folder, path := bits[0], bits[1]
if folder != "proto" {
continue
}
if filepath.Ext(path) != ".proto" {
continue
}

fname := path[:len(path)-6]
rc, err := f.Open()
maybePanic(err)

// move each {name}.proto into a {name}/{name}.proto
// to better support modules correctly
os.MkdirAll(filepath.Join(dst, fname), 0o755)
fdst, err := os.Create(filepath.Join(dst, fname, fname+".proto"))
maybePanic(err)

copyAndRewriteImports(fdst, rc, version)
fdst.Close()
rc.Close()
}

fname := path[:len(path)-6]

rc, err := f.Open()
maybePanic(err)

// move each {name}.proto into a {name}/{name}.proto
// to better support modules correctly
os.MkdirAll(filepath.Join(dst, fname), 0o755)
fdst, err := os.Create(filepath.Join(dst, fname, fname+".proto"))
maybePanic(err)

copyAndRewriteImports(fdst, rc)
fdst.Close()
rc.Close()
}

data := struct{ Version string }{version}
executeToFile(filepath.Join(dst, "buf.gen.yaml"), templates, data)
executeToFile(filepath.Join(dst, "gen.yaml"), templates, data)

fmt.Printf("==> %s: finished=%s\n", version, time.Since(start))
}

var importRe = regexp.MustCompile(`([a-z]+).proto`)

func copyAndRewriteImports(dst io.Writer, src io.Reader) error {
func copyAndRewriteImports(dst io.Writer, src io.Reader, version string) error {
scanner := bufio.NewScanner(src)
for scanner.Scan() {
line := scanner.Bytes()
Expand All @@ -142,6 +153,12 @@ func copyAndRewriteImports(dst io.Writer, src io.Reader) error {
// in a subdirectory
if bytes.HasPrefix(line, []byte("import ")) {
line = importRe.ReplaceAll(line, []byte("${1}/${1}.proto"))
} else if bytes.HasPrefix(line, []byte("option go_package")) {
line = bytes.Replace(line,
[]byte("vitess.io/vitess/go/vt/proto/"),
[]byte("github.com/planetscale/vitess-types/gen/vitess/"+version+"/"),
1,
)
}

dst.Write(line)
Expand All @@ -150,6 +167,10 @@ func copyAndRewriteImports(dst io.Writer, src io.Reader) error {
return scanner.Err()
}

func isLicense(path string) bool {
return strings.SplitN(path, "/", 2)[1:][0] == "LICENSE"
}

func executeToFile(path string, t *template.Template, data any) error {
fname := filepath.Base(path)
f, err := os.Create(path)
Expand Down
39 changes: 11 additions & 28 deletions gen/vitess/dev/automation/automation_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0e8b75

Please sign in to comment.