Skip to content

Commit

Permalink
Makefile: Change "GOPATH not set" to "No GO command or GOPATH not set"
Browse files Browse the repository at this point in the history
The cause that make "sudo make install" fail is not "GOPATH not set",
but no go command in path.
But the commit still keep the "GOPATH not set" because
execute "unset GOPATH; make" will fail because "go build" cannot work
without GOPATH.

Fixes: kata-containers#1285

Signed-off-by: Hui Zhu <teawater@hyper.sh>
  • Loading branch information
teawater committed Mar 1, 2019
1 parent e8a8e0d commit a1ddf53
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
18 changes: 5 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ for file in /etc/os-release /usr/lib/os-release; do \
fi \
done)

HOST_ARCH=$(shell arch)
ifeq ($(GOPATH),)
SKIP_GO_VERSION_CHECK=y
else
SKIP_GO_VERSION_CHECK=
endif

ifeq ($(SKIP_GO_VERSION_CHECK),)
include golang.mk
endif
SKIP_GO_VERSION_CHECK=
include golang.mk

#Get ARCH.
ifneq ($(GOPATH),)
ifneq (,$(golang_version_raw))
GOARCH=$(shell go env GOARCH)
ifeq ($(ARCH),)
ARCH = $(GOARCH)
Expand Down Expand Up @@ -608,7 +600,7 @@ show-footer:
@printf "\tBugs: $(PROJECT_BUG_URL)\n\n"

show-summary: show-header
ifneq ($(GOPATH),)
ifneq (,$(golang_version_raw))
@printf "• architecture:\n"
@printf "\tHost: $(HOST_ARCH)\n"
@printf "\tgolang: $(GOARCH)\n"
Expand All @@ -618,7 +610,7 @@ ifneq ($(GOPATH),)
@printf "\t"
@go version
else
@printf "• GOPATH not set:\n"
@printf "• No GO command or GOPATH not set:\n"
@printf "\tCan only install prebuilt binaries\n"
endif
@printf "\n"
Expand Down
70 changes: 39 additions & 31 deletions golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,57 @@
# Check that the system golang version is within the required version range
# for this project.

have_yq=$(shell if [ -x "$(GOPATH)/bin/yq" ]; then echo "true"; else echo ""; fi)
ifeq (,$(have_yq))
$(info INFO: yq was not found, installing it)
install_yq=$(shell .ci/install-yq.sh)
golang_version_raw=$(shell go version 2>/dev/null)
not_check_version=
ifeq (,$(GOPATH))
golang_version_raw=
endif
ifneq (,$(install_yq))
$(error "ERROR: install yq failed")
ifeq (,$(golang_version_raw))
not_check_version=y
endif
golang_version_min=$(shell $(GOPATH)/bin/yq r versions.yaml languages.golang.version)

ifeq (,$(golang_version_min))
$(error "ERROR: cannot determine minimum golang version")
ifneq (,$(SKIP_GO_VERSION_CHECK))
not_check_version=y
endif

golang_version_min_fields=$(subst ., ,$(golang_version_min))
ifeq (,$(not_check_version))
have_yq=$(shell if [ -x "$(GOPATH)/bin/yq" ]; then echo "true"; else echo ""; fi)
ifeq (,$(have_yq))
$(info INFO: yq was not found, installing it)
install_yq=$(shell .ci/install-yq.sh)
endif
ifneq (,$(install_yq))
$(error "ERROR: install yq failed")
endif
golang_version_min=$(shell $(GOPATH)/bin/yq r versions.yaml languages.golang.version)

golang_version_min_major=$(word 1,$(golang_version_min_fields))
golang_version_min_minor=$(word 2,$(golang_version_min_fields))
ifeq (,$(golang_version_min))
$(error "ERROR: cannot determine minimum golang version")
endif

# for error messages
golang_version_needed=$(golang_version_min_major).$(golang_version_min_minor)
golang_version_min_fields=$(subst ., ,$(golang_version_min))

golang_version_raw=$(shell go version 2>/dev/null)
golang_version_min_major=$(word 1,$(golang_version_min_fields))
golang_version_min_minor=$(word 2,$(golang_version_min_fields))

ifeq (,$(golang_version_raw))
$(error "ERROR: cannot determine golang version")
endif
# for error messages
golang_version_needed=$(golang_version_min_major).$(golang_version_min_minor)

# determine actual version of golang
golang_version=$(subst go,,$(word 3,$(golang_version_raw)))
# determine actual version of golang
golang_version=$(subst go,,$(word 3,$(golang_version_raw)))

golang_version_fields=$(subst ., ,$(golang_version))
golang_version_fields=$(subst ., ,$(golang_version))

golang_version_major=$(word 1,$(golang_version_fields))
golang_version_minor=$(word 2,$(golang_version_fields))
golang_version_major=$(word 1,$(golang_version_fields))
golang_version_minor=$(word 2,$(golang_version_fields))

golang_major_ok=$(shell test $(golang_version_major) -ge $(golang_version_min_major) && echo ok)
golang_minor_ok=$(shell test $(golang_version_major) -eq $(golang_version_min_major) -a $(golang_version_minor) -ge $(golang_version_min_minor) && echo ok)
golang_major_ok=$(shell test $(golang_version_major) -ge $(golang_version_min_major) && echo ok)
golang_minor_ok=$(shell test $(golang_version_major) -eq $(golang_version_min_major) -a $(golang_version_minor) -ge $(golang_version_min_minor) && echo ok)

ifeq (,$(golang_major_ok))
$(error "ERROR: golang major version too old: got $(golang_version), need atleast $(golang_version_needed)")
endif
ifeq (,$(golang_major_ok))
$(error "ERROR: golang major version too old: got $(golang_version), need atleast $(golang_version_needed)")
endif

ifeq (,$(golang_minor_ok))
$(error "ERROR: golang minor version too old: got $(golang_version), need atleast $(golang_version_needed)")
ifeq (,$(golang_minor_ok))
$(error "ERROR: golang minor version too old: got $(golang_version), need atleast $(golang_version_needed)")
endif
endif

0 comments on commit a1ddf53

Please sign in to comment.