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 | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | DEPENDS_GOLANG_class-target = "virtual/${TARGET_PREFIX}go virtual/${TARGET_PREFIX}go-runtime" |
| 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 GOCACHE = "off" |
| 49 | export GOTMPDIR ?= "${WORKDIR}/go-tmp" |
| 50 | GOTMPDIR[vardepvalue] = "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 51 | |
| 52 | python go_do_unpack() { |
| 53 | src_uri = (d.getVar('SRC_URI') or "").split() |
| 54 | if len(src_uri) == 0: |
| 55 | return |
| 56 | |
| 57 | try: |
| 58 | fetcher = bb.fetch2.Fetch(src_uri, d) |
| 59 | for url in fetcher.urls: |
| 60 | if fetcher.ud[url].type == 'git': |
| 61 | if fetcher.ud[url].parm.get('destsuffix') is None: |
| 62 | s_dirname = os.path.basename(d.getVar('S')) |
| 63 | fetcher.ud[url].parm['destsuffix'] = os.path.join(s_dirname, 'src', |
| 64 | d.getVar('GO_IMPORT')) + '/' |
| 65 | fetcher.unpack(d.getVar('WORKDIR')) |
| 66 | except bb.fetch2.BBFetchException as e: |
| 67 | raise bb.build.FuncFailed(e) |
| 68 | } |
| 69 | |
| 70 | go_list_packages() { |
| 71 | ${GO} list -f '{{.ImportPath}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ |
| 72 | egrep -v '${GO_INSTALL_FILTEROUT}' |
| 73 | } |
| 74 | |
| 75 | go_list_package_tests() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 76 | ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 77 | grep -v '\[\]$' | \ |
| 78 | egrep -v '${GO_INSTALL_FILTEROUT}' | \ |
| 79 | awk '{ print $1 }' |
| 80 | } |
| 81 | |
| 82 | go_do_configure() { |
| 83 | ln -snf ${S}/src ${B}/ |
| 84 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 85 | do_configure[dirs] =+ "${GOTMPDIR}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 86 | |
| 87 | go_do_compile() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 88 | export TMPDIR="${GOTMPDIR}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 89 | if [ -n "${GO_INSTALL}" ]; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 90 | if [ -n "${GO_LINKSHARED}" ]; then |
| 91 | ${GO} install ${GOBUILDFLAGS} `go_list_packages` |
| 92 | rm -rf ${B}/bin |
| 93 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 94 | ${GO} install ${GO_LINKSHARED} ${GOBUILDFLAGS} `go_list_packages` |
| 95 | fi |
| 96 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 97 | do_compile[dirs] =+ "${GOTMPDIR}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 98 | do_compile[cleandirs] = "${B}/bin ${B}/pkg" |
| 99 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 100 | do_compile_ptest_base() { |
| 101 | export TMPDIR="${GOTMPDIR}" |
| 102 | rm -f ${B}/.go_compiled_tests.list |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 103 | go_list_package_tests | while read pkg; do |
| 104 | cd ${B}/src/$pkg |
| 105 | ${GO} test ${GOPTESTBUILDFLAGS} $pkg |
| 106 | find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \ |
| 107 | sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list |
| 108 | done |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 109 | do_compile_ptest |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 110 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 111 | do_compile_ptest_base[dirs] =+ "${GOTMPDIR}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 112 | |
| 113 | go_do_install() { |
| 114 | install -d ${D}${libdir}/go/src/${GO_IMPORT} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 115 | 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] | 116 | tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf - |
| 117 | tar -C ${B} -cf - pkg | tar -C ${D}${libdir}/go --no-same-owner -xf - |
| 118 | |
| 119 | if [ -n "`ls ${B}/${GO_BUILD_BINDIR}/`" ]; then |
| 120 | install -d ${D}${bindir} |
| 121 | install -m 0755 ${B}/${GO_BUILD_BINDIR}/* ${D}${bindir}/ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 122 | fi |
| 123 | } |
| 124 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 125 | go_make_ptest_wrapper() { |
| 126 | cat >${D}${PTEST_PATH}/run-ptest <<EOF |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 127 | #!/bin/sh |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 128 | RC=0 |
| 129 | run_test() ( |
| 130 | cd "\$1" |
| 131 | ((((./\$2 ${GOPTESTFLAGS}; echo \$? >&3) | sed -r -e"s,^(PASS|SKIP|FAIL)\$,\\1: \$1/\$2," >&4) 3>&1) | (read rc; exit \$rc)) 4>&1 |
| 132 | exit \$?) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 133 | EOF |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 134 | |
| 135 | } |
| 136 | |
| 137 | go_stage_testdata() { |
| 138 | oldwd="$PWD" |
| 139 | cd ${S}/src |
| 140 | find ${GO_IMPORT} -depth -type d -name testdata | while read d; do |
| 141 | if echo "$d" | grep -q '/vendor/'; then |
| 142 | continue |
| 143 | fi |
| 144 | parent=`dirname $d` |
| 145 | install -d ${D}${PTEST_PATH}/$parent |
| 146 | cp --preserve=mode,timestamps -R $d ${D}${PTEST_PATH}/$parent/ |
| 147 | done |
| 148 | cd "$oldwd" |
| 149 | } |
| 150 | |
| 151 | do_install_ptest_base() { |
| 152 | test -f "${B}/.go_compiled_tests.list" || exit 0 |
| 153 | install -d ${D}${PTEST_PATH} |
| 154 | go_stage_testdata |
| 155 | go_make_ptest_wrapper |
| 156 | havetests="" |
| 157 | while read test; do |
| 158 | testdir=`dirname $test` |
| 159 | testprog=`basename $test` |
| 160 | install -d ${D}${PTEST_PATH}/$testdir |
| 161 | install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test |
| 162 | echo "run_test $testdir $testprog || RC=1" >> ${D}${PTEST_PATH}/run-ptest |
| 163 | havetests="yes" |
| 164 | done < ${B}/.go_compiled_tests.list |
| 165 | if [ -n "$havetests" ]; then |
| 166 | echo "exit \$RC" >> ${D}${PTEST_PATH}/run-ptest |
| 167 | chmod +x ${D}${PTEST_PATH}/run-ptest |
| 168 | else |
| 169 | rm -rf ${D}${PTEST_PATH} |
| 170 | fi |
| 171 | do_install_ptest |
| 172 | chown -R root:root ${D}${PTEST_PATH} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 175 | EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 176 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 177 | FILES_${PN}-dev = "${libdir}/go/src" |
| 178 | FILES_${PN}-staticdev = "${libdir}/go/pkg" |
| 179 | |
| 180 | INSANE_SKIP_${PN} += "ldflags" |
| 181 | INSANE_SKIP_${PN}-ptest += "ldflags" |