Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom proto path #4071

Merged
merged 32 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f3a712f
support custom proto path
Apr 4, 2024
6f65cb3
Merge branch 'main' into feat/custom-proto-path
Pantani Apr 4, 2024
9fcff90
add changelog
Apr 4, 2024
95c96fc
check buf work proto
Apr 4, 2024
160b762
check if the buf.work.yaml has the same proto path from the config file
Apr 4, 2024
15ba5c6
add comments
Apr 4, 2024
3b03538
rmeove unused code
Apr 4, 2024
a9474b4
remove unused proto paths and add integrations tests
Apr 4, 2024
3012a9b
fix resolve includes function
Apr 4, 2024
33bd6eb
fix integration tests
Apr 4, 2024
3e80404
scaffold a list into the tests
Apr 5, 2024
9b0808b
proto dir flag
Apr 5, 2024
39338ac
avoid read config for scaffold commands
Apr 5, 2024
2933962
fix wrong embed path
Apr 5, 2024
8b73bce
scaffold a chain with a custom proto path
Apr 5, 2024
ecf03b1
fix proto-dir flag
Apr 5, 2024
e93fbfa
fix protoDir var for plush files
Apr 5, 2024
dd96bb4
fix buf pkg
Apr 5, 2024
f201eed
fix unit tests for buf files
Apr 5, 2024
4aa2f33
add proto dir to scaffold chain
Apr 6, 2024
3c041cf
fix wrong prodir for the module
Apr 6, 2024
53a443d
fix wrong proto dir
Apr 6, 2024
02b9687
fix text scaffold conflits
Apr 6, 2024
02e8dff
Merge remote-tracking branch 'origin/main' into feat/custom-proto-path
Apr 8, 2024
4bc120f
fix wront proto path
Apr 9, 2024
d2fbcc6
Merge branch 'main' into feat/custom-proto-path
Pantani Apr 12, 2024
be7f00d
Merge branch 'main' into feat/custom-proto-path
Pantani Apr 16, 2024
9118645
Merge branch 'main' into feat/custom-proto-path
Pantani Apr 17, 2024
a180ec9
Merge remote-tracking branch 'origin/main' into feat/custom-proto-path
Apr 18, 2024
6b1c97c
Merge branch 'main' into feat/custom-proto-path
Pantani Apr 18, 2024
45c7ed2
Merge branch 'main' into feat/custom-proto-path
Pantani Apr 19, 2024
3afaf3f
Merge branch 'main' into feat/custom-proto-path
Pantani Apr 19, 2024
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [#4001](https://github.com/ignite/cli/pull/4001) Improve `xgenny` dry run
- [#3967](https://github.com/ignite/cli/issues/3967) Add HD wallet parameters `address index` and `account number` to the chain account config
- [#4004](https://github.com/ignite/cli/pull/4004) Remove all import placeholders using the `xast` pkg
- [#4071](https://github.com/ignite/cli/pull/4071) Support custom proto path

### Changes

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ require (
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
mvdan.cc/gofumpt v0.6.0
sigs.k8s.io/yaml v1.4.0
)
Expand Down Expand Up @@ -467,7 +468,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
honnef.co/go/tools v0.4.7 // indirect
mvdan.cc/unparam v0.0.0-20240104100049-c549a3470d14 // indirect
Expand Down
83 changes: 58 additions & 25 deletions ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import (
)

const (
msgMigration = "Migrating blockchain config file from v%d to v%d..."
msgMigrationPrefix = "Your blockchain config version is v%d and the latest is v%d."
msgMigrationPrompt = "Would you like to upgrade your config file to v%d"
msgMigrationBuf = "Now ignite supports the `buf.build` (https://buf.build) registry to manage the protobuf dependencies. The embed protoc binary was deprecated and, your blockchain is still using it. Would you like to upgrade and add the `buf.build` config files to `proto/` folder"
msgMigrationAddTools = "Some required imports are missing in %s file: %s. Would you like to add them"
msgMigrationRemoveTools = "File %s contains deprecated imports: %s. Would you like to remove them"
msgMigration = "Migrating blockchain config file from v%d to v%d..."
msgMigrationPrefix = "Your blockchain config version is v%d and the latest is v%d."
msgMigrationPrompt = "Would you like to upgrade your config file to v%d"
msgMigrationBuf = "Now ignite supports the `buf.build` (https://buf.build) registry to manage the protobuf dependencies. The embed protoc binary was deprecated and, your blockchain is still using it. Would you like to upgrade and add the `buf.build` config files to `proto/` folder"
msgMigrationBufProtoDir = "Ignite proto directory path from the chain config doesn't match the proto directory path from the chain `buf.work.yaml`. Do you want to add the proto path `%[1]v` to the directories list from the buf work file"
msgMigrationBufProtoDirs = "Chain `buf.work.yaml` file contains directories that don't exist anymore (%[1]v). Do you want to delete them"
msgMigrationAddTools = "Some required imports are missing in %s file: %s. Would you like to add them"
msgMigrationRemoveTools = "File %s contains deprecated imports: %s. Would you like to remove them"
)

var ErrProtocUnsupported = errors.New("code generation using protoc is only supported by Ignite CLI v0.26.1 or older")
Expand Down Expand Up @@ -134,7 +136,12 @@ func preRunHandler(cmd *cobra.Command, _ []string) error {
return err
}

return bufMigrationPreRunHandler(cmd, session, appPath)
protoDir, err := getProtoDirFromConfig(cmd)
if err != nil {
return err
}

return bufMigrationPreRunHandler(cmd, session, appPath, protoDir)
}

func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) error {
Expand Down Expand Up @@ -190,39 +197,65 @@ func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, app
return os.WriteFile(toolsFilename, buf.Bytes(), 0o644)
}

func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) error {
hasFiles := chain.CheckBufFiles(appPath)
if hasFiles {
return nil
func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath, protoDir string) error {
// check if the buf files exist.
hasFiles, err := chain.CheckBufFiles(appPath, protoDir)
if err != nil {
return err
}

if !getYes(cmd) {
if err := session.AskConfirm(msgMigrationBuf); err != nil {
return ErrProtocUnsupported
if !hasFiles {
if !getYes(cmd) {
if err := session.AskConfirm(msgMigrationBuf); err != nil {
return ErrProtocUnsupported
}
}

runner := xgenny.NewRunner(cmd.Context(), appPath)
sm, err := chain.BoxBufFiles(runner, appPath, protoDir)
if err != nil {
return err
}

session.Print("\n🎉 buf.build files added: \n\n")
session.Printf("%s\n\n", strings.Join(sm.CreatedFiles(), "\n"))
}

runner := xgenny.NewRunner(cmd.Context(), appPath)
sm, err := chain.BoxBufFiles(runner, appPath)
// check if the buf.work.yaml has the same proto path from the config file.
hasProtoPath, missingPaths, err := chain.CheckBufProtoDir(appPath, protoDir)
if err != nil {
return err
}

session.Print("\n🎉 buf.build files added: \n\n")
session.Printf("%s\n\n", strings.Join(sm.CreatedFiles(), "\n"))
if !hasProtoPath {
if !getYes(cmd) {
if err := session.AskConfirm(fmt.Sprintf(msgMigrationBufProtoDir, protoDir)); err != nil {
return nil
}
}

return nil
}
if err := chain.AddBufProtoDir(appPath, protoDir); err != nil {
return err
}
}

func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) (err error) {
configPath := getConfig(cmd)
if configPath == "" {
if configPath, err = chainconfig.LocateDefault(appPath); err != nil {
if len(missingPaths) > 0 {
if !getYes(cmd) {
if err := session.AskConfirm(fmt.Sprintf(msgMigrationBufProtoDirs, strings.Join(missingPaths, ", "))); err != nil {
return nil
}
}

if err := chain.RemoveBufProtoDirs(appPath, missingPaths...); err != nil {
return err
}
}

rawCfg, err := os.ReadFile(configPath)
return nil
}

func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) error {
rawCfg, configPath, err := getRawConfig(cmd)
if err != nil {
return err
}
Expand Down
41 changes: 41 additions & 0 deletions ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ignitecmd

import (
"bytes"
"context"
"fmt"
"os"
Expand All @@ -13,6 +14,8 @@ import (
flag "github.com/spf13/pflag"

"github.com/ignite/cli/v29/ignite/config"
chainconfig "github.com/ignite/cli/v29/ignite/config/chain"
"github.com/ignite/cli/v29/ignite/config/chain/defaults"
"github.com/ignite/cli/v29/ignite/pkg/cache"
"github.com/ignite/cli/v29/ignite/pkg/cliui"
uilog "github.com/ignite/cli/v29/ignite/pkg/cliui/log"
Expand Down Expand Up @@ -131,6 +134,17 @@ func getHome(cmd *cobra.Command) (home string) {
return
}

func flagSetProtoDir() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.String(flagProtoDir, defaults.ProtoDir, "chain proto directory")
return fs
}

func flagGetProtoDir(cmd *cobra.Command) (config string) {
config, _ = cmd.Flags().GetString(flagProtoDir)
return
}

func flagSetConfig() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.StringP(flagConfig, "c", "", "path to Ignite config file (default: ./config.yml)")
Expand All @@ -142,6 +156,33 @@ func getConfig(cmd *cobra.Command) (config string) {
return
}

func getRawConfig(cmd *cobra.Command) ([]byte, string, error) {
configPath := getConfig(cmd)

path := flagGetPath(cmd)
path, err := filepath.Abs(path)
if err != nil {
return nil, "", err
}

if configPath == "" {
if configPath, err = chainconfig.LocateDefault(path); err != nil {
return nil, "", err
}
}

rawConfig, err := os.ReadFile(configPath)
return rawConfig, configPath, err
}

func getProtoDirFromConfig(cmd *cobra.Command) (string, error) {
rawCfg, _, err := getRawConfig(cmd)
if err != nil {
return "", err
}
return chainconfig.ReadProtoPath(bytes.NewReader(rawCfg))
}

func flagSetYes() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.BoolP(flagYes, "y", false, "answers interactive yes/no questions with yes")
Expand Down
17 changes: 12 additions & 5 deletions ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
flagNoSimulation = "no-simulation"
flagResponse = "response"
flagDescription = "desc"
flagProtoDir = "proto-dir"

msgCommitPrefix = "Your saved project changes have not been committed.\nTo enable reverting to your current state, commit your saved changes."
msgCommitPrompt = "Do you want to proceed without committing your saved changes"
Expand Down Expand Up @@ -131,6 +132,9 @@ with an "--ibc" flag. Note that the default module is not IBC-enabled.
NewScaffoldReact(),
)

// Add flags required for the configMigrationPreRunHandler
c.PersistentFlags().AddFlagSet(flagSetProtoDir())

return c
}

Expand All @@ -139,10 +143,12 @@ func migrationPreRunHandler(cmd *cobra.Command, args []string) error {
return err
}

session := cliui.New()
var (
path = flagGetPath(cmd)
protoDir = flagGetProtoDir(cmd)
session = cliui.New()
)
defer session.End()

path := flagGetPath(cmd)
path, err := filepath.Abs(path)
if err != nil {
return err
Expand All @@ -166,7 +172,7 @@ func migrationPreRunHandler(cmd *cobra.Command, args []string) error {
return err
}

return bufMigrationPreRunHandler(cmd, session, appPath)
return bufMigrationPreRunHandler(cmd, session, appPath, protoDir)
}

func scaffoldType(
Expand All @@ -182,6 +188,7 @@ func scaffoldType(
withoutSimulation = flagGetNoSimulation(cmd)
signer = flagGetSigner(cmd)
appPath = flagGetPath(cmd)
protoDir = flagGetProtoDir(cmd)
)

var options []scaffolder.AddTypeOption
Expand All @@ -206,7 +213,7 @@ func scaffoldType(
session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
defer session.End()

sc, err := scaffolder.New(cmd.Context(), appPath)
sc, err := scaffolder.New(cmd.Context(), appPath, protoDir)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion ignite/cmd/scaffold_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
name = args[0]
addressPrefix = getAddressPrefix(cmd)
appPath = flagGetPath(cmd)
protoDir = flagGetProtoDir(cmd)
noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule)
skipGit, _ = cmd.Flags().GetBool(flagSkipGit)
minimal, _ = cmd.Flags().GetBool(flagMinimal)
Expand Down Expand Up @@ -131,6 +132,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
appPath,
name,
addressPrefix,
protoDir,
noDefaultModule,
minimal,
isConsumer,
Expand All @@ -150,7 +152,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
return err
}

if err := scaffolder.PostScaffold(cmd.Context(), cacheStorage, appDir, goModule, skipProto); err != nil {
if err := scaffolder.PostScaffold(cmd.Context(), cacheStorage, appDir, protoDir, goModule, skipProto); err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion ignite/cmd/scaffold_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func scaffoldConfigsHandler(cmd *cobra.Command, args []string) error {
configs = args[0:]
appPath = flagGetPath(cmd)
moduleName = flagGetModule(cmd)
protoDir = flagGetProtoDir(cmd)
)

session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
Expand All @@ -56,7 +57,7 @@ func scaffoldConfigsHandler(cmd *cobra.Command, args []string) error {
return err
}

sc, err := scaffolder.New(cmd.Context(), appPath)
sc, err := scaffolder.New(cmd.Context(), appPath, protoDir)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion ignite/cmd/scaffold_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func messageHandler(cmd *cobra.Command, args []string) error {
signer = flagGetSigner(cmd)
appPath = flagGetPath(cmd)
withoutSimulation = flagGetNoSimulation(cmd)
protoDir = flagGetProtoDir(cmd)
)

session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
Expand Down Expand Up @@ -113,7 +114,7 @@ func messageHandler(cmd *cobra.Command, args []string) error {
options = append(options, scaffolder.WithoutSimulation())
}

sc, err := scaffolder.New(cmd.Context(), appPath)
sc, err := scaffolder.New(cmd.Context(), appPath, protoDir)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions ignite/cmd/scaffold_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ params.

func scaffoldModuleHandler(cmd *cobra.Command, args []string) error {
var (
name = args[0]
appPath = flagGetPath(cmd)
name = args[0]
appPath = flagGetPath(cmd)
protoDir = flagGetProtoDir(cmd)
)

session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
Expand Down Expand Up @@ -171,7 +172,7 @@ func scaffoldModuleHandler(cmd *cobra.Command, args []string) error {
var msg bytes.Buffer
fmt.Fprintf(&msg, "\n🎉 Module created %s.\n\n", name)

sc, err := scaffolder.New(cmd.Context(), appPath)
sc, err := scaffolder.New(cmd.Context(), appPath, protoDir)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion ignite/cmd/scaffold_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func createPacketHandler(cmd *cobra.Command, args []string) error {
packetFields = args[1:]
signer = flagGetSigner(cmd)
appPath = flagGetPath(cmd)
protoDir = flagGetProtoDir(cmd)
)

session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
Expand All @@ -66,7 +67,7 @@ func createPacketHandler(cmd *cobra.Command, args []string) error {
options = append(options, scaffolder.PacketWithSigner(signer))
}

sc, err := scaffolder.New(cmd.Context(), appPath)
sc, err := scaffolder.New(cmd.Context(), appPath, protoDir)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion ignite/cmd/scaffold_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func scaffoldParamsHandler(cmd *cobra.Command, args []string) error {
params = args[0:]
appPath = flagGetPath(cmd)
moduleName = flagGetModule(cmd)
protoDir = flagGetProtoDir(cmd)
)

session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
Expand All @@ -58,7 +59,7 @@ func scaffoldParamsHandler(cmd *cobra.Command, args []string) error {
return err
}

sc, err := scaffolder.New(cmd.Context(), appPath)
sc, err := scaffolder.New(cmd.Context(), appPath, protoDir)
if err != nil {
return err
}
Expand Down
Loading
Loading