Skip to content

Commit

Permalink
refactor build facility
Browse files Browse the repository at this point in the history
  • Loading branch information
hangxie committed Oct 10, 2024
1 parent e3655e4 commit 8f34082
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
28 changes: 17 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ GOBIN = $(shell go env GOPATH)/bin
GOFLAGS := -trimpath
GOSOURCES := $(shell find . -type f -name '*.go')
LDFLAGS := -w -s
LDFLAGS += -extldflags "-static"
LDFLAGS += -X $(PKG_PREFIX)/cmd.version=$(VERSION) -X $(PKG_PREFIX)/cmd.build=$(BUILD_TIME) -X $(PKG_PREFIX)/cmd.gitHash=$(GIT_HASH)
TAGS :=
LDFLAGS += -extldflags "-static" \
-X $(PKG_PREFIX)/cmd.version=$(VERSION) \
-X $(PKG_PREFIX)/cmd.build=$(BUILD_TIME) \
-X $(PKG_PREFIX)/cmd.gitHash=$(GIT_HASH)

.EXPORT_ALL_VARIABLES:

Expand Down Expand Up @@ -68,7 +69,9 @@ build: deps ## Build locally for local os/arch creating $(BUILD_DIR) in ./
@echo "==> Building executable"
@mkdir -p $(BUILD_DIR)
@CGO_ENABLED=$(CGO_ENABLED) \
$(GO) build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $(BUILD_DIR) ./
$(GO) build $(GOFLAGS) \
-ldflags '$(LDFLAGS)' \
-o $(BUILD_DIR) ./

.PHONY: clean
clean: ## Clean up the build dirs
Expand All @@ -80,19 +83,22 @@ docker-build: ## Build docker image for local test
@echo "==> Building docker image"
@mkdir -p $(BUILD_DIR)/release/
@package/scripts/build-bin.sh
@sleep 2 # to address podman volume issue on MacOS
@docker build . -f package/container/Dockerfile -t parquet-tools:local

.PHONY: test
test: deps tools ## Run unit tests
@echo "==> Running unit tests"
@mkdir -p $(BUILD_DIR)/test $(BUILD_DIR)/junit
@mkdir -p $(BUILD_DIR)/test
@set -euo pipefail ; \
CGO_ENABLED=1 go test -v -race -count 1 -trimpath -coverprofile=$(BUILD_DIR)/test/cover.out ./... \
| tee $(BUILD_DIR)/test/go-test.output ; \
go tool cover -html=$(BUILD_DIR)/test/cover.out -o $(BUILD_DIR)/test/coverage.html ; \
go tool cover -func=$(BUILD_DIR)/test/cover.out -o $(BUILD_DIR)/test/coverage.txt ; \
cat $(BUILD_DIR)/test/go-test.output | $(GOBIN)/go-junit-report > $(BUILD_DIR)/junit/junit.xml ; \
cat $(BUILD_DIR)/test/coverage.txt
cd $(BUILD_DIR)/test; \
CGO_ENABLED=1 go test -v -race -count 1 -trimpath \
-coverprofile=coverage.out $(CURDIR)/... \
| tee go-test.output ; \
go tool cover -html=coverage.out -o coverage.html ; \
go tool cover -func=coverage.out -o coverage.txt ; \
cat go-test.output | $(GOBIN)/go-junit-report > junit.xml ; \
cat coverage.txt

.PHONY: release-build
release-build: deps ## Build release binaries
Expand Down
1 change: 0 additions & 1 deletion package/scripts/build-bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ for TARGET in ${REL_TARGET}; do
export GOOS=$(echo ${TARGET} | cut -f 1 -d \-)
export GOARCH=$(echo ${TARGET} | cut -f 2 -d \-)
${GO} build ${GOFLAGS} \
-tags "${TAGS}" \
-ldflags "${LDFLAGS} -X ${PKG_PREFIX}/cmd.source=github" \
-o ${BINARY} ./
if [ ${GOOS} == "windows" ]; then
Expand Down
8 changes: 4 additions & 4 deletions package/scripts/build-brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ for ARCH in arm64 amd64; do

# rebuild just in case we need any special setting for homebrew
GOOS=darwin GOARCH=${ARCH} \
${GO} build ${GOFLAGS} -tags "${TAGS}" \
-ldflags "${LDFLAGS} -X ${PKG_PREFIX}/cmd.source=bottle" \
-o ${BOTTLE_DIR}/bin/parquet-tools ${SOURCE_DIR}
${GO} build ${GOFLAGS} \
-ldflags "${LDFLAGS} -X ${PKG_PREFIX}/cmd.source=bottle" \
-o ${BOTTLE_DIR}/bin/parquet-tools ${SOURCE_DIR}

# nice-to-have files
cp ${SOURCE_DIR}/LICENSE ${BOTTLE_DIR}/
cp ${SOURCE_DIR}/README.md ${BOTTLE_DIR}/

# tarball
# tarball
tar zcf ${BUILD_DIR}/brew/${ARCH}.tar.gz -C ${ARCH_DIR} go-parquet-tools/
done

Expand Down

0 comments on commit 8f34082

Please sign in to comment.