Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <proglottis@gmail.com>2020-06-19 00:18:41 +0300
committerJames Fargher <proglottis@gmail.com>2020-06-19 00:18:41 +0300
commit93e2fe75603fe36fc35076aceb9e40d65a9aa99e (patch)
tree82ca86b95d056eb30ba9b75b3c6c62ff8c6df787
parent75833b9f188807b44bed573b2ee21500a90baef5 (diff)
parenteace779a9c000f59a5af118f707ede239f97e9c6 (diff)
Merge branch 'pks-makefile-refactoring' into 'master'
Makefile: Get rid of templating See merge request gitlab-org/gitaly!2277
-rw-r--r--Makefile439
-rw-r--r--_support/Makefile.template318
-rw-r--r--_support/makegen.go401
3 files changed, 343 insertions, 815 deletions
diff --git a/Makefile b/Makefile
index 069a30535..9d257a8be 100644
--- a/Makefile
+++ b/Makefile
@@ -1,145 +1,392 @@
-# Top-level Makefile for Gitaly
-#
-# Responsibilities of this file:
-# - create GOPATH in _build with symlink to current dir
-# - re-generate _build/Makefile from makegen.go on each run
-# - dispatch commands to _build/Makefile
-#
-# Besides the targets that manage _build and _build/Makefile, all
-# targets in this Makefile should look like this:
-#
-# .PHONY: foobar
-# foobar: prepare-build
-# cd $(BUILD_DIR) && $(MAKE) $@
-#
-# All other logic should happen in _support/Makefile.template and
-# _support/makegen.go.
-#
-
-BUILD_DIR = _build
-PKG = gitlab.com/gitlab-org/gitaly
-MAKEGEN = $(BUILD_DIR)/makegen
-
-# These variables are used by makegen
-export SOURCE_DIR := $(CURDIR)
-
-# Used to build _support/makegen.go
-export GO111MODULE = on
-
-all: build
+# Makefile for Gitaly
+
+SHELL = /usr/bin/env bash -eo pipefail
+
+# Host information
+OS := $(shell uname)
+ARCH := $(shell uname -m)
+
+# Directories
+SOURCE_DIR := $(abspath $(dir $(lastword ${MAKEFILE_LIST})))
+BUILD_DIR := ${SOURCE_DIR}/_build
+COVERAGE_DIR := ${BUILD_DIR}/cover
+GITALY_RUBY_DIR := ${SOURCE_DIR}/ruby
+GITLAB_SHELL_DIR := ${GITALY_RUBY_DIR}/gitlab-shell
+
+# These variables may be overridden at runtime by top-level make
+PREFIX ?= /usr/local
+prefix ?= ${PREFIX}
+exec_prefix ?= ${prefix}
+bindir ?= ${exec_prefix}/bin
+INSTALL_DEST_DIR := ${DESTDIR}${bindir}
+ASSEMBLY_ROOT ?= ${BUILD_DIR}/assembly
+GIT_PREFIX ?= ${GIT_INSTALL_DIR}
+
+# Tools
+GOIMPORTS := ${BUILD_DIR}/bin/goimports
+GITALYFMT := ${BUILD_DIR}/bin/gitalyfmt
+GOLANGCI_LINT := ${BUILD_DIR}/bin/golangci-lint
+GO_LICENSES := ${BUILD_DIR}/bin/go-licenses
+PROTOC := ${BUILD_DIR}/protoc/bin/protoc
+PROTOC_GEN_GO := ${BUILD_DIR}/bin/protoc-gen-go
+PROTOC_GEN_GITALY := ${BUILD_DIR}/bin/protoc-gen-gitaly
+GO_JUNIT_REPORT := ${BUILD_DIR}/bin/go-junit-report
+
+# Build information
+BUNDLE_FLAGS ?= $(shell test -f ${SOURCE_DIR}/../.gdk-install-root && echo --no-deployment || echo --deployment)
+GITALY_PACKAGE := gitlab.com/gitlab-org/gitaly
+BUILD_TIME := $(shell date +"%Y%m%d.%H%M%S")
+GITALY_VERSION := $(shell git describe --match v* 2>/dev/null | sed 's/^v//' || cat ${SOURCE_DIR}/VERSION 2>/dev/null || echo unknown)
+GO_LDFLAGS := -ldflags '-X ${GITALY_PACKAGE}/internal/version.version=${GITALY_VERSION} -X ${GITALY_PACKAGE}/internal/version.buildtime=${BUILD_TIME}'
+GO_TEST_LDFLAGS := -X gitlab.com/gitlab-org/gitaly/auth.timestampThreshold=5s
+GO_BUILD_TAGS := tracer_static tracer_static_jaeger continuous_profiler_stackdriver
+
+# Dependency versions
+GOLANGCI_LINT_VERSION ?= 1.24.0
+PROTOC_VERSION ?= 3.6.1
+
+# Dependency downloads
+ifeq (${OS},Darwin)
+PROTOC_URL := https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-osx-x86_64.zip
+PROTOC_HASH := 0decc6ce5beed07f8c20361ddeb5ac7666f09cf34572cca530e16814093f9c0c
+GOLANGCI_LINT_ARCHIVE := golangci-lint-${GOLANGCI_LINT_VERSION}-darwin-amd64
+GOLANGCI_LINT_HASH := f05af56f15ebbcf77663a8955d1e39009b584ce8ea4c5583669369d80353a113
+else ifeq (${OS},Linux)
+PROTOC_URL := https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip
+PROTOC_HASH := 6003de742ea3fcf703cfec1cd4a3380fd143081a2eb0e559065563496af27807
+GOLANGCI_LINT_ARCHIVE := golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64
+GOLANGCI_LINT_HASH := 241ca454102e909de04957ff8a5754c757cefa255758b3e1fba8a4533d19d179
+else
+$(error Unsupported OS: ${OS})
+endif
+GOLANGCI_LINT_URL := https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/${GOLANGCI_LINT_ARCHIVE}.tar.gz
+
+# Git target
+GIT_VERSION ?= v2.27.0
+GIT_REPO_URL ?= https://gitlab.com/gitlab-org/gitlab-git.git
+GIT_BINARIES_URL ?= https://gitlab.com/gitlab-org/gitlab-git/-/jobs/artifacts/${GIT_VERSION}/raw/git_full_bins.tgz?job=build
+GIT_INSTALL_DIR := ${BUILD_DIR}/git
+GIT_SOURCE_DIR := ${BUILD_DIR}/src/git
+
+ifeq (${GIT_BUILD_OPTIONS},)
+# activate developer checks
+GIT_BUILD_OPTIONS += DEVELOPER=1
+# make it easy to debug in case of crashes
+GIT_BUILD_OPTIONS += CFLAGS='-O0 -g3'
+GIT_BUILD_OPTIONS += NO_PERL=YesPlease
+GIT_BUILD_OPTIONS += NO_EXPAT=YesPlease
+GIT_BUILD_OPTIONS += NO_TCLTK=YesPlease
+# fix compilation on musl libc
+GIT_BUILD_OPTIONS += NO_REGEX=YesPlease
+GIT_BUILD_OPTIONS += NO_GETTEXT=YesPlease
+GIT_BUILD_OPTIONS += NO_PYTHON=YesPlease
+GIT_BUILD_OPTIONS += NO_INSTALL_HARDLINKS=YesPlease
+GIT_BUILD_OPTIONS += NO_R_TO_GCC_LINKER=YesPlease
+endif
+
+# These variables control test options and artifacts
+TEST_OPTIONS ?=
+TEST_REPORT_DIR ?= ${BUILD_DIR}/reports
+TEST_OUTPUT ?= ${TEST_REPORT_DIR}/go-tests-output-${CI_JOB_NAME}.txt
+TEST_REPORT ?= ${TEST_REPORT_DIR}/go-tests-report-${CI_JOB_NAME}.xml
+TEST_EXIT ?= ${TEST_REPORT_DIR}/go-tests-exit-${CI_JOB_NAME}.txt
+TEST_REPO_DIR := ${SOURCE_DIR}/internal/testhelper/testdata/data
+TEST_REPO := ${TEST_REPO_DIR}/gitlab-test.git
+TEST_REPO_GIT := ${TEST_REPO_DIR}/gitlab-git-test.git
+
+# Find all commands.
+find_commands = $(notdir $(shell find ${SOURCE_DIR}/cmd -mindepth 1 -maxdepth 1 -type d -print))
+# Find all command binaries.
+find_command_binaries = $(addprefix ${BUILD_DIR}/bin/, $(call find_commands))
+
+# Find all Go source files.
+find_go_sources = $(shell find ${SOURCE_DIR} -type d \( -name ruby -o -name vendor -o -name testdata -o -name '_*' -o -path '*/proto/go' \) -prune -o -type f -name '*.go' -not -name '*.pb.go' -print | sort -u)
+# Find all Go packages.
+find_go_packages = $(dir $(call find_go_sources, 's|[^/]*\.go||'))
+
+unexport GOROOT
+export GOBIN = ${BUILD_DIR}/bin
+export GO111MODULE = on
+export GOPROXY ?= https://proxy.golang.org
+export PATH := ${BUILD_DIR}/bin:${PATH}
+
+.NOTPARALLEL:
+
+.PHONY: all
+all: INSTALL_DEST_DIR = ${SOURCE_DIR}
+all: install
.PHONY: build
-build: prepare-build
- cd $(BUILD_DIR) && $(MAKE) install INSTALL_DEST_DIR=$(CURDIR)
+build: ${SOURCE_DIR}/.ruby-bundle
+ go install ${GO_LDFLAGS} -tags "${GO_BUILD_TAGS}" $(addprefix ${GITALY_PACKAGE}/cmd/, $(call find_commands))
.PHONY: install
-install: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+install: build
+ mkdir -p ${INSTALL_DEST_DIR}
+ install $(call find_command_binaries) ${INSTALL_DEST_DIR}
+.PHONY: force-ruby-bundle
+force-ruby-bundle:
+ rm -f ${SOURCE_DIR}/.ruby-bundle
+
+# Assembles all runtime components into a directory
+# Used by the GDK: run 'make assemble ASSEMBLY_ROOT=.../gitaly'
.PHONY: assemble
-assemble: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+assemble: force-ruby-bundle assemble-internal
+
+# assemble-internal does not force 'bundle install' to run again
+.PHONY: assemble-internal
+assemble-internal: assemble-ruby assemble-go
+
+.PHONY: assemble-go
+assemble-go: build
+ rm -rf ${ASSEMBLY_ROOT}/bin
+ mkdir -p ${ASSEMBLY_ROOT}/bin
+ install $(call find_command_binaries) ${ASSEMBLY_ROOT}/bin
+
+.PHONY: assemble-ruby
+assemble-ruby:
+ mkdir -p ${ASSEMBLY_ROOT}
+ rm -rf ${GITALY_RUBY_DIR}/tmp ${GITLAB_SHELL_DIR}/tmp
+ mkdir -p ${ASSEMBLY_ROOT}/ruby/
+ rsync -a --delete ${GITALY_RUBY_DIR}/ ${ASSEMBLY_ROOT}/ruby/
+ rm -rf ${ASSEMBLY_ROOT}/ruby/spec ${ASSEMBLY_ROOT}/ruby/gitlab-shell/spec ${ASSEMBLY_ROOT}/ruby/gitlab-shell/gitlab-shell.log
.PHONY: binaries
-binaries: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+binaries: assemble
+ @if [ ${ARCH} != 'x86_64' ]; then echo Incorrect architecture for build: ${ARCH}; exit 1; fi
+ @cd ${ASSEMBLY_ROOT} && shasum -a 256 bin/* | tee checksums.sha256.txt
.PHONY: prepare-tests
-prepare-tests: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+prepare-tests: ${GITLAB_SHELL_DIR}/config.yml ${TEST_REPO} ${TEST_REPO_GIT} ${SOURCE_DIR}/.ruby-bundle
.PHONY: test
-test: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+test: test-go rspec rspec-gitlab-shell
-.PHONY: test-with-praefect
-test-with-praefect: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+.PHONY: test-go
+test-go: prepare-tests ${GO_JUNIT_REPORT}
+ @mkdir -p ${TEST_REPORT_DIR}
+ @echo 0 >${TEST_EXIT} && \
+ (go test ${TEST_OPTIONS} -v -tags "${GO_BUILD_TAGS}" -ldflags='${GO_TEST_LDFLAGS}' -count=1 $(call find_go_packages) 2>&1 | tee ${TEST_OUTPUT} || echo $$? >${TEST_EXIT}) && \
+ ${GO_JUNIT_REPORT} <${TEST_OUTPUT} >${TEST_REPORT} && \
+ exit `cat ${TEST_EXIT}`
.PHONY: test-with-proxies
-test-with-proxies: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+test-with-proxies: prepare-tests
+ @go test -tags "${GO_BUILD_TAGS}" -count=1 -exec ${SOURCE_DIR}/_support/bad-proxies ${GITALY_PACKAGE}/internal/rubyserver/
+
+.PHONY: test-with-praefect
+test-with-praefect: build prepare-tests
+ @GITALY_TEST_PRAEFECT_BIN=${BUILD_DIR}/bin/praefect go test -tags "${GO_BUILD_TAGS}" -ldflags='${GO_TEST_LDFLAGS}' -count=1 $(call find_go_packages) # count=1 bypasses go 1.10 test caching
+
+.PHONY: race-go
+race-go: TEST_OPTIONS = -race
+race-go: test-go
.PHONY: rspec
-rspec: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+rspec: assemble-go prepare-tests
+ cd ${GITALY_RUBY_DIR} && bundle exec rspec
.PHONY: rspec-gitlab-shell
-rspec-gitlab-shell: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+rspec-gitlab-shell: ${GITLAB_SHELL_DIR}/config.yml assemble-go prepare-tests
+ @cd ${GITALY_RUBY_DIR} && bundle exec bin/ruby-cd ${GITLAB_SHELL_DIR} rspec
.PHONY: test-postgres
-test-postgres: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+test-postgres: prepare-tests
+ @go test -tags postgres -count=1 gitlab.com/gitlab-org/gitaly/internal/praefect/...
.PHONY: verify
-verify: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+verify: check-mod-tidy check-formatting notice-up-to-date check-proto rubocop
+
+.PHONY: check-mod-tidy
+check-mod-tidy:
+ @${SOURCE_DIR}/_support/check-mod-tidy
.PHONY: lint
-lint: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+lint: ${GOLANGCI_LINT}
+ @${GOLANGCI_LINT} cache clean && ${GOLANGCI_LINT} run --out-format tab --config ${SOURCE_DIR}/.golangci.yml
-.PHONY: lint-warnings
-lint-warnings: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+.PHONY: check-formatting
+check-formatting: ${GITALYFMT}
+ @${GITALYFMT} $(call find_go_sources) | awk '{ print } END { if(NR>0) { print "Formatting error, run make format"; exit(1) } }'
.PHONY: format
-format: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+format: ${GOIMPORTS} ${GITALYFMT}
+ @${GOIMPORTS} -w -l $(call find_go_sources)
+ @${GITALYFMT} -w $(call find_go_sources)
+ @${GOIMPORTS} -w -l $(call find_go_sources)
-.PHONY: cover
-cover: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+.PHONY: staticcheck-deprecations
+staticcheck-deprecations: ${GOLANGCI_LINT}
+ @${GOLANGCI_LINT} run --out-format tab --config ${SOURCE_DIR}/_support/golangci.warnings.yml
+
+.PHONY: lint-warnings
+lint-warnings: staticcheck-deprecations
+ # Runs verification analysis that is okay to fail (but not ignore completely)
+
+.PHONY: notice-up-to-date
+notice-up-to-date: notice-tmp
+ # notice-up-to-date
+ @(cmp ${BUILD_DIR}/NOTICE ${SOURCE_DIR}/NOTICE) || (echo >&2 "NOTICE requires update: 'make notice'" && false)
.PHONY: notice
-notice: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+notice: notice-tmp
+ mv ${BUILD_DIR}/NOTICE ${SOURCE_DIR}/NOTICE
-.PHONY: race-go
-race-go: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+.PHONY: notice-tmp
+notice-tmp: ${GO_LICENSES} clean-ruby-vendor-go
+ rm -rf ${BUILD_DIR}/licenses
+ ${GO_LICENSES} save ./... --save_path=${BUILD_DIR}/licenses
+ go run ${SOURCE_DIR}/_support/noticegen/noticegen.go -source ${BUILD_DIR}/licenses -template ${SOURCE_DIR}/_support/noticegen/notice.template > ${BUILD_DIR}/NOTICE
+
+.PHONY: clean
+clean:
+ rm -rf ${BUILD_DIR} ${SOURCE_DIR}/internal/testhelper/testdata/data/ ${SOURCE_DIR}/ruby/.bundle/ ${SOURCE_DIR}/ruby/gitlab-shell/config.yml ${SOURCE_DIR}/ruby/vendor/bundle/ $(addprefix ${SOURCE_DIR}/, $(notdir $(call find_commands)))
+
+.PHONY: clean-ruby-vendor-go
+clean-ruby-vendor-go:
+ mkdir -p ${SOURCE_DIR}/ruby/vendor && find ${SOURCE_DIR}/ruby/vendor -type f -name '*.go' -delete
+
+.PHONY: check-proto
+check-proto: proto no-changes
+
+.PHONY: rubocop
+rubocop: ${SOURCE_DIR}/.ruby-bundle
+ cd ${GITALY_RUBY_DIR} && bundle exec rubocop --parallel
+
+.PHONY: cover
+cover: prepare-tests
+ @echo "NOTE: make cover does not exit 1 on failure, don't use it to check for tests success!"
+ mkdir -p "${COVERAGE_DIR}"
+ rm -f "${COVERAGE_DIR}/all.merged" "${COVERAGE_DIR}/all.html"
+ @go test -ldflags='${GO_TEST_LDFLAGS}' -coverprofile "${COVERAGE_DIR}/all.merged" $(call find_go_packages)
+ @go tool cover -html "${COVERAGE_DIR}/all.merged" -o "${COVERAGE_DIR}/all.html"
+ @echo ""
+ @echo "=====> Total test coverage: <====="
+ @echo ""
+ @go tool cover -func "${COVERAGE_DIR}/all.merged"
.PHONY: docker
-docker: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+docker:
+ rm -rf ${BUILD_DIR}/docker/
+ mkdir -p ${BUILD_DIR}/docker/bin/
+ rm -rf ${GITALY_RUBY_DIR}/tmp
+ cp -r ${GITALY_RUBY_DIR} ${BUILD_DIR}/docker/ruby
+ rm -rf ${BUILD_DIR}/docker/ruby/vendor/bundle
+ for command in $(call find_commands); do \
+ GOOS=linux GOARCH=amd64 go build -tags "${GO_BUILD_TAGS}" ${GO_LDFLAGS} -o "${BUILD_DIR}/docker/bin/$${command}" ${GITALY_PACKAGE}/cmd/$${command}; \
+ done
+ cp ${SOURCE_DIR}/Dockerfile ${BUILD_DIR}/docker/
+ docker build -t gitlab/gitaly:v${GITALY_VERSION} -t gitlab/gitaly:latest ${BUILD_DIR}/docker/
.PHONY: proto
-proto: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+proto: ${PROTOC_GEN_GITALY} ${SOURCE_DIR}/.ruby-bundle
+ ${PROTOC} --gitaly_out=proto_dir=./proto,gitalypb_dir=./proto/go/gitalypb:. --go_out=paths=source_relative,plugins=grpc:./proto/go/gitalypb -I./proto ./proto/*.proto
+ ${SOURCE_DIR}/_support/generate-proto-ruby
+ # this part is related to the generation of sources from testing proto files
+ ${PROTOC} --plugin=${PROTOC_GEN_GO} --go_out=plugins=grpc:. internal/praefect/grpc-proxy/testdata/test.proto
+
+.PHONY: proto-lint
+proto-lint: ${PROTOC} ${PROTOC_GEN_GO}
+ mkdir -p ${SOURCE_DIR}/proto/go/gitalypb
+ rm -rf ${SOURCE_DIR}/proto/go/gitalypb/*.pb.go
+ ${PROTOC} --go_out=paths=source_relative:./proto/go/gitalypb -I./proto ./proto/lint.proto
.PHONY: no-changes
-no-changes: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+no-changes:
+ @git status --porcelain | awk '{ print } END { if (NR > 0) { exit 1 } }'
.PHONY: smoke-test
-smoke-test: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+smoke-test: all rspec
+ @go test ./internal/rubyserver
.PHONY: download-git
-download-git: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
+download-git: | ${BUILD_DIR}
+ @echo "Getting Git from ${GIT_BINARIES_URL}"
+ curl -o ${BUILD_DIR}/git_full_bins.tgz --silent --show-error -L ${GIT_BINARIES_URL}
+ rm -rf ${GIT_INSTALL_DIR}
+ mkdir -p ${GIT_INSTALL_DIR}
+ tar -C ${GIT_INSTALL_DIR} -xvzf ${BUILD_DIR}/git_full_bins.tgz
.PHONY: build-git
-build-git: prepare-build
- cd $(BUILD_DIR) && $(MAKE) $@
-
-.PHONY: prepare-build
-prepare-build: $(BUILD_DIR)/.ok update-makefile
-$(BUILD_DIR)/.ok:
- mkdir -p $(BUILD_DIR)
+build-git:
+ @echo "Getting Git from ${GIT_REPO_URL}"
+ rm -rf ${GIT_SOURCE_DIR} ${GIT_INSTALL_DIR}
+ git clone ${GIT_REPO_URL} ${GIT_SOURCE_DIR}
+ git -C ${GIT_SOURCE_DIR} checkout ${GIT_VERSION}
+ rm -rf ${GIT_INSTALL_DIR}
+ mkdir -p ${GIT_INSTALL_DIR}
+ ${MAKE} -C ${GIT_SOURCE_DIR} -j$(shell nproc) prefix=${GIT_PREFIX} ${GIT_BUILD_OPTIONS} install
+
+# This file is used by Omnibus and CNG to skip the "bundle install"
+# step. Both Omnibus and CNG assume it is in the Gitaly root, not in
+# _build. Hence the '../' in front.
+${SOURCE_DIR}/.ruby-bundle: ${GITALY_RUBY_DIR}/Gemfile.lock ${GITALY_RUBY_DIR}/Gemfile
+ cd ${GITALY_RUBY_DIR} && bundle config # for debugging
+ cd ${GITALY_RUBY_DIR} && bundle install ${BUNDLE_FLAGS}
touch $@
-.PHONY: update-makefile
-update-makefile: _build/makegen $(BUILD_DIR)/.ok
- cd $(BUILD_DIR) && ./makegen > Makefile
+${BUILD_DIR}:
+ mkdir -p ${BUILD_DIR}
-# This go.mod file soaks up go.mod/go.sum changes that we don't want in the top-level go.mod.
-$(BUILD_DIR)/go.mod: $(BUILD_DIR)/.ok
- (cd $(BUILD_DIR) && go mod init _build)
+${BUILD_DIR}/bin: | ${BUILD_DIR}
+ mkdir -p ${BUILD_DIR}/bin
-_build/makegen: _support/makegen.go $(BUILD_DIR)/go.mod
- cd $(BUILD_DIR) && go build -o $(CURDIR)/$@ $(SOURCE_DIR)/_support/makegen.go
+${BUILD_DIR}/go.mod: | ${BUILD_DIR}
+ cd ${BUILD_DIR} && go mod init _build
-clean:
- rm -rf $(BUILD_DIR) internal/testhelper/testdata/data/ ruby/.bundle/ ruby/gitlab-shell/config.yml ruby/vendor/bundle/
+${PROTOC}: ${BUILD_DIR}/protoc.zip | ${BUILD_DIR}
+ rm -rf ${BUILD_DIR}/protoc
+ mkdir -p ${BUILD_DIR}/protoc
+ cd ${BUILD_DIR}/protoc && unzip ${BUILD_DIR}/protoc.zip
+
+${BUILD_DIR}/protoc.zip: | ${BUILD_DIR}
+ curl -o $@.tmp --silent --show-error -L ${PROTOC_URL}
+ printf '${PROTOC_HASH} $@.tmp' | shasum -a256 -c -
+ mv $@.tmp $@
+
+${GOIMPORTS}: ${BUILD_DIR}/go.mod | ${BUILD_DIR}/bin
+ cd ${BUILD_DIR} && go get golang.org/x/tools/cmd/goimports@2538eef75904eff384a2551359968e40c207d9d2
+
+${GO_JUNIT_REPORT}: ${BUILD_DIR}/go.mod | ${BUILD_DIR}/bin
+ cd ${BUILD_DIR} && go get github.com/jstemmer/go-junit-report@984a47ca6b0a7d704c4b589852051b4d7865aa17
+
+${GITALYFMT}: ${BUILD_DIR}/bin
+ go build -o $@ ${SOURCE_DIR}/internal/cmd/gitalyfmt
+
+${GO_LICENSES}: ${BUILD_DIR}/go.mod | ${BUILD_DIR}/bin
+ cd ${BUILD_DIR} && go get github.com/google/go-licenses@0fa8c766a59182ce9fd94169ddb52abe568b7f4e
+
+${PROTOC_GEN_GO}: ${BUILD_DIR}/go.mod | ${BUILD_DIR}/bin
+ cd ${BUILD_DIR} && go get github.com/golang/protobuf/protoc-gen-go@v1.3.2
+
+${PROTOC_GEN_GITALY}: ${BUILD_DIR}/go.mod proto-lint | ${BUILD_DIR}/bin
+ go build -o $@ gitlab.com/gitlab-org/gitaly/proto/go/internal/cmd/protoc-gen-gitaly
+
+${GOLANGCI_LINT}: ${BUILD_DIR}/golangci-lint.tar.gz | ${BUILD_DIR}/bin
+ tar -x -z --strip-components 1 -C ${BUILD_DIR}/bin -f ${BUILD_DIR}/golangci-lint.tar.gz ${GOLANGCI_LINT_ARCHIVE}/golangci-lint
+ touch $@
+
+${BUILD_DIR}/golangci-lint.tar.gz: | ${BUILD_DIR}
+ curl -o $@.tmp --silent --show-error -L ${GOLANGCI_LINT_URL}
+ printf '${GOLANGCI_LINT_HASH} $@.tmp' | shasum -a256 -c -
+ mv $@.tmp $@
+
+${TEST_REPO}:
+ git clone --bare --quiet https://gitlab.com/gitlab-org/gitlab-test.git $@
+ # Git notes aren't fetched by default with git clone
+ git -C $@ fetch origin refs/notes/*:refs/notes/*
+ rm -rf $@/refs
+ mkdir -p $@/refs/heads $@/refs/tags
+ cp ${SOURCE_DIR}/_support/gitlab-test.git-packed-refs $@/packed-refs
+ git -C $@ fsck --no-progress
+
+${TEST_REPO_GIT}:
+ git clone --bare --quiet https://gitlab.com/gitlab-org/gitlab-git-test.git $@
+ rm -rf $@/refs
+ mkdir -p $@/refs/heads $@/refs/tags
+ cp ${SOURCE_DIR}/_support/gitlab-git-test.git-packed-refs $@/packed-refs
+ git -C $@ fsck --no-progress
+
+${GITLAB_SHELL_DIR}/config.yml: ${GITLAB_SHELL_DIR}/config.yml.example
+ cp $< $@
diff --git a/_support/Makefile.template b/_support/Makefile.template
deleted file mode 100644
index f3beb71d2..000000000
--- a/_support/Makefile.template
+++ /dev/null
@@ -1,318 +0,0 @@
-# _build/Makefile
-#
-# This is an auto-generated Makefile. Do not edit. Do not invoke
-# directly, use ../Makefile instead. This file is generated using
-# makegen.go.
-#
-
-# These variables may be overridden at runtime by top-level make
-PREFIX ?= /usr/local
-prefix ?= $(PREFIX)
-exec_prefix ?= $(prefix)
-bindir ?= $(exec_prefix)/bin
-INSTALL_DEST_DIR := $(DESTDIR)$(bindir)
-BUNDLE_FLAGS ?= {{ .BundleFlags }}
-ASSEMBLY_ROOT ?= {{ .BuildDir }}/assembly
-BUILD_TAGS := tracer_static tracer_static_jaeger continuous_profiler_stackdriver
-GO_TEST_LD_FLAGS := -X gitlab.com/gitlab-org/gitaly/auth.timestampThreshold=5s
-SHELL = /usr/bin/env bash -eo pipefail
-# These variables control test options and artifacts
-TEST_OPTIONS ?=
-TEST_REPORT_DIR ?= {{ .BuildDir }}/reports
-TEST_OUTPUT ?= $(TEST_REPORT_DIR)/go-tests-output-$(CI_JOB_NAME).txt
-TEST_REPORT ?= $(TEST_REPORT_DIR)/go-tests-report-$(CI_JOB_NAME).xml
-TEST_EXIT ?= $(TEST_REPORT_DIR)/go-tests-exit-$(CI_JOB_NAME).txt
-TEST_PACKAGES ?= {{ join .AllPackages " " }}
-
-unexport GOROOT
-export GOBIN = {{ .BuildDir }}/bin
-export GO111MODULE=on
-export GOPROXY ?= https://proxy.golang.org
-export PATH := {{ .BuildDir }}/bin:$(PATH)
-
-.NOTPARALLEL:
-
-.PHONY: all
-all: build
-
-.PHONY: build
-build: ../.ruby-bundle
- # go install
- @cd {{ .SourceDir }} && go install {{ .GoLdFlags }} -tags "$(BUILD_TAGS)" {{ join .CommandPackages " " }}
-
-# This file is used by Omnibus and CNG to skip the "bundle install"
-# step. Both Omnibus and CNG assume it is in the Gitaly root, not in
-# _build. Hence the '../' in front.
-../.ruby-bundle: {{ .GitalyRubyDir }}/Gemfile.lock {{ .GitalyRubyDir }}/Gemfile
- cd {{ .GitalyRubyDir }} && bundle config # for debugging
- cd {{ .GitalyRubyDir }} && bundle install $(BUNDLE_FLAGS)
- touch $@
-
-.PHONY: install
-install: build
- mkdir -p $(INSTALL_DEST_DIR)
- cd bin && install {{ join .Commands " " }} $(INSTALL_DEST_DIR)
-
-.PHONY: force-ruby-bundle
-force-ruby-bundle:
- rm -f ../.ruby-bundle
-
-# Assembles all runtime components into a directory
-# Used by the GDK: run 'make assemble ASSEMBLY_ROOT=.../gitaly'
-.PHONY: assemble
-assemble: force-ruby-bundle build assemble-internal
-
-# assemble-internal does not force 'bundle install' to run again
-.PHONY: assemble-internal
-assemble-internal: assemble-ruby assemble-go
-
-.PHONY: assemble-go
-assemble-go: build
- rm -rf $(ASSEMBLY_ROOT)/bin
- mkdir -p $(ASSEMBLY_ROOT)/bin
- cd bin && install {{ join .Commands " " }} $(ASSEMBLY_ROOT)/bin
-
-.PHONY: assemble-ruby
-assemble-ruby:
- mkdir -p $(ASSEMBLY_ROOT)
- rm -rf {{ .GitalyRubyDir }}/tmp {{ .GitlabShellDir }}/tmp
- mkdir -p $(ASSEMBLY_ROOT)/ruby/
- rsync -a --delete {{ .GitalyRubyDir }}/ $(ASSEMBLY_ROOT)/ruby/
- rm -rf $(ASSEMBLY_ROOT)/ruby/spec $(ASSEMBLY_ROOT)/{{ .GitlabShellRelDir }}/spec $(ASSEMBLY_ROOT)/{{ .GitlabShellRelDir }}/gitlab-shell.log
-
-binaries: assemble
- @if [ $$(uname -m) != 'x86_64' ]; then echo Incorrect architecture for build: $(uname -m); exit 1; fi
- @cd $(ASSEMBLY_ROOT) && shasum -a 256 bin/* | tee checksums.sha256.txt
-
-{{ .TestRepo }}:
- git clone --bare --quiet https://gitlab.com/gitlab-org/gitlab-test.git $@
- # Git notes aren't fetched by default with git clone
- git -C $@ fetch origin refs/notes/*:refs/notes/*
- rm -rf $@/refs
- mkdir -p $@/refs/heads $@/refs/tags
- cp {{ .SourceDir }}/_support/gitlab-test.git-packed-refs $@/packed-refs
- git -C $@ fsck --no-progress
-
-{{ .GitTestRepo }}:
- git clone --bare --quiet https://gitlab.com/gitlab-org/gitlab-git-test.git $@
- rm -rf $@/refs
- mkdir -p $@/refs/heads $@/refs/tags
- cp {{ .SourceDir }}/_support/gitlab-git-test.git-packed-refs $@/packed-refs
- git -C $@ fsck --no-progress
-
-.PHONY: prepare-tests
-prepare-tests: {{ .GitlabShellDir }}/config.yml {{ .TestRepo }} {{ .GitTestRepo }} ../.ruby-bundle
-
-{{ .GitlabShellDir }}/config.yml: {{ .GitlabShellDir }}/config.yml.example
- cp $< $@
-
-.PHONY: test
-test: test-go rspec rspec-gitlab-shell
-
-.PHONY: test-go
-test-go: prepare-tests {{ .GoJunitReport }}
- @mkdir -p $(TEST_REPORT_DIR)
- @cd {{ .SourceDir }} && \
- echo 0 > $(TEST_EXIT) && \
- (go test $(TEST_OPTIONS) -v -tags "$(BUILD_TAGS)" -ldflags='$(GO_TEST_LD_FLAGS)' -count=1 $(TEST_PACKAGES) 2>&1 | tee $(TEST_OUTPUT) || echo $$? > $(TEST_EXIT)) && \
- cat $(TEST_OUTPUT) | {{ .GoJunitReport }} > $(TEST_REPORT) && \
- exit `cat $(TEST_EXIT)`
-
-.PHONY: test-with-proxies
-test-with-proxies: prepare-tests
- @cd {{ .SourceDir }} &&\
- go test -tags "$(BUILD_TAGS)" -count=1 -exec {{ .SourceDir }}/_support/bad-proxies {{ .Pkg }}/internal/rubyserver/
-
-
-.PHONY: test-with-praefect
-test-with-praefect: build prepare-tests
- @cd {{ .SourceDir }} &&\
- GITALY_TEST_PRAEFECT_BIN={{ .BuildDir }}/bin/praefect go test -tags "$(BUILD_TAGS)" -ldflags='$(GO_TEST_LD_FLAGS)' -count=1 {{ join .AllPackages " " }} # count=1 bypasses go 1.10 test caching
-
-.PHONY: race-go
-race-go: TEST_OPTIONS = -race
-race-go: test-go
-
-.PHONY: rspec
-rspec: assemble-go prepare-tests
- cd {{ .GitalyRubyDir }} && bundle exec rspec
-
-.PHONY: rspec-gitlab-shell
-rspec-gitlab-shell: {{ .GitlabShellDir }}/config.yml assemble-go prepare-tests
- # rspec in {{ .GitlabShellRelDir }}
- @cd {{ .GitalyRubyDir }} && bundle exec bin/ruby-cd {{ .GitlabShellDir }} rspec
-
-.PHONY: test-postgres
-test-postgres: prepare-tests
- @cd {{ .SourceDir }} && go test -tags postgres -count=1 gitlab.com/gitlab-org/gitaly/internal/praefect/...
-
-.PHONY: verify
-verify: check-mod-tidy check-formatting notice-up-to-date check-proto rubocop
-
-.PHONY: check-mod-tidy
-check-mod-tidy:
- # check-mod-tidy
- @cd {{ .SourceDir }} && _support/check-mod-tidy
-
-.PHONY: lint
-lint: {{ .GoLint }}
- @cd {{ .SourceDir }} && \
- {{ .GoLint }} cache clean; \
- {{ .GoLint }} run --out-format tab --config .golangci.yml
-
-.PHONY: check-formatting
-check-formatting: {{ .GitalyFmt }}
- # gitalyfmt
- @cd {{ .SourceDir }} && {{ .GitalyFmt }} {{ join .GoFiles " " }} | {{ .MakeFormatCheck }}
-
-{{ .GoImports }}: {{ .MakegenDep }}
- go get golang.org/x/tools/cmd/goimports@2538eef75904eff384a2551359968e40c207d9d2
-
-{{ .GoJunitReport }}: {{ .MakegenDep }}
- go get github.com/jstemmer/go-junit-report@984a47ca6b0a7d704c4b589852051b4d7865aa17
-
-.PHONY: {{ .GitalyFmt }}
-{{ .GitalyFmt }}:
- @cd {{ .SourceDir }} && go build -o $@ ./internal/cmd/gitalyfmt
-
-.PHONY: format
-format: {{ .GoImports }} {{ .GitalyFmt }}
- # goimports pass 1
- @cd {{ .SourceDir }} && goimports -w -l {{ join .GoFiles " " }}
- # gitalyfmt
- @cd {{ .SourceDir }} && {{ .GitalyFmt }} -w {{ join .GoFiles " " }}
- # goimports pass 2
- @cd {{ .SourceDir }} && goimports -w -l {{ join .GoFiles " " }}
-
-.PHONY: staticcheck-deprecations
-staticcheck-deprecations: {{ .GoLint }}
- # Only returns deprecated code usage
- @cd {{ .SourceDir }} && \
- {{ .GoLint }} run --out-format tab --config _support/golangci.warnings.yml; \
- EXIT_CODE=$$?;\
- exit $$EXIT_CODE
-
-.PHONY: lint-warnings
-lint-warnings: staticcheck-deprecations
- # Runs verification analysis that is okay to fail (but not ignore completely)
-
-{{ .GoLicenses }}: {{ .MakegenDep }}
- go get github.com/google/go-licenses@0fa8c766a59182ce9fd94169ddb52abe568b7f4e
-
-.PHONY: notice-up-to-date
-notice-up-to-date: notice-tmp
- # notice-up-to-date
- @(cmp {{ .BuildDir }}/NOTICE {{ .SourceDir }}/NOTICE) || (echo >&2 "NOTICE requires update: 'make notice'" && false)
-
-.PHONY: notice
-notice: notice-tmp
- mv {{ .BuildDir }}/NOTICE {{ .SourceDir }}/NOTICE
-
-.PHONY: notice-tmp
-notice-tmp: {{ .GoLicenses }} clean-ruby-vendor-go
- rm -rf {{ .BuildDir}}/licenses
- cd {{ .SourceDir }} && {{ .BuildDir }}/{{ .GoLicenses }} save ./... --save_path={{ .BuildDir }}/licenses
- go run {{ .SourceDir }}/_support/noticegen/noticegen.go -source {{ .BuildDir }}/licenses -template {{ .SourceDir }}/_support/noticegen/notice.template > {{ .BuildDir }}/NOTICE
-
-.PHONY: clean-ruby-vendor-go
-clean-ruby-vendor-go:
- cd {{ .SourceDir }} && mkdir -p ruby/vendor && find ruby/vendor -type f -name '*.go' -delete
-
-.PHONY: check-proto
-check-proto: proto no-changes
-
-.PHONY: rubocop
-rubocop: ../.ruby-bundle
- cd {{ .GitalyRubyDir }} && bundle exec rubocop --parallel
-
-.PHONY: cover
-cover: prepare-tests
- @echo "NOTE: make cover does not exit 1 on failure, don't use it to check for tests success!"
- mkdir -p "{{ .CoverageDir }}"
- rm -f "{{ .CoverageDir }}/all.merged" "{{ .CoverageDir }}/all.html"
- @cd {{ .SourceDir }} && go test -ldflags='$(GO_TEST_LD_FLAGS)' -coverprofile "{{ .CoverageDir }}/all.merged" {{ join .AllPackages " " }}
- @cd {{ .SourceDir }} && go tool cover -html "{{ .CoverageDir }}/all.merged" -o "{{ .CoverageDir }}/all.html"
- @echo ""
- @echo "=====> Total test coverage: <====="
- @echo ""
- @@cd {{ .SourceDir }} && go tool cover -func "{{ .CoverageDir }}/all.merged"
-
-.PHONY: docker
-docker:
- rm -rf docker/
- mkdir -p docker/bin/
- rm -rf {{ .GitalyRubyDir }}/tmp
- cp -r {{ .GitalyRubyDir }} docker/ruby
- rm -rf docker/ruby/vendor/bundle
-{{ $pkg := .Pkg }}
-{{ $goLdFlags := .GoLdFlags }}
-{{ range $cmd := .Commands }}
- GOOS=linux GOARCH=amd64 go build -tags "$(BUILD_TAGS)" {{ $goLdFlags }} -o "docker/bin/{{ $cmd }}" {{ $pkg }}/cmd/{{ $cmd }}
-{{ end }}
- cp {{ .SourceDir }}/Dockerfile docker/
- docker build -t gitlab/gitaly:{{ .VersionPrefixed }} -t gitlab/gitaly:latest docker/
-
-.PHONY: proto
-proto: {{ .ProtoCGenGitaly }} ../.ruby-bundle
- cd {{ .SourceDir }} && {{ .ProtoC }} --gitaly_out=proto_dir=./proto,gitalypb_dir=./proto/go/gitalypb:. --go_out=paths=source_relative,plugins=grpc:./proto/go/gitalypb -I./proto ./proto/*.proto
- cd {{ .SourceDir }} && _support/generate-proto-ruby
-# this part is related to the generation of sources from testing proto files
- cd {{ .SourceDir }} && {{ .ProtoC }} --plugin={{ .ProtoCGenGo }} --go_out=plugins=grpc:. internal/praefect/grpc-proxy/testdata/test.proto
-
-.PHONY: proto-lint
-proto-lint: {{ .ProtoC }} {{ .ProtoCGenGo }}
- mkdir -p {{ .SourceDir }}/proto/go/gitalypb
- rm -rf {{ .SourceDir }}/proto/go/gitalypb/*.pb.go
- cd {{ .SourceDir }} && {{ .ProtoC }} --go_out=paths=source_relative:./proto/go/gitalypb -I./proto ./proto/lint.proto
-
-{{ .ProtoC }}: {{ .BuildDir }}/protoc.zip
- rm -rf {{ .BuildDir }}/protoc
- mkdir -p {{ .BuildDir }}/protoc
- cd {{ .BuildDir }}/protoc && unzip {{ .BuildDir }}/protoc.zip
- touch $@
-
-{{ .BuildDir }}/protoc.zip: {{ .MakegenDep }}
- curl -o $@.tmp --silent -L {{ .ProtoCURL }}
- printf '{{ .ProtoCSHA256 }} $@.tmp' | shasum -a256 -c -
- mv $@.tmp $@
-
-{{ .ProtoCGenGo }}: {{ .MakegenDep }}
- go get github.com/golang/protobuf/protoc-gen-go@v1.3.2
-
-.PHONY: {{ .ProtoCGenGitaly }}
-{{ .ProtoCGenGitaly }}: proto-lint
- cd {{ .SourceDir }}/proto/go/internal && go build -o $@ gitlab.com/gitlab-org/gitaly/proto/go/internal/cmd/protoc-gen-gitaly
-
-{{ .GoLint }}: {{ .BuildDir }}/golangci-lint.tar.gz
- mkdir -p {{ .BuildDir }}/bin
- cd {{ .BuildDir }} && tar -x -z --strip-components 1 -C {{ .BuildDir }}/bin -f golangci-lint.tar.gz {{ .GolangCILint }}/golangci-lint
-
-{{ .BuildDir }}/golangci-lint.tar.gz: {{ .MakegenDep }}
- curl -o $@.tmp --silent -L {{ .GolangCILintURL }}
- printf '{{ .GolangCILintSHA256 }} $@.tmp' | shasum -a256 -c -
- mv $@.tmp $@
-
-no-changes:
- # looking for changed files
- @cd {{ .SourceDir }} && git status --porcelain | awk '{ print } END { if (NR > 0) { exit 1 } }'
-
-smoke-test: all rspec
- @cd {{ .SourceDir }} && go test ./internal/rubyserver
-
-.PHONY: download-git
-download-git:
- @echo "Getting Git from {{ .GitArtifactUrl }}"
- wget -P {{ .BuildDir }} -O {{ .GitBuildTarball }} {{ .GitArtifactUrl }}
- rm -rf {{ .GitInstallDir }}
- mkdir -p {{ .GitInstallDir }}
- tar -C {{ .GitInstallDir }} -xvzf {{ .BuildDir }}/{{ .GitBuildTarball }}
-
-.PHONY: build-git
-build-git:
- @echo "Getting Git from {{ .GitDefaultRepoUrl }}"
- rm -rf {{ .GitSourceDir }} {{ .GitInstallDir }}
- git clone {{ .GitDefaultRepoUrl }} {{ .GitSourceDir }}
- git -C {{ .GitSourceDir }} checkout {{ .GitDefaultRev }}
- rm -rf {{ .GitInstallDir }}
- mkdir -p {{ .GitInstallDir }}
- $(MAKE) -C {{ .GitSourceDir }} prefix={{ .GitDefaultPrefix }} {{ .GitBuildOptions }} install
diff --git a/_support/makegen.go b/_support/makegen.go
deleted file mode 100644
index 2b5250ab6..000000000
--- a/_support/makegen.go
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- makegen.go -- Makefile generator for Gitaly
-
-This file is used to generate _build/Makefile. In _build/Makefile we
-can assume that we are in a GOPATH (rooted at _build) and that
-$GOPATH/bin is in PATH. The generator runs in the root of the Gitaly
-tree. The goal of the generator is to use as little dynamic behaviors
-in _build/Makefile (e.g. shelling out to find a list of files), and do
-these things as much as possible in Go and then pass them into the
-template.
-
-The working directory of makegen.go and the Makefile it generates is
-_build.
-*/
-
-package main
-
-import (
- "fmt"
- "io/ioutil"
- "log"
- "os"
- "os/exec"
- "path/filepath"
- "runtime"
- "sort"
- "strings"
- "text/template"
- "time"
-)
-
-func main() {
- gm := &gitalyMake{}
-
- tmpl := template.New("Makefile")
- tmpl.Funcs(map[string]interface{}{
- "join": strings.Join,
- })
- tmpl = template.Must(tmpl.Parse(templateText))
-
- err := tmpl.Execute(os.Stdout, gm)
- if err != nil {
- log.Fatalf("execution failed: %s", err)
- }
-}
-
-type gitalyMake struct {
- commandPackages []string
- cwd string
- versionPrefixed string
- goFiles []string
- buildTime string
-}
-
-// BuildDir is the GOPATH root. It is also the working directory of the Makefile we are generating.
-func (gm *gitalyMake) BuildDir() string {
- if len(gm.cwd) > 0 {
- return gm.cwd
- }
-
- cwd, err := os.Getwd()
- if err != nil {
- log.Fatal(err)
- }
- gm.cwd, err = filepath.EvalSymlinks(cwd)
- if err != nil {
- log.Fatal(err)
- }
-
- return gm.cwd
-}
-
-func (gm *gitalyMake) Pkg() string { return "gitlab.com/gitlab-org/gitaly" }
-func (gm *gitalyMake) GoImports() string { return "bin/goimports" }
-func (gm *gitalyMake) GitalyFmt() string { return filepath.Join(gm.BuildDir(), "bin/gitalyfmt") }
-func (gm *gitalyMake) GoLint() string { return filepath.Join(gm.BuildDir(), "bin/golangci-lint") }
-func (gm *gitalyMake) GoLicenses() string { return "bin/go-licenses" }
-func (gm *gitalyMake) StaticCheck() string { return filepath.Join(gm.BuildDir(), "bin/staticcheck") }
-func (gm *gitalyMake) ProtoC() string { return filepath.Join(gm.BuildDir(), "protoc/bin/protoc") }
-func (gm *gitalyMake) ProtoCGenGo() string { return filepath.Join(gm.BuildDir(), "bin/protoc-gen-go") }
-func (gm *gitalyMake) GoJunitReport() string {
- return filepath.Join(gm.BuildDir(), "bin/go-junit-report")
-}
-func (gm *gitalyMake) ProtoCGenGitaly() string {
- return filepath.Join(gm.BuildDir(), "bin/protoc-gen-gitaly")
-}
-func (gm *gitalyMake) GrpcToolsRuby() string {
- return filepath.Join(gm.BuildDir(), "bin/grpc_tools_ruby_protoc")
-}
-func (gm *gitalyMake) CoverageDir() string { return filepath.Join(gm.BuildDir(), "cover") }
-func (gm *gitalyMake) GitalyRubyDir() string { return filepath.Join(gm.SourceDir(), "ruby") }
-func (gm *gitalyMake) GitlabShellRelDir() string { return "ruby/gitlab-shell" }
-func (gm *gitalyMake) GitlabShellDir() string {
- return filepath.Join(gm.SourceDir(), gm.GitlabShellRelDir())
-}
-
-func (gm *gitalyMake) SourceDir() string {
- return os.Getenv("SOURCE_DIR")
-}
-
-func (gm *gitalyMake) TestRepoStoragePath() string {
- return filepath.Join(gm.SourceDir(), "internal/testhelper/testdata/data")
-}
-
-func (gm *gitalyMake) TestRepo() string {
- return filepath.Join(gm.TestRepoStoragePath(), "gitlab-test.git")
-}
-
-func (gm *gitalyMake) GitTestRepo() string {
- return filepath.Join(gm.TestRepoStoragePath(), "gitlab-git-test.git")
-}
-
-func (gm *gitalyMake) MakegenDep() string {
- return strings.Join([]string{
- filepath.Join(gm.SourceDir(), "_support/makegen.go"),
- filepath.Join(gm.SourceDir(), "_support/Makefile.template"),
- }, " ")
-}
-
-func (gm *gitalyMake) CommandPackages() []string {
- if len(gm.commandPackages) > 0 {
- return gm.commandPackages
- }
-
- entries, err := ioutil.ReadDir(filepath.Join(gm.SourceDir(), "cmd"))
- if err != nil {
- log.Fatal(err)
- }
-
- for _, dir := range entries {
- if !dir.IsDir() {
- continue
- }
-
- gm.commandPackages = append(gm.commandPackages, filepath.Join(gm.Pkg(), "cmd", dir.Name()))
- }
-
- return gm.commandPackages
-}
-
-func (gm *gitalyMake) Commands() []string {
- var out []string
- for _, pkg := range gm.CommandPackages() {
- out = append(out, filepath.Base(pkg))
- }
- return out
-}
-
-func (gm *gitalyMake) BuildTime() string {
- if len(gm.buildTime) > 0 {
- return gm.buildTime
- }
-
- now := time.Now().UTC()
- gm.buildTime = fmt.Sprintf("%d%02d%02d.%02d%02d%02d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
- return gm.buildTime
-}
-
-func (gm *gitalyMake) GoLdFlags() string {
- return fmt.Sprintf("-ldflags '-X %s/internal/version.version=%s -X %s/internal/version.buildtime=%s'", gm.Pkg(), gm.Version(), gm.Pkg(), gm.BuildTime())
-}
-
-func (gm *gitalyMake) VersionFromFile() string {
- data, err := ioutil.ReadFile("../VERSION")
- if err != nil {
- log.Printf("error obtaining version from file: %v", err)
- return ""
- }
-
- return fmt.Sprintf("v%s", strings.TrimSpace(string(data)))
-}
-
-func (gm *gitalyMake) VersionFromGit() string {
- cmd := exec.Command("git", "describe", "--match", "v*")
- cmd.Stderr = os.Stderr
- out, err := cmd.Output()
- if err != nil {
- log.Printf("error obtaining version from git: %s: %v", strings.Join(cmd.Args, " "), err)
- return ""
- }
-
- return strings.TrimSpace(string(out))
-}
-
-func (gm *gitalyMake) VersionPrefixed() string {
- if len(gm.versionPrefixed) > 0 {
- return gm.versionPrefixed
- }
-
- version := gm.VersionFromGit()
- if version == "" {
- log.Printf("Attempting to get the version from file")
- version = gm.VersionFromFile()
- }
-
- if version == "" {
- version = "unknown"
- }
-
- gm.versionPrefixed = version
- return gm.versionPrefixed
-}
-
-func (gm *gitalyMake) Version() string { return strings.TrimPrefix(gm.VersionPrefixed(), "v") }
-
-func (gm *gitalyMake) GoFiles() []string {
- if len(gm.goFiles) > 0 {
- return gm.goFiles
- }
-
- root := gm.SourceDir() + "/." // Add "/." to traverse symlink
-
- filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
-
- if info.IsDir() && path != root {
- switch path {
- case filepath.Join(root, "ruby"):
- return filepath.SkipDir
- case filepath.Join(root, "vendor"):
- return filepath.SkipDir
- case filepath.Join(root, "proto/go"):
- return filepath.SkipDir
- }
-
- if name := info.Name(); name == "testdata" || strings.HasPrefix(name, "_") || strings.HasPrefix(name, ".") {
- return filepath.SkipDir
- }
- }
-
- if !info.IsDir() && strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, ".pb.go") {
- rel, err := filepath.Rel(root, path)
- if err != nil {
- return err
- }
- gm.goFiles = append(gm.goFiles, rel)
- }
-
- return nil
- })
-
- sort.Strings(gm.goFiles)
-
- return gm.goFiles
-}
-
-func (gm *gitalyMake) AllPackages() []string {
- pkgMap := make(map[string]struct{})
- for _, f := range gm.GoFiles() {
- pkgMap[filepath.Dir(filepath.Join(gm.Pkg(), f))] = struct{}{}
- }
-
- var pkgs []string
- for k := range pkgMap {
- pkgs = append(pkgs, k)
- }
-
- sort.Strings(pkgs)
-
- return pkgs
-}
-
-type downloadInfo struct {
- url string
- sha256 string
-}
-
-var protoCDownload = map[string]downloadInfo{
- "darwin/amd64": downloadInfo{
- url: "https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-osx-x86_64.zip",
- sha256: "0decc6ce5beed07f8c20361ddeb5ac7666f09cf34572cca530e16814093f9c0c",
- },
- "linux/amd64": downloadInfo{
- url: "https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip",
- sha256: "6003de742ea3fcf703cfec1cd4a3380fd143081a2eb0e559065563496af27807",
- },
-}
-
-func (gm *gitalyMake) ProtoCURL() string {
- return protoCDownload[runtime.GOOS+"/"+runtime.GOARCH].url
-}
-
-func (gm *gitalyMake) ProtoCSHA256() string {
- return protoCDownload[runtime.GOOS+"/"+runtime.GOARCH].sha256
-}
-
-func (gm *gitalyMake) MakeFormatCheck() string {
- return `awk '{ print } END { if(NR>0) { print "Formatting error, run make format"; exit(1) } }'`
-}
-
-func (gm *gitalyMake) GolangCILintURL() string {
- return "https://github.com/golangci/golangci-lint/releases/download/v" + gm.GolangCILintVersion() + "/" + gm.GolangCILint() + ".tar.gz"
-}
-
-func (gm *gitalyMake) GolangCILintSHA256() string {
- switch runtime.GOOS + "/" + runtime.GOARCH {
- case "darwin/amd64":
- return "f05af56f15ebbcf77663a8955d1e39009b584ce8ea4c5583669369d80353a113"
- case "linux/amd64":
- return "241ca454102e909de04957ff8a5754c757cefa255758b3e1fba8a4533d19d179"
- default:
- return "unknown"
- }
-}
-
-func (gm *gitalyMake) GolangCILintVersion() string {
- return "1.24.0"
-}
-
-func (gm *gitalyMake) GolangCILint() string {
- return fmt.Sprintf("golangci-lint-%s-%s-%s", gm.GolangCILintVersion(), runtime.GOOS, runtime.GOARCH)
-}
-
-func (gm *gitalyMake) BundleFlags() string {
- if gm.IsGDK() {
- return "--no-deployment"
- }
-
- return "--deployment"
-}
-
-func (gm *gitalyMake) IsGDK() bool {
- _, err := os.Stat(filepath.Join(gm.SourceDir(), "../.gdk-install-root"))
- return err == nil
-}
-
-// Variables used with Git
-
-func (gm *gitalyMake) GitDefaultRev() string {
- rev := os.Getenv("GIT_REV")
- if rev != "" {
- return rev
- }
-
- // Gitaly defaults to a supported version for Git, which should be a
- // valid tag in: https://gitlab.com/gitlab-org/gitlab-git/-/tags
- return "v2.27.0"
-}
-
-func (gm *gitalyMake) GitDefaultBuildJob() string {
- job := os.Getenv("GIT_BUILD_JOB")
- if job != "" {
- return job
- }
- return "build"
-}
-
-func (gm *gitalyMake) GitInstallDir() string { return filepath.Join(gm.BuildDir(), "git") }
-func (gm *gitalyMake) GitBuildTarball() string { return "git_full_bins.tgz" }
-
-func (gm *gitalyMake) GitArtifactUrl() string {
- return "https://gitlab.com/gitlab-org/gitlab-git/-/jobs/artifacts/" +
- gm.GitDefaultRev() + "/raw/" +
- gm.GitBuildTarball() + "?job=" +
- gm.GitDefaultBuildJob()
-}
-
-func (gm *gitalyMake) GitDefaultRepoUrl() string {
- url := os.Getenv("GIT_REPO_URL")
- if url != "" {
- return url
- }
- return "https://gitlab.com/gitlab-org/gitlab-git.git"
-}
-
-func (gm *gitalyMake) GitSourceDir() string { return filepath.Join(gm.BuildDir(), "src", "git") }
-
-func (gm *gitalyMake) GitBuildOptions() string {
- buildOptions := []string{
- fmt.Sprintf("-j%v", runtime.NumCPU() + 1), // use multiple parallele jobs
- "DEVELOPER=1", // activate developer checks
- "CFLAGS='-O0 -g3'", // make it easy to debug in case of crashes
- "NO_PERL=YesPlease",
- "NO_EXPAT=YesPlease",
- "NO_TCLTK=YesPlease",
- "NO_REGEX=YesPlease", // fix compilation on musl libc
- "NO_GETTEXT=YesPlease",
- "NO_PYTHON=YesPlease",
- "NO_INSTALL_HARDLINKS=YesPlease",
- "NO_R_TO_GCC_LINKER=YesPlease",
- }
- return strings.Join(buildOptions, " ")
-}
-
-func (gm *gitalyMake) GitDefaultPrefix() string {
- prefix := os.Getenv("GIT_PREFIX")
- if prefix != "" {
- return prefix
- }
- return gm.GitInstallDir()
-}
-
-var templateText = func() string {
- contents, err := ioutil.ReadFile("../_support/Makefile.template")
- if err != nil {
- panic(err)
- }
- return string(contents)
-}()