Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
build: check golang version meets min req.
Browse files Browse the repository at this point in the history
Check that the system golang version is new enough to build with
according to the data from the `versions.yaml` file.

Update the verions in the versions.yaml accordingly, and add a note
describing what the 'newest-version' item represents.
Note, we only do a minimum requirement check, and are not checking
against the 'newest-version' info from the yaml.

Fixes: #148

Inspired-by: Wei Zhang <zhangwei555@huawei.com>
Idea-by: James O. D. Hunt <james.o.hunt@intel.com>
Signed-off-by: Graham Whaley <graham.whaley@intel.com>
  • Loading branch information
Graham Whaley committed Oct 30, 2018
1 parent 1fe408e commit b318759
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ done)
GOARCH=$(shell go env GOARCH)
HOST_ARCH=$(shell arch)

include golang.mk

ifeq ($(ARCH),)
ARCH = $(GOARCH)
endif
Expand Down
46 changes: 46 additions & 0 deletions golang.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
# Check that the system golang version is within the required version range
# for this project.

golang_version_min=$(shell yq r versions.yaml languages.golang.version)

ifeq (,$(golang_version_min))
$(error "ERROR: cannot determine minimum golang version")
endif

golang_version_min_fields=$(subst ., ,$(golang_version_min))

golang_version_min_major=$(word 1,$(golang_version_min_fields))
golang_version_min_minor=$(word 2,$(golang_version_min_fields))

# for error messages
golang_version_needed=$(golang_version_min_major).$(golang_version_min_minor)

golang_version_raw=$(shell go version 2>/dev/null)

ifeq (,$(golang_version_raw))
$(error "ERROR: cannot determine golang version")
endif

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

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

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)

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)")
endif
5 changes: 4 additions & 1 deletion versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ languages:
issue: "https://github.com/golang/go/issues/20676"
version: "1.10.4"
meta:
newest-version: "1.11"
description: |
'newest-version' is the latest version known to work when
building Kata
newest-version: "1.11.1"

specs:
description: "Details of important specifications"
Expand Down

0 comments on commit b318759

Please sign in to comment.