|
| 1 | +PKG := github.com/lightninglabs/shushtar |
| 2 | +ESCPKG := github.com\/lightninglabs\/shushtar |
| 3 | +LND_PKG := github.com/lightningnetwork/lnd |
| 4 | + |
| 5 | +LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint |
| 6 | +GOVERALLS_PKG := github.com/mattn/goveralls |
| 7 | +GOACC_PKG := github.com/ory/go-acc |
| 8 | +STATIK_PKG := github.com/rakyll/statik |
| 9 | + |
| 10 | +GO_BIN := ${GOPATH}/bin |
| 11 | +GOVERALLS_BIN := $(GO_BIN)/goveralls |
| 12 | +LINT_BIN := $(GO_BIN)/golangci-lint |
| 13 | +GOACC_BIN := $(GO_BIN)/go-acc |
| 14 | +STATIK_BIN := $(GO_BIN)/statik |
| 15 | + |
| 16 | +COMMIT := $(shell git describe --abbrev=40 --dirty --tags) |
| 17 | + |
| 18 | +LINT_COMMIT := v1.18.0 |
| 19 | +GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5 |
| 20 | + |
| 21 | +DEPGET := cd /tmp && GO111MODULE=on go get -v |
| 22 | +GOBUILD := GO111MODULE=on go build -v |
| 23 | +GOINSTALL := GO111MODULE=on go install -v |
| 24 | +GOTEST := GO111MODULE=on go test -v |
| 25 | +GOMOD := GO111MODULE=on go mod |
| 26 | + |
| 27 | +GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*") |
| 28 | +GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/' |
| 29 | +GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./') |
| 30 | + |
| 31 | +RM := rm -f |
| 32 | +CP := cp |
| 33 | +MAKE := make |
| 34 | +XARGS := xargs -L 1 |
| 35 | + |
| 36 | +LINT = $(LINT_BIN) run -v |
| 37 | + |
| 38 | +include make/release_flags.mk |
| 39 | + |
| 40 | +# We only return the part inside the double quote here to avoid escape issues |
| 41 | +# when calling the external release script. The second parameter can be used to |
| 42 | +# add additional ldflags if needed (currently only used for the release). |
| 43 | +make_ldflags = $(2) -X $(LND_PKG)/build.Commit=$(COMMIT) \ |
| 44 | + -X $(LND_PKG)/build.CommitHash=$(COMMIT_HASH) \ |
| 45 | + -X $(LND_PKG)/build.GoVersion=$(GOVERSION) \ |
| 46 | + -X $(LND_PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g') |
| 47 | + |
| 48 | +LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS)) |
| 49 | + |
| 50 | +# For the release, we want to remove the symbol table and debug information (-s) |
| 51 | +# and omit the DWARF symbol table (-w). Also we clear the build ID. |
| 52 | +RELEASE_LDFLAGS := $(call make_ldflags, $(LND_RELEASE_TAGS), -s -w -buildid=) |
| 53 | + |
| 54 | +GREEN := "\\033[0;32m" |
| 55 | +NC := "\\033[0m" |
| 56 | +define print |
| 57 | + echo $(GREEN)$1$(NC) |
| 58 | +endef |
| 59 | + |
| 60 | +default: scratch |
| 61 | + |
| 62 | +all: scratch check install |
| 63 | + |
| 64 | +# ============ |
| 65 | +# DEPENDENCIES |
| 66 | +# ============ |
| 67 | + |
| 68 | +$(GOVERALLS_BIN): |
| 69 | + @$(call print, "Fetching goveralls.") |
| 70 | + go get -u $(GOVERALLS_PKG) |
| 71 | + |
| 72 | +$(LINT_BIN): |
| 73 | + @$(call print, "Fetching linter") |
| 74 | + $(DEPGET) $(LINT_PKG)@$(LINT_COMMIT) |
| 75 | + |
| 76 | +$(GOACC_BIN): |
| 77 | + @$(call print, "Fetching go-acc") |
| 78 | + $(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT) |
| 79 | + |
| 80 | +$(STATIK_BIN): |
| 81 | + @$(call print, "Fetching statik") |
| 82 | + $(DEPGET) $(STATIK_PKG) |
| 83 | + |
| 84 | +yarn-install: |
| 85 | + @$(call print, "Installing app dependencies with yarn") |
| 86 | + cd app; yarn |
| 87 | + |
| 88 | +# ============ |
| 89 | +# INSTALLATION |
| 90 | +# ============ |
| 91 | +statik-build: $(STATIK_BIN) app-build |
| 92 | + @$(call print, "Building statik package.") |
| 93 | + statik -src=app/build |
| 94 | + |
| 95 | +build: statik-build go-build |
| 96 | +install: statik-build go-install |
| 97 | + |
| 98 | +go-build: |
| 99 | + @$(call print, "Building shushtar.") |
| 100 | + $(GOBUILD) -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" -o shushtar-debug $(PKG)/cmd/shushtar |
| 101 | + |
| 102 | +go-install: |
| 103 | + @$(call print, "Installing shushtar.") |
| 104 | + $(GOINSTALL) -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" $(PKG)/cmd/shushtar |
| 105 | + |
| 106 | +app-build: yarn-install |
| 107 | + @$(call print, "Building production app.") |
| 108 | + cd app; yarn build |
| 109 | + |
| 110 | +release: statik-build |
| 111 | + @$(call print, "Creating release of shushtar.") |
| 112 | + ./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)" |
| 113 | + |
| 114 | +scratch: build |
| 115 | + |
| 116 | +# ======= |
| 117 | +# TESTING |
| 118 | +# ======= |
| 119 | + |
| 120 | +check: unit |
| 121 | + |
| 122 | +unit: |
| 123 | + @$(call print, "Running unit tests.") |
| 124 | + $(UNIT) |
| 125 | + |
| 126 | +unit-cover: $(GOACC_BIN) |
| 127 | + @$(call print, "Running unit coverage tests.") |
| 128 | + $(GOACC_BIN) $(COVER_PKG) |
| 129 | + |
| 130 | +unit-race: |
| 131 | + @$(call print, "Running unit race tests.") |
| 132 | + env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE) |
| 133 | + |
| 134 | +goveralls: $(GOVERALLS_BIN) |
| 135 | + @$(call print, "Sending coverage report.") |
| 136 | + $(GOVERALLS_BIN) -coverprofile=coverage.txt -service=travis-ci |
| 137 | + |
| 138 | +travis-race: lint unit-race |
| 139 | + |
| 140 | +travis-cover: lint unit-cover goveralls |
| 141 | + |
| 142 | +travis-itest: lint |
| 143 | + |
| 144 | + |
| 145 | +# ============= |
| 146 | +# FLAKE HUNTING |
| 147 | +# ============= |
| 148 | +flake-unit: |
| 149 | + @$(call print, "Flake hunting unit tests.") |
| 150 | + while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done |
| 151 | + |
| 152 | +# ========= |
| 153 | +# UTILITIES |
| 154 | +# ========= |
| 155 | +fmt: |
| 156 | + @$(call print, "Formatting source.") |
| 157 | + gofmt -l -w -s $(GOFILES_NOVENDOR) |
| 158 | + |
| 159 | +lint: $(LINT_BIN) |
| 160 | + @$(call print, "Linting source.") |
| 161 | + $(LINT) |
| 162 | + |
| 163 | +mod: |
| 164 | + @$(call print, "Tidying modules.") |
| 165 | + $(GOMOD) tidy |
| 166 | + |
| 167 | +mod-check: |
| 168 | + @$(call print, "Checking modules.") |
| 169 | + $(GOMOD) tidy |
| 170 | + if test -n "$$(git status | grep -e "go.mod\|go.sum")"; then echo "Running go mod tidy changes go.mod/go.sum"; git status; git diff; exit 1; fi |
| 171 | + |
| 172 | +list: |
| 173 | + @$(call print, "Listing commands.") |
| 174 | + @$(MAKE) -qp | \ |
| 175 | + awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | \ |
| 176 | + grep -v Makefile | \ |
| 177 | + sort |
| 178 | + |
| 179 | +clean: |
| 180 | + @$(call print, "Cleaning source.$(NC)") |
| 181 | + $(RM) ./shushtar-debug |
| 182 | + $(RM) coverage.txt |
| 183 | + $(RM) -r statik |
0 commit comments