Skip to content

Commit

Permalink
ci: upstream dep-assert and nomenclature from server/v2 (cosmos#19703)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Mar 8, 2024
1 parent 2bfc037 commit 0f5314c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
14 changes: 7 additions & 7 deletions docs/build/building-apps/01-app-go-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sidebar_position: 1
---

# Overview of `app_v2.go`
# Overview of `app_di.go`

:::note Synopsis

Expand All @@ -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`

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions docs/build/building-modules/15-depinject.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
23 changes: 20 additions & 3 deletions scripts/dep-assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion x/auth/tx/config/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 0f5314c

Please sign in to comment.