Browse Source

Update golang-base.eclass

master
KronoZed 2 years ago
parent
commit
efe9ec19f8
1 changed files with 28 additions and 21 deletions
  1. 28
    21
      eclass/golang-base.eclass

+ 28
- 21
eclass/golang-base.eclass View File

@@ -159,7 +159,7 @@ GOLANG_PKG_TAGS="${GOLANG_PKG_TAGS:-}"
159 159
 # Sets additional standard Go workspaces to be appended to the environment
160 160
 # variable GOPATH, as described in http://golang.org/doc/code.html.
161 161
 # This eclass defaults to an empty list.
162
-GOLANG_PKG_VENDOR=()
162
+GOLANG_PKG_VENDOR="${GOLANG_PKG_VENDOR:-}"
163 163
 
164 164
 # @ECLASS-VARIABLE: GOLANG_PKG_STATIK
165 165
 # @DESCRIPTION:
@@ -395,7 +395,6 @@ golang_setup() {
395 395
 		export GOBIN="$_GOBIN"
396 396
 		export CGO_ENABLED
397 397
 		export GOEXPERIMENT
398
-		export GO15VENDOREXPERIMENT=0
399 398
 
400 399
 		debug-print "${FUNCNAME}: GOPATH = ${GOPATH}"
401 400
 		debug-print "${FUNCNAME}: GOBIN = ${GOBIN}"
@@ -521,7 +520,6 @@ golang-base_src_prepare() {
521 520
 	local VENDOR="${S}/vendor"
522 521
 	if [[ -d "${VENDOR}" ]]; then
523 522
 		golang_add_vendor "${VENDOR}"
524
-		export GO15VENDOREXPERIMENT=1
525 523
 	fi
526 524
 
527 525
 	# Auto-detects the presence of Go's vendored
@@ -549,7 +547,7 @@ golang-base_src_prepare() {
549 547
 	# (see github.com/tools/godep for more infos).
550 548
 	VENDOR="${S}/Godeps/_workspace"
551 549
 	if [[ -d "${VENDOR}" ]]; then
552
-		golang_add_vendor "${VENDOR}"
550
+		GOLANG_PKG_VENDOR+=" ${VENDOR}"
553 551
 	fi
554 552
 
555 553
 
@@ -678,19 +676,22 @@ golang-base_src_compile() {
678 676
 	[[ ${EGO} ]] || die "No GoLang implementation set (golang_setup not called?)."
679 677
 
680 678
 	# Populates env variable GOPATH with vendored workspaces (if present).
681
-	if [[ -n ${GOLANG_PKG_VENDOR} ]]; then
679
+	if [[ -n ${GOLANG_PKG_VENDOR} || "1" == ${GO15VENDOREXPERIMENT} ]]; then
682 680
 		einfo "Using vendored dependencies from:"
683 681
 
682
+		# Prints Go's vendored directory.
683
+		if [[ "1" == ${GO15VENDOREXPERIMENT} ]]; then
684
+			einfo "- vendor"
685
+		fi
686
+	fi
687
+
688
+	# Prints user defined vendored directories.
689
+	if [[ -n ${GOLANG_PKG_VENDOR} ]]; then
684 690
 		for path in "${GOLANG_PKG_VENDOR[@]}"; do
685 691
 			[ -d ${path} ] || continue
686 692
 
687
-			if [[ ${path//${S}\//} == "vendor" ]]; then
688
-				einfo "- vendor/ (native vendoring support)"
689
-				continue
690
-			fi
691
-
692 693
 			debug-print "$FUNCNAME: GOPATH: Adding vendor path ${path}"
693
-			ebegin "- ${path//${S}\//}"
694
+			ebegin "- ${path//${WORKDIR}\//}"
694 695
 				GOPATH="${GOPATH}:$( echo ${path} )"
695 696
 			eend
696 697
 		done
@@ -831,7 +832,7 @@ golang-base_src_test() {
831 832
 
832 833
 	# Defines sub-packages.
833 834
 	local EGO_SUBPACKAGES="${GOLANG_PKG_IMPORTPATH_ALIAS}/${GOLANG_PKG_NAME}${GOLANG_PKG_BUILDPATH}"
834
-	[[ -z ${GOLANG_PKG_IS_MULTIPLE} ]] || EGO_SUBPACKAGES="./..."
835
+	[[ -n ${GOLANG_PKG_IS_MULTIPLE} ]] || EGO_SUBPACKAGES="./..."
835 836
 
836 837
 	# Runs the unit tests.
837 838
 	einfo "${EGO} test ${EGO_BUILD_FLAGS} ${EGO_SUBPACKAGES}"
@@ -900,16 +901,22 @@ golang_add_vendor() {
900 901
 
901 902
 	[[ ${GOLANG_VERSION} ]] || die "No Golang implementation set (golang_setup not called?)."
902 903
 
903
-	[[ ! -d "${1}" ]] && return
904
-
905
-	# NOTE: this hack is required by Go v1.4 and older versions.
906
-	if [[ ! -d "${1}"/src ]]; then
907
-		ebegin "Fixing $1"
908
-			ln -s "${1}" "${1}"/src || die
909
-		eend
910
-	fi
904
+	case $( get_version_component_range 1-2 ${GOLANG_VERSION} ) in
905
+		1.4*)
906
+			# TODO: traverse $1 and expose all the bundled /vendor
907
+			#       sub-directories to GOLANG_PKG_VENDOR
908
+			if [[ ! -d "${1}"/src ]]; then
909
+				ebegin "Fixing $1"
910
+					ln -s "${1}" "${1}"/src || die
911
+				eend
912
+			fi
911 913
 
912
-	GOLANG_PKG_VENDOR+=(${1})
914
+			GOLANG_PKG_VENDOR+=" ${1}"
915
+			;;
916
+		1.5*)
917
+			export GO15VENDOREXPERIMENT=1
918
+			;;
919
+	esac
913 920
 }
914 921
 
915 922
 

Loading…
Cancel
Save