github.com/decred/dcrlnd@v0.7.6/Makefile (about)

     1  PKG := github.com/decred/dcrlnd
     2  ESCPKG := github.com\/decred\/dcrlnd
     3  
     4  DCRD_PKG := github.com/decred/dcrd
     5  DCRWALLET_PKG := github.com/decred/dcrwallet
     6  LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
     7  GOACC_PKG := github.com/ory/go-acc
     8  FALAFEL_PKG := github.com/lightninglabs/falafel
     9  GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports
    10  GOFUZZ_BUILD_PKG := github.com/dvyukov/go-fuzz/go-fuzz-build
    11  GOFUZZ_PKG := github.com/dvyukov/go-fuzz/go-fuzz
    12  GOFUZZ_DEP_PKG := github.com/dvyukov/go-fuzz/go-fuzz-dep
    13  
    14  GO_BIN := ${GOPATH}/bin
    15  DCRD_BIN := $(GO_BIN)/dcrd
    16  GOMOBILE_BIN := GO111MODULE=off $(GO_BIN)/gomobile
    17  LINT_BIN := $(GO_BIN)/golangci-lint
    18  GOACC_BIN := $(GO_BIN)/go-acc
    19  GOFUZZ_BUILD_BIN := $(GO_BIN)/go-fuzz-build
    20  GOFUZZ_BIN := $(GO_BIN)/go-fuzz
    21  
    22  MOBILE_BUILD_DIR :=${GOPATH}/src/$(MOBILE_PKG)/build
    23  IOS_BUILD_DIR := $(MOBILE_BUILD_DIR)/ios
    24  IOS_BUILD := $(IOS_BUILD_DIR)/Lndmobile.xcframework
    25  ANDROID_BUILD_DIR := $(MOBILE_BUILD_DIR)/android
    26  ANDROID_BUILD := $(ANDROID_BUILD_DIR)/Lndmobile.aar
    27  
    28  WTDIRTY := $(shell git diff-index --quiet HEAD -- || echo "-dirty" || echo "")
    29  COMMIT := $(shell git log -1 --format="%H$(WTDIRTY)")
    30  LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)"
    31  ITEST_LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)"
    32  
    33  # For the release, we want to remove the symbol table and debug information (-s)
    34  # and omit the DWARF symbol table (-w). Also we clear the build ID.
    35  RELEASE_LDFLAGS := $(call make_ldflags, $(RELEASE_TAGS), -s -w -buildid=)
    36  
    37  DCRD_REPO := github.com/decred/dcrd
    38  DCRD_COMMIT := release-v2.0.3
    39  DCRD_META := "$(DCRD_COMMIT).from-dcrlnd"
    40  DCRD_LDFLAGS := "-X github.com/decred/dcrd/internal/version.BuildMetadata=$(DCRD_META)"
    41  DCRD_TMPDIR := $(shell mktemp -d)
    42  
    43  DCRWALLET_REPO := github.com/decred/dcrwallet
    44  DCRWALLET_COMMIT := release-v2.0.3
    45  DCRWALLET_META := $(DCRWALLET_COMMIT).from-dcrlnd
    46  DCRWALLET_LDFLAGS := "-X decred.org/dcrwallet/version.BuildMetadata=$(DCRWALLET_META)"
    47  DCRWALLET_TMPDIR := $(shell mktemp -d)
    48  
    49  GOACC_COMMIT := 80342ae2e0fcf265e99e76bcc4efd022c7c3811b
    50  LINT_COMMIT := v1.18.0
    51  FALAFEL_COMMIT := v0.7.1
    52  GOFUZZ_COMMIT := b1f3d6f
    53  
    54  GOBUILD := go build -v
    55  GOINSTALL := go install -v
    56  GOTEST := go test
    57  
    58  GOVERSION := $(shell go version | awk '{print $$3}')
    59  GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -name "*pb.go" -not -name "*pb.gw.go" -not -name "*.pb.json.go")
    60  
    61  TESTBINPKG := dcrlnd_testbins.tar.gz
    62  
    63  RM := rm -f
    64  CP := cp
    65  MAKE := make
    66  
    67  include make/testing_flags.mk
    68  include make/release_flags.mk
    69  include make/fuzz_flags.mk
    70  
    71  DEV_TAGS := $(if ${tags},$(DEV_TAGS) ${tags},$(DEV_TAGS))
    72  
    73  LINT = $(LINT_BIN) run
    74  
    75  GREEN := "\\033[0;32m"
    76  NC := "\\033[0m"
    77  define print
    78  	echo $(GREEN)$1$(NC)
    79  endef
    80  
    81  default: scratch
    82  
    83  all: scratch check install
    84  
    85  # ============
    86  # DEPENDENCIES
    87  # ============
    88  $(LINT_BIN):
    89  	@$(call print, "Installing linter.")
    90  	go install $(LINT_PKG)
    91  
    92  $(GOACC_BIN):
    93  	@$(call print, "Installing go-acc.")
    94  	go install $(GOACC_PKG)
    95  
    96  dcrd:
    97  	@$(call print, "Installing dcrd $(DCRD_COMMIT).")
    98  	git clone https://$(DCRD_REPO) $(DCRD_TMPDIR)
    99  	cd $(DCRD_TMPDIR) && \
   100  		git checkout $(DCRD_COMMIT) && \
   101  		GO111MODULE=on go build -o "$$GOPATH/bin/dcrd-dcrlnd" -ldflags $(DCRD_LDFLAGS) .
   102  	rm -rf $(DCRD_TMPDIR)
   103  
   104  dcrwallet:
   105  	@$(call print, "Installing dcrwallet $(DCRWALLET_COMMIT).")
   106  	git clone https://$(DCRWALLET_REPO) $(DCRWALLET_TMPDIR)
   107  	cd $(DCRWALLET_TMPDIR) && \
   108  		git checkout $(DCRWALLET_COMMIT) && \
   109  		GO111MODULE=on go build -o "$$GOPATH/bin/dcrwallet-dcrlnd" -ldflags $(DCRWALLET_LDFLAGS) .
   110  	rm -rf $(DCRWALLET_TMPDIR)
   111  
   112  falafel:
   113  	@$(call print, "Installing falafel.")
   114  	$(DEPGET) $(FALAFEL_PKG)@$(FALAFEL_COMMIT)
   115  
   116  goimports:
   117  	@$(call print, "Installing goimports.")
   118  	go install $(GOIMPORTS_PKG)
   119  
   120  $(GOFUZZ_BIN):
   121  	@$(call print, "Installing go-fuzz.")
   122  	go install $(GOFUZZ_PKG)
   123  
   124  $(GOFUZZ_BUILD_BIN):
   125  	@$(call print, "Installing go-fuzz-build.")
   126  	go install $(GOFUZZ_BUILD_PKG)
   127  
   128  $(GOFUZZ_DEP_BIN):
   129  	@$(call print, "Installing go-fuzz-dep.")
   130  	go install $(GOFUZZ_DEP_PKG)
   131  
   132  # ============
   133  # INSTALLATION
   134  # ============
   135  
   136  build:
   137  	@$(call print, "Building debug dcrlnd and dcrlncli.")
   138  	CGO_ENABLED=0 $(GOBUILD) -tags="$(DEV_TAGS)" -o dcrlnd-debug $(LDFLAGS) $(PKG)/cmd/dcrlnd
   139  	CGO_ENABLED=0 $(GOBUILD) -tags="$(DEV_TAGS)" -o dcrlncli-debug $(LDFLAGS) $(PKG)/cmd/dcrlncli
   140  
   141  build-itest:
   142  	@$(call print, "Building itest dcrlnd and dcrlncli.")
   143  	CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o dcrlnd-itest$(EXEC_SUFFIX) $(ITEST_LDFLAGS) $(PKG)/cmd/dcrlnd
   144  	CGO_ENABLED=0 $(GOBUILD) -tags="$(ITEST_TAGS)" -o dcrlncli-itest$(EXEC_SUFFIX) $(ITEST_LDFLAGS) $(PKG)/cmd/dcrlncli
   145  
   146  build-itest-race:
   147  	@$(call print, "Building itest with race detector.")
   148  	CGO_ENABLED=1 $(GOBUILD) -race -tags="$(ITEST_TAGS)" -o lntest/itest/lnd-itest$(EXEC_SUFFIX) $(ITEST_LDFLAGS) $(PKG)/cmd/dcrlnd
   149  
   150  	@$(call print, "Building itest binary for ${backend} backend.")
   151  	CGO_ENABLED=0 $(GOTEST) -v ./lntest/itest -tags="$(DEV_TAGS) $(RPC_TAGS) rpctest $(backend)" -c -o lntest/itest/itest.test$(EXEC_SUFFIX)
   152  
   153  install:
   154  	@$(call print, "Installing dcrlnd and dcrlncli.")
   155  	$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/dcrlnd
   156  	$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/dcrlncli
   157  
   158  release-install:
   159  	@$(call print, "Installing release lnd and lncli.")
   160  	env CGO_ENABLED=0 $(GOINSTALL) -v -trimpath -ldflags="$(RELEASE_LDFLAGS)" -tags="$(RELEASE_TAGS)" $(PKG)/cmd/lnd
   161  	env CGO_ENABLED=0 $(GOINSTALL) -v -trimpath -ldflags="$(RELEASE_LDFLAGS)" -tags="$(RELEASE_TAGS)" $(PKG)/cmd/lncli
   162  
   163  release: clean-mobile
   164  	@$(call print, "Releasing dcrlnd and dcrlncli binaries.")
   165  	$(VERSION_CHECK)
   166  	./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
   167  
   168  scratch: build
   169  
   170  
   171  # =======
   172  # TESTING
   173  # =======
   174  
   175  check: unit itest
   176  
   177  db-instance:
   178  ifeq ($(dbbackend),postgres)
   179  	# Remove a previous postgres instance if it exists.
   180  	docker rm lnd-postgres --force || echo "Starting new postgres container"
   181  
   182  	# Start a fresh postgres instance. Allow a maximum of 500 connections so
   183  	# that multiple lnd instances with a maximum number of connections of 50
   184  	# each can run concurrently.
   185  	docker run --name lnd-postgres -e POSTGRES_PASSWORD=postgres -p 6432:5432 -d postgres:13-alpine -N 500
   186  	docker logs -f lnd-postgres &
   187  
   188  	# Wait for the instance to be started.
   189  	sleep $(POSTGRES_START_DELAY)
   190  endif
   191  
   192  
   193  itest-only: db-instance
   194  	@$(call print, "Building itest binary for $(backend) backend")
   195  	CGO_ENABLED=0 $(GOTEST) -v ./lntest/itest -tags="$(DEV_TAGS) $(RPC_TAGS) rpctest $(backend)" -c -o lntest/itest/itest.test
   196  
   197  	@$(call print, "Running integration tests with ${backend} backend.")
   198  	rm -rf lntest/itest/*.log lntest/itest/.logs-*; date
   199  	EXEC_SUFFIX=$(EXEC_SUFFIX) scripts/itest_part.sh 0 1 $(TEST_FLAGS) $(ITEST_FLAGS)
   200  	lntest/itest/log_check_errors.sh
   201  
   202  itest: dcrd dcrwallet build-itest itest-only
   203  
   204  itest-parallel-run:
   205  	@$(call print, "Building itest binary for $(backend) backend")
   206  	CGO_ENABLED=0 $(GOTEST) -v ./lntest/itest -tags="$(DEV_TAGS) $(RPC_TAGS) rpctest $(backend)" -c -o lntest/itest/itest.test
   207  
   208  	@$(call print, "Running tests")
   209  	rm -rf lntest/itest/*.log lntest/itest/.logs-*
   210  	EXEC_SUFFIX=$(EXEC_SUFFIX) echo "$$(seq 0 $$(expr $(ITEST_PARALLELISM) - 1))" | xargs -P $(ITEST_PARALLELISM) -n 1 -I {} scripts/itest_part.sh {} $(NUM_ITEST_TRANCHES) $(TEST_FLAGS) $(ITEST_FLAGS)
   211  
   212  
   213  itest-race: build-itest-race itest-only
   214  
   215  itest-parallel: dcrd dcrwallet db-instance build-itest itest-parallel-run
   216  
   217  itest-clean:
   218  	@$(call print, "Cleaning old itest processes")
   219  	killall dcrlnd-itest || echo "no running dcrlnd-itest process found";
   220  
   221  unit-only:
   222  	@$(call print, "Running unit tests.")
   223  	$(UNIT)
   224  
   225  unit: dcrd dcrwallet unit-only
   226  
   227  unit-debug: dcrd
   228  	@$(call print, "Running debug unit tests.")
   229  	$(UNIT_DEBUG)
   230  
   231  unit-cover: $(GOACC_BIN)
   232  	@$(call print, "Running unit coverage tests.")
   233  	$(GOACC_BIN) $(COVER_PKG) -- -test.tags="$(DEV_TAGS) $(LOG_TAGS)"
   234  
   235  
   236  unit-race:
   237  	@$(call print, "Running unit race tests.")
   238  	$(UNIT_RACE)
   239  
   240  ci-race: dcrd dcrwallet unit-race
   241  
   242  ci-itest: itest
   243  
   244  package-test-binaries: dcrd dcrwallet build-itest
   245  	@$(call print, "Creating test binaries package $(TESTBINPKG)")
   246  	tar --transform 's/.*\///g' -czf $(TESTBINPKG) $(GO_BIN)/dcrd-dcrlnd $(GO_BIN)/dcrwallet-dcrlnd dcrlnd-itest dcrlncli-itest
   247  
   248  unpack-test-binaries:
   249  	@$(call print, "Unpacking test binaries from $(TESTBINPKG)")
   250  	tar -xf $(TESTBINPKG)
   251  	mkdir -p $(GO_BIN)
   252  	mv dcrd-dcrlnd $(GO_BIN)/dcrd-dcrlnd
   253  	mv dcrwallet-dcrlnd $(GO_BIN)/dcrwallet-dcrlnd
   254  
   255  # =============
   256  # FLAKE HUNTING
   257  # =============
   258  
   259  flakehunter: build-itest
   260  	@$(call print, "Flake hunting ${backend} integration tests.")
   261  	while [ $$? -eq 0 ]; do make itest-only icase='${icase}' backend='${backend}'; done
   262  
   263  flake-unit:
   264  	@$(call print, "Flake hunting unit tests.")
   265  	while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
   266  
   267  flakehunter-parallel:
   268  	@$(call print, "Flake hunting ${backend} integration tests in parallel.")
   269  	while [ $$? -eq 0 ]; do make itest-parallel tranches=1 parallel=${ITEST_PARALLELISM} icase='${icase}' backend='${backend}'; done
   270  
   271  # =============
   272  # FUZZING
   273  # =============
   274  fuzz-build: $(GOFUZZ_BUILD_BIN) $(GOFUZZ_DEP_BIN)
   275  	@$(call print, "Creating fuzz harnesses for packages '$(FUZZPKG)'.")
   276  	scripts/fuzz.sh build "$(FUZZPKG)"
   277  
   278  fuzz-run: $(GOFUZZ_BIN)
   279  	@$(call print, "Fuzzing packages '$(FUZZPKG)'.")
   280  	scripts/fuzz.sh run "$(FUZZPKG)" "$(FUZZ_TEST_RUN_TIME)" "$(FUZZ_TEST_TIMEOUT)" "$(FUZZ_NUM_PROCESSES)" "$(FUZZ_BASE_WORKDIR)"
   281  
   282  # =========
   283  # UTILITIES
   284  # =========
   285  
   286  fmt: goimports
   287  	@$(call print, "Fixing imports.")
   288  	goimports -w $(GOFILES_NOVENDOR)
   289  	@$(call print, "Formatting source.")
   290  	gofmt -l -w -s $(GOFILES_NOVENDOR)
   291  
   292  lint: $(LINT_BIN)
   293  	@$(call print, "Linting source.")
   294  	$(LINT)
   295  
   296  list:
   297  	@$(call print, "Listing commands.")
   298  	@$(MAKE) -qp | \
   299  		awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | \
   300  		grep -v Makefile | \
   301  		sort
   302  
   303  rpc:
   304  	@$(call print, "Compiling protos.")
   305  	cd ./lnrpc; ./gen_protos.sh
   306  
   307  rpc-format:
   308  	@$(call print, "Formatting protos.")
   309  	cd ./lnrpc; find . -name "*.proto" | xargs clang-format --style=file -i
   310  
   311  rpc-check: rpc
   312  	@$(call print, "Verifying protos.")
   313  	cd ./lnrpc; ../scripts/check-rest-annotations.sh
   314  	if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi
   315  
   316  sample-conf-check:
   317  	@$(call print, "Making sure every flag has an example in the sample-dcrlnd.conf file")
   318  	for flag in $$(GO_FLAGS_COMPLETION=1 go run -tags="$(RELEASE_TAGS)" $(PKG)/cmd/dcrlnd -- | grep -v help | cut -c3-); do if ! grep -q $$flag sample-dcrlnd.conf; then echo "Command line flag --$$flag not added to sample-dcrlnd.conf"; exit 1; fi; done
   319  
   320  mobile-rpc:
   321  	@$(call print, "Creating mobile RPC from protos (prefix=$(prefix)).")
   322  	cd ./lnrpc; COMPILE_MOBILE=1 SUBSERVER_PREFIX=$(prefix) ./gen_protos_docker.sh
   323  
   324  vendor:
   325  	@$(call print, "Re-creating vendor directory.")
   326  	rm -r vendor/; go mod vendor
   327  
   328  ios: vendor mobile-rpc
   329  	@$(call print, "Building iOS framework ($(IOS_BUILD)).")
   330  	mkdir -p $(IOS_BUILD_DIR)
   331  	$(GOMOBILE_BIN) bind -target=ios -tags="mobile $(DEV_TAGS)" $(LDFLAGS) -v -o $(IOS_BUILD) $(MOBILE_PKG)
   332  
   333  android: vendor mobile-rpc
   334  	@$(call print, "Building Android library ($(ANDROID_BUILD)).")
   335  	mkdir -p $(ANDROID_BUILD_DIR)
   336  	$(GOMOBILE_BIN) bind -target=android -tags="mobile $(DEV_TAGS)" $(LDFLAGS) -v -o $(ANDROID_BUILD) $(MOBILE_PKG)
   337  
   338  mobile: ios android
   339  
   340  clean:
   341  	@$(call print, "Cleaning source.$(NC)")
   342  	$(RM) ./dcrlnd-debug ./dcrlncli-debug
   343  	$(RM) ./dcrlnd-itest ./dcrlncli-itest
   344  
   345  clean-mobile:
   346  	@$(call print, "Cleaning autogenerated mobile RPC stubs.")
   347  	$(RM) -r mobile/build
   348  	$(RM) mobile/*_generated.go
   349  
   350  .PHONY: all \
   351  	dcrd \
   352  	default \
   353  	build \
   354  	install \
   355  	scratch \
   356  	check \
   357  	itest-only \
   358  	itest \
   359  	unit \
   360  	unit-debug \
   361  	unit-cover \
   362  	unit-race \
   363  	falafel \
   364  	ci-race \
   365  	ci-itest \
   366  	flakehunter \
   367  	flake-unit \
   368  	fmt \
   369  	lint \
   370  	list \
   371  	rpc \
   372  	rpc-format \
   373  	rpc-check \
   374  	mobile-rpc \
   375  	vendor \
   376  	ios \
   377  	android \
   378  	mobile \
   379  	package-test-binaries \
   380  	unpack-test-binaries \
   381  	clean