Skip to content

Commit

Permalink
feat(cmd): allow to manually skip rebuilding (#4457)
Browse files Browse the repository at this point in the history
* feat(cmd): allow to manually skip rebuilding

* updates
  • Loading branch information
julienrbrt authored Jan 9, 2025
1 parent 4e57f4f commit ffa901e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

### Changes

- [#4457](https://github.com/ignite/cli/pull/4457) Add `ski-build` flag to `chain serve` command to avoid building the chain
- [#4094](https://github.com/ignite/cli/pull/4094) Scaffolding a multi-index map using `ignite s map foo bar baz --index foobar,foobaz` is no longer supported. Use one index instead of use `collections.IndexedMap`.
- [#4058](https://github.com/ignite/cli/pull/4058) Simplify scaffolded modules by including `ValidateBasic()` logic in message handler.
- [#4058](https://github.com/ignite/cli/pull/4058) Use `address.Codec` instead of `AccAddressFromBech32`.
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 @@ -71,6 +71,7 @@ production, you may want to run "appd start" manually.
c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetCheckDependencies())
c.Flags().AddFlagSet(flagSetSkipProto())
c.Flags().AddFlagSet(flagSetSkipBuild())
c.Flags().AddFlagSet(flagSetVerbose())
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 the app state once on init")
Expand Down Expand Up @@ -183,6 +184,10 @@ func chainServe(cmd *cobra.Command, session *cliui.Session) error {
serveOptions = append(serveOptions, chain.ServeSkipProto())
}

if flagGetSkipBuild(cmd) {
serveOptions = append(serveOptions, chain.ServeSkipBuild())
}

if quitOnFail {
serveOptions = append(serveOptions, chain.QuitOnFail())
}
Expand Down
12 changes: 12 additions & 0 deletions ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
flagYes = "yes"
flagClearCache = "clear-cache"
flagSkipProto = "skip-proto"
flagSkipBuild = "skip-build"

checkVersionTimeout = time.Millisecond * 600
cacheFileName = "ignite_cache.db"
Expand Down Expand Up @@ -216,6 +217,17 @@ func flagGetSkipProto(cmd *cobra.Command) bool {
return skip
}

func flagSetSkipBuild() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.Bool(flagSkipBuild, false, "skip initial build of the app (uses local binary)")
return fs
}

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

func flagSetClearCache(cmd *cobra.Command) {
cmd.PersistentFlags().Bool(flagClearCache, false, "clear the build cache (advanced)")
}
Expand Down
20 changes: 18 additions & 2 deletions ignite/services/chain/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type serveOptions struct {
forceReset bool
resetOnce bool
skipProto bool
skipBuild bool
quitOnFail bool
generateClients bool
buildTags []string
Expand Down Expand Up @@ -119,6 +120,14 @@ func ServeSkipProto() ServeOption {
}
}

// ServeSkipBuild allows to serve the app without rebuilding it.
// It looks up the binary in the PATH.
func ServeSkipBuild() ServeOption {
return func(c *serveOptions) {
c.skipBuild = true
}
}

// BuildTags set the build tags for the go build.
func BuildTags(buildTags ...string) ServeOption {
return func(c *serveOptions) {
Expand Down Expand Up @@ -190,6 +199,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options .
serveOptions.buildTags,
shouldReset,
serveOptions.skipProto,
serveOptions.skipBuild,
serveOptions.generateClients,
)
serveOptions.resetOnce = false
Expand Down Expand Up @@ -324,7 +334,7 @@ func (c *Chain) serve(
ctx context.Context,
cacheStorage cache.Storage,
buildTags []string,
forceReset, skipProto, generateClients bool,
forceReset, skipProto, skipBuild, generateClients bool,
) error {
conf, err := c.Config()
if err != nil {
Expand Down Expand Up @@ -406,7 +416,13 @@ func (c *Chain) serve(
}

// build phase
if !isInit || appModified {
// if the app is not initialized or the source/binary has been modified
// and if the --skip-build flag is not set
if skipBuild {
c.ev.SendInfo("Skip building activated. Binary won't be rebuilt, nor refresh on changes")
}

if (!isInit || appModified) && !skipBuild {
// build the blockchain app
if err := c.build(ctx, cacheStorage, buildTags, "", skipProto, generateClients, true); err != nil {
return err
Expand Down

0 comments on commit ffa901e

Please sign in to comment.