Skip to content

Commit

Permalink
build: Refactor Makefile for dependencies and installation of tools (#10
Browse files Browse the repository at this point in the history
)

Signed-off-by: jannfis <[email protected]>
  • Loading branch information
jannfis authored Feb 22, 2024
1 parent cba22ee commit 5912b1b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
40 changes: 30 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ BIN_NAME_PRINCIPAL=argocd-agent-principal
BIN_ARCH?=$(shell go env GOARCH)
BIN_OS?=$(shell go env GOOS)

current_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BIN_DIR := $(current_dir)/build/bin

.PHONY: build
build: agent principal

Expand All @@ -28,31 +31,48 @@ mod-vendor:
clean:
rm -rf dist/ vendor/ build/

./build/bin/protoc-gen-go:
./hack/install/install-codegen-go-tools.sh
./build/bin:
mkdir -p build/bin

./build/bin/golangci-lint: ./build/bin
GOBIN=$(current_dir)/build/bin go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

./build/bin/protoc-gen-go: ./build/bin
GOBIN=$(current_dir)/build/bin go install google.golang.org/protobuf/cmd/[email protected]

./build/bin/protoc-gen-go-grpc:
./hack/install/install-codegen-go-tools.sh
./build/bin/protoc-gen-go-grpc: ./build/bin
GOBIN=$(current_dir)/build/bin go install google.golang.org/grpc/cmd/protoc-gen-go-[email protected]

./build/bin/protoc:
./build/bin/protoc: ./build/bin
./hack/install/install-protoc.sh

.PHONY: install-golangci-lint
install-golangci-lint: ./build/bin/golangci-lint

.PHONY: install-protoc-go
install-protoc-go: ./build/bin/protoc-gen-go ./build/bin/protoc-gen-go-grpc

.PHONY: install-protoc
install-protoc: ./build/bin/protoc

.PHONY: codegen
codegen: protogen
.PHONY: install-proto-toolchain
install-proto-toolchain: install-protoc install-protoc-go
@echo "Build toolchain installed."

.PHONY: install-lint-toolchain
install-lint-toolchain: install-golangci-lint
@echo "Lint toolchain installed."

.PHONY: protogen
protogen: mod-vendor install-protoc-go install-protoc
protogen: mod-vendor install-proto-toolchain
./hack/generate-proto.sh

.PHONY: codegen
codegen: protogen

.PHONY: lint
lint:
golangci-lint run --verbose
lint: install-lint-toolchain
$(BIN_DIR)/golangci-lint run --verbose

.PHONY: agent
agent:
Expand Down
2 changes: 1 addition & 1 deletion hack/generate-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ for p in ${GENERATE_PATHS}; do
for f in $(ls $src_path/*.proto); do
echo "--> Generating Protobuf and gRPC client for $api_name"
mkdir -p ${PROJECT_ROOT}/pkg/api/grpc/${api_name}
protoc -I=${src_path} \
${PROJECT_ROOT}/build/bin/protoc -I=${src_path} \
-I=${PROJECT_ROOT}/vendor \
-I=${PROJECT_ROOT}/proto \
-I=${PROJECT_ROOT}/build/bin/protoc-include \
Expand Down
5 changes: 2 additions & 3 deletions hack/install/install-protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ url=https://github.com/protocolbuffers/protobuf/releases/download/v${protoc_vers
mkdir -p /tmp/protoc-${protoc_version}
unzip -o $DOWNLOADS/${TARGET_FILE} -d /tmp/protoc-${protoc_version}
mkdir -p ${DIST_PATH}/protoc-include
cp /tmp/protoc-${protoc_version}/bin/protoc ${DIST_PATH}/protoc
chmod +x ${DIST_PATH}/protoc
install -m 0755 /tmp/protoc-${protoc_version}/bin/protoc ${DIST_PATH}/protoc
cp -a /tmp/protoc-${protoc_version}/include/* ${DIST_PATH}/protoc-include
chmod -R +rx ${DIST_PATH}/protoc-include
#chmod -R ${DIST_PATH}/protoc-include
protoc --version

0 comments on commit 5912b1b

Please sign in to comment.