diff mbox series

[meta-lts-mixins,scarthgap/go,5/7] go: ptest: fix GOROOT detection and improve cleanup/exit handling

Message ID 20260513170902.2468061-5-peter.marko@siemens.com
State New
Headers show
Series [meta-lts-mixins,scarthgap/go,1/7] go-helloworld: upgrade to latest revision | expand

Commit Message

Peter Marko May 13, 2026, 5:08 p.m. UTC
From: Pratik Farkase <pratik.farkase@est.tech>

Changes:
  - Derive GOROOT dynamically from PTEST_DIR instead of hardcoding
    /usr/lib/go, which breaks on distros using lib64.
  - Track and clean up VERSION and pkg/include files that were copied
    into GOROOT, preventing stale artifacts after ptest runs.
  - Track failures with RC variable and exit non-zero when tests fail,
    consistent with other ptest scripts.

Signed-off-by: Pratik Farkase <pratik.farkase@est.tech>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(From OE-Core rev: a912153baed08d8d1d563341e29a2d596546bdb4)
Signed-off-by: Peter Marko <peter.marko@siemens.com>
---
 recipes-devtools/go/go/run-ptest | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/recipes-devtools/go/go/run-ptest b/recipes-devtools/go/go/run-ptest
index b8a0805..5fc9367 100755
--- a/recipes-devtools/go/go/run-ptest
+++ b/recipes-devtools/go/go/run-ptest
@@ -2,7 +2,7 @@ 
 # SPDX-License-Identifier: MIT
 
 PTEST_DIR=$(cd "$(dirname "$0")" && pwd)
-GOROOT=/usr/lib/go
+GOROOT=$(dirname "$PTEST_DIR")
 
 export GOROOT
 export PATH=$GOROOT/bin:$PATH
@@ -16,11 +16,18 @@  if [ -d "$GOROOT/src" ] && [ ! -L "$GOROOT/src" ]; then
 fi
 ln -sf "$PTEST_DIR/src" "$GOROOT/src"
 
-if [ -f "$PTEST_DIR/VERSION" ]; then
+CLEANUP_VERSION=0
+if [ -f "$PTEST_DIR/VERSION" ] && [ ! -f "$GOROOT/VERSION" ]; then
     cp "$PTEST_DIR/VERSION" "$GOROOT/VERSION"
+    CLEANUP_VERSION=1
 fi
+
+CLEANUP_INCLUDE=0
 if ls "$PTEST_DIR/pkg/include/"* >/dev/null 2>&1; then
-    mkdir -p "$GOROOT/pkg/include"
+    if [ ! -d "$GOROOT/pkg/include" ]; then
+        mkdir -p "$GOROOT/pkg/include"
+        CLEANUP_INCLUDE=1
+    fi
     cp "$PTEST_DIR/pkg/include/"* "$GOROOT/pkg/include/"
 fi
 
@@ -38,6 +45,7 @@  SKIP_PKGS="debug/dwarf debug/elf debug/pe debug/plan9obj go/types internal/xcoff
 
 SKIP_REGEX=$(echo "$SKIP_PKGS" | sed 's/ /|/g')
 
+RC=0
 for pkg in $(go list std); do
     # Skip package and all its subpackages
     if echo "$pkg" | grep -qE "^($SKIP_REGEX)(/|$)"; then
@@ -52,6 +60,7 @@  for pkg in $(go list std); do
     else
         echo "FAIL: $pkg"
         echo "$output"
+        RC=1
     fi
 done
 
@@ -60,4 +69,12 @@  rm -f "$GOROOT/src"
 if [ -d "$GOROOT/src.orig" ]; then
     mv "$GOROOT/src.orig" "$GOROOT/src"
 fi
+if [ $CLEANUP_VERSION -eq 1 ]; then
+    rm -f "$GOROOT/VERSION"
+fi
+if [ $CLEANUP_INCLUDE -eq 1 ]; then
+    rm -rf "$GOROOT/pkg/include"
+fi
 rm -rf "$GOCACHE"
+
+exit $RC