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