Skip to content

Commit

Permalink
Merge branch 'main' into chore/ts-dep-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Nov 6, 2023
2 parents 9731816 + 897b1cc commit 3b363e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- [#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
- [#3726](https://github.com/ignite/cli/pull/3726) Update TS client dependencies. Bump vue/react template versions
- [#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

0 comments on commit 3b363e7

Please sign in to comment.