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