diff options
author | Otavio Salvador <otavio@ossystems.com.br> | 2017-09-13 14:54:08 -0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-09-14 11:35:45 +0100 |
commit | a9fdf491ca97368d60c1a055ec33055480233232 (patch) | |
tree | 0350baeb7d6c99385da18e53b31606299e5e85d4 /meta/classes | |
parent | d61d4823a91cd46aac48fb5d3030f385d2e716c9 (diff) | |
download | poky-a9fdf491ca97368d60c1a055ec33055480233232.tar.gz |
go.bbclass: Add ptest support
This adds ptest support for Go packages so its unittest content is
packaged and integrated onto the test framework.
(From OE-Core rev: 2343cd90b9706589b33510c560ed83a9648fb133)
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r-- | meta/classes/go.bbclass | 62 |
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 @@ | |||
1 | inherit goarch | 1 | inherit goarch ptest |
2 | 2 | ||
3 | def get_go_parallel_make(d): | 3 | def 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 | |||
39 | GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}" | 39 | GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}" |
40 | GO_LDFLAGS ?= '-ldflags="${GO_RPATH} -extldflags '${GO_EXTLDFLAGS}'"' | 40 | GO_LDFLAGS ?= '-ldflags="${GO_RPATH} -extldflags '${GO_EXTLDFLAGS}'"' |
41 | export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}" | 41 | export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}" |
42 | export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c" | ||
43 | export GOPTESTFLAGS ?= "-test.v" | ||
42 | GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} " | 44 | GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} " |
43 | 45 | ||
44 | export GO = "${HOST_PREFIX}go" | 46 | export 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 | ||
86 | go_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 | |||
84 | go_do_configure() { | 93 | go_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 | } |
94 | do_compile[cleandirs] = "${B}/bin ${B}/pkg" | 103 | do_compile[cleandirs] = "${B}/bin ${B}/pkg" |
95 | 104 | ||
105 | do_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 | |||
96 | go_do_install() { | 115 | go_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 | ||
127 | do_install_ptest_base() { | ||
128 | set -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 | ||
144 | ANYFAILED=0 | ||
145 | for 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 | ||
150 | done | ||
151 | if [ \$ANYFAILED -ne 0 ]; then | ||
152 | echo "FAIL: ${PN}" | ||
153 | exit 1 | ||
154 | fi | ||
155 | echo "PASS: ${PN}" | ||
156 | exit 0 | ||
157 | EOF | ||
158 | chmod +x ${D}${PTEST_PATH}/run-ptest | ||
159 | else | ||
160 | rm -rf ${D}${PTEST_PATH} | ||
161 | fi | ||
162 | set +x | ||
163 | } | ||
164 | |||
108 | EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install | 165 | EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install |
109 | 166 | ||
110 | FILES_${PN}-dev = "${libdir}/go/src" | 167 | FILES_${PN}-dev = "${libdir}/go/src" |
111 | FILES_${PN}-staticdev = "${libdir}/go/pkg" | 168 | FILES_${PN}-staticdev = "${libdir}/go/pkg" |
112 | 169 | ||
113 | INSANE_SKIP_${PN} += "ldflags" | 170 | INSANE_SKIP_${PN} += "ldflags" |
171 | INSANE_SKIP_${PN}-ptest += "ldflags" | ||