Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't cache modules with tmp includes #3729

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [#3661](https://github.com/ignite/cli/pull/3661) Change `pkg/cosmosanalysis` to find Cosmos SDK runtime app registered modules
- [#3716](https://github.com/ignite/cli/pull/3716) Fix invalid plugin hook check
- [#3725](https://github.com/ignite/cli/pull/3725) Fix flaky TS client generation issues on linux
- [#3729](https://github.com/ignite/cli/pull/3729) Fix broken generator due to caching /tmp include folders

## [`v0.27.0`](https://github.com/ignite/cli/releases/tag/v0.27.0)

Expand Down
28 changes: 15 additions & 13 deletions ignite/pkg/cosmosgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (g *generator) setup() (err error) {
if err != nil {
return err
}
g.appIncludes, err = g.resolveIncludes(g.appPath)
g.appIncludes, _, err = g.resolveIncludes(g.appPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -120,9 +120,10 @@ func (g *generator) setup() (err error) {
}

var includes []string
cacheable := true
if len(modules) > 0 {
// For versioning issues, we do dependency/includes resolution per module
includes, err = g.resolveIncludes(path)
includes, cacheable, err = g.resolveIncludes(path)
if err != nil {
return err
}
Expand All @@ -133,9 +134,10 @@ func (g *generator) setup() (err error) {
Modules: modules,
Includes: includes,
}

if err := moduleCache.Put(cacheKey, modulesInPath); err != nil {
return err
if cacheable {
if err := moduleCache.Put(cacheKey, modulesInPath); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -197,21 +199,21 @@ 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) (paths []string, cacheable bool, err error) {
// Init paths with the global include paths for protoc
paths, err = protocGlobalInclude()
if err != nil {
return nil, err
return nil, false, err
}

// Check that the app proto directory exists
protoPath := filepath.Join(path, g.protoDir)
fi, err := os.Stat(protoPath)
if err != nil && !os.IsNotExist(err) {
return nil, err
return nil, false, err
} else if !fi.IsDir() {
// Just return the global includes when a proto directory doesn't exist
return paths, nil
return paths, true, nil
}

// Add app's proto path to the list of proto paths
Expand All @@ -220,25 +222,25 @@ func (g *generator) resolveIncludes(path string) (paths []string, err error) {
// Check if a Buf config file is present
bufPath, err := g.findBufPath(protoPath)
if err != nil {
return nil, err
return nil, false, 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)
if err != nil && !errors.Is(err, cosmosbuf.ErrProtoFilesNotFound) {
return nil, err
return nil, false, err
}

// Use exported files only when the path contains ".proto" files
if includePath != "" {
return append(paths, includePath), nil
return append(paths, includePath), false, nil
}
}

// By default use the configured directories
return append(paths, g.getProtoIncludeFolders(path)...), nil
return append(paths, g.getProtoIncludeFolders(path)...), true, nil
}

func (g *generator) discoverModules(path, protoDir string) ([]module.Module, error) {
Expand Down
Loading