Skip to content

Commit

Permalink
Merge branch 'main' into feat/buf-dependency-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jeronimoalbi committed Nov 3, 2023
2 parents 1c97777 + 897b1cc commit 9120b40
Show file tree
Hide file tree
Showing 2 changed files with 19 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 @@
- [#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
31 changes: 18 additions & 13 deletions ignite/pkg/cosmosgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (g *generator) setup(ctx context.Context) (err error) {
return err
}

g.appIncludes, err = g.resolveIncludes(ctx, g.appPath)
g.appIncludes, _, err = g.resolveIncludes(ctx, g.appPath)

Check warning on line 117 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L117

Added line #L117 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -156,9 +156,12 @@ func (g *generator) setup(ctx context.Context) (err error) {
}

// Dependency/includes resolution per module is done to solve versioning issues
var includes protoIncludes
var (
includes protoIncludes
cacheable = true
)

Check warning on line 162 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L159-L162

Added lines #L159 - L162 were not covered by tests
if len(modules) > 0 {
includes, err = g.resolveIncludes(ctx, path)
includes, cacheable, err = g.resolveIncludes(ctx, path)

Check warning on line 164 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L164

Added line #L164 was not covered by tests
if err != nil {
return err
}
Expand All @@ -170,8 +173,10 @@ func (g *generator) setup(ctx context.Context) (err error) {
Includes: includes,
}

Check warning on line 175 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L175

Added line #L175 was not covered by tests
if err := moduleCache.Put(cacheKey, depInfo); err != nil {
return err
if cacheable {
if err = moduleCache.Put(cacheKey, depInfo); err != nil {

Check warning on line 177 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L177

Added line #L177 was not covered by tests
return err
}
}
}

Expand Down Expand Up @@ -225,11 +230,11 @@ func (g *generator) generateBufIncludeFolder(ctx context.Context, modpath string
return protoPath, nil
}

func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncludes, error) {
func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncludes, bool, error) {

Check warning on line 233 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L233

Added line #L233 was not covered by tests
// Init paths with the global include paths for protoc
paths, err := protocGlobalInclude()

Check warning on line 235 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L235

Added line #L235 was not covered by tests
if err != nil {
return protoIncludes{}, err
return protoIncludes{}, false, err

Check warning on line 237 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L237

Added line #L237 was not covered by tests
}

includes := protoIncludes{Paths: paths}
Expand All @@ -238,10 +243,10 @@ func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncl
protoPath := filepath.Join(path, g.protoDir)
fi, err := os.Stat(protoPath)
if err != nil && !os.IsNotExist(err) {
return protoIncludes{}, err
return protoIncludes{}, false, err

Check warning on line 246 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L246

Added line #L246 was not covered by tests
} else if !fi.IsDir() {
// Just return the global includes when a proto directory doesn't exist
return includes, nil
return includes, true, nil

Check warning on line 249 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L249

Added line #L249 was not covered by tests
}

// Add app's proto path to the list of proto paths
Expand All @@ -251,7 +256,7 @@ func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncl
// Check if a Buf config file is present
bufPath, err := g.findBufPath(protoPath)
if err != nil {
return includes, err
return includes, false, err

Check warning on line 259 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L259

Added line #L259 was not covered by tests
}

if bufPath != "" {
Expand All @@ -261,21 +266,21 @@ func (g *generator) resolveIncludes(ctx context.Context, path string) (protoIncl
// to build the modules to a temporary include folder.
bufProtoPath, err := g.generateBufIncludeFolder(ctx, protoPath)

Check warning on line 267 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L263-L267

Added lines #L263 - L267 were not covered by tests
if err != nil && !errors.Is(err, cosmosbuf.ErrProtoFilesNotFound) {
return protoIncludes{}, err
return protoIncludes{}, false, err

Check warning on line 269 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L269

Added line #L269 was not covered by tests
}

// Use exported files only when the path contains ".proto" files
if bufProtoPath != "" {
includes.Paths = append(includes.Paths, bufProtoPath)
return includes, nil
return includes, false, nil

Check warning on line 275 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L273-L275

Added lines #L273 - L275 were not covered by tests
}
}

// 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
return includes, true, nil

Check warning on line 283 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L281-L283

Added lines #L281 - L283 were not covered by tests
}

func (g *generator) discoverModules(ctx context.Context, path, protoDir string) ([]module.Module, error) {

Check warning on line 286 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L286

Added line #L286 was not covered by tests
Expand Down

0 comments on commit 9120b40

Please sign in to comment.