| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | inherit goarch ptest | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 3 | GO_PARALLEL_BUILD ?= "${@oe.utils.parallel_make_argument(d, '-p %d')}" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 4 |  | 
|  | 5 | GOROOT_class-native = "${STAGING_LIBDIR_NATIVE}/go" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6 | GOROOT_class-nativesdk = "${STAGING_DIR_TARGET}${libdir}/go" | 
|  | 7 | GOROOT = "${STAGING_LIBDIR}/go" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8 | export GOROOT | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9 | export GOROOT_FINAL = "${libdir}/go" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10 |  | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 11 | DEPENDS_GOLANG_class-target = "virtual/${TUNE_PKGARCH}-go virtual/${TARGET_PREFIX}go-runtime" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | DEPENDS_GOLANG_class-native = "go-native" | 
|  | 13 | DEPENDS_GOLANG_class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk virtual/${TARGET_PREFIX}go-runtime" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 15 | DEPENDS_append = " ${DEPENDS_GOLANG}" | 
|  | 16 |  | 
|  | 17 | GO_LINKSHARED ?= "${@'-linkshared' if d.getVar('GO_DYNLINK') else ''}" | 
|  | 18 | GO_RPATH_LINK = "${@'-Wl,-rpath-link=${STAGING_DIR_TARGET}${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" | 
|  | 19 | GO_RPATH = "${@'-r ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" | 
|  | 20 | GO_RPATH_class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" | 
|  | 21 | GO_RPATH_LINK_class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" | 
|  | 22 | GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}" | 
|  | 23 | GO_LINKMODE ?= "" | 
|  | 24 | GO_LINKMODE_class-nativesdk = "--linkmode=external" | 
|  | 25 | GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} -extldflags '${GO_EXTLDFLAGS}'"' | 
|  | 26 | export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}" | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 27 | export GOPATH_OMIT_IN_ACTIONID ?= "1" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 28 | export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c" | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 29 | export GOPTESTFLAGS ?= "" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} " | 
|  | 31 |  | 
|  | 32 | export GO = "${HOST_PREFIX}go" | 
|  | 33 | GOTOOLDIR = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go/pkg/tool/${BUILD_GOTUPLE}" | 
|  | 34 | GOTOOLDIR_class-native = "${STAGING_LIBDIR_NATIVE}/go/pkg/tool/${BUILD_GOTUPLE}" | 
|  | 35 | export GOTOOLDIR | 
|  | 36 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 37 | export CGO_ENABLED ?= "1" | 
|  | 38 | export CGO_CFLAGS ?= "${CFLAGS}" | 
|  | 39 | export CGO_CPPFLAGS ?= "${CPPFLAGS}" | 
|  | 40 | export CGO_CXXFLAGS ?= "${CXXFLAGS}" | 
|  | 41 | export CGO_LDFLAGS ?= "${LDFLAGS}" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 |  | 
|  | 43 | GO_INSTALL ?= "${GO_IMPORT}/..." | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | GO_INSTALL_FILTEROUT ?= "${GO_IMPORT}/vendor/" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 45 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 46 | B = "${WORKDIR}/build" | 
|  | 47 | export GOPATH = "${B}" | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 48 | export GOTMPDIR ?= "${WORKDIR}/go-tmp" | 
|  | 49 | GOTMPDIR[vardepvalue] = "" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 50 |  | 
|  | 51 | python go_do_unpack() { | 
|  | 52 | src_uri = (d.getVar('SRC_URI') or "").split() | 
|  | 53 | if len(src_uri) == 0: | 
|  | 54 | return | 
|  | 55 |  | 
|  | 56 | try: | 
|  | 57 | fetcher = bb.fetch2.Fetch(src_uri, d) | 
|  | 58 | for url in fetcher.urls: | 
|  | 59 | if fetcher.ud[url].type == 'git': | 
|  | 60 | if fetcher.ud[url].parm.get('destsuffix') is None: | 
|  | 61 | s_dirname = os.path.basename(d.getVar('S')) | 
|  | 62 | fetcher.ud[url].parm['destsuffix'] = os.path.join(s_dirname, 'src', | 
|  | 63 | d.getVar('GO_IMPORT')) + '/' | 
|  | 64 | fetcher.unpack(d.getVar('WORKDIR')) | 
|  | 65 | except bb.fetch2.BBFetchException as e: | 
|  | 66 | raise bb.build.FuncFailed(e) | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | go_list_packages() { | 
|  | 70 | ${GO} list -f '{{.ImportPath}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ | 
|  | 71 | egrep -v '${GO_INSTALL_FILTEROUT}' | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | go_list_package_tests() { | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 75 | ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 76 | grep -v '\[\]$' | \ | 
|  | 77 | egrep -v '${GO_INSTALL_FILTEROUT}' | \ | 
|  | 78 | awk '{ print $1 }' | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | go_do_configure() { | 
|  | 82 | ln -snf ${S}/src ${B}/ | 
|  | 83 | } | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 84 | do_configure[dirs] =+ "${GOTMPDIR}" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 85 |  | 
|  | 86 | go_do_compile() { | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 87 | export TMPDIR="${GOTMPDIR}" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | if [ -n "${GO_INSTALL}" ]; then | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 89 | if [ -n "${GO_LINKSHARED}" ]; then | 
|  | 90 | ${GO} install ${GOBUILDFLAGS} `go_list_packages` | 
|  | 91 | rm -rf ${B}/bin | 
|  | 92 | fi | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 93 | ${GO} install ${GO_LINKSHARED} ${GOBUILDFLAGS} `go_list_packages` | 
|  | 94 | fi | 
|  | 95 | } | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 96 | do_compile[dirs] =+ "${GOTMPDIR}" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 97 | do_compile[cleandirs] = "${B}/bin ${B}/pkg" | 
|  | 98 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 99 | do_compile_ptest_base() { | 
|  | 100 | export TMPDIR="${GOTMPDIR}" | 
|  | 101 | rm -f ${B}/.go_compiled_tests.list | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 102 | go_list_package_tests | while read pkg; do | 
|  | 103 | cd ${B}/src/$pkg | 
|  | 104 | ${GO} test ${GOPTESTBUILDFLAGS} $pkg | 
|  | 105 | find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \ | 
|  | 106 | sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list | 
|  | 107 | done | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 108 | do_compile_ptest | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 109 | } | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 110 | do_compile_ptest_base[dirs] =+ "${GOTMPDIR}" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 111 |  | 
|  | 112 | go_do_install() { | 
|  | 113 | install -d ${D}${libdir}/go/src/${GO_IMPORT} | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 114 | tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' --exclude 'testdata' . | \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 115 | tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf - | 
|  | 116 | tar -C ${B} -cf - pkg | tar -C ${D}${libdir}/go --no-same-owner -xf - | 
|  | 117 |  | 
|  | 118 | if [ -n "`ls ${B}/${GO_BUILD_BINDIR}/`" ]; then | 
|  | 119 | install -d ${D}${bindir} | 
|  | 120 | install -m 0755 ${B}/${GO_BUILD_BINDIR}/* ${D}${bindir}/ | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 121 | fi | 
|  | 122 | } | 
|  | 123 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 124 | go_make_ptest_wrapper() { | 
|  | 125 | cat >${D}${PTEST_PATH}/run-ptest <<EOF | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 126 | #!/bin/sh | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 127 | RC=0 | 
|  | 128 | run_test() ( | 
|  | 129 | cd "\$1" | 
|  | 130 | ((((./\$2 ${GOPTESTFLAGS}; echo \$? >&3) | sed -r -e"s,^(PASS|SKIP|FAIL)\$,\\1: \$1/\$2," >&4) 3>&1) | (read rc; exit \$rc)) 4>&1 | 
|  | 131 | exit \$?) | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 132 | EOF | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 133 |  | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | go_stage_testdata() { | 
|  | 137 | oldwd="$PWD" | 
|  | 138 | cd ${S}/src | 
|  | 139 | find ${GO_IMPORT} -depth -type d -name testdata | while read d; do | 
|  | 140 | if echo "$d" | grep -q '/vendor/'; then | 
|  | 141 | continue | 
|  | 142 | fi | 
|  | 143 | parent=`dirname $d` | 
|  | 144 | install -d ${D}${PTEST_PATH}/$parent | 
|  | 145 | cp --preserve=mode,timestamps -R $d ${D}${PTEST_PATH}/$parent/ | 
|  | 146 | done | 
|  | 147 | cd "$oldwd" | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | do_install_ptest_base() { | 
|  | 151 | test -f "${B}/.go_compiled_tests.list" || exit 0 | 
|  | 152 | install -d ${D}${PTEST_PATH} | 
|  | 153 | go_stage_testdata | 
|  | 154 | go_make_ptest_wrapper | 
|  | 155 | havetests="" | 
|  | 156 | while read test; do | 
|  | 157 | testdir=`dirname $test` | 
|  | 158 | testprog=`basename $test` | 
|  | 159 | install -d ${D}${PTEST_PATH}/$testdir | 
|  | 160 | install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test | 
|  | 161 | echo "run_test $testdir $testprog || RC=1" >> ${D}${PTEST_PATH}/run-ptest | 
|  | 162 | havetests="yes" | 
|  | 163 | done < ${B}/.go_compiled_tests.list | 
|  | 164 | if [ -n "$havetests" ]; then | 
|  | 165 | echo "exit \$RC" >> ${D}${PTEST_PATH}/run-ptest | 
|  | 166 | chmod +x ${D}${PTEST_PATH}/run-ptest | 
|  | 167 | else | 
|  | 168 | rm -rf ${D}${PTEST_PATH} | 
|  | 169 | fi | 
|  | 170 | do_install_ptest | 
|  | 171 | chown -R root:root ${D}${PTEST_PATH} | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 174 | EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 175 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 176 | FILES_${PN}-dev = "${libdir}/go/src" | 
|  | 177 | FILES_${PN}-staticdev = "${libdir}/go/pkg" | 
|  | 178 |  | 
|  | 179 | INSANE_SKIP_${PN} += "ldflags" | 
|  | 180 | INSANE_SKIP_${PN}-ptest += "ldflags" | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 181 |  | 
|  | 182 | # Add -buildmode=pie to GOBUILDFLAGS to satisfy "textrel" QA checking, but mips | 
|  | 183 | # doesn't support -buildmode=pie, so skip the QA checking for mips and its | 
|  | 184 | # variants. | 
|  | 185 | python() { | 
|  | 186 | if 'mips' in d.getVar('TARGET_ARCH'): | 
|  | 187 | d.appendVar('INSANE_SKIP_%s' % d.getVar('PN'), " textrel") | 
|  | 188 | else: | 
|  | 189 | d.appendVar('GOBUILDFLAGS', ' -buildmode=pie') | 
|  | 190 | } |