Skip to content

Commit

Permalink
bump protogen buf.gen.yaml deps, fix absolute path issue, prep 1.10.7
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Oct 17, 2024
1 parent fb481d0 commit a180baf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
3 changes: 1 addition & 2 deletions cmd/substreams/protogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
27 changes: 14 additions & 13 deletions codegen/proto_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ 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,
generateMod: generateMod,
}
}

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 {
Expand All @@ -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
Expand All @@ -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{
Expand Down
5 changes: 4 additions & 1 deletion docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a180baf

Please sign in to comment.