summaryrefslogtreecommitdiff
blob: 1ca83ab1189740a020b9baa32c2f63bc5e745354 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/golang-build.eclass,v 1.2 2015/06/24 17:04:53 williamh Exp $

# @ECLASS: golang-build.eclass
# @MAINTAINER:
# William Hubbs <williamh@gentoo.org>
# @BLURB: Eclass for compiling go packages.
# @DESCRIPTION:
# This eclass provides default  src_compile, src_test and src_install
# functions for software written in the Go programming language.

case "${EAPI:-0}" in
	5)
		;;
	*)
		die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
		;;
esac

EXPORT_FUNCTIONS src_compile src_install src_test

if [[ -z ${_GOLANG_BUILD} ]]; then

_GOLANG_BUILD=1

DEPEND=">=dev-lang/go-1.4.2:="
STRIP_MASK="*.a"

# @ECLASS-VARIABLE: EGO_PN
# @REQUIRED
# @DESCRIPTION:
# This is the import path for the go package(s) to build. Please emerge
# dev-lang/go and read "go help importpath" for syntax.
#
# Example:
# @CODE
# EGO_PN=github.com/user/package
# @CODE

# @FUNCTION: _golang-build_setup
# @INTERNAL
# @DESCRIPTION:
# Make sure EGO_PN has a value.
_golang-build_setup() {
	[[ -z "${EGO_PN}" ]] &&
		die "${ECLASS}.eclass: EGO_PN is not set"
	return 0
}

golang-build_src_compile() {
	debug-print-function ${FUNCNAME} "$@"

	_golang-build_setup
	set -- env GOPATH="${WORKDIR}/${P}:${EPREFIX}/usr/lib/go-gentoo" \
		go build -v -work -x "${EGO_PN}"
	echo "$@"
	"$@" || die
}

golang-build_src_install() {
	debug-print-function ${FUNCNAME} "$@"

	_golang-build_setup
	set -- env GOPATH="${WORKDIR}/${P}:${EPREFIX}/usr/lib/go-gentoo" \
		go install -v -work -x "${EGO_PN}"
	echo "$@"
	"$@" || die
	insinto /usr/lib/go-gentoo
	insopts -m0644 -p # preserve timestamps for bug 551486
	doins -r pkg src
}

golang-build_src_test() {
	debug-print-function ${FUNCNAME} "$@"

	_golang-build_setup
	set -- env GOPATH="${WORKDIR}/${P}:${EPREFIX}/usr/lib/go-gentoo" \
		go test -v -work -x "${EGO_PN}"
	echo "$@"
	"$@" || die
}

fi