summaryrefslogtreecommitdiff
blob: 59be9e42923eeeef3a42e9acfebfe93cb7a6535e (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=5

inherit eutils golang-base

MY_PN=${PN##*-}
EGO_PN="golang.org/x/${MY_PN}/..."
EGIT_COMMIT="2cd4472c321b6cba78e029d99f0e7fe51032fd21"

HOMEPAGE="https://godoc.org/${EGO_PN%/*}"
DESCRIPTION="Go client implementation for OAuth 2.0 spec"
SRC_URI="
	https://github.com/golang/${MY_PN}/archive/${EGIT_COMMIT}.tar.gz -> ${P}.tar.gz
	https://github.com/golang/net/archive/b6d7b1396ec874c3b00f6c84cd4301a17c56c8ed.tar.gz -> go-net-0_pre20160216.tar.gz
	https://github.com/GoogleCloudPlatform/gcloud-golang/archive/872c736f496c2ba12786bedbb8325576bbdb33cf.tar.gz -> gcloud-golang-872c736f496c2ba12786bedbb8325576bbdb33cf.tar.gz"

SLOT="0/${PVR}"
LICENSE="BSD"
KEYWORDS="~amd64"
IUSE=""

DEPEND="dev-go/go-tools"
RDEPEND=""

EGIT_CHECKOUT_DIR="${S}"

get_archive_go_package() {
	local archive=${1} uri x
	case ${archive} in
		${PN}-*) echo "oauth2-* golang.org/x/oauth2"; return;;
		gcloud-golang-*) echo "gcloud-golang-* google.golang.org/cloud"; return;;
		go-net-*) echo "net-* golang.org/x/net"; return;;
	esac
	for x in ${SRC_URI}; do
		if [[ ${x} == http* ]]; then
			uri=${x}
		elif [[ ${x} == ${archive} ]]; then
			break
		fi
	done
	uri=${uri#https://}
	uri=${uri%/archive/*}
	echo "${uri##*/}-* ${uri}"
}

unpack_go_packages() {
	local go_package pattern x
	# Unpack packages to appropriate locations for GOPATH
	for x in ${A}; do
		unpack ${x}
		if [[ ${x} == *.tar.gz ]]; then
			go_package=$(get_archive_go_package ${x})
			pattern=${go_package%% *}
			go_package=${go_package##* }
			if [[ ${x%.tar.gz} -ef ${S} ]]; then
				mv "${S}"{,_} || die
				mkdir -p "${S}/src/${go_package%/*}" || die
				mv "${S}"_ "${S}/src/${go_package}" || die || die
			else
				mkdir -p "${S}/src/${go_package%/*}" || die
				for x in ${pattern}; do
					if [[ ! ${x} -ef ${S} ]]; then
						mv "${x}" "${S}/src/${go_package}" || die
					fi
				done
			fi
		fi
	done
}

src_unpack() {
	unpack_go_packages

	# Create a writable GOROOT in order to avoid sandbox violations.
	# Omit $(get_golibdir_gopath) from GOPATH, in order to avoid
	# more sandbox violations (bug 575722).
	GOROOT="${WORKDIR}/goroot" GOPATH="${S}"
	cp -sR "$(go env GOROOT)" "${GOROOT}" || die
	rm -rf "${GOROOT}/src/${EGO_PN%/*}" || die
	export GOROOT GOPATH

	mkdir -p "${GOROOT}/src/google.golang.org" || die
	rm -rf "${GOROOT}/src/google.golang.org"/* || die
	rm -rf "${GOROOT}/pkg/${KERNEL}_${ARCH}/google.golang.org" || die
}

src_compile() {
	GOROOT="${GOROOT}" GOPATH="${GOPATH}" \
		go install -v -work -x ${EGO_BUILD_FLAGS} "${EGO_PN}" || die
}

src_test() {
	# google/example_test.go imports appengine, introducing a circular dep
	mv src/${EGO_PN%/*}/google/example_test.go{,_} || die
	go test -x -v "${EGO_PN}" || die $?
	mv src/${EGO_PN%/*}/google/example_test.go{_,} || die
}

src_install() {
	golang_install_pkgs
}

golang_install_pkgs() {
	insinto $(dirname "${EPREFIX}$(get_golibdir)/src/${EGO_PN%/*}")
	rm -rf "${S}"/src/${EGO_PN%/*}/.git*
	doins -r "${S}"/src/${EGO_PN%/*}
	insinto $(dirname "${EPREFIX}$(get_golibdir)/pkg/$(go env GOOS)_$(go env GOARCH)/${EGO_PN%/*}")
	doins -r "${S}"/pkg/$(go env GOOS)_$(go env GOARCH)/${EGO_PN%/*}{,.a}
}