app-admin/mtail: add package
[gentoo.git] / app-admin / mtail / mtail-0_pre20161108.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=6
6
7 KEYWORDS="~amd64"
8 EGO_PN=github.com/google/mtail
9 EGIT_COMMIT=a780a6342bd70a8fb8ffe187ef988d5417d43a96
10 SRC_URI="https://${EGO_PN}/archive/${EGIT_COMMIT}.tar.gz -> ${P}.tar.gz
11         https://github.com/spf13/afero/archive/06b7e5f50606ecd49148a01a6008942d9b669217.tar.gz -> afero-06b7e5f50606ecd49148a01a6008942d9b669217.tar.gz
12         https://github.com/golang/glog/archive/23def4e6c14b4da8ac2ed8007337bc5eb5007998.tar.gz -> go-glog-23def4e6c14b4da8ac2ed8007337bc5eb5007998.tar.gz
13         https://github.com/fsnotify/fsnotify/archive/v1.4.2.tar.gz -> go-fsnotify-1.4.2.tar.gz
14         https://github.com/golang/tools/archive/76b6c242fbd3fa734fbfe26a653f14fd495cb03a.tar.gz -> go-tools-76b6c242fbd3fa734fbfe26a653f14fd495cb03a.tar.gz
15         https://github.com/golang/sys/archive/30237cf4eefd639b184d1f2cb77a581ea0be8947.tar.gz -> go-sys-30237cf4eefd639b184d1f2cb77a581ea0be8947.tar.gz
16         https://github.com/golang/text/archive/b01949dc0793a9af5e4cb3fce4d42999e76e8ca1.tar.gz -> go-text-b01949dc0793a9af5e4cb3fce4d42999e76e8ca1.tar.gz
17         test? (
18                 https://github.com/kylelemons/godebug/archive/d99083b96f422f8fd5a93bc02040acec769e178f.tar.gz -> godebug-d99083b96f422f8fd5a93bc02040acec769e178f.tar.gz
19         )"
20 DESCRIPTION="A tool for extracting metrics from application logs"
21 HOMEPAGE="https://${EGO_PN}/"
22 LICENSE="Apache-2.0"
23 SLOT="0"
24 IUSE="test"
25 DEPEND=">=dev-lang/go-1.6:="
26 RDEPEND=""
27
28 get_archive_go_package() {
29         local archive=${1} uri x
30         for x in ${SRC_URI}; do
31                 if [[ ${x} == http* ]]; then
32                         uri=${x}
33                 elif [[ ${x} == ${archive} ]]; then
34                         break
35                 fi
36         done
37         uri=${uri#https://}
38         uri=${uri%/archive/*}
39         case ${uri} in
40                 github.com/fsnotify/fsnotify)
41                         echo "gopkg.in/fsnotify.v1|fsnotify-*"
42                         ;;
43                 github.com/golang/glog)
44                         echo "${uri}|${uri##*/}-*"
45                         ;;
46                 github.com/golang/*)
47                         echo "golang.org/x/${uri##*/}|${uri##*/}-*"
48                         ;;
49                 *)
50                         echo "${uri}|${uri##*/}-*"
51                         ;;
52         esac
53 }
54
55 unpack_go_packages() {
56         local go_package x
57         # Unpack packages to appropriate locations for GOPATH
58         for x in ${A}; do
59                 unpack ${x}
60                 if [[ ${x} == *.tar.gz ]]; then
61                         go_package=$(get_archive_go_package ${x})
62                         x=${go_package#*|}
63                         go_package=${go_package%|*}
64                         mkdir -p src/${go_package%/*}
65                         mv ${x} src/${go_package} || die
66                 fi
67         done
68 }
69
70 src_unpack() {
71         mkdir "${S}" || die
72         cd "${S}" || die
73         unpack_go_packages
74 }
75
76 src_prepare() {
77         default
78         sed '/^[[:space:]]*go get .*/d' -i "${S}/src/${EGO_PN}/Makefile" || die
79 }
80
81 src_compile() {
82         export GOPATH="${S}"
83         go install -v -work -x ${EGO_BUILD_FLAGS} "golang.org/x/tools/cmd/goyacc" || die
84         PATH=${S}/bin:${PATH} emake -C "${S}/src/${EGO_PN}"
85 }
86
87 src_test() {
88         cd "${S}/src/${EGO_PN}" || die
89         default
90 }
91
92 src_install() {
93         dobin bin/mtail
94         dodoc "${S}/src/${EGO_PN}/"{CONTRIBUTING.md,README.md,TODO}
95 }