From: Stefan Herbrechtsmeier <stefan.herbrechtsme...@weidmueller.com>

The go class assume a specific layout inside the source directory and
requires the GO_SRCURI_DESTSUFFIX as destsuffix for the fetcher. Make
the source directory configurable via GO_SRC_DIR because it is uncommon
and isn’t required for go mod. Additionally make the unpack directory
configurable via GO_INSTALL_PREFIX.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsme...@weidmueller.com>
---

 meta/classes-recipe/go.bbclass | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/meta/classes-recipe/go.bbclass b/meta/classes-recipe/go.bbclass
index e3e4782025..cd6367278c 100644
--- a/meta/classes-recipe/go.bbclass
+++ b/meta/classes-recipe/go.bbclass
@@ -70,8 +70,9 @@ export CGO_CPPFLAGS ?= "${CPPFLAGS}"
 export CGO_CXXFLAGS ?= "${CXXFLAGS}"
 export CGO_LDFLAGS ?= "${LDFLAGS}"
 
-GO_INSTALL ?= "${GO_IMPORT}/..."
-GO_INSTALL_FILTEROUT ?= "${GO_IMPORT}/vendor/"
+GO_INSTALL_PREFIX ?= "${GO_IMPORT}"
+GO_INSTALL ?= "${GO_INSTALL_PREFIX}/..."
+GO_INSTALL_FILTEROUT ?= "${GO_INSTALL_PREFIX}/vendor/"
 
 B = "${WORKDIR}/build"
 export GOPATH = "${B}"
@@ -80,7 +81,8 @@ export GOPROXY ??= "https://proxy.golang.org,direct";
 export GOTMPDIR ?= "${WORKDIR}/build-tmp"
 GOTMPDIR[vardepvalue] = ""
 
-GO_SRCURI_DESTSUFFIX = "${@os.path.join(os.path.basename(d.getVar('S')), 
'src', d.getVar('GO_IMPORT')) + '/'}"
+GO_SRC_DIR ??= "src/${GO_IMPORT}"
+GO_SRCURI_DESTSUFFIX ?= "${@os.path.join(os.path.basename(d.getVar('S')), 
d.getVar('GO_SRC_DIR')) + '/'}"
 
 go_list_packages() {
        ${GO} list -f '{{.ImportPath}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
@@ -95,7 +97,9 @@ go_list_package_tests() {
 }
 
 go_do_configure() {
-       ln -snf ${S}/src ${B}/
+       if [ -n "${GO_SRCURI_DESTSUFFIX}" ]; then
+               ln -snf ${S}/src ${B}/
+       fi
 }
 do_configure[dirs] =+ "${GOTMPDIR}"
 
@@ -114,7 +118,7 @@ do_compile[cleandirs] = "${B}/bin ${B}/pkg"
 
 go_do_install() {
        install -d ${D}${libdir}/go/src/${GO_IMPORT}
-       tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' 
--exclude 'testdata' . | \
+       tar -C ${S}/${GO_SRC_DIR} -cf - --exclude-vcs --exclude '*.test' 
--exclude 'testdata' . | \
                tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf -
        tar -C ${B} -cf - --exclude-vcs --exclude '*.test' --exclude 'testdata' 
pkg | \
                tar -C ${D}${libdir}/go --no-same-owner -xf -
@@ -127,14 +131,14 @@ go_do_install() {
 
 go_stage_testdata() {
        oldwd="$PWD"
-       cd ${S}/src
-       find ${GO_IMPORT} -depth -type d -name testdata | while read d; do
+       cd ${S}/${GO_SRC_DIR}
+       find . -depth -type d -name testdata -printf '%P\n'| while read d; do
                if echo "$d" | grep -q '/vendor/'; then
                        continue
                fi
                parent=`dirname $d`
-               install -d ${D}${PTEST_PATH}/$parent
-               cp --preserve=mode,timestamps -R $d ${D}${PTEST_PATH}/$parent/
+               install -d ${D}${PTEST_PATH}/${GO_IMPORT}/$parent
+               cp --preserve=mode,timestamps -R $d 
${D}${PTEST_PATH}/${GO_IMPORT}/$parent/
        done
        cd "$oldwd"
 }
-- 
2.39.5

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#211139): 
https://lists.openembedded.org/g/openembedded-core/message/211139
Mute This Topic: https://lists.openembedded.org/mt/111123535/21656
Group Owner: openembedded-core+ow...@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to