Skip to content

Commit 48b8f50

Browse files
author
Graham Whaley
committed
build: check golang version meets min req.
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: kata-containers#148 Inspired-by: Wei Zhang <[email protected]> Idea-by: James O. D. Hunt <[email protected]> Signed-off-by: Graham Whaley <[email protected]>
1 parent 75e4219 commit 48b8f50

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ done)
1515
GOARCH=$(shell go env GOARCH)
1616
HOST_ARCH=$(shell arch)
1717

18+
include golang.mk
19+
1820
ifeq ($(ARCH),)
1921
ARCH = $(GOARCH)
2022
endif

golang.mk

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Copyright (c) 2018 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Check that the system golang version is within the required version range
7+
# for this project.
8+
9+
golang_version_min=$(shell yq r versions.yaml languages.golang.version)
10+
11+
ifeq (,$(golang_version_min))
12+
$(error "ERROR: cannot determine minimum golang version")
13+
endif
14+
15+
golang_version_min_fields=$(subst ., ,$(golang_version_min))
16+
17+
golang_version_min_major=$(word 1,$(golang_version_min_fields))
18+
golang_version_min_minor=$(word 2,$(golang_version_min_fields))
19+
20+
# for error messages
21+
golang_version_needed=$(golang_version_min_major).$(golang_version_min_minor)
22+
23+
golang_version_raw=$(shell go version 2>/dev/null)
24+
25+
ifeq (,$(golang_version_raw))
26+
$(error "ERROR: cannot determine golang version")
27+
endif
28+
29+
# determine actual version of golang
30+
golang_version=$(subst go,,$(word 3,$(golang_version_raw)))
31+
32+
golang_version_fields=$(subst ., ,$(golang_version))
33+
34+
golang_version_major=$(word 1,$(golang_version_fields))
35+
golang_version_minor=$(word 2,$(golang_version_fields))
36+
37+
golang_major_ok=$(shell test $(golang_version_major) -ge $(golang_version_min_major) && echo ok)
38+
golang_minor_ok=$(shell test $(golang_version_major) -eq $(golang_version_min_major) -a $(golang_version_minor) -ge $(golang_version_min_minor) && echo ok)
39+
40+
ifeq (,$(golang_major_ok))
41+
$(error "ERROR: golang major version too old: got $(golang_version), need atleast $(golang_version_needed)")
42+
endif
43+
44+
ifeq (,$(golang_minor_ok))
45+
$(error "ERROR: golang minor version too old: got $(golang_version), need atleast $(golang_version_needed)")
46+
endif

versions.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ languages:
189189
issue: "https://github.com/golang/go/issues/20676"
190190
version: "1.10.4"
191191
meta:
192-
newest-version: "1.11"
192+
description: |
193+
'newest-version' is the latest version known to work when
194+
building Kata
195+
newest-version: "1.11.1"
193196

194197
specs:
195198
description: "Details of important specifications"

0 commit comments

Comments
 (0)