Skip to content

Commit ee9f371

Browse files
authored
feat(chain): add skip-proto flag (ignite#2696)
* change interface * add flag * add option * add changelog * refactor from comments
1 parent 9a38a64 commit ee9f371

File tree

9 files changed

+60
-12
lines changed

9 files changed

+60
-12
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Add `--skip-proto` flag to `build`, `init` and `serve` commands to build the chain without building proto files
8+
39
## [`v0.23.0`](https://github.com/ignite/cli/releases/tag/v0.23.0)
410

511
### Features

ignite/cmd/chain_build.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Sample usages:
4545
c.Flags().AddFlagSet(flagSetHome())
4646
c.Flags().AddFlagSet(flagSetProto3rdParty("Available only without the --release flag"))
4747
c.Flags().AddFlagSet(flagSetCheckDependencies())
48+
c.Flags().AddFlagSet(flagSetSkipProto())
4849
c.Flags().Bool(flagRelease, false, "build for a release")
4950
c.Flags().StringSliceP(flagReleaseTargets, "t", []string{}, "release targets. Available only with --release flag")
5051
c.Flags().String(flagReleasePrefix, "", "tarball prefix for each release target. Available only with --release flag")
@@ -96,7 +97,7 @@ func chainBuildHandler(cmd *cobra.Command, _ []string) error {
9697
return nil
9798
}
9899

99-
binaryName, err := c.Build(cmd.Context(), cacheStorage, output)
100+
binaryName, err := c.Build(cmd.Context(), cacheStorage, output, flagGetSkipProto(cmd))
100101
if err != nil {
101102
return err
102103
}

ignite/cmd/chain_init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func NewChainInit() *cobra.Command {
2222
flagSetClearCache(c)
2323
c.Flags().AddFlagSet(flagSetHome())
2424
c.Flags().AddFlagSet(flagSetCheckDependencies())
25+
c.Flags().AddFlagSet(flagSetSkipProto())
2526

2627
return c
2728
}
@@ -46,7 +47,7 @@ func chainInitHandler(cmd *cobra.Command, _ []string) error {
4647
return err
4748
}
4849

49-
if _, err := c.Build(cmd.Context(), cacheStorage, ""); err != nil {
50+
if _, err := c.Build(cmd.Context(), cacheStorage, "", flagGetSkipProto(cmd)); err != nil {
5051
return err
5152
}
5253

ignite/cmd/chain_serve.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func NewChainServe() *cobra.Command {
2727
c.Flags().AddFlagSet(flagSetHome())
2828
c.Flags().AddFlagSet(flagSetProto3rdParty(""))
2929
c.Flags().AddFlagSet(flagSetCheckDependencies())
30+
c.Flags().AddFlagSet(flagSetSkipProto())
3031
c.Flags().BoolP("verbose", "v", false, "Verbose output")
3132
c.Flags().BoolP(flagForceReset, "f", false, "Force reset of the app state on start and every source change")
3233
c.Flags().BoolP(flagResetOnce, "r", false, "Reset of the app state on first start")
@@ -85,5 +86,9 @@ func chainServeHandler(cmd *cobra.Command, args []string) error {
8586
serveOptions = append(serveOptions, chain.ServeResetOnce())
8687
}
8788

89+
if flagGetSkipProto(cmd) {
90+
serveOptions = append(serveOptions, chain.ServeSkipProto())
91+
}
92+
8893
return c.Serve(cmd.Context(), cacheStorage, serveOptions...)
8994
}

ignite/cmd/cmd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
flagProto3rdParty = "proto-all-modules"
3333
flagYes = "yes"
3434
flagClearCache = "clear-cache"
35+
flagSkipProto = "skip-proto"
3536

3637
checkVersionTimeout = time.Millisecond * 600
3738
cacheFileName = "ignite_cache.db"
@@ -140,6 +141,17 @@ func flagGetProto3rdParty(cmd *cobra.Command) bool {
140141
return isEnabled
141142
}
142143

144+
func flagSetSkipProto() *flag.FlagSet {
145+
fs := flag.NewFlagSet("", flag.ContinueOnError)
146+
fs.Bool(flagSkipProto, false, "Skip file generation from proto")
147+
return fs
148+
}
149+
150+
func flagGetSkipProto(cmd *cobra.Command) bool {
151+
skip, _ := cmd.Flags().GetBool(flagSkipProto)
152+
return skip
153+
}
154+
143155
func flagSetClearCache(cmd *cobra.Command) {
144156
cmd.PersistentFlags().Bool(flagClearCache, false, "Clear the build cache (advanced)")
145157
}

ignite/services/chain/build.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,29 @@ const (
3030
)
3131

3232
// Build builds and installs app binaries.
33-
func (c *Chain) Build(ctx context.Context, cacheStorage cache.Storage, output string) (binaryName string, err error) {
33+
func (c *Chain) Build(
34+
ctx context.Context,
35+
cacheStorage cache.Storage,
36+
output string,
37+
skipProto bool,
38+
) (binaryName string, err error) {
3439
if err := c.setup(); err != nil {
3540
return "", err
3641
}
3742

38-
if err := c.build(ctx, cacheStorage, output); err != nil {
43+
if err := c.build(ctx, cacheStorage, output, skipProto); err != nil {
3944
return "", err
4045
}
4146

4247
return c.Binary()
4348
}
4449

45-
func (c *Chain) build(ctx context.Context, cacheStorage cache.Storage, output string) (err error) {
50+
func (c *Chain) build(
51+
ctx context.Context,
52+
cacheStorage cache.Storage,
53+
output string,
54+
skipProto bool,
55+
) (err error) {
4656
defer func() {
4757
var exitErr *exec.ExitError
4858

@@ -51,8 +61,11 @@ func (c *Chain) build(ctx context.Context, cacheStorage cache.Storage, output st
5161
}
5262
}()
5363

54-
if err := c.generateAll(ctx, cacheStorage); err != nil {
55-
return err
64+
// generate from proto files
65+
if !skipProto {
66+
if err := c.generateFromConfig(ctx, cacheStorage); err != nil {
67+
return err
68+
}
5669
}
5770

5871
buildFlags, err := c.preBuild(ctx, cacheStorage)

ignite/services/chain/generate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ func GenerateOpenAPI() GenerateTarget {
5555
}
5656
}
5757

58-
func (c *Chain) generateAll(ctx context.Context, cacheStorage cache.Storage) error {
58+
// generateFromConfig makes code generation from proto files from the given config
59+
func (c *Chain) generateFromConfig(ctx context.Context, cacheStorage cache.Storage) error {
5960
conf, err := c.Config()
6061
if err != nil {
6162
return err
6263
}
6364

6465
var additionalTargets []GenerateTarget
6566

67+
// parse config for additional target
6668
if conf.Client.Vuex.Path != "" {
6769
additionalTargets = append(additionalTargets, GenerateVuex())
6870
}

ignite/services/chain/serve.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
type serveOptions struct {
5858
forceReset bool
5959
resetOnce bool
60+
skipProto bool
6061
}
6162

6263
func newServeOption() serveOptions {
@@ -83,6 +84,13 @@ func ServeResetOnce() ServeOption {
8384
}
8485
}
8586

87+
// ServeSkipProto allows to serve the app without generate Go from proto
88+
func ServeSkipProto() ServeOption {
89+
return func(c *serveOptions) {
90+
c.skipProto = true
91+
}
92+
}
93+
8694
// Serve serves an app.
8795
func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options ...ServeOption) error {
8896
serveOptions := newServeOption()
@@ -138,7 +146,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options .
138146
shouldReset := serveOptions.forceReset || serveOptions.resetOnce
139147

140148
// serve the app.
141-
err = c.serve(serveCtx, cacheStorage, shouldReset)
149+
err = c.serve(serveCtx, cacheStorage, shouldReset, serveOptions.skipProto)
142150
serveOptions.resetOnce = false
143151

144152
switch {
@@ -247,7 +255,7 @@ func (c *Chain) watchAppBackend(ctx context.Context) error {
247255
// serve performs the operations to serve the blockchain: build, init and start
248256
// if the chain is already initialized and the file didn't changed, the app is directly started
249257
// if the files changed, the state is imported
250-
func (c *Chain) serve(ctx context.Context, cacheStorage cache.Storage, forceReset bool) error {
258+
func (c *Chain) serve(ctx context.Context, cacheStorage cache.Storage, forceReset, skipProto bool) error {
251259
conf, err := c.Config()
252260
if err != nil {
253261
return &CannotBuildAppError{err}
@@ -328,7 +336,7 @@ func (c *Chain) serve(ctx context.Context, cacheStorage cache.Storage, forceRese
328336
// build phase
329337
if !isInit || appModified {
330338
// build the blockchain app
331-
if err := c.build(ctx, cacheStorage, ""); err != nil {
339+
if err := c.build(ctx, cacheStorage, "", skipProto); err != nil {
332340
return err
333341
}
334342
}

ignite/services/network/networkchain/networkchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (c *Chain) Build(ctx context.Context, cacheStorage cache.Storage) (binaryNa
290290
c.ev.Send(events.New(events.StatusOngoing, "Building the chain's binary"))
291291

292292
// build binary
293-
if binaryName, err = c.chain.Build(ctx, cacheStorage, ""); err != nil {
293+
if binaryName, err = c.chain.Build(ctx, cacheStorage, "", true); err != nil {
294294
return "", err
295295
}
296296

0 commit comments

Comments
 (0)