From fbafd40099364615ce106332cab7bedc72a22873 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Mon, 30 Oct 2023 10:24:04 +0100 Subject: [PATCH 01/16] refactor: change `cosmosgen` proto discovery to add extra paths --- ignite/pkg/cosmosgen/cosmosgen.go | 6 +- ignite/pkg/cosmosgen/generate.go | 119 ++++++++++++-------- ignite/pkg/cosmosgen/generate_typescript.go | 7 +- 3 files changed, 79 insertions(+), 53 deletions(-) diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 57eb8417b3..3805f9e10e 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -115,9 +115,9 @@ type generator struct { sdkImport string deps []gomodule.Version appModules []module.Module - appIncludes []string + appIncludes protoIncludes thirdModules map[string][]module.Module - thirdModuleIncludes map[string][]string + thirdModuleIncludes map[string]protoIncludes tmpDirs []string } @@ -146,7 +146,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir gomodPath: gomodPath, opts: &generateOptions{}, thirdModules: make(map[string][]module.Module), - thirdModuleIncludes: make(map[string][]string), + thirdModuleIncludes: make(map[string]protoIncludes), cacheStorage: cacheStorage, } diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index fd85995f57..f80ada8f6f 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -29,10 +29,30 @@ var protocGlobalInclude = xfilepath.List( xfilepath.JoinFromHome(xfilepath.Path(".local/include")), ) -type ModulesInPath struct { - Path string - Modules []module.Module - Includes []string +// protoIncludes contains proto include paths for a package. +type protoIncludes struct { + // Paths is a list of proto include paths. + Paths []string + + // BufPath is the path to the Buf config file when it exists. + BufPath string + + // ProtoPath contains the path to the package's proto directory. + ProtoPath string +} + +// protoAnalysis contains proto module analysis data for a Go package dependency. +type protoAnalysis struct { + // Path is the full path to the Go dependency + Path string + + // Modules contains the proto modules analysis data. + // The list is empty when the Go package has no proto files. + Modules []module.Module + + // Includes contain proto include paths. + // These paths should be used when generating code. + Includes protoIncludes } func (g *generator) setup() (err error) { @@ -80,27 +100,30 @@ func (g *generator) setup() (err error) { if err != nil { return err } + g.appIncludes, err = g.resolveIncludes(g.appPath) if err != nil { return err } - // Go through the Go dependencies of the user's app within go.mod, some of them might be hosting Cosmos SDK modules - // that could be in use by user's blockchain. + + // Go through the Go dependencies of the user's app within go.mod, some of them + // might be hosting Cosmos SDK modules that could be in use by user's blockchain. // - // Cosmos SDK is a dependency of all blockchains, so it's absolute that we'll be discovering all modules of the - // SDK as well during this process. + // Cosmos SDK is a dependency of all blockchains, so it's absolute that we'll be + // discovering all modules of the SDK as well during this process. // - // Even if a dependency contains some SDK modules, not all of these modules could be used by user's blockchain. - // this is fine, we can still generate TS clients for those non modules, it is up to user to use (import in typescript) - // not use generated modules. + // Even if a dependency contains some SDK modules, not all of these modules could + // be used by user's blockchain. This is fine, we can still generate TS clients + // for those non modules, it is up to user to use (import in typescript) not use + // generated modules. // - // TODO: we can still implement some sort of smart filtering to detect non used modules by the user's blockchain - // at some point, it is a nice to have. - moduleCache := cache.New[ModulesInPath](g.cacheStorage, moduleCacheNamespace) + // TODO: we can still implement some sort of smart filtering to detect non used + // modules by the user's blockchain at some point, it is a nice to have. + moduleCache := cache.New[protoAnalysis](g.cacheStorage, moduleCacheNamespace) for _, dep := range g.deps { // Try to get the cached list of modules for the current dependency package cacheKey := cache.Key(dep.Path, dep.Version) - modulesInPath, err := moduleCache.Get(cacheKey) + depInfo, err := moduleCache.Get(cacheKey) if err != nil && !errors.Is(err, cache.ErrorNotFound) { return err } @@ -119,37 +142,28 @@ func (g *generator) setup() (err error) { return err } - var includes []string + // Dependency/includes resolution per module is done to solve versioning issues + var includes protoIncludes if len(modules) > 0 { - // For versioning issues, we do dependency/includes resolution per module includes, err = g.resolveIncludes(path) if err != nil { return err } } - modulesInPath = ModulesInPath{ + depInfo = protoAnalysis{ Path: path, Modules: modules, Includes: includes, } - if err := moduleCache.Put(cacheKey, modulesInPath); err != nil { + if err := moduleCache.Put(cacheKey, depInfo); err != nil { return err } } - g.thirdModules[modulesInPath.Path] = append( - g.thirdModules[modulesInPath.Path], - modulesInPath.Modules..., - ) - - if modulesInPath.Includes != nil { - g.thirdModuleIncludes[modulesInPath.Path] = append( - g.thirdModuleIncludes[modulesInPath.Path], - modulesInPath.Includes..., - ) - } + g.thirdModules[depInfo.Path] = depInfo.Modules + g.thirdModuleIncludes[depInfo.Path] = depInfo.Includes } return nil @@ -170,7 +184,8 @@ func (g *generator) findBufPath(modpath string) (string, error) { if err != nil { return err } - if filepath.Base(path) == "buf.yaml" { + base := filepath.Base(path) + if base == "buf.yaml" || base == "buf.yml" { bufPath = path return filepath.SkipAll } @@ -197,48 +212,58 @@ func (g *generator) generateBufIncludeFolder(modpath string) (string, error) { return protoPath, nil } -func (g *generator) resolveIncludes(path string) (paths []string, err error) { +func (g *generator) resolveIncludes(path string) (protoIncludes, error) { // Init paths with the global include paths for protoc - paths, err = protocGlobalInclude() + paths, err := protocGlobalInclude() if err != nil { - return nil, err + return protoIncludes{}, err } - // Check that the app proto directory exists + includes := protoIncludes{Paths: paths} + + // Check that the app/package proto directory exists protoPath := filepath.Join(path, g.protoDir) fi, err := os.Stat(protoPath) if err != nil && !os.IsNotExist(err) { - return nil, err + return protoIncludes{}, err } else if !fi.IsDir() { // Just return the global includes when a proto directory doesn't exist - return paths, nil + return includes, nil } // Add app's proto path to the list of proto paths - paths = append(paths, protoPath) + includes.Paths = append(includes.Paths, protoPath) + includes.ProtoPath = protoPath // Check if a Buf config file is present bufPath, err := g.findBufPath(protoPath) if err != nil { - return nil, err + return includes, err } - // When a Buf config exists export all protos needed - // to build the modules to a temporary include folder. if bufPath != "" { - includePath, err := g.generateBufIncludeFolder(protoPath) + includes.BufPath = bufPath + + // When a Buf config exists export all protos needed + // to build the modules to a temporary include folder. + // TODO: Should this be optional and not done for the app includes? Duplicates proto folder. + bufProtoPath, err := g.generateBufIncludeFolder(protoPath) if err != nil && !errors.Is(err, cosmosbuf.ErrProtoFilesNotFound) { - return nil, err + return protoIncludes{}, err } // Use exported files only when the path contains ".proto" files - if includePath != "" { - return append(paths, includePath), nil + if bufProtoPath != "" { + includes.Paths = append(includes.Paths, bufProtoPath) + return includes, nil } } - // By default use the configured directories - return append(paths, g.getProtoIncludeFolders(path)...), nil + // When there is no Buf config add the configured directories + // instead to keep the legacy (non Buf) behavior. + includes.Paths = append(includes.Paths, g.getProtoIncludeFolders(path)...) + + return includes, nil } func (g *generator) discoverModules(path, protoDir string) ([]module.Module, error) { diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 05f988a75e..a16ef2f42a 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -132,7 +132,7 @@ func (g *tsGenerator) generateModuleTemplates() error { } } - add(g.g.appPath, g.g.appModules, g.g.appIncludes) + add(g.g.appPath, g.g.appModules, g.g.appIncludes.Paths) // Always generate third party modules; This is required because not generating them might // lead to issues with the module registration in the root template. The root template must @@ -140,8 +140,9 @@ func (g *tsGenerator) generateModuleTemplates() error { // is available and not generated it would lead to the registration of a new not generated // 3rd party module. for sourcePath, modules := range g.g.thirdModules { - includes := g.g.thirdModuleIncludes[sourcePath] - add(sourcePath, modules, append(g.g.appIncludes, includes...)) + // TODO: Skip modules without proto files? + thirdIncludes := g.g.thirdModuleIncludes[sourcePath] + add(sourcePath, modules, append(g.g.appIncludes.Paths, thirdIncludes.Paths...)) } return gg.Wait() From b3f89a48281e490342baa6a17d783c01901e0b66 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 1 Nov 2023 11:34:46 +0100 Subject: [PATCH 02/16] feat(pkg/cosmosbuf): add Buf mod update support --- ignite/pkg/cosmosbuf/buf.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ignite/pkg/cosmosbuf/buf.go b/ignite/pkg/cosmosbuf/buf.go index 7c4a70500e..b1b5a2c7e4 100644 --- a/ignite/pkg/cosmosbuf/buf.go +++ b/ignite/pkg/cosmosbuf/buf.go @@ -35,17 +35,20 @@ const ( flagOutput = "output" flagErrorFormat = "error-format" flagLogFormat = "log-format" + flagOnly = "only" fmtJSON = "json" // CMDGenerate generate command. CMDGenerate Command = "generate" CMDExport Command = "export" + CMDMod Command = "mod" ) var ( commands = map[Command]struct{}{ CMDGenerate: {}, CMDExport: {}, + CMDMod: {}, } // ErrInvalidCommand indicates an invalid command name. @@ -72,6 +75,24 @@ func (c Command) String() string { return string(c) } +// Update updates module dependencies. +// By default updates all dependencies unless one or more dependencies are specified. +func (b Buf) Update(ctx context.Context, modDir string, dependencies ...string) error { + var flags map[string]string + if dependencies != nil { + flags = map[string]string{ + flagOnly: strings.Join(dependencies, ","), + } + } + + cmd, err := b.generateCommand(CMDMod, flags, "update", modDir) + if err != nil { + return err + } + + return b.runCommand(ctx, cmd...) +} + // Export runs the buf Export command for the files in the proto directory. func (b Buf) Export(ctx context.Context, protoDir, output string) error { // Check if the proto directory is the Cosmos SDK one From 355e804fdfb85cc68370108762aa2a00f7113005 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 1 Nov 2023 12:10:05 +0100 Subject: [PATCH 03/16] feat: add third party deps to app's Buf config Third party deps are added to app's Buf config when the dependency is not present and the Go package protos have a Buf config with a `name` assigned. --- ignite/pkg/cosmosgen/cosmosgen.go | 11 +++ ignite/pkg/cosmosgen/generate.go | 118 ++++++++++++++++++++++++++++ ignite/pkg/cosmosgen/generate_go.go | 18 ++--- 3 files changed, 134 insertions(+), 13 deletions(-) diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 3805f9e10e..88685c06c8 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -138,6 +138,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir defer b.Cleanup() + // TODO: Move context to be a func/method argument instead of an instance one g := &generator{ ctx: ctx, buf: b, @@ -160,6 +161,16 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir return err } + // Update app's Buf config for third party discovered proto modules. + // Go dependency packages might contain proto files which could also + // optionally be using Buf, so for those cases the discovered proto + // files should be available before code generation. + if g.opts.isGoEnabled || g.opts.isPulsarEnabled { + if err := g.updateBufConfig(); err != nil { + return err + } + } + // Go generation must run first so the types are created before other // generated code that requires sdk.Msg implementations to be defined if g.opts.isGoEnabled { diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index f80ada8f6f..d65b7c7a82 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -2,12 +2,15 @@ package cosmosgen import ( "bytes" + "fmt" "io/fs" "os" "path/filepath" + "slices" "strings" "github.com/pkg/errors" + "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cmdrunner" @@ -55,6 +58,10 @@ type protoAnalysis struct { Includes protoIncludes } +func newBufConfigError(path string, cause error) error { + return fmt.Errorf("invalid Buf config: %s: %w", path, cause) +} + func (g *generator) setup() (err error) { // Cosmos SDK hosts proto files of own x/ modules and some third party ones needed by itself and // blockchain apps. Generate should be aware of these and make them available to the blockchain @@ -286,3 +293,114 @@ func (g *generator) discoverModules(path, protoDir string) ([]module.Module, err return filteredModules, nil } + +func (g generator) updateBufConfig() error { + for pkgPath, includes := range g.thirdModuleIncludes { + // Skip third party dependencies without proto files + if includes.ProtoPath == "" { + continue + } + + // Resolve the Go package and use the module name as the proto vendor directory name + modFile, err := gomodule.ParseAt(pkgPath) + if err != nil { + return err + } + + pkgName := modFile.Module.Mod.Path + + // When a Buf config with name is available add it to app's dependencies + // or otherwise export the proto files to a vendor directory. + if includes.BufPath != "" { + if err := g.resolveBufDependency(pkgName, includes.BufPath); err != nil { + return err + } + } else { + if err := g.vendorProtoPackage(pkgName, includes.ProtoPath); err != nil { + return err + } + } + } + return nil +} + +func (g generator) resolveBufDependency(pkgName, bufPath string) error { + // Open the dependency Buf config to find the BSR package name + f, err := os.Open(bufPath) + if err != nil { + return err + } + defer f.Close() + + cfg := struct { + Name string `yaml:"name"` + }{} + + if err := yaml.NewDecoder(f).Decode(&cfg); err != nil { + return newBufConfigError(bufPath, err) + } + + // When dependency package has a Buf config name try to add it to app's + // dependencies. Name is optional and defines the BSR package name. + if cfg.Name != "" { + return g.addBufDependency(cfg.Name) + } + // By defaoult just vendor the proto package + return g.vendorBufDependency(pkgName, bufPath) +} + +// TODO: Check BSR before adding the dependency to app's Buf deps +func (g generator) addBufDependency(depName string) error { + // Read app's Buf config + path := g.appIncludes.BufPath + bz, err := os.ReadFile(path) + if err != nil { + return err + } + + // Check if the proto dependency is already present in app's Buf config + cfg := struct { + Deps []string `yaml:"deps"` + }{} + if err := yaml.Unmarshal(bz, &cfg); err != nil { + return newBufConfigError(path, err) + } + + if slices.Contains(cfg.Deps, depName) { + return nil + } + + // Add the new dependency and update app's Buf config + f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0o644) + if err != nil { + return err + } + defer f.Close() + + var rawCfg map[string]interface{} + if err := yaml.Unmarshal(bz, &rawCfg); err != nil { + return newBufConfigError(path, err) + } + + rawCfg["deps"] = append(cfg.Deps, depName) + + enc := yaml.NewEncoder(f) + defer enc.Close() + + if err := enc.Encode(rawCfg); err != nil { + return err + } + + // Update Buf lock so it contains the new dependency + return g.buf.Update(g.ctx, filepath.Dir(path), depName) +} + +func (g generator) vendorBufDependency(pkgName, bufPath string) error { + // TODO: Implement + return nil +} + +func (g generator) vendorProtoPackage(pkgName, pkgProtoPath string) error { + // TODO: Implement + return nil +} diff --git a/ignite/pkg/cosmosgen/generate_go.go b/ignite/pkg/cosmosgen/generate_go.go index ae8dfc6ce5..ebfe5f8a9f 100644 --- a/ignite/pkg/cosmosgen/generate_go.go +++ b/ignite/pkg/cosmosgen/generate_go.go @@ -5,6 +5,7 @@ import ( "path/filepath" "github.com/otiai10/copy" + "github.com/pkg/errors" ) @@ -29,13 +30,8 @@ func (g *generator) generateGo() error { protoPath := filepath.Join(g.appPath, g.protoDir) // code generate for each module. - if err := g.buf.Generate( - g.ctx, - protoPath, - tmp, - g.gogoTemplate(), - "module.proto", - ); err != nil { + err = g.buf.Generate(g.ctx, protoPath, tmp, g.gogoTemplate(), "module.proto") + if err != nil { return err } @@ -68,12 +64,8 @@ func (g *generator) generatePulsar() error { protoPath := filepath.Join(g.appPath, g.protoDir) // code generate for each module. - if err := g.buf.Generate( - g.ctx, - protoPath, - tmp, - g.pulsarTemplate(), - ); err != nil { + err = g.buf.Generate(g.ctx, protoPath, tmp, g.pulsarTemplate()) + if err != nil { return err } From 61b9144f218209839b74ef241a4e5cb343bedad3 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 1 Nov 2023 12:24:49 +0100 Subject: [PATCH 04/16] chore: update changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index b2f0f9c8bb..47df5920eb 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ - [#3614](https://github.com/ignite/cli/pull/3614) feat: use DefaultBaseappOptions for app.New method - [#3536](https://github.com/ignite/cli/pull/3536) Change app.go to v2 and add AppWiring feature - [#3670](https://github.com/ignite/cli/pull/3670) Remove nodetime binaries +- [#3724](https://github.com/ignite/cli/pull/3724) Add or vendor proto packages from Go dependencies ### Changes From 94ab03ecbffc04bbbc260997956253e2b5e64e4c Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 1 Nov 2023 15:07:56 +0100 Subject: [PATCH 05/16] feat: add vendoring support for Go dependencies with proto files --- ignite/pkg/cosmosgen/generate.go | 60 +++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index d65b7c7a82..4809e23157 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -20,11 +20,13 @@ import ( "github.com/ignite/cli/ignite/pkg/cosmosver" "github.com/ignite/cli/ignite/pkg/gomodule" "github.com/ignite/cli/ignite/pkg/xfilepath" + "github.com/ignite/cli/ignite/pkg/xos" ) const ( moduleCacheNamespace = "generate.setup.module" includeProtoCacheNamespace = "generator.includes.proto" + workFilename = "buf.work.yaml" ) var protocGlobalInclude = xfilepath.List( @@ -345,8 +347,8 @@ func (g generator) resolveBufDependency(pkgName, bufPath string) error { if cfg.Name != "" { return g.addBufDependency(cfg.Name) } - // By defaoult just vendor the proto package - return g.vendorBufDependency(pkgName, bufPath) + // By default just vendor the proto package + return g.vendorProtoPackage(pkgName, filepath.Dir(bufPath)) } // TODO: Check BSR before adding the dependency to app's Buf deps @@ -395,12 +397,52 @@ func (g generator) addBufDependency(depName string) error { return g.buf.Update(g.ctx, filepath.Dir(path), depName) } -func (g generator) vendorBufDependency(pkgName, bufPath string) error { - // TODO: Implement - return nil -} +func (g generator) vendorProtoPackage(pkgName, protoPath string) error { + // Check that the dependency vendor directory doesn't exist + vendorRelPath := filepath.Join("proto_vendor", pkgName) + vendorPath := filepath.Join(g.appPath, vendorRelPath) + _, err := os.Stat(vendorPath) + if err != nil && !os.IsNotExist(err) { + return err + } -func (g generator) vendorProtoPackage(pkgName, pkgProtoPath string) error { - // TODO: Implement - return nil + // Skip vendoring when the dependency is already vendored + if !os.IsNotExist(err) { + return nil + } + + if err = os.MkdirAll(vendorPath, 0o777); err != nil { + return err + } + + if err = xos.CopyFolder(protoPath, vendorPath); err != nil { + return err + } + + path := filepath.Join(g.appPath, workFilename) + bz, err := os.ReadFile(path) + if err != nil { + return fmt.Errorf("error reading Buf workspace file: %s: %w", path, err) + } + + ws := struct { + Version string `yaml:"version"` + Directories []string `yaml:"directories"` + }{} + if err := yaml.Unmarshal(bz, &ws); err != nil { + return err + } + + ws.Directories = append(ws.Directories, vendorRelPath) + + f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0o644) + if err != nil { + return err + } + defer f.Close() + + enc := yaml.NewEncoder(f) + defer enc.Close() + + return enc.Encode(ws) } From 07e00ed855f28a1cd3c41aa087dda67141835cba Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 1 Nov 2023 17:01:17 +0100 Subject: [PATCH 06/16] refactor(pkg/cosmosgen): use context as function argument --- ignite/pkg/cosmosgen/cosmosgen.go | 15 +++----- ignite/pkg/cosmosgen/generate.go | 41 +++++++++++---------- ignite/pkg/cosmosgen/generate_go.go | 9 +++-- ignite/pkg/cosmosgen/generate_openapi.go | 27 +++++--------- ignite/pkg/cosmosgen/generate_typescript.go | 12 +++--- 5 files changed, 46 insertions(+), 58 deletions(-) diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 88685c06c8..1e00647153 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -105,7 +105,6 @@ func IncludeDirs(dirs []string) Option { // generator generates code for sdk and sdk apps. type generator struct { - ctx context.Context buf cosmosbuf.Buf cacheStorage cache.Storage appPath string @@ -138,9 +137,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir defer b.Cleanup() - // TODO: Move context to be a func/method argument instead of an instance one g := &generator{ - ctx: ctx, buf: b, appPath: appPath, protoDir: protoDir, @@ -157,7 +154,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir apply(g.opts) } - if err := g.setup(); err != nil { + if err := g.setup(ctx); err != nil { return err } @@ -166,7 +163,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir // optionally be using Buf, so for those cases the discovered proto // files should be available before code generation. if g.opts.isGoEnabled || g.opts.isPulsarEnabled { - if err := g.updateBufConfig(); err != nil { + if err := g.updateBufConfig(ctx); err != nil { return err } } @@ -174,24 +171,24 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir // Go generation must run first so the types are created before other // generated code that requires sdk.Msg implementations to be defined if g.opts.isGoEnabled { - if err := g.generateGo(); err != nil { + if err := g.generateGo(ctx); err != nil { return err } } if g.opts.isPulsarEnabled { - if err := g.generatePulsar(); err != nil { + if err := g.generatePulsar(ctx); err != nil { return err } } if g.opts.specOut != "" { - if err := g.generateOpenAPISpec(); err != nil { + if err := g.generateOpenAPISpec(ctx); err != nil { return err } } if g.opts.jsOut != nil { - if err := g.generateTS(); err != nil { + if err := g.generateTS(ctx); err != nil { return err } } diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index 4809e23157..11b2bb9b11 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -2,6 +2,7 @@ package cosmosgen import ( "bytes" + "context" "fmt" "io/fs" "os" @@ -64,7 +65,7 @@ func newBufConfigError(path string, cause error) error { return fmt.Errorf("invalid Buf config: %s: %w", path, cause) } -func (g *generator) setup() (err error) { +func (g *generator) setup(ctx context.Context) (err error) { // Cosmos SDK hosts proto files of own x/ modules and some third party ones needed by itself and // blockchain apps. Generate should be aware of these and make them available to the blockchain // app that wants to generate code for its own proto. @@ -78,7 +79,7 @@ func (g *generator) setup() (err error) { New( cmdrunner.DefaultStderr(&errb), cmdrunner.DefaultWorkdir(g.appPath), - ).Run(g.ctx, step.New(step.Exec("go", "mod", "download"))); err != nil { + ).Run(ctx, step.New(step.Exec("go", "mod", "download"))); err != nil { return errors.Wrap(err, errb.String()) } @@ -105,12 +106,12 @@ func (g *generator) setup() (err error) { } // Discover any custom modules defined by the user's app - g.appModules, err = g.discoverModules(g.appPath, g.protoDir) + g.appModules, err = g.discoverModules(ctx, g.appPath, g.protoDir) if err != nil { return err } - g.appIncludes, err = g.resolveIncludes(g.appPath) + g.appIncludes, err = g.resolveIncludes(ctx, g.appPath) if err != nil { return err } @@ -140,13 +141,13 @@ func (g *generator) setup() (err error) { // Discover the modules of the dependency package when they are not cached if errors.Is(err, cache.ErrorNotFound) { // Get the absolute path to the package's directory - path, err := gomodule.LocatePath(g.ctx, g.cacheStorage, g.appPath, dep) + path, err := gomodule.LocatePath(ctx, g.cacheStorage, g.appPath, dep) if err != nil { return err } // Discover any modules defined by the package - modules, err := g.discoverModules(path, "") + modules, err := g.discoverModules(ctx, path, "") if err != nil { return err } @@ -154,7 +155,7 @@ func (g *generator) setup() (err error) { // Dependency/includes resolution per module is done to solve versioning issues var includes protoIncludes if len(modules) > 0 { - includes, err = g.resolveIncludes(path) + includes, err = g.resolveIncludes(ctx, path) if err != nil { return err } @@ -206,7 +207,7 @@ func (g *generator) findBufPath(modpath string) (string, error) { return bufPath, nil } -func (g *generator) generateBufIncludeFolder(modpath string) (string, error) { +func (g *generator) generateBufIncludeFolder(ctx context.Context, modpath string) (string, error) { protoPath, err := os.MkdirTemp("", "includeFolder") if err != nil { return "", err @@ -214,14 +215,14 @@ func (g *generator) generateBufIncludeFolder(modpath string) (string, error) { g.tmpDirs = append(g.tmpDirs, protoPath) - err = g.buf.Export(g.ctx, modpath, protoPath) + err = g.buf.Export(ctx, modpath, protoPath) if err != nil { return "", err } return protoPath, nil } -func (g *generator) resolveIncludes(path string) (protoIncludes, error) { +func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncludes, error) { // Init paths with the global include paths for protoc paths, err := protocGlobalInclude() if err != nil { @@ -256,7 +257,7 @@ func (g *generator) resolveIncludes(path string) (protoIncludes, error) { // When a Buf config exists export all protos needed // to build the modules to a temporary include folder. // TODO: Should this be optional and not done for the app includes? Duplicates proto folder. - bufProtoPath, err := g.generateBufIncludeFolder(protoPath) + bufProtoPath, err := g.generateBufIncludeFolder(ctx, protoPath) if err != nil && !errors.Is(err, cosmosbuf.ErrProtoFilesNotFound) { return protoIncludes{}, err } @@ -275,10 +276,10 @@ func (g *generator) resolveIncludes(path string) (protoIncludes, error) { return includes, nil } -func (g *generator) discoverModules(path, protoDir string) ([]module.Module, error) { +func (g *generator) discoverModules(ctx context.Context, path, protoDir string) ([]module.Module, error) { var filteredModules []module.Module - modules, err := module.Discover(g.ctx, g.appPath, path, protoDir) + modules, err := module.Discover(ctx, g.appPath, path, protoDir) if err != nil { return nil, err } @@ -296,7 +297,7 @@ func (g *generator) discoverModules(path, protoDir string) ([]module.Module, err return filteredModules, nil } -func (g generator) updateBufConfig() error { +func (g generator) updateBufConfig(ctx context.Context) error { for pkgPath, includes := range g.thirdModuleIncludes { // Skip third party dependencies without proto files if includes.ProtoPath == "" { @@ -314,7 +315,7 @@ func (g generator) updateBufConfig() error { // When a Buf config with name is available add it to app's dependencies // or otherwise export the proto files to a vendor directory. if includes.BufPath != "" { - if err := g.resolveBufDependency(pkgName, includes.BufPath); err != nil { + if err := g.resolveBufDependency(ctx, pkgName, includes.BufPath); err != nil { return err } } else { @@ -326,7 +327,7 @@ func (g generator) updateBufConfig() error { return nil } -func (g generator) resolveBufDependency(pkgName, bufPath string) error { +func (g generator) resolveBufDependency(ctx context.Context, pkgName, bufPath string) error { // Open the dependency Buf config to find the BSR package name f, err := os.Open(bufPath) if err != nil { @@ -345,14 +346,14 @@ func (g generator) resolveBufDependency(pkgName, bufPath string) error { // When dependency package has a Buf config name try to add it to app's // dependencies. Name is optional and defines the BSR package name. if cfg.Name != "" { - return g.addBufDependency(cfg.Name) + return g.addBufDependency(ctx, cfg.Name) } // By default just vendor the proto package return g.vendorProtoPackage(pkgName, filepath.Dir(bufPath)) } -// TODO: Check BSR before adding the dependency to app's Buf deps -func (g generator) addBufDependency(depName string) error { +func (g generator) addBufDependency(ctx context.Context, depName string) error { + // TODO: Check BSR before adding the dependency to app's Buf deps // Read app's Buf config path := g.appIncludes.BufPath bz, err := os.ReadFile(path) @@ -394,7 +395,7 @@ func (g generator) addBufDependency(depName string) error { } // Update Buf lock so it contains the new dependency - return g.buf.Update(g.ctx, filepath.Dir(path), depName) + return g.buf.Update(ctx, filepath.Dir(path), depName) } func (g generator) vendorProtoPackage(pkgName, protoPath string) error { diff --git a/ignite/pkg/cosmosgen/generate_go.go b/ignite/pkg/cosmosgen/generate_go.go index ebfe5f8a9f..8423c17fca 100644 --- a/ignite/pkg/cosmosgen/generate_go.go +++ b/ignite/pkg/cosmosgen/generate_go.go @@ -1,6 +1,7 @@ package cosmosgen import ( + "context" "os" "path/filepath" @@ -17,7 +18,7 @@ func (g *generator) pulsarTemplate() string { return filepath.Join(g.appPath, g.protoDir, "buf.gen.pulsar.yaml") } -func (g *generator) generateGo() error { +func (g *generator) generateGo(ctx context.Context) error { // create a temporary dir to locate generated code under which later only some of them will be moved to the // app's source code. this also prevents having leftover files in the app's source code or its parent dir - when // command executed directly there - in case of an interrupt. @@ -30,7 +31,7 @@ func (g *generator) generateGo() error { protoPath := filepath.Join(g.appPath, g.protoDir) // code generate for each module. - err = g.buf.Generate(g.ctx, protoPath, tmp, g.gogoTemplate(), "module.proto") + err = g.buf.Generate(ctx, protoPath, tmp, g.gogoTemplate(), "module.proto") if err != nil { return err } @@ -51,7 +52,7 @@ func (g *generator) generateGo() error { return nil } -func (g *generator) generatePulsar() error { +func (g *generator) generatePulsar(ctx context.Context) error { // create a temporary dir to locate generated code under which later only some of them will be moved to the // app's source code. this also prevents having leftover files in the app's source code or its parent dir - when // command executed directly there - in case of an interrupt. @@ -64,7 +65,7 @@ func (g *generator) generatePulsar() error { protoPath := filepath.Join(g.appPath, g.protoDir) // code generate for each module. - err = g.buf.Generate(g.ctx, protoPath, tmp, g.pulsarTemplate()) + err = g.buf.Generate(ctx, protoPath, tmp, g.pulsarTemplate()) if err != nil { return err } diff --git a/ignite/pkg/cosmosgen/generate_openapi.go b/ignite/pkg/cosmosgen/generate_openapi.go index f4897d5472..557d83d8aa 100644 --- a/ignite/pkg/cosmosgen/generate_openapi.go +++ b/ignite/pkg/cosmosgen/generate_openapi.go @@ -1,6 +1,7 @@ package cosmosgen import ( + "context" "errors" "fmt" "os" @@ -29,7 +30,7 @@ func (g *generator) openAPITemplateForSTA() string { return filepath.Join(g.appPath, g.protoDir, "buf.gen.sta.yaml") } -func (g *generator) generateOpenAPISpec() error { +func (g *generator) generateOpenAPISpec(ctx context.Context) error { var ( specDirs []string conf = swaggercombine.Config{ @@ -78,13 +79,8 @@ func (g *generator) generateOpenAPISpec() error { } hasAnySpecChanged = true - if err := g.buf.Generate( - g.ctx, - m.Pkg.Path, - dir, - g.openAPITemplate(), - "module.proto", - ); err != nil { + err = g.buf.Generate(ctx, m.Pkg.Path, dir, g.openAPITemplate(), "module.proto") + if err != nil { return err } @@ -157,14 +153,14 @@ func (g *generator) generateOpenAPISpec() error { } // combine specs into one and save to out. - if err := swaggercombine.Combine(g.ctx, conf, out); err != nil { + if err := swaggercombine.Combine(ctx, conf, out); err != nil { return err } return dirchange.SaveDirChecksum(specCache, out, g.appPath, out) } -func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error { +func (g *generator) generateModuleOpenAPISpec(ctx context.Context, m module.Module, out string) error { var ( specDirs []string conf = swaggercombine.Config{ @@ -189,13 +185,8 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error return err } - if err := g.buf.Generate( - g.ctx, - m.Pkg.Path, - dir, - g.openAPITemplateForSTA(), - "module.proto", - ); err != nil { + err = g.buf.Generate(ctx, m.Pkg.Path, dir, g.openAPITemplateForSTA(), "module.proto") + if err != nil { return err } @@ -244,5 +235,5 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error } // combine specs into one and save to out. - return swaggercombine.Combine(g.ctx, conf, out) + return swaggercombine.Combine(ctx, conf, out) } diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index a16ef2f42a..328eb69b51 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -37,7 +37,7 @@ func newTSGenerator(g *generator) *tsGenerator { return &tsGenerator{g} } -func (g *generator) generateTS() error { +func (g *generator) generateTS(ctx context.Context) error { chainPath, _, err := gomodulepath.Find(g.appPath) if err != nil { return err @@ -70,14 +70,14 @@ func (g *generator) generateTS() error { }) tsg := newTSGenerator(g) - if err := tsg.generateModuleTemplates(); err != nil { + if err := tsg.generateModuleTemplates(ctx); err != nil { return err } return tsg.generateRootTemplates(data) } -func (g *tsGenerator) generateModuleTemplates() error { +func (g *tsGenerator) generateModuleTemplates(ctx context.Context) error { protocCmd, cleanupProtoc, err := protoc.Command() if err != nil { return err @@ -122,7 +122,7 @@ func (g *tsGenerator) generateModuleTemplates() error { } } - err = g.generateModuleTemplate(g.g.ctx, protocCmd, staCmd, tsprotoPluginPath, sourcePath, m, includes) + err = g.generateModuleTemplate(ctx, protocCmd, staCmd, tsprotoPluginPath, sourcePath, m, includes) if err != nil { return err } @@ -182,9 +182,7 @@ func (g *tsGenerator) generateModuleTemplate( specPath := filepath.Join(out, "api.swagger.yml") - err = g.g.generateModuleOpenAPISpec(m, specPath) - - if err != nil { + if err = g.g.generateModuleOpenAPISpec(ctx, m, specPath); err != nil { return err } // generate the REST client from the OpenAPI spec From ab40b4818c76a620996e7170d7c37a72c5dcc8f8 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Thu, 2 Nov 2023 12:06:23 +0100 Subject: [PATCH 07/16] feat: add `--update-buf-module` flag to generate go commands The flag explicitly enables proto vendoring or Buf config dependency updates. --- ignite/cmd/generate.go | 16 ++++++++++++++++ ignite/cmd/generate_go.go | 5 ++++- ignite/cmd/generate_pulsar.go | 5 ++++- ignite/pkg/cosmosgen/cosmosgen.go | 18 ++++++++++++++---- ignite/pkg/cosmosgen/generate.go | 2 +- ignite/services/chain/generate.go | 13 ++++++++++--- 6 files changed, 49 insertions(+), 10 deletions(-) diff --git a/ignite/cmd/generate.go b/ignite/cmd/generate.go index 4b6bec9e0f..1de5a122f7 100644 --- a/ignite/cmd/generate.go +++ b/ignite/cmd/generate.go @@ -2,6 +2,11 @@ package ignitecmd import ( "github.com/spf13/cobra" + flag "github.com/spf13/pflag" +) + +const ( + flagUpdateBufModule = "update-buf-module" ) // NewGenerate returns a command that groups code generation related sub commands. @@ -34,3 +39,14 @@ meant to be edited by hand. return c } + +func flagSetUpdateBufModule() *flag.FlagSet { + fs := flag.NewFlagSet("", flag.ContinueOnError) + fs.Bool(flagUpdateBufModule, false, "update Buf config with missing proto dependencies") + return fs +} + +func flagGetUpdateBufModule(cmd *cobra.Command) bool { + skip, _ := cmd.Flags().GetBool(flagUpdateBufModule) + return skip +} diff --git a/ignite/cmd/generate_go.go b/ignite/cmd/generate_go.go index 677f202b8a..f1e9ed511e 100644 --- a/ignite/cmd/generate_go.go +++ b/ignite/cmd/generate_go.go @@ -16,6 +16,7 @@ func NewGenerateGo() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) + c.Flags().AddFlagSet(flagSetUpdateBufModule()) return c } @@ -39,7 +40,9 @@ func generateGoHandler(cmd *cobra.Command, _ []string) error { return err } - if err := c.Generate(cmd.Context(), cacheStorage, chain.GenerateGo()); err != nil { + updateBufModule := flagGetUpdateBufModule(cmd) + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateGo(updateBufModule)) + if err != nil { return err } diff --git a/ignite/cmd/generate_pulsar.go b/ignite/cmd/generate_pulsar.go index 2c05104954..ca58d6f1e8 100644 --- a/ignite/cmd/generate_pulsar.go +++ b/ignite/cmd/generate_pulsar.go @@ -16,6 +16,7 @@ func NewGeneratePulsar() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) + c.Flags().AddFlagSet(flagSetUpdateBufModule()) return c } @@ -39,7 +40,9 @@ func generatePulsarHandler(cmd *cobra.Command, _ []string) error { return err } - if err := c.Generate(cmd.Context(), cacheStorage, chain.GeneratePulsar()); err != nil { + updateBufModule := flagGetUpdateBufModule(cmd) + err = c.Generate(cmd.Context(), cacheStorage, chain.GeneratePulsar(updateBufModule)) + if err != nil { return err } diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 1e00647153..b01e840034 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -16,8 +16,9 @@ import ( // generateOptions used to configure code generation. type generateOptions struct { - includeDirs []string - useCache bool + includeDirs []string + useCache bool + updateBufModule bool isGoEnabled bool isPulsarEnabled bool @@ -103,6 +104,15 @@ func IncludeDirs(dirs []string) Option { } } +// UpdateBufModule enables Buf config proto dependencies update. +// This option updates app's Buf config when proto packages or +// Buf modules are found within the Go dependencies. +func UpdateBufModule() Option { + return func(o *generateOptions) { + o.updateBufModule = true + } +} + // generator generates code for sdk and sdk apps. type generator struct { buf cosmosbuf.Buf @@ -162,8 +172,8 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir // Go dependency packages might contain proto files which could also // optionally be using Buf, so for those cases the discovered proto // files should be available before code generation. - if g.opts.isGoEnabled || g.opts.isPulsarEnabled { - if err := g.updateBufConfig(ctx); err != nil { + if g.opts.updateBufModule && (g.opts.isGoEnabled || g.opts.isPulsarEnabled) { + if err := g.updateBufModule(ctx); err != nil { return err } } diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index 11b2bb9b11..f0408cbec0 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -297,7 +297,7 @@ func (g *generator) discoverModules(ctx context.Context, path, protoDir string) return filteredModules, nil } -func (g generator) updateBufConfig(ctx context.Context) error { +func (g generator) updateBufModule(ctx context.Context) error { for pkgPath, includes := range g.thirdModuleIncludes { // Skip third party dependencies without proto files if includes.ProtoPath == "" { diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 64f5570b6e..28b80cfce6 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -16,6 +16,7 @@ import ( type generateOptions struct { useCache bool + updateBufModule bool isGoEnabled bool isPulsarEnabled bool isTSClientEnabled bool @@ -33,16 +34,18 @@ type generateOptions struct { type GenerateTarget func(*generateOptions) // GenerateGo enables generating proto based Go code needed for the chain's source code. -func GenerateGo() GenerateTarget { +func GenerateGo(updateBufModule bool) GenerateTarget { return func(o *generateOptions) { o.isGoEnabled = true + o.updateBufModule = updateBufModule } } // GeneratePulsar enables generating proto based Go code needed for the chain's source code. -func GeneratePulsar() GenerateTarget { +func GeneratePulsar(updateBufModule bool) GenerateTarget { return func(o *generateOptions) { o.isPulsarEnabled = true + o.updateBufModule = updateBufModule } } @@ -129,7 +132,7 @@ func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Stora } // Generate proto based code for Go and optionally for any optional targets - return c.Generate(ctx, cacheStorage, GenerateGo(), targets...) + return c.Generate(ctx, cacheStorage, GenerateGo(false), targets...) } // Generate makes code generation from proto files for given target and additionalTargets. @@ -168,6 +171,10 @@ func (c *Chain) Generate( options = append(options, cosmosgen.WithPulsarGeneration()) } + if targetOptions.updateBufModule { + options = append(options, cosmosgen.UpdateBufModule()) + } + var ( openAPIPath, tsClientPath, vuexPath, composablesPath, hooksPath string updateConfig bool From 65f3983f8b1b2dfebdc0a19aac551bb863cdabe6 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Thu, 2 Nov 2023 15:36:11 +0100 Subject: [PATCH 08/16] feat: change scaffolder to update Buf with third party dependencies This updates Buf dependencies and vendors proto files from third party Go dependencies by default for the scaffold commands --- ignite/services/scaffolder/scaffolder.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index 6caa944113..6052ddae13 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -92,6 +92,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP options := []cosmosgen.Option{ cosmosgen.WithGoGeneration(), cosmosgen.WithPulsarGeneration(), + cosmosgen.UpdateBufModule(), cosmosgen.IncludeDirs(conf.Build.Proto.ThirdPartyPaths), } From 4416e946171c086aa68ffc8642bfc43e05e6cade Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Thu, 2 Nov 2023 16:24:23 +0100 Subject: [PATCH 09/16] feat: add events support to generator --- ignite/pkg/cosmosgen/cosmosgen.go | 9 +++++++++ ignite/pkg/cosmosgen/generate.go | 29 ++++++++++++++++++++++++++--- ignite/services/chain/generate.go | 1 + 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index b01e840034..e6310f2e5b 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -12,6 +12,7 @@ import ( "github.com/ignite/cli/ignite/pkg/cache" "github.com/ignite/cli/ignite/pkg/cosmosanalysis/module" "github.com/ignite/cli/ignite/pkg/cosmosbuf" + "github.com/ignite/cli/ignite/pkg/events" ) // generateOptions used to configure code generation. @@ -19,6 +20,7 @@ type generateOptions struct { includeDirs []string useCache bool updateBufModule bool + ev events.Bus isGoEnabled bool isPulsarEnabled bool @@ -113,6 +115,13 @@ func UpdateBufModule() Option { } } +// CollectEvents sets an event bus for sending generation feedback events. +func CollectEvents(ev events.Bus) Option { + return func(c *generateOptions) { + c.ev = ev + } +} + // generator generates code for sdk and sdk apps. type generator struct { buf cosmosbuf.Buf diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index f0408cbec0..bcdfb195c6 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -14,11 +14,14 @@ import ( "gopkg.in/yaml.v2" "github.com/ignite/cli/ignite/pkg/cache" + "github.com/ignite/cli/ignite/pkg/cliui/colors" + "github.com/ignite/cli/ignite/pkg/cliui/icons" "github.com/ignite/cli/ignite/pkg/cmdrunner" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosanalysis/module" "github.com/ignite/cli/ignite/pkg/cosmosbuf" "github.com/ignite/cli/ignite/pkg/cosmosver" + "github.com/ignite/cli/ignite/pkg/events" "github.com/ignite/cli/ignite/pkg/gomodule" "github.com/ignite/cli/ignite/pkg/xfilepath" "github.com/ignite/cli/ignite/pkg/xos" @@ -394,15 +397,20 @@ func (g generator) addBufDependency(ctx context.Context, depName string) error { return err } + g.opts.ev.Send( + fmt.Sprintf("New Buf dependency added: %s", colors.Name(depName)), + events.Icon(icons.OK), + ) + // Update Buf lock so it contains the new dependency return g.buf.Update(ctx, filepath.Dir(path), depName) } -func (g generator) vendorProtoPackage(pkgName, protoPath string) error { +func (g generator) vendorProtoPackage(pkgName, protoPath string) (err error) { // Check that the dependency vendor directory doesn't exist vendorRelPath := filepath.Join("proto_vendor", pkgName) vendorPath := filepath.Join(g.appPath, vendorRelPath) - _, err := os.Stat(vendorPath) + _, err = os.Stat(vendorPath) if err != nil && !os.IsNotExist(err) { return err } @@ -416,6 +424,13 @@ func (g generator) vendorProtoPackage(pkgName, protoPath string) error { return err } + // Make sure that the vendor folder is removed on error + defer func() { + if err != nil { + _ = os.RemoveAll(vendorPath) + } + }() + if err = xos.CopyFolder(protoPath, vendorPath); err != nil { return err } @@ -444,6 +459,14 @@ func (g generator) vendorProtoPackage(pkgName, protoPath string) error { enc := yaml.NewEncoder(f) defer enc.Close() + if err = enc.Encode(ws); err != nil { + return err + } - return enc.Encode(ws) + g.opts.ev.Send( + fmt.Sprintf("New Buf vendored dependency added: %s", colors.Name(vendorRelPath)), + events.Icon(icons.OK), + ) + + return nil } diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 28b80cfce6..b5dcac48ad 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -160,6 +160,7 @@ func (c *Chain) Generate( c.ev.Send("Building proto...", events.ProgressUpdate()) options := []cosmosgen.Option{ + cosmosgen.CollectEvents(c.ev), cosmosgen.IncludeDirs(conf.Build.Proto.ThirdPartyPaths), } From 1c97777af211c7d92841d572252b316a3431f8f2 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Thu, 2 Nov 2023 18:57:04 +0100 Subject: [PATCH 10/16] chore: remove invalid TODO comments --- ignite/pkg/cosmosgen/generate.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index bcdfb195c6..6424eef9d4 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -259,7 +259,6 @@ func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncl // When a Buf config exists export all protos needed // to build the modules to a temporary include folder. - // TODO: Should this be optional and not done for the app includes? Duplicates proto folder. bufProtoPath, err := g.generateBufIncludeFolder(ctx, protoPath) if err != nil && !errors.Is(err, cosmosbuf.ErrProtoFilesNotFound) { return protoIncludes{}, err @@ -356,7 +355,6 @@ func (g generator) resolveBufDependency(ctx context.Context, pkgName, bufPath st } func (g generator) addBufDependency(ctx context.Context, depName string) error { - // TODO: Check BSR before adding the dependency to app's Buf deps // Read app's Buf config path := g.appIncludes.BufPath bz, err := os.ReadFile(path) From 10cfe6d5fc63ac875ef4d15ebb48fc1316813fd0 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 8 Nov 2023 10:47:53 +0100 Subject: [PATCH 11/16] chore: add Buf config error variable Co-authored-by: Danilo Pantani --- ignite/pkg/cosmosgen/generate.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index 44527eabd6..cc7eef550e 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -33,9 +33,13 @@ const ( workFilename = "buf.work.yaml" ) -var protocGlobalInclude = xfilepath.List( - xfilepath.JoinFromHome(xfilepath.Path("local/include")), - xfilepath.JoinFromHome(xfilepath.Path(".local/include")), +var ( + ErrBufConfig = errors.New("invalid Buf config") + + protocGlobalInclude = xfilepath.List( + xfilepath.JoinFromHome(xfilepath.Path("local/include")), + xfilepath.JoinFromHome(xfilepath.Path(".local/include")), + ) ) // protoIncludes contains proto include paths for a package. @@ -65,7 +69,7 @@ type protoAnalysis struct { } func newBufConfigError(path string, cause error) error { - return fmt.Errorf("invalid Buf config: %s: %w", path, cause) + return fmt.Errorf("%w: %s: %w", ErrBufConfig, path, cause) } func (g *generator) setup(ctx context.Context) (err error) { From e37aaa0dd7907fb0accc471433b4dfea63dfb819 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 8 Nov 2023 11:03:49 +0100 Subject: [PATCH 12/16] chore: change `--update-buf-module` flag to be persistent Co-authored-by: Danilo Pantani --- ignite/cmd/generate.go | 3 +++ ignite/cmd/generate_go.go | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ignite/cmd/generate.go b/ignite/cmd/generate.go index 1de5a122f7..e417a1bda7 100644 --- a/ignite/cmd/generate.go +++ b/ignite/cmd/generate.go @@ -27,8 +27,11 @@ meant to be edited by hand. PersistentPreRunE: migrationPreRunHandler, } + c.PersistentFlags().AddFlagSet(flagSetUpdateBufModule()) + flagSetPath(c) flagSetClearCache(c) + c.AddCommand(NewGenerateGo()) c.AddCommand(NewGeneratePulsar()) c.AddCommand(NewGenerateTSClient()) diff --git a/ignite/cmd/generate_go.go b/ignite/cmd/generate_go.go index f1e9ed511e..f8b4537f7e 100644 --- a/ignite/cmd/generate_go.go +++ b/ignite/cmd/generate_go.go @@ -16,7 +16,6 @@ func NewGenerateGo() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().AddFlagSet(flagSetUpdateBufModule()) return c } From 39d52b0d9c023a91a3f472cb0b7937e2f576a9e2 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 8 Nov 2023 11:15:10 +0100 Subject: [PATCH 13/16] refactor: enable Buf dep vendoring for generate ts-client command This is required because OpenAPI generation is done using Buf while TS client is being generated. --- ignite/cmd/generate_typescript_client.go | 7 ++++++- ignite/pkg/cosmosgen/cosmosgen.go | 2 +- ignite/services/chain/generate.go | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ignite/cmd/generate_typescript_client.go b/ignite/cmd/generate_typescript_client.go index ed1bc5a1ae..44089f2e59 100644 --- a/ignite/cmd/generate_typescript_client.go +++ b/ignite/cmd/generate_typescript_client.go @@ -73,7 +73,12 @@ func generateTSClientHandler(cmd *cobra.Command, _ []string) error { return err } - err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output, useCache)) + updateBufModule := flagGetUpdateBufModule(cmd) + err = c.Generate( + cmd.Context(), + cacheStorage, + chain.GenerateTSClient(output, useCache, updateBufModule), + ) if err != nil { return err } diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index e6310f2e5b..1e08ad0006 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -181,7 +181,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir // Go dependency packages might contain proto files which could also // optionally be using Buf, so for those cases the discovered proto // files should be available before code generation. - if g.opts.updateBufModule && (g.opts.isGoEnabled || g.opts.isPulsarEnabled) { + if g.opts.updateBufModule { if err := g.updateBufModule(ctx); err != nil { return err } diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 6d51e5d120..2e46432bf2 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -52,12 +52,13 @@ func GeneratePulsar(updateBufModule bool) GenerateTarget { // GenerateTSClient enables generating proto based Typescript Client. // The path assigns the output path to use for the generated Typescript client // overriding the configured or default path. Path can be an empty string. -func GenerateTSClient(path string, useCache bool) GenerateTarget { +func GenerateTSClient(path string, useCache, updateBufModule bool) GenerateTarget { return func(o *generateOptions) { o.isOpenAPIEnabled = true o.isTSClientEnabled = true o.tsClientPath = path o.useCache = useCache + o.updateBufModule = updateBufModule } } @@ -114,7 +115,7 @@ func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Stora if generateClients { if p := conf.Client.Typescript.Path; p != "" { - targets = append(targets, GenerateTSClient(p, true)) + targets = append(targets, GenerateTSClient(p, true, false)) } //nolint:staticcheck //ignore SA1019 until vuex config option is removed From 1246448a22c40d400a94af7b1b1ff24013edc7a8 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 8 Nov 2023 11:56:11 +0100 Subject: [PATCH 14/16] refactor: add generate proto vendor target All generate commands require support for proto vendoring and Buf dependencies updates. A new target was added to make proto vendoring optional and to avoid using an extra argument in all generate targets. --- ignite/cmd/generate_composables.go | 8 ++++++- ignite/cmd/generate_go.go | 8 +++++-- ignite/cmd/generate_hooks.go | 8 ++++++- ignite/cmd/generate_openapi.go | 8 ++++++- ignite/cmd/generate_pulsar.go | 8 +++++-- ignite/cmd/generate_typescript_client.go | 12 +++++----- ignite/cmd/generate_vuex.go | 8 ++++++- ignite/services/chain/generate.go | 29 ++++++++++++++++-------- 8 files changed, 65 insertions(+), 24 deletions(-) diff --git a/ignite/cmd/generate_composables.go b/ignite/cmd/generate_composables.go index 67de559cd7..d7940b7c1a 100644 --- a/ignite/cmd/generate_composables.go +++ b/ignite/cmd/generate_composables.go @@ -44,7 +44,13 @@ func generateComposablesHandler(cmd *cobra.Command, _ []string) error { return err } - if err := c.Generate(cmd.Context(), cacheStorage, chain.GenerateComposables(output)); err != nil { + var opts []chain.GenerateTarget + if flagGetUpdateBufModule(cmd) { + opts = append(opts, chain.GenerateProtoVendor()) + } + + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateComposables(output), opts...) + if err != nil { return err } diff --git a/ignite/cmd/generate_go.go b/ignite/cmd/generate_go.go index f8b4537f7e..76c4615670 100644 --- a/ignite/cmd/generate_go.go +++ b/ignite/cmd/generate_go.go @@ -39,8 +39,12 @@ func generateGoHandler(cmd *cobra.Command, _ []string) error { return err } - updateBufModule := flagGetUpdateBufModule(cmd) - err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateGo(updateBufModule)) + var opts []chain.GenerateTarget + if flagGetUpdateBufModule(cmd) { + opts = append(opts, chain.GenerateProtoVendor()) + } + + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateGo(), opts...) if err != nil { return err } diff --git a/ignite/cmd/generate_hooks.go b/ignite/cmd/generate_hooks.go index 0af0be9d78..f42fd7fc4d 100644 --- a/ignite/cmd/generate_hooks.go +++ b/ignite/cmd/generate_hooks.go @@ -44,7 +44,13 @@ func generateHooksHandler(cmd *cobra.Command, _ []string) error { return err } - if err := c.Generate(cmd.Context(), cacheStorage, chain.GenerateHooks(output)); err != nil { + var opts []chain.GenerateTarget + if flagGetUpdateBufModule(cmd) { + opts = append(opts, chain.GenerateProtoVendor()) + } + + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateHooks(output), opts...) + if err != nil { return err } diff --git a/ignite/cmd/generate_openapi.go b/ignite/cmd/generate_openapi.go index 6b4e1e00c1..259cebe77b 100644 --- a/ignite/cmd/generate_openapi.go +++ b/ignite/cmd/generate_openapi.go @@ -39,7 +39,13 @@ func generateOpenAPIHandler(cmd *cobra.Command, _ []string) error { return err } - if err := c.Generate(cmd.Context(), cacheStorage, chain.GenerateOpenAPI()); err != nil { + var opts []chain.GenerateTarget + if flagGetUpdateBufModule(cmd) { + opts = append(opts, chain.GenerateProtoVendor()) + } + + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateOpenAPI(), opts...) + if err != nil { return err } diff --git a/ignite/cmd/generate_pulsar.go b/ignite/cmd/generate_pulsar.go index ca58d6f1e8..bbb3af598b 100644 --- a/ignite/cmd/generate_pulsar.go +++ b/ignite/cmd/generate_pulsar.go @@ -40,8 +40,12 @@ func generatePulsarHandler(cmd *cobra.Command, _ []string) error { return err } - updateBufModule := flagGetUpdateBufModule(cmd) - err = c.Generate(cmd.Context(), cacheStorage, chain.GeneratePulsar(updateBufModule)) + var opts []chain.GenerateTarget + if flagGetUpdateBufModule(cmd) { + opts = append(opts, chain.GenerateProtoVendor()) + } + + err = c.Generate(cmd.Context(), cacheStorage, chain.GeneratePulsar(), opts...) if err != nil { return err } diff --git a/ignite/cmd/generate_typescript_client.go b/ignite/cmd/generate_typescript_client.go index 44089f2e59..93301e6cf7 100644 --- a/ignite/cmd/generate_typescript_client.go +++ b/ignite/cmd/generate_typescript_client.go @@ -73,12 +73,12 @@ func generateTSClientHandler(cmd *cobra.Command, _ []string) error { return err } - updateBufModule := flagGetUpdateBufModule(cmd) - err = c.Generate( - cmd.Context(), - cacheStorage, - chain.GenerateTSClient(output, useCache, updateBufModule), - ) + var opts []chain.GenerateTarget + if flagGetUpdateBufModule(cmd) { + opts = append(opts, chain.GenerateProtoVendor()) + } + + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output, useCache), opts...) if err != nil { return err } diff --git a/ignite/cmd/generate_vuex.go b/ignite/cmd/generate_vuex.go index a28ea1ee64..e9a76aeeb2 100644 --- a/ignite/cmd/generate_vuex.go +++ b/ignite/cmd/generate_vuex.go @@ -45,7 +45,13 @@ func generateVuexHandler(cmd *cobra.Command, _ []string) error { return err } - if err := c.Generate(cmd.Context(), cacheStorage, chain.GenerateVuex(output)); err != nil { + var opts []chain.GenerateTarget + if flagGetUpdateBufModule(cmd) { + opts = append(opts, chain.GenerateProtoVendor()) + } + + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateVuex(output), opts...) + if err != nil { return err } diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 2e46432bf2..3ebcbfaedb 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -16,7 +16,7 @@ import ( type generateOptions struct { useCache bool - updateBufModule bool + isProtoVendorEnabled bool isGoEnabled bool isPulsarEnabled bool isTSClientEnabled bool @@ -34,31 +34,28 @@ type generateOptions struct { type GenerateTarget func(*generateOptions) // GenerateGo enables generating proto based Go code needed for the chain's source code. -func GenerateGo(updateBufModule bool) GenerateTarget { +func GenerateGo() GenerateTarget { return func(o *generateOptions) { o.isGoEnabled = true - o.updateBufModule = updateBufModule } } // GeneratePulsar enables generating proto based Go code needed for the chain's source code. -func GeneratePulsar(updateBufModule bool) GenerateTarget { +func GeneratePulsar() GenerateTarget { return func(o *generateOptions) { o.isPulsarEnabled = true - o.updateBufModule = updateBufModule } } // GenerateTSClient enables generating proto based Typescript Client. // The path assigns the output path to use for the generated Typescript client // overriding the configured or default path. Path can be an empty string. -func GenerateTSClient(path string, useCache, updateBufModule bool) GenerateTarget { +func GenerateTSClient(path string, useCache bool) GenerateTarget { return func(o *generateOptions) { o.isOpenAPIEnabled = true o.isTSClientEnabled = true o.tsClientPath = path o.useCache = useCache - o.updateBufModule = updateBufModule } } @@ -99,6 +96,18 @@ func GenerateOpenAPI() GenerateTarget { } } +// GenerateProtoVendor enables `proto_vendor` folder generation. +// Proto vendor is generated from Go dependencies that contain proto files that +// are not included in the app's Buf config. +// Enabling proto vendoring might update Buf config with missing dependencies +// if a Go dependency contains proto files and a Buf config with a name that is +// not listed in the Buf dependencies. +func GenerateProtoVendor() GenerateTarget { + return func(o *generateOptions) { + o.isProtoVendorEnabled = true + } +} + // generateFromConfig makes code generation from proto files from the given config. func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Storage, generateClients bool) error { conf, err := c.Config() @@ -115,7 +124,7 @@ func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Stora if generateClients { if p := conf.Client.Typescript.Path; p != "" { - targets = append(targets, GenerateTSClient(p, true, false)) + targets = append(targets, GenerateTSClient(p, true)) } //nolint:staticcheck //ignore SA1019 until vuex config option is removed @@ -133,7 +142,7 @@ func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Stora } // Generate proto based code for Go and optionally for any optional targets - return c.Generate(ctx, cacheStorage, GenerateGo(false), targets...) + return c.Generate(ctx, cacheStorage, GenerateGo(), targets...) } // Generate makes code generation from proto files for given target and additionalTargets. @@ -173,7 +182,7 @@ func (c *Chain) Generate( options = append(options, cosmosgen.WithPulsarGeneration()) } - if targetOptions.updateBufModule { + if targetOptions.isProtoVendorEnabled { options = append(options, cosmosgen.UpdateBufModule()) } From 6d93c2692fb4a067717352d711ffc2cb276daf57 Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 8 Nov 2023 12:04:49 +0100 Subject: [PATCH 15/16] chore: improve variable usage Co-authored-by: Danilo Pantani --- ignite/pkg/cosmosgen/generate.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index cc7eef550e..9fcac8cceb 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -258,14 +258,12 @@ func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncl includes.ProtoPath = protoPath // Check if a Buf config file is present - bufPath, err := g.findBufPath(protoPath) + includes.BufPath, err = g.findBufPath(protoPath) if err != nil { return includes, false, err } - if bufPath != "" { - includes.BufPath = bufPath - + if includes.BufPath != "" { // When a Buf config exists export all protos needed // to build the modules to a temporary include folder. bufProtoPath, err := g.generateBufIncludeFolder(ctx, protoPath) From 6fdc2897386f87b806efbb888e3273952503d72b Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Thu, 9 Nov 2023 14:52:27 +0100 Subject: [PATCH 16/16] refactor: rename proto vendoring flag to `--enable-proto-vendor` --- ignite/cmd/generate.go | 12 ++++++------ ignite/cmd/generate_composables.go | 2 +- ignite/cmd/generate_go.go | 2 +- ignite/cmd/generate_hooks.go | 2 +- ignite/cmd/generate_openapi.go | 2 +- ignite/cmd/generate_pulsar.go | 3 +-- ignite/cmd/generate_typescript_client.go | 2 +- ignite/cmd/generate_vuex.go | 2 +- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ignite/cmd/generate.go b/ignite/cmd/generate.go index e417a1bda7..9e366c012a 100644 --- a/ignite/cmd/generate.go +++ b/ignite/cmd/generate.go @@ -6,7 +6,7 @@ import ( ) const ( - flagUpdateBufModule = "update-buf-module" + flagEnableProtoVendor = "enable-proto-vendor" ) // NewGenerate returns a command that groups code generation related sub commands. @@ -27,7 +27,7 @@ meant to be edited by hand. PersistentPreRunE: migrationPreRunHandler, } - c.PersistentFlags().AddFlagSet(flagSetUpdateBufModule()) + c.PersistentFlags().AddFlagSet(flagSetEnableProtoVendor()) flagSetPath(c) flagSetClearCache(c) @@ -43,13 +43,13 @@ meant to be edited by hand. return c } -func flagSetUpdateBufModule() *flag.FlagSet { +func flagSetEnableProtoVendor() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) - fs.Bool(flagUpdateBufModule, false, "update Buf config with missing proto dependencies") + fs.Bool(flagEnableProtoVendor, false, "enable proto package vendor for missing Buf dependencies") return fs } -func flagGetUpdateBufModule(cmd *cobra.Command) bool { - skip, _ := cmd.Flags().GetBool(flagUpdateBufModule) +func flagGetEnableProtoVendor(cmd *cobra.Command) bool { + skip, _ := cmd.Flags().GetBool(flagEnableProtoVendor) return skip } diff --git a/ignite/cmd/generate_composables.go b/ignite/cmd/generate_composables.go index d7940b7c1a..258a9acc47 100644 --- a/ignite/cmd/generate_composables.go +++ b/ignite/cmd/generate_composables.go @@ -45,7 +45,7 @@ func generateComposablesHandler(cmd *cobra.Command, _ []string) error { } var opts []chain.GenerateTarget - if flagGetUpdateBufModule(cmd) { + if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) } diff --git a/ignite/cmd/generate_go.go b/ignite/cmd/generate_go.go index 76c4615670..263ebd388b 100644 --- a/ignite/cmd/generate_go.go +++ b/ignite/cmd/generate_go.go @@ -40,7 +40,7 @@ func generateGoHandler(cmd *cobra.Command, _ []string) error { } var opts []chain.GenerateTarget - if flagGetUpdateBufModule(cmd) { + if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) } diff --git a/ignite/cmd/generate_hooks.go b/ignite/cmd/generate_hooks.go index f42fd7fc4d..76f125f498 100644 --- a/ignite/cmd/generate_hooks.go +++ b/ignite/cmd/generate_hooks.go @@ -45,7 +45,7 @@ func generateHooksHandler(cmd *cobra.Command, _ []string) error { } var opts []chain.GenerateTarget - if flagGetUpdateBufModule(cmd) { + if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) } diff --git a/ignite/cmd/generate_openapi.go b/ignite/cmd/generate_openapi.go index 259cebe77b..e0795e0d06 100644 --- a/ignite/cmd/generate_openapi.go +++ b/ignite/cmd/generate_openapi.go @@ -40,7 +40,7 @@ func generateOpenAPIHandler(cmd *cobra.Command, _ []string) error { } var opts []chain.GenerateTarget - if flagGetUpdateBufModule(cmd) { + if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) } diff --git a/ignite/cmd/generate_pulsar.go b/ignite/cmd/generate_pulsar.go index bbb3af598b..080063d980 100644 --- a/ignite/cmd/generate_pulsar.go +++ b/ignite/cmd/generate_pulsar.go @@ -16,7 +16,6 @@ func NewGeneratePulsar() *cobra.Command { } c.Flags().AddFlagSet(flagSetYes()) - c.Flags().AddFlagSet(flagSetUpdateBufModule()) return c } @@ -41,7 +40,7 @@ func generatePulsarHandler(cmd *cobra.Command, _ []string) error { } var opts []chain.GenerateTarget - if flagGetUpdateBufModule(cmd) { + if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) } diff --git a/ignite/cmd/generate_typescript_client.go b/ignite/cmd/generate_typescript_client.go index 93301e6cf7..3bb349ca73 100644 --- a/ignite/cmd/generate_typescript_client.go +++ b/ignite/cmd/generate_typescript_client.go @@ -74,7 +74,7 @@ func generateTSClientHandler(cmd *cobra.Command, _ []string) error { } var opts []chain.GenerateTarget - if flagGetUpdateBufModule(cmd) { + if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) } diff --git a/ignite/cmd/generate_vuex.go b/ignite/cmd/generate_vuex.go index e9a76aeeb2..41880b4aa3 100644 --- a/ignite/cmd/generate_vuex.go +++ b/ignite/cmd/generate_vuex.go @@ -46,7 +46,7 @@ func generateVuexHandler(cmd *cobra.Command, _ []string) error { } var opts []chain.GenerateTarget - if flagGetUpdateBufModule(cmd) { + if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) }