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