Skip to content

Commit

Permalink
chore(Makefile)_: generate, clean-generated-files
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Oct 2, 2024
1 parent 490a208 commit 1e232c1
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 34 deletions.
63 changes: 31 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ nix-purge: ##@nix Completely remove Nix setup, including /nix directory
all: $(GO_CMD_NAMES)

.PHONY: $(GO_CMD_NAMES) $(GO_CMD_PATHS) $(GO_CMD_BUILDS)
$(GO_CMD_BUILDS): generate
$(GO_CMD_BUILDS): ##@build Build any Go project from cmd folder
go build -mod=vendor -v \
-tags '$(BUILD_TAGS)' $(BUILD_FLAGS) \
Expand All @@ -155,6 +156,7 @@ bootnode: ##@build Build discovery v5 bootnode using status-go deps
bootnode: build/bin/bootnode

node-canary: ##@build Build P2P node canary using status-go deps
node-canary: generate
node-canary: build/bin/node-canary

statusgo: ##@build Build status-go as statusd server
Expand Down Expand Up @@ -190,6 +192,7 @@ statusgo-cross: statusgo-android statusgo-ios
@echo "Full cross compilation done."
@ls -ld build/bin/statusgo-*

statusgo-android: generate
statusgo-android: ##@cross-compile Build status-go for Android
@echo "Building status-go for Android..."
export GO111MODULE=off; \
Expand All @@ -203,6 +206,7 @@ statusgo-android: ##@cross-compile Build status-go for Android
github.com/status-im/status-go/mobile
@echo "Android cross compilation done in build/bin/statusgo.aar"

statusgo-ios: generate
statusgo-ios: ##@cross-compile Build status-go for iOS
@echo "Building status-go for iOS..."
export GO111MODULE=off; \
Expand All @@ -215,6 +219,7 @@ statusgo-ios: ##@cross-compile Build status-go for iOS
github.com/status-im/status-go/mobile
@echo "iOS framework cross compilation done in build/bin/Statusgo.xcframework"

statusgo-library: generate
statusgo-library: ##@cross-compile Build status-go as static library for current platform
## cmd/library/README.md explains the magic incantation behind this
mkdir -p build/bin/statusgo-lib
Expand All @@ -229,6 +234,7 @@ statusgo-library: ##@cross-compile Build status-go as static library for current
@echo "Static library built:"
@ls -la build/bin/libstatus.*

statusgo-shared-library: generate
statusgo-shared-library: ##@cross-compile Build status-go as shared library for current platform
## cmd/library/README.md explains the magic incantation behind this
mkdir -p build/bin/statusgo-lib
Expand Down Expand Up @@ -312,14 +318,20 @@ setup-dev: ##@setup Install all necessary tools for development
setup-dev:
echo "Replaced by Nix shell. Use 'make shell' or just any target as-is."

generate-handlers:
go generate ./cmd/generate_handlers/
generate: ##@other Regenerate assets and other auto-generated stuff
go generate ./static ./static/mailserver_db_migrations ./t ./multiaccounts/... ./appdatabase/... ./protocol/... ./walletdatabase/... ./cmd/generate_handlers

generate-appdatabase:
go generate ./appdatabase/...

generate: PACKAGES ?= $$(go list -e ./... | grep -v "/contracts/")
generate: GO_GENERATE_FAST ?= $(if $(shell which go-generate-fast),"true")
generate: export GO_GENERATE_FAST_DEBUG ?= false
generate: export GO_GENERATE_FAST_RECACHE ?= false
generate: ##@ Run generate for all given packages using go-generate-fast, fallback to `go generate` (e.g. for docker)
@GOROOT=$$(go env GOROOT); \
if [ "$(GO_GENERATE_FAST)" = "true" ]; then \
go-generate-fast -x $(PACKAGES); \
else \
go generate -x $(PACKAGES); \
fi

generate-contracts:
go generate ./contracts
download-uniswap-tokens:
go run ./services/wallet/token/downloader/main.go

Expand All @@ -341,38 +353,20 @@ lint-fix:
-and -not -name 'bindata*' \
-and -not -name 'migrations.go' \
-and -not -name 'messenger_handlers.go' \
-and -not -name '*/mock/*' \
-and -not -name 'mock.go' \
-and -not -wholename '*/vendor/*' \
-exec goimports \
-local 'github.com/ethereum/go-ethereum,github.com/status-im/status-go,github.com/status-im/markdown' \
-w {} \;
$(MAKE) vendor

mock: ##@other Regenerate mocks
mockgen -package=fake -destination=transactions/fake/mock.go -source=transactions/fake/txservice.go
mockgen -package=peer -destination=services/peer/discoverer_mock.go -source=services/peer/service.go
mockgen -package=mock_contracts -destination=contracts/mock/contracts.go -source=contracts/contracts.go
mockgen -package=mocksettings -destination=multiaccounts/settings/mocks/database_settings_manager_mock.go -source=multiaccounts/settings/database_settings_manager.go
mockgen -package=mock_transactor -destination=transactions/mock_transactor/transactor.go -source=transactions/transactor.go
mockgen -package=mock_rpcclient -destination=rpc/mock/client/client.go -source=rpc/client.go
mockgen -package=mock_network -destination=rpc/network/mock/network.go -source=rpc/network/network.go
mockgen -package=mock_ethclient -destination=rpc/chain/mock/client/ethclient/eth_client.go -source=rpc/chain/ethclient/eth_client.go
mockgen -package=mock_ethclient -destination=rpc/chain/mock/client/ethclient/rps_limited_eth_client.go -source=rpc/chain/ethclient/rps_limited_eth_client.go
mockgen -package=mock_client -destination=rpc/chain/mock/client/client.go -source=rpc/chain/client.go
mockgen -package=mock_token -destination=services/wallet/token/mock/token/tokenmanager.go -source=services/wallet/token/token.go
mockgen -package=mock_balance_persistence -destination=services/wallet/token/mock/balance_persistence/balance_persistence.go -source=services/wallet/token/balance_persistence.go
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collectible_data_db.go -source=services/wallet/collectibles/collectible_data_db.go
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collection_data_db.go -source=services/wallet/collectibles/collection_data_db.go
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/types.go -source=services/wallet/thirdparty/types.go
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/collectible_types.go -source=services/wallet/thirdparty/collectible_types.go
mockgen -package=mock_paraswap -destination=services/wallet/thirdparty/paraswap/mock/types.go -source=services/wallet/thirdparty/paraswap/types.go
mockgen -package=mock_pathprocessor -destination=services/wallet/router/pathprocessor/mock_pathprocessor/processor.go -source=services/wallet/router/pathprocessor/processor.go
mockgen -package=mock_onramp -destination=services/wallet/onramp/mock/types.go -source=services/wallet/onramp/types.go

docker-test: ##@tests Run tests in a docker container with golang.
docker run --privileged --rm -it -v "$(PWD):$(DOCKER_TEST_WORKDIR)" -w "$(DOCKER_TEST_WORKDIR)" $(DOCKER_TEST_IMAGE) go test ${ARGS}

test: test-unit ##@tests Run basic, short tests during development

test-unit: generate
test-unit: export BUILD_TAGS ?=
test-unit: export UNIT_TEST_DRY_RUN ?= false
test-unit: export UNIT_TEST_COUNT ?= 1
Expand Down Expand Up @@ -403,13 +397,14 @@ canary-test: node-canary
# TODO: uncomment that!
#_assets/scripts/canary_test_mailservers.sh ./config/cli/fleet-eth.prod.json

lint:
lint: generate
golangci-lint run ./...

ci: lint canary-test test-unit test-e2e ##@tests Run all linters and tests at once
ci: generate lint canary-test test-unit test-e2e ##@tests Run all linters and tests at once

ci-race: lint canary-test test-unit test-e2e-race ##@tests Run all linters and tests at once + race
ci-race: generate lint canary-test test-unit test-e2e-race ##@tests Run all linters and tests at once + race

clean: clean-generated-files
clean: ##@other Cleanup
rm -fr build/bin/* mailserver-config.json

Expand All @@ -419,6 +414,10 @@ git-clean:
deep-clean: clean git-clean
rm -Rdf .ethereumtest/StatusChain

clean-generated-files: SHELL := /bin/sh
clean-generated-files:
./_assets/scripts/clean_generated_files.sh

tidy:
go mod tidy

Expand Down
6 changes: 5 additions & 1 deletion _assets/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM golang:1.21-alpine3.18 as builder
ENV CC=clang
ENV CXX=clang++

RUN apk add --no-cache make llvm clang musl-dev linux-headers
RUN apk add --no-cache git make llvm clang musl-dev linux-headers protobuf-dev~3.21

ARG build_tags
ARG build_flags
Expand All @@ -14,6 +14,10 @@ ARG build_target=statusgo
RUN mkdir -p /go/src/github.com/status-im/status-go
WORKDIR /go/src/github.com/status-im/status-go
ADD . .

RUN go install go.uber.org/mock/[email protected]
RUN go install github.com/kevinburke/go-bindata/v4/[email protected]
RUN go install google.golang.org/protobuf/cmd/[email protected]
RUN make $build_target BUILD_TAGS="$build_tags" BUILD_FLAGS="$build_flags" SHELL="/bin/sh"

# Copy the binary to the second image
Expand Down
10 changes: 10 additions & 0 deletions _assets/ci/Jenkinsfile.android
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ pipeline {
}
}

stage('Generate') {
environment {
/* Regenerate at least once */
GO_GENERATE_FAST_RECACHE = "true"
}
steps { script {
nix.shell('make generate', pure: false)
} }
}

stage('Compile') {
steps { script {
nix.shell('make statusgo-android', pure: false)
Expand Down
9 changes: 9 additions & 0 deletions _assets/ci/Jenkinsfile.ios
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pipeline {
)
/* fix for gomobile complaining about missing packages */
CGO_ENABLED = "1"
/* Use `go generate`, ignore cache on CI.
Also, `go-generate-fast` was struggling with some paths access and didn't work anyway */
GO_GENERATE_FAST = "false"
}

stages {
Expand All @@ -57,6 +60,12 @@ pipeline {
}
}

stage('Generate') {
steps { script {
nix.shell('make generate', pure: false)
} }
}

stage('Compile') {
steps { script {
nix.shell('make statusgo-ios', pure: false, sandbox: false)
Expand Down
10 changes: 10 additions & 0 deletions _assets/ci/Jenkinsfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ pipeline {
}
}

stage('Generate') {
environment {
/* Regenerate at least once */
GO_GENERATE_FAST_RECACHE = "true"
}
steps { script {
nix.shell('make generate', pure: false)
} }
}

/* Sanity-check C bindings */
stage('Build Static Lib') {
steps { script {
Expand Down
11 changes: 10 additions & 1 deletion _assets/ci/Jenkinsfile.tests
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ pipeline {
}
}

stage('Generate') {
environment {
/* Regenerate at least once */
GO_GENERATE_FAST_RECACHE = "true"
}
steps { script {
nix.shell('make generate', pure: false)
} }
}

stage('Vendor Check') {
steps { script {
nix.shell('make vendor', pure: false)
Expand Down Expand Up @@ -166,7 +176,6 @@ pipeline {
"--filter",
"--lightpush"
].join(' ')) { c2 ->
nix.shell('make generate-handlers', pure: true)
withCredentials([
string(
credentialsId: 'codeclimate-test-reporter-id',
Expand Down
30 changes: 30 additions & 0 deletions _assets/scripts/clean_generated_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/_assets/scripts/colors.sh"

echo -e "${GRN}Removing mockgen files from ./mock directories${RST}" # excluding ./vendor and ./contracts directories
find . \
\( \
-type d -name "mock" \
-and -not -path "./vendor/*" \
-and -not -path "./contracts/*" \
\) \
-exec rm -rf {} +

echo -e "${GRN}Removing mock.go files${RST}" # In theory this is only ./transactions/fake/mock.go
find . \
-name "mock.go" \
-and -not -path "./vendor/*" \
-exec rm -f {} +

echo -e "${GRN}Removing protoc and go-bindata files${RST}"
find . \
\( \
-name '*.pb.go' \
-or -name 'bindata.go' \
-or -name 'migrations.go' \
-or -name 'messenger_handlers.go' \
\) \
-and -not -path './vendor/*' \
-exec rm -f {} +

0 comments on commit 1e232c1

Please sign in to comment.