Skip to content

Commit

Permalink
Merge pull request ElementsProject#127 from nepet/refactor-makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
nepet committed Sep 14, 2022
2 parents 165350b + 4693997 commit 5553411
Show file tree
Hide file tree
Showing 21 changed files with 704 additions and 662 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
nix_file: 'ci.nix'

- name: Build peerswap
run: make build
run: make bins

- name: Run go tests
run: make test
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dist/
# build output
peerswap-plugin
out/peerswapd
out/pscli
out/peerswap-plugin

out/pscli
out/test-builds/peerswapd
out/test-builds/peerswap-plugin
out/test-builds/pscli
161 changes: 65 additions & 96 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
OUTDIR=./out
TEST_BIN_DIR=${OUTDIR}/test-builds
PAYMENT_RETRY_TIME=10
PEERSWAP_TEST_FILTER="peerswap"
GIT_COMMIT=$(shell git rev-list -1 HEAD)

BUILD_OPTS= \
-ldflags "-X main.GitCommit=$(shell git rev-parse HEAD)"

TEST_BUILD_OPTS= \
-ldflags "-X main.GitCommit=$(shell git rev-parse HEAD)" \
-tags dev \
-tags fast_test

INTEGRATION_TEST_ENV= \
RUN_INTEGRATION_TESTS=1 \
PAYMENT_RETRY_TIME=$(PAYMENT_RETRY_TIME) \
Expand All @@ -13,48 +22,77 @@ INTEGRATION_TEST_OPTS= \
-tags fast_test \
-timeout=30m -v

.DEFAULT_GOAL := release
BINS= \
${OUTDIR}/peerswapd \
${OUTDIR}/pscli \
${OUTDIR}/peerswap-plugin \

TEST_BINS= \
${TEST_BIN_DIR}/peerswapd \
${TEST_BIN_DIR}/pscli \
${TEST_BIN_DIR}/peerswap-plugin \

.PHONY: subdirs ${BINS} ${TEST_BINS}

include peerswaprpc/Makefile
include docs/Makefile

release: lnd-release cln-release
.PHONY: release

build:
go build -tags dev -o $(OUTDIR)/peerswap-plugin -ldflags "-X main.GitCommit=$(GIT_COMMIT)" ./cmd/peerswap-plugin/main.go
chmod a+x $(OUTDIR)/peerswap-plugin
go build -o $(OUTDIR)/peerswapd -ldflags "-X main.GitCommit=$(GIT_COMMIT)" ./cmd/peerswaplnd/peerswapd/main.go
chmod a+x $(OUTDIR)/peerswapd
go build -o $(OUTDIR)/pscli -ldflags "-X main.GitCommit=$(GIT_COMMIT)" ./cmd/peerswaplnd/pscli/main.go
chmod a+x $(OUTDIR)/pscli
.PHONY: build
clean-bins:
rm ${BINS}

bins: ${BINS}

test-bins: ${TEST_BINS}

build-with-fast-test:
go build -tags dev -tags fast_test -o $(OUTDIR)/peerswap-plugin ./cmd/peerswap-plugin/main.go
chmod a+x $(OUTDIR)/peerswap-plugin
go build -tags dev -tags fast_test -o $(OUTDIR)/peerswapd ./cmd/peerswaplnd/peerswapd/main.go
chmod a+x $(OUTDIR)/peerswapd
.PHONY: build-with-fast-test
# Binaries for local testing and the integration tests.
${OUTDIR}/peerswapd:
go build ${BUILD_OPTS} -o ${OUTDIR}/peerswapd ./cmd/peerswaplnd/peerswapd
chmod a+x out/peerswapd

test: build-with-fast-test
${OUTDIR}/pscli:
go build ${BUILD_OPTS} -o ${OUTDIR}/pscli ./cmd/peerswaplnd/pscli
chmod a+x out/pscli

${OUTDIR}/peerswap-plugin:
go build ${BUILD_OPTS} -o ${OUTDIR}/peerswap-plugin ./cmd/peerswap-plugin
chmod a+x out/peerswap-plugin

${TEST_BIN_DIR}/peerswapd:
go build ${TEST_BUILD_OPTS} -o ${TEST_BIN_DIR}/peerswapd ./cmd/peerswaplnd/peerswapd
chmod a+x ${TEST_BIN_DIR}/peerswapd

${TEST_BIN_DIR}/pscli:
go build ${TEST_BUILD_OPTS} -o ${TEST_BIN_DIR}/pscli ./cmd/peerswaplnd/pscli
chmod a+x ${TEST_BIN_DIR}/pscli

${TEST_BIN_DIR}/peerswap-plugin:
go build ${TEST_BUILD_OPTS} -o ${TEST_BIN_DIR}/peerswap-plugin ./cmd/peerswap-plugin
chmod a+x ${TEST_BIN_DIR}/peerswap-plugin

# Test section. Has commads for local and ci testing.
test:
PAYMENT_RETRY_TIME=5 go test -tags dev -tags fast_test -timeout=10m -v ./...
.PHONY: test

test-integration: build-with-fast-test
test-integration: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} ./test
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} ./lnd
.PHONY: test-integration

test-bitcoin-cln: build-with-fast-test
test-bitcoin-cln: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_ClnCln_Bitcoin_SwapOut|'\
'Test_ClnCln_Bitcoin_SwapIn|'\
'Test_ClnLnd_Bitcoin_SwapOut|'\
'Test_ClnLnd_Bitcoin_SwapIn)'\
./test
.PHONY: test-bitcoin-cln
.PHONY: test-bitoin-cln

test-bitcoin-lnd: build-with-fast-test
test-bitcoin-lnd: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_LndLnd_Bitcoin_SwapOut|'\
Expand All @@ -63,9 +101,9 @@ test-bitcoin-lnd: build-with-fast-test
'Test_LndCln_Bitcoin_SwapIn)'\
./test
${INTEGRATION_TEST_ENV} go test $(INTEGRATION_TEST_OPTS) ./lnd
.PHONY: test-liquid-lnd
.PHONY: test-bitcoin-lnd

test-liquid-cln: build-with-fast-test
test-liquid-cln: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_ClnCln_Liquid_SwapOut|'\
Expand All @@ -75,7 +113,7 @@ test-liquid-cln: build-with-fast-test
./test
.PHONY: test-liquid-cln

test-liquid-lnd: build-with-fast-test
test-liquid-lnd: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_LndLnd_Liquid_SwapOut|'\
Expand All @@ -85,22 +123,23 @@ test-liquid-lnd: build-with-fast-test
./test
.PHONY: test-liquid-lnd

test-misc-integration: build-with-fast-test
test-misc-integration: test-bins
${INTEGRATION_TEST_ENV} go test ${INTEGRATION_TEST_OPTS} \
-run '^('\
'Test_GrpcReconnectStream|'\
'Test_GrpcRetryRequest|'\
'Test_RestoreFromPassedCSV|'\
'Test_ClnCln_MPP|'\
'Test_ClnLnd_MPP)'\
./test
.PHONY: test-misc-integration

# Release section. Has the commands to install binaries into the distinct locations.
lnd-release: clean-lnd
go install -ldflags "-X main.GitCommit=$(GIT_COMMIT)" ./cmd/peerswaplnd/peerswapd
go install -ldflags "-X main.GitCommit=$(GIT_COMMIT)" ./cmd/peerswaplnd/pscli
.PHONY: lnd-release


cln-release: clean-cln
# peerswap-plugin binary is not installed in GOPATH because it must be called by full pathname as a CLN plugin.
# You may choose to install it to any location you wish.
Expand All @@ -120,74 +159,4 @@ clean-lnd:
.PHONY: clean-lnd

clean: clean-cln clean-lnd
.PHONY: clean

proto:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
./peerswaprpc/peerswaprpc.proto
protoc --grpc-gateway_out . \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt grpc_api_configuration=./peerswaprpc/peerswap.yaml \
./peerswaprpc/peerswaprpc.proto
protoc -I . --openapiv2_out . \
--openapiv2_opt logtostderr=true \
--openapiv2_opt grpc_api_configuration=./peerswaprpc/peerswap.yaml \
./peerswaprpc/peerswaprpc.proto
.PHONY: proto

docs/mmd/swap-in-receiver-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-in-receiver-states.md -fsm swap_in_receiver

docs/mmd/swap-in-sender-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-in-sender-states.md -fsm swap_in_sender

docs/mmd/swap-out-receiver-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-out-receiver-states.md -fsm swap_out_receiver

docs/mmd/swap-out-sender-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-out-sender-states.md -fsm swap_out_sender

IMG_WIDTH=1600
IMG_HEIGHT=400

docs/img/swap-in-receiver-states.png: docs/mmd/swap-in-receiver-states.md
sed 's/`//g' docs/mmd/swap-in-receiver-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-in-receiver-states.png
.PHONY: docs/img/swap-in-receiver-states.png

docs/img/swap-in-sender-states.png: docs/mmd/swap-in-sender-states.md
sed 's/`//g' docs/mmd/swap-in-sender-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-in-sender-states.png
.PHONY: docs/img/swap-in-sender-states.png

docs/img/swap-out-receiver-states.png: docs/mmd/swap-out-receiver-states.md
sed 's/`//g' docs/mmd/swap-out-receiver-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-out-receiver-states.png
.PHONY: docs/img/swap-out-receiver-states.png

docs/img/swap-out-sender-states.png: docs/mmd/swap-out-sender-states.md
sed 's/`//g' docs/mmd/swap-out-sender-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-out-sender-states.png
.PHONY: docs/img/swap-out-sender-states.png

docs/img/swap-in-sequence.png: docs/mmd/swap-in-sequence.md
sed 's/`//g' docs/mmd/swap-in-sequence.md | sed 's/mermaid//' | mmdc -o docs/img/swap-in-sequence.png
.PHONY: docs/img/swap-in-sequence.png

docs/img/swap-out-sequence.png: docs/mmd/swap-out-sequence.md
sed 's/`//g' docs/mmd/swap-out-sequence.md | sed 's/mermaid//' | mmdc -o docs/img/swap-out-sequence.png
.PHONY: docs/img/swap-out-sequence.png

docs: docs/img/swap-in-receiver-states.png docs/img/swap-in-sender-states.png docs/img/swap-out-receiver-states.png docs/img/swap-out-sender-states.png docs/img/swap-in-sequence.png docs/img/swap-out-sequence.png
.PHONY: docs

clean-docs:
rm -f docs/mmd/swap-in-receiver-states.md
rm -f docs/mmd/swap-out-receiver-states.md
rm -f docs/mmd/swap-in-sender-states.md
rm -f docs/mmd/swap-out-sender-states.md
rm -f docs/img/swap-in-receiver-states.png
rm -f docs/img/swap-in-sender-states.png
rm -f docs/img/swap-out-sender-states.png
rm -f docs/img/swap-out-receiver-states.png
rm -f docs/img/swap-in-sequence.png
rm -f docs/img/swap-out-sequence.png
.PHONY: clean-docs
.PHONY: clean
7 changes: 5 additions & 2 deletions contrib/startup_regtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ connect_nodes() {
echo "$(l2-cli connect $LND_URI2)"
}
rebuild() {
make build
make clean-bins
make bins
restart
}
restart() {
Expand Down Expand Up @@ -376,6 +377,8 @@ stop_peerswap_lnd() {

rebuild_peerswap_lnd() {
stop_peerswap_lnd
make build
rm out/peerswapd
rm out/pscli
make bins
start_peerswap_lnd
}
58 changes: 58 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
IMG_WIDTH=1600
IMG_HEIGHT=400

MD_FILES= \
docs/mmd/swap-in-receiver-states.md \
docs/mmd/swap-in-sender-states.md \
docs/mmd/swap-out-receiver-states.md \
docs/mmd/swap-out-sender-states.md \
docs/mmd/swap-in-sequence.md \
docs/mmd/swap-out-sequence.md

DOC_FILES= \
docs/img/swap-in-receiver-states.png \
docs/img/swap-in-sender-states.png \
docs/img/swap-out-receiver-states.png \
docs/img/swap-out-sender-states.png \
docs/img/swap-in-sequence.png \
docs/img/swap-out-sequence.png

.PHONY: subdirs ${MD_FILES}

all-states: ${MD_FILES}

all-docs: all-states ${DOC_FILES}

clean-docs:
rm -f ${DOC_FILES}
.PHONY: clean-docs

docs/mmd/swap-in-receiver-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-in-receiver-states.md -fsm swap_in_receiver

docs/mmd/swap-in-sender-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-in-sender-states.md -fsm swap_in_sender

docs/mmd/swap-out-receiver-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-out-receiver-states.md -fsm swap_out_receiver

docs/mmd/swap-out-sender-states.md:
go run ./contrib/stateparser.go -out docs/mmd/swap-out-sender-states.md -fsm swap_out_sender

docs/img/swap-in-receiver-states.png: docs/mmd/swap-in-receiver-states.md
sed 's/`//g' docs/mmd/swap-in-receiver-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-in-receiver-states.png

docs/img/swap-in-sender-states.png: docs/mmd/swap-in-sender-states.md
sed 's/`//g' docs/mmd/swap-in-sender-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-in-sender-states.png

docs/img/swap-out-receiver-states.png: docs/mmd/swap-out-receiver-states.md
sed 's/`//g' docs/mmd/swap-out-receiver-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-out-receiver-states.png

docs/img/swap-out-sender-states.png: docs/mmd/swap-out-sender-states.md
sed 's/`//g' docs/mmd/swap-out-sender-states.md | sed 's/mermaid//' | mmdc -w $(IMG_WIDTH) -H $(IMG_HEIGHT) -o docs/img/swap-out-sender-states.png

docs/img/swap-in-sequence.png: docs/mmd/swap-in-sequence.md
sed 's/`//g' docs/mmd/swap-in-sequence.md | sed 's/mermaid//' | mmdc -o docs/img/swap-in-sequence.png

docs/img/swap-out-sequence.png: docs/mmd/swap-out-sequence.md
sed 's/`//g' docs/mmd/swap-out-sequence.md | sed 's/mermaid//' | mmdc -o docs/img/swap-out-sequence.png
Binary file modified docs/img/swap-in-receiver-states.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/swap-in-sender-states.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/swap-in-sequence.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/swap-out-receiver-states.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/swap-out-sender-states.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/swap-out-sequence.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5553411

Please sign in to comment.