Skip to content
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
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Add `--skip-proto` flag to `build`, `init` and `serve` commands to build the chain without building proto files

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

### Features
Expand Down
3 changes: 2 additions & 1 deletion ignite/cmd/chain_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Sample usages:
c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetProto3rdParty("Available only without the --release flag"))
c.Flags().AddFlagSet(flagSetCheckDependencies())
c.Flags().AddFlagSet(flagSetSkipProto())
c.Flags().Bool(flagRelease, false, "build for a release")
c.Flags().StringSliceP(flagReleaseTargets, "t", []string{}, "release targets. Available only with --release flag")
c.Flags().String(flagReleasePrefix, "", "tarball prefix for each release target. Available only with --release flag")
Expand Down Expand Up @@ -96,7 +97,7 @@ func chainBuildHandler(cmd *cobra.Command, _ []string) error {
return nil
}

binaryName, err := c.Build(cmd.Context(), cacheStorage, output)
binaryName, err := c.Build(cmd.Context(), cacheStorage, output, flagGetSkipProto(cmd))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion ignite/cmd/chain_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewChainInit() *cobra.Command {
flagSetClearCache(c)
c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetCheckDependencies())
c.Flags().AddFlagSet(flagSetSkipProto())

return c
}
Expand All @@ -46,7 +47,7 @@ func chainInitHandler(cmd *cobra.Command, _ []string) error {
return err
}

if _, err := c.Build(cmd.Context(), cacheStorage, ""); err != nil {
if _, err := c.Build(cmd.Context(), cacheStorage, "", flagGetSkipProto(cmd)); err != nil {
return err
}

Expand Down
5 changes: 5 additions & 0 deletions ignite/cmd/chain_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewChainServe() *cobra.Command {
c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetProto3rdParty(""))
c.Flags().AddFlagSet(flagSetCheckDependencies())
c.Flags().AddFlagSet(flagSetSkipProto())
c.Flags().BoolP("verbose", "v", false, "Verbose output")
c.Flags().BoolP(flagForceReset, "f", false, "Force reset of the app state on start and every source change")
c.Flags().BoolP(flagResetOnce, "r", false, "Reset of the app state on first start")
Expand Down Expand Up @@ -85,5 +86,9 @@ func chainServeHandler(cmd *cobra.Command, args []string) error {
serveOptions = append(serveOptions, chain.ServeResetOnce())
}

if flagGetSkipProto(cmd) {
serveOptions = append(serveOptions, chain.ServeSkipProto())
}

return c.Serve(cmd.Context(), cacheStorage, serveOptions...)
}
12 changes: 12 additions & 0 deletions ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
flagProto3rdParty = "proto-all-modules"
flagYes = "yes"
flagClearCache = "clear-cache"
flagSkipProto = "skip-proto"

checkVersionTimeout = time.Millisecond * 600
cacheFileName = "ignite_cache.db"
Expand Down Expand Up @@ -140,6 +141,17 @@ func flagGetProto3rdParty(cmd *cobra.Command) bool {
return isEnabled
}

func flagSetSkipProto() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.Bool(flagSkipProto, false, "Skip file generation from proto")
return fs
}

func flagGetSkipProto(cmd *cobra.Command) bool {
skip, _ := cmd.Flags().GetBool(flagSkipProto)
return skip
}

func flagSetClearCache(cmd *cobra.Command) {
cmd.PersistentFlags().Bool(flagClearCache, false, "Clear the build cache (advanced)")
}
Expand Down
23 changes: 18 additions & 5 deletions ignite/services/chain/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ const (
)

// Build builds and installs app binaries.
func (c *Chain) Build(ctx context.Context, cacheStorage cache.Storage, output string) (binaryName string, err error) {
func (c *Chain) Build(
ctx context.Context,
cacheStorage cache.Storage,
output string,
skipProto bool,
) (binaryName string, err error) {
if err := c.setup(); err != nil {
return "", err
}

if err := c.build(ctx, cacheStorage, output); err != nil {
if err := c.build(ctx, cacheStorage, output, skipProto); err != nil {
return "", err
}

return c.Binary()
}

func (c *Chain) build(ctx context.Context, cacheStorage cache.Storage, output string) (err error) {
func (c *Chain) build(
ctx context.Context,
cacheStorage cache.Storage,
output string,
skipProto bool,
) (err error) {
defer func() {
var exitErr *exec.ExitError

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

if err := c.generateAll(ctx, cacheStorage); err != nil {
return err
// generate from proto files
if !skipProto {
if err := c.generateFromConfig(ctx, cacheStorage); err != nil {
return err
}
}

buildFlags, err := c.preBuild(ctx, cacheStorage)
Expand Down
4 changes: 3 additions & 1 deletion ignite/services/chain/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ func GenerateOpenAPI() GenerateTarget {
}
}

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

var additionalTargets []GenerateTarget

// parse config for additional target
if conf.Client.Vuex.Path != "" {
additionalTargets = append(additionalTargets, GenerateVuex())
}
Expand Down
14 changes: 11 additions & 3 deletions ignite/services/chain/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
type serveOptions struct {
forceReset bool
resetOnce bool
skipProto bool
}

func newServeOption() serveOptions {
Expand All @@ -83,6 +84,13 @@ func ServeResetOnce() ServeOption {
}
}

// ServeSkipProto allows to serve the app without generate Go from proto
func ServeSkipProto() ServeOption {
return func(c *serveOptions) {
c.skipProto = true
}
}

// Serve serves an app.
func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options ...ServeOption) error {
serveOptions := newServeOption()
Expand Down Expand Up @@ -138,7 +146,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options .
shouldReset := serveOptions.forceReset || serveOptions.resetOnce

// serve the app.
err = c.serve(serveCtx, cacheStorage, shouldReset)
err = c.serve(serveCtx, cacheStorage, shouldReset, serveOptions.skipProto)
serveOptions.resetOnce = false

switch {
Expand Down Expand Up @@ -247,7 +255,7 @@ func (c *Chain) watchAppBackend(ctx context.Context) error {
// serve performs the operations to serve the blockchain: build, init and start
// if the chain is already initialized and the file didn't changed, the app is directly started
// if the files changed, the state is imported
func (c *Chain) serve(ctx context.Context, cacheStorage cache.Storage, forceReset bool) error {
func (c *Chain) serve(ctx context.Context, cacheStorage cache.Storage, forceReset, skipProto bool) error {
conf, err := c.Config()
if err != nil {
return &CannotBuildAppError{err}
Expand Down Expand Up @@ -328,7 +336,7 @@ func (c *Chain) serve(ctx context.Context, cacheStorage cache.Storage, forceRese
// build phase
if !isInit || appModified {
// build the blockchain app
if err := c.build(ctx, cacheStorage, ""); err != nil {
if err := c.build(ctx, cacheStorage, "", skipProto); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion ignite/services/network/networkchain/networkchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (c *Chain) Build(ctx context.Context, cacheStorage cache.Storage) (binaryNa
c.ev.Send(events.New(events.StatusOngoing, "Building the chain's binary"))

// build binary
if binaryName, err = c.chain.Build(ctx, cacheStorage, ""); err != nil {
if binaryName, err = c.chain.Build(ctx, cacheStorage, "", true); err != nil {
return "", err
}

Expand Down