summaryrefslogtreecommitdiffstats
path: root/meta/classes/go.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/go.bbclass')
-rw-r--r--meta/classes/go.bbclass62
1 files changed, 60 insertions, 2 deletions
diff --git a/meta/classes/go.bbclass b/meta/classes/go.bbclass
index 4af148e302..33502bf722 100644
--- a/meta/classes/go.bbclass
+++ b/meta/classes/go.bbclass
@@ -1,4 +1,4 @@
1inherit goarch 1inherit goarch ptest
2 2
3def get_go_parallel_make(d): 3def get_go_parallel_make(d):
4 pm = (d.getVar('PARALLEL_MAKE') or '').split() 4 pm = (d.getVar('PARALLEL_MAKE') or '').split()
@@ -39,6 +39,8 @@ GO_RPATH_LINK_class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pk
39GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}" 39GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}"
40GO_LDFLAGS ?= '-ldflags="${GO_RPATH} -extldflags '${GO_EXTLDFLAGS}'"' 40GO_LDFLAGS ?= '-ldflags="${GO_RPATH} -extldflags '${GO_EXTLDFLAGS}'"'
41export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}" 41export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}"
42export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
43export GOPTESTFLAGS ?= "-test.v"
42GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} " 44GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} "
43 45
44export GO = "${HOST_PREFIX}go" 46export GO = "${HOST_PREFIX}go"
@@ -81,6 +83,13 @@ go_list_packages() {
81 egrep -v '${GO_INSTALL_FILTEROUT}' 83 egrep -v '${GO_INSTALL_FILTEROUT}'
82} 84}
83 85
86go_list_package_tests() {
87 ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
88 grep -v '\[\]$' | \
89 egrep -v '${GO_INSTALL_FILTEROUT}' | \
90 awk '{ print $1 }'
91}
92
84go_do_configure() { 93go_do_configure() {
85 ln -snf ${S}/src ${B}/ 94 ln -snf ${S}/src ${B}/
86} 95}
@@ -93,9 +102,19 @@ go_do_compile() {
93} 102}
94do_compile[cleandirs] = "${B}/bin ${B}/pkg" 103do_compile[cleandirs] = "${B}/bin ${B}/pkg"
95 104
105do_compile_ptest() {
106 rm -f ${B}/.go_compiled_tests.list
107 go_list_package_tests | while read pkg; do
108 cd ${B}/src/$pkg
109 ${GO} test ${GOPTESTBUILDFLAGS} $pkg
110 find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \
111 sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list
112 done
113}
114
96go_do_install() { 115go_do_install() {
97 install -d ${D}${libdir}/go/src/${GO_IMPORT} 116 install -d ${D}${libdir}/go/src/${GO_IMPORT}
98 tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs . | \ 117 tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' . | \
99 tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf - 118 tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf -
100 tar -C ${B} -cf - pkg | tar -C ${D}${libdir}/go --no-same-owner -xf - 119 tar -C ${B} -cf - pkg | tar -C ${D}${libdir}/go --no-same-owner -xf -
101 120
@@ -105,9 +124,48 @@ go_do_install() {
105 fi 124 fi
106} 125}
107 126
127do_install_ptest_base() {
128set -x
129 test -f "${B}/.go_compiled_tests.list" || exit 0
130 tests=""
131 while read test; do
132 tests="$tests${tests:+ }${test%.test}"
133 testdir=`dirname $test`
134 install -d ${D}${PTEST_PATH}/$testdir
135 install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test
136 if [ -d "${B}/src/$testdir/testdata" ]; then
137 cp --preserve=mode,timestamps -R "${B}/src/$testdir/testdata" ${D}${PTEST_PATH}/$testdir
138 fi
139 done < ${B}/.go_compiled_tests.list
140 if [ -n "$tests" ]; then
141 install -d ${D}${PTEST_PATH}
142 cat >${D}${PTEST_PATH}/run-ptest <<EOF
143#!/bin/sh
144ANYFAILED=0
145for t in $tests; do
146 testdir=\`dirname \$t.test\`
147 if ( cd "${PTEST_PATH}/\$testdir"; "${PTEST_PATH}/\$t.test" ${GOPTESTFLAGS} | tee /dev/fd/9 | grep -q "^FAIL" ) 9>&1; then
148 ANYFAILED=1
149 fi
150done
151if [ \$ANYFAILED -ne 0 ]; then
152 echo "FAIL: ${PN}"
153 exit 1
154fi
155echo "PASS: ${PN}"
156exit 0
157EOF
158 chmod +x ${D}${PTEST_PATH}/run-ptest
159 else
160 rm -rf ${D}${PTEST_PATH}
161 fi
162set +x
163}
164
108EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install 165EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install
109 166
110FILES_${PN}-dev = "${libdir}/go/src" 167FILES_${PN}-dev = "${libdir}/go/src"
111FILES_${PN}-staticdev = "${libdir}/go/pkg" 168FILES_${PN}-staticdev = "${libdir}/go/pkg"
112 169
113INSANE_SKIP_${PN} += "ldflags" 170INSANE_SKIP_${PN} += "ldflags"
171INSANE_SKIP_${PN}-ptest += "ldflags"