From 0f5314c031bc02589a19c5b1d180e61ba633f8ff Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 8 Mar 2024 18:00:09 +0100 Subject: [PATCH] ci: upstream dep-assert and nomenclature from server/v2 (#19703) --- docs/build/building-apps/01-app-go-v2.md | 14 ++++++------- docs/build/building-modules/15-depinject.md | 6 +----- scripts/dep-assert.sh | 23 ++++++++++++++++++--- simapp/{app_v2.go => app_di.go} | 0 simapp/simd/cmd/{root_v2.go => root_di.go} | 0 x/auth/tx/config/depinject.go | 2 +- 6 files changed, 29 insertions(+), 16 deletions(-) rename simapp/{app_v2.go => app_di.go} (100%) rename simapp/simd/cmd/{root_v2.go => root_di.go} (100%) diff --git a/docs/build/building-apps/01-app-go-v2.md b/docs/build/building-apps/01-app-go-v2.md index 1be1bb90aa..d77899d26e 100644 --- a/docs/build/building-apps/01-app-go-v2.md +++ b/docs/build/building-apps/01-app-go-v2.md @@ -2,7 +2,7 @@ sidebar_position: 1 --- -# Overview of `app_v2.go` +# Overview of `app_di.go` :::note Synopsis @@ -19,7 +19,7 @@ Learn more about the rationale of App Wiring in [ADR-057](../architecture/adr-05 ::: -This section is intended to provide an overview of the `SimApp` `app_v2.go` file with App Wiring. +This section is intended to provide an overview of the `SimApp` `app_di.go` file with App Wiring. ## `app_config.go` @@ -57,7 +57,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go :::tip The example above shows how to create an `AppConfig` using Go. However, it is also possible to create an `AppConfig` using YAML, or JSON. -The configuration can then be embed with `go:embed` and read with [`appconfig.LoadYAML`](https://pkg.go.dev/cosmossdk.io/core/appconfig#LoadYAML), or [`appconfig.LoadJSON`](https://pkg.go.dev/cosmossdk.io/core/appconfig#LoadJSON), in `app_v2.go`. +The configuration can then be embed with `go:embed` and read with [`appconfig.LoadYAML`](https://pkg.go.dev/cosmossdk.io/core/appconfig#LoadYAML), or [`appconfig.LoadJSON`](https://pkg.go.dev/cosmossdk.io/core/appconfig#LoadJSON), in `app_di.go`. ```go //go:embed app_config.yaml @@ -95,9 +95,9 @@ modules: A more complete example of `app.yaml` can be found [here](https://github.com/cosmos/cosmos-sdk/blob/91b1d83f1339e235a1dfa929ecc00084101a19e3/simapp/app.yaml). -## `app_v2.go` +## `app_di.go` -`app_v2.go` is the place where `SimApp` is constructed. `depinject.Inject` facilitates that by automatically wiring the app modules and keepers, provided an application configuration `AppConfig` is provided. `SimApp` is constructed, when calling the injected `*runtime.AppBuilder`, with `appBuilder.Build(...)`. +`app_di.go` is the place where `SimApp` is constructed. `depinject.Inject` facilitates that by automatically wiring the app modules and keepers, provided an application configuration `AppConfig` is provided. `SimApp` is constructed, when calling the injected `*runtime.AppBuilder`, with `appBuilder.Build(...)`. In short `depinject` and the [`runtime` package](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/runtime) abstract the wiring of the app, and the `AppBuilder` is the place where the app is constructed. [`runtime`](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/runtime) takes care of registering the codecs, KV store, subspaces and instantiating `baseapp`. ```go reference @@ -143,10 +143,10 @@ When using AutoCLI and combining app wiring and non app wiring modules. The Auto Otherwise it will miss the non depinject modules and not register their CLI. ::: -### Complete `app_v2.go` +### Complete `app_di.go` :::tip -Note that in the complete `SimApp` `app_v2.go` file, testing utilities are also defined, but they could as well be defined in a separate file. +Note that in the complete `SimApp` `app_di.go` file, testing utilities are also defined, but they could as well be defined in a separate file. ::: ```go reference diff --git a/docs/build/building-modules/15-depinject.md b/docs/build/building-modules/15-depinject.md index 06636fefbc..905a21ce7c 100644 --- a/docs/build/building-modules/15-depinject.md +++ b/docs/build/building-modules/15-depinject.md @@ -123,12 +123,8 @@ All methods, structs and their fields must be public for `depinject`. https://github.com/cosmos/cosmos-sdk/blob/f4bdec3433373cc4950f4680743e969495763fbb/x/group/module/module.go#L64-L65 ``` - - - - The module is now ready to be used with `depinject` by a chain developer. ## Integrate in an application -The App Wiring is done in `app_config.go` / `app.yaml` and `app_v2.go` and is explained in detail in the [overview of `app_v2.go`](https://docs.cosmos.network/main/build/building-apps/app-go-v2). +The App Wiring is done in `app_config.go` / `app.yaml` and `app_di.go` and is explained in detail in the [overview of `app_di.go`](https://docs.cosmos.network/main/build/building-apps/app-go-v2). diff --git a/scripts/dep-assert.sh b/scripts/dep-assert.sh index 0fa8a86501..2f4dfd0dbf 100755 --- a/scripts/dep-assert.sh +++ b/scripts/dep-assert.sh @@ -2,14 +2,14 @@ set -o errexit -SIMAPP_REGEX="cosmossdk.io/simapp" CWD=$(pwd) - +# no simapp imports in modules +SIMAPP_REGEX="cosmossdk.io/simapp" find . -type f -name 'go.mod' -print0 | while IFS= read -r -d '' file do d=$(dirname "$file") - if [[ "$d" =~ \./simapp$|\./tests* ]]; then + if [[ "$d" =~ \./simapp$|\./simapp/v2$|\./tests* ]]; then continue fi @@ -18,3 +18,20 @@ do exit 1 fi done + +# no runtime/v2 or server/v2 imports in x/ modules +RUNTIMEV2_REGEX="cosmossdk.io/runtime/v2" +SEVERV2_REGEX="cosmossdk.io/server/v2" +find ./x/ -type f -name 'go.mod' -print0 | while IFS= read -r -d '' file +do + d=$(dirname "$file") + if cd "$CWD/$d" && go list -test -f '{{ .Imports }}' ./... | grep -q -E "${RUNTIMEV2_REGEX}"; then + echo "${d} has a dependency on runtime/v2!" + exit 1 + fi + + if cd "$CWD/$d" && go list -test -f '{{ .Imports }}' ./... | grep -q -E "${SEVERV2_REGEX}"; then + echo "${d} has a dependency on server/v2!" + exit 1 + fi +done \ No newline at end of file diff --git a/simapp/app_v2.go b/simapp/app_di.go similarity index 100% rename from simapp/app_v2.go rename to simapp/app_di.go diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_di.go similarity index 100% rename from simapp/simd/cmd/root_v2.go rename to simapp/simd/cmd/root_di.go diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index 85ce366c9b..8b553520e9 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -164,7 +164,7 @@ func newAnteHandler(txConfig client.TxConfig, in ModuleInputs) (sdk.AnteHandler, // NewBankKeeperCoinMetadataQueryFn creates a new Textual struct using the given // BankKeeper to retrieve coin metadata. // -// This function should be used in the server (app.go) and is already injected thanks to app wiring for app_v2. +// This function should be used in the server (app.go) and is already injected thanks to app wiring for app_di. func NewBankKeeperCoinMetadataQueryFn(bk BankKeeper) textual.CoinMetadataQueryFn { return func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { res, err := bk.DenomMetadataV2(ctx, &bankv1beta1.QueryDenomMetadataRequest{Denom: denom})