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 | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 3 | def get_go_parallel_make(d): |
| 4 | pm = (d.getVar('PARALLEL_MAKE') or '').split() |
| 5 | # look for '-j' and throw other options (e.g. '-l') away |
| 6 | # because they might have a different meaning in golang |
| 7 | while pm: |
| 8 | opt = pm.pop(0) |
| 9 | if opt == '-j': |
| 10 | v = pm.pop(0) |
| 11 | elif opt.startswith('-j'): |
| 12 | v = opt[2:].strip() |
| 13 | else: |
| 14 | continue |
| 15 | |
| 16 | return '-p %d' % int(v) |
| 17 | |
| 18 | return "" |
| 19 | |
| 20 | GO_PARALLEL_BUILD ?= "${@get_go_parallel_make(d)}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 21 | |
| 22 | GOROOT_class-native = "${STAGING_LIBDIR_NATIVE}/go" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | GOROOT_class-nativesdk = "${STAGING_DIR_TARGET}${libdir}/go" |
| 24 | GOROOT = "${STAGING_LIBDIR}/go" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | export GOROOT |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 26 | export GOROOT_FINAL = "${libdir}/go" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 28 | DEPENDS_GOLANG_class-target = "virtual/${TARGET_PREFIX}go virtual/${TARGET_PREFIX}go-runtime" |
| 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}" |
| 44 | export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c" |
| 45 | export GOPTESTFLAGS ?= "-test.v" |
| 46 | GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} " |
| 47 | |
| 48 | export GO = "${HOST_PREFIX}go" |
| 49 | GOTOOLDIR = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go/pkg/tool/${BUILD_GOTUPLE}" |
| 50 | GOTOOLDIR_class-native = "${STAGING_LIBDIR_NATIVE}/go/pkg/tool/${BUILD_GOTUPLE}" |
| 51 | export GOTOOLDIR |
| 52 | |
| 53 | SECURITY_CFLAGS = "${SECURITY_NOPIE_CFLAGS}" |
| 54 | SECURITY_LDFLAGS = "" |
| 55 | |
| 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}" |
| 67 | GO_TMPDIR ?= "${WORKDIR}/go-tmp" |
| 68 | GO_TMPDIR[vardepvalue] = "" |
| 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() { |
| 94 | ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ |
| 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 | } |
| 103 | |
| 104 | go_do_compile() { |
| 105 | export TMPDIR="${GO_TMPDIR}" |
| 106 | ${GO} env |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 107 | if [ -n "${GO_INSTALL}" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 108 | ${GO} install ${GO_LINKSHARED} ${GOBUILDFLAGS} `go_list_packages` |
| 109 | fi |
| 110 | } |
| 111 | do_compile[dirs] =+ "${GO_TMPDIR}" |
| 112 | do_compile[cleandirs] = "${B}/bin ${B}/pkg" |
| 113 | |
| 114 | do_compile_ptest() { |
| 115 | export TMPDIR="${GO_TMPDIR}" |
| 116 | rm -f ${B}/.go_compiled_tests.list |
| 117 | go_list_package_tests | while read pkg; do |
| 118 | cd ${B}/src/$pkg |
| 119 | ${GO} test ${GOPTESTBUILDFLAGS} $pkg |
| 120 | find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \ |
| 121 | sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list |
| 122 | done |
| 123 | } |
| 124 | do_compile_ptest_base[dirs] =+ "${GO_TMPDIR}" |
| 125 | |
| 126 | go_do_install() { |
| 127 | install -d ${D}${libdir}/go/src/${GO_IMPORT} |
| 128 | tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' . | \ |
| 129 | tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf - |
| 130 | tar -C ${B} -cf - pkg | tar -C ${D}${libdir}/go --no-same-owner -xf - |
| 131 | |
| 132 | if [ -n "`ls ${B}/${GO_BUILD_BINDIR}/`" ]; then |
| 133 | install -d ${D}${bindir} |
| 134 | install -m 0755 ${B}/${GO_BUILD_BINDIR}/* ${D}${bindir}/ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 135 | fi |
| 136 | } |
| 137 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 138 | do_install_ptest_base() { |
| 139 | set -x |
| 140 | test -f "${B}/.go_compiled_tests.list" || exit 0 |
| 141 | tests="" |
| 142 | while read test; do |
| 143 | tests="$tests${tests:+ }${test%.test}" |
| 144 | testdir=`dirname $test` |
| 145 | install -d ${D}${PTEST_PATH}/$testdir |
| 146 | install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test |
| 147 | if [ -d "${B}/src/$testdir/testdata" ]; then |
| 148 | cp --preserve=mode,timestamps -R "${B}/src/$testdir/testdata" ${D}${PTEST_PATH}/$testdir |
| 149 | fi |
| 150 | done < ${B}/.go_compiled_tests.list |
| 151 | if [ -n "$tests" ]; then |
| 152 | install -d ${D}${PTEST_PATH} |
| 153 | cat >${D}${PTEST_PATH}/run-ptest <<EOF |
| 154 | #!/bin/sh |
| 155 | ANYFAILED=0 |
| 156 | for t in $tests; do |
| 157 | testdir=\`dirname \$t.test\` |
| 158 | if ( cd "${PTEST_PATH}/\$testdir"; "${PTEST_PATH}/\$t.test" ${GOPTESTFLAGS} | tee /dev/fd/9 | grep -q "^FAIL" ) 9>&1; then |
| 159 | ANYFAILED=1 |
| 160 | fi |
| 161 | done |
| 162 | if [ \$ANYFAILED -ne 0 ]; then |
| 163 | echo "FAIL: ${PN}" |
| 164 | exit 1 |
| 165 | fi |
| 166 | echo "PASS: ${PN}" |
| 167 | exit 0 |
| 168 | EOF |
| 169 | chmod +x ${D}${PTEST_PATH}/run-ptest |
| 170 | else |
| 171 | rm -rf ${D}${PTEST_PATH} |
| 172 | fi |
| 173 | set +x |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 176 | EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 177 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 178 | FILES_${PN}-dev = "${libdir}/go/src" |
| 179 | FILES_${PN}-staticdev = "${libdir}/go/pkg" |
| 180 | |
| 181 | INSANE_SKIP_${PN} += "ldflags" |
| 182 | INSANE_SKIP_${PN}-ptest += "ldflags" |