From a180baf4a11a52d341679b04bc1e20eddcaa1079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Thu, 17 Oct 2024 12:11:14 -0400 Subject: [PATCH] bump protogen buf.gen.yaml deps, fix absolute path issue, prep 1.10.7 --- cmd/substreams/protogen.go | 3 +-- codegen/proto_generator.go | 27 ++++++++++++++------------- docs/release-notes/change-log.md | 5 ++++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmd/substreams/protogen.go b/cmd/substreams/protogen.go index 6f34d861..570bbde8 100644 --- a/cmd/substreams/protogen.go +++ b/cmd/substreams/protogen.go @@ -47,7 +47,6 @@ func runProtogen(cmd *cobra.Command, args []string) error { outputPath := sflags.MustGetString(cmd, "output-path") excludePaths := sflags.MustGetStringArray(cmd, "exclude-paths") generateMod := sflags.MustGetBool(cmd, "generate-mod-rs") - showGeneratedBufGen := sflags.MustGetBool(cmd, "show-generated-buf-gen") manifestPath := "" if len(args) == 1 { @@ -83,5 +82,5 @@ func runProtogen(cmd *cobra.Command, args []string) error { } generator := codegen.NewProtoGenerator(outputPath, excludePaths, generateMod) - return generator.GenerateProto(pkgBundle.Package, showGeneratedBufGen) + return generator.GenerateProto(pkgBundle.Package) } diff --git a/codegen/proto_generator.go b/codegen/proto_generator.go index 300fdf59..47314671 100644 --- a/codegen/proto_generator.go +++ b/codegen/proto_generator.go @@ -20,6 +20,14 @@ type ProtoGenerator struct { } func NewProtoGenerator(outputPath string, excludedPaths []string, generateMod bool) *ProtoGenerator { + if filepath.IsAbs(outputPath) { + if wd, err := os.Getwd(); err == nil { + if rel, err := filepath.Rel(wd, outputPath); err == nil { + outputPath = rel + } + } + } + return &ProtoGenerator{ outputPath: outputPath, excludedPaths: excludedPaths, @@ -27,7 +35,7 @@ func NewProtoGenerator(outputPath string, excludedPaths []string, generateMod bo } } -func (g *ProtoGenerator) GenerateProto(pkg *pbsubstreams.Package, showBufContent bool) error { +func (g *ProtoGenerator) GenerateProto(pkg *pbsubstreams.Package) error { spkgTemporaryFilePath := filepath.Join(os.TempDir(), pkg.PackageMeta[0].Name+".tmp.spkg") cnt, err := proto.Marshal(pkg) if err != nil { @@ -40,13 +48,15 @@ func (g *ProtoGenerator) GenerateProto(pkg *pbsubstreams.Package, showBufContent _, err = os.Stat("buf.gen.yaml") bufFileNotFound := errors.Is(err, os.ErrNotExist) + prostVersion := "v0.4.0" + prostCrateVersion := "v0.4.1" if bufFileNotFound { // Beware, the indentation after initial column is important, it's 2 spaces! content := dedent.Dedent(` version: v1 plugins: - - plugin: buf.build/community/neoeinstein-prost:v0.2.2 + - plugin: buf.build/community/neoeinstein-prost:` + prostVersion + ` out: ` + g.outputPath + ` opt: - file_descriptor_set=false @@ -55,27 +65,18 @@ func (g *ProtoGenerator) GenerateProto(pkg *pbsubstreams.Package, showBufContent if g.generateMod { // Beware, the indentation after initial column is important, it's 2 spaces! content += dedent.Dedent(` - - plugin: buf.build/community/neoeinstein-prost-crate:v0.3.1 + - plugin: buf.build/community/neoeinstein-prost-crate:` + prostCrateVersion + ` out: ` + g.outputPath + ` opt: - no_features `) } - if showBufContent { - fmt.Println("Writing to temporary 'buf.gen.yaml'") - fmt.Println("---") - fmt.Println(content) - fmt.Println("---") - } + fmt.Printf("Generating 'buf.gen.yaml' for protobuf generation using neoeinstein-prost %q and neoeinstein-prost-crate %q\n", prostVersion, prostCrateVersion) if err := os.WriteFile("buf.gen.yaml", []byte(content), 0644); err != nil { return fmt.Errorf("error writing buf.gen.yaml: %w", err) } - //defer func() { - // // Too bad if there is an error, nothing we can do - // _ = os.Remove("buf.gen.yaml") - //}() } cmdArgs := []string{ diff --git a/docs/release-notes/change-log.md b/docs/release-notes/change-log.md index 4265c112..575f2244 100644 --- a/docs/release-notes/change-log.md +++ b/docs/release-notes/change-log.md @@ -9,9 +9,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## v1.10.7 * Fix small bug making some requests in development-mode slow to start (when starting close to the module initialBlock with a store that doesn't start on a boundary) +* Fixed `substreams build` creating a buf.gen.yaml file with absolute paths (should be relative) +* Removed `--show-generated-buf-gen` flag to `substreams protogen` +* Bumped neoeinstein-prost version in auto-generated `buf.gen.yaml` file when using `substreams protogen` or `substreams build` (compatible with new substreams-0.6 and prost-0.13) ## v1.10.6