Subject: [bug#73299] [PATCH] build/go: Replace symlinks with a copy of the file.

From: Efraim Flashner <[email-masked]>
Date: Mon, 16 Sep 2024 18:38:46 +0300

* guix/build/go-build-system.scm (fix-embed-files): New procedure.
(%standard-phases): Add 'fix-embed-files after 'unpack.

Co-authored-by: Sharlatan Hellseher <[email-masked]>
Change-Id: I27bc46fa1a3f4675ff73b6cba4ef5c3d177c22b1
---

I saw this pattern coming up a couple of times in the go-team branch so
I figured I could factor it out, as the comment said. I figure later we
can adjust it to match other symlinked files.

 guix/build/go-build-system.scm | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index 3f0f5700a1e..c953976b485 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -4,10 +4,11 @@
 ;;; Copyright © 2019 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2020 Jack Hill <[email-masked]>
 ;;; Copyright © 2020 Jakub Kądziołka <[email-masked]>
-;;; Copyright © 2020, 2021, 2023 Efraim Flashner <[email-masked]>
+;;; Copyright © 2020, 2021, 2023, 2024 Efraim Flashner <[email-masked]>
 ;;; Copyright © 2021 Sarah Morgensen <[email-masked]>
 ;;; Copyright © 2024 Ekaitz Zarraga <[email-masked]>
 ;;; Copyright © 2024 Picnoir <[email-masked]>
+;;; Copyright © 2024 Sharlatan Hellseher <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -201,6 +202,23 @@ (define* (setup-go-environment #:key inputs outputs goos goarch #:allow-other-ke
     (delete-file-recursively tmpdir))
   #t)
 
+(define* (fix-embed-files #:rest args)
+  "Golang can't determine the valid directory of the module of embed file
+which is symlinked during setup environment phase, but easy resolved after
+coping file from the store to the build directory of the current package."
+;; see details in Golang source:
+;;
+;; - URL: <https://github.com/golang/go/blob/>
+;; - commit: 82c14346d89ec0eeca114f9ca0e88516b2cda454
+;; - file: src/cmd/go/internal/load/pkg.go#L2059
+  (for-each (lambda (file)
+              (when (eq? (stat:type (lstat file))
+                         'symlink)
+                (let ((file-store-path (readlink file)))
+                  (delete-file file)
+                  (copy-recursively file-store-path file))))
+            (find-files "src" ".*(editions_defaults.binpb)$")))
+
 (define* (unpack #:key source import-path unpack-path #:allow-other-keys)
   "Relative to $GOPATH, unpack SOURCE in UNPACK-PATH, or IMPORT-PATH when
 UNPACK-PATH is unset.  If the SOURCE archive has a single top level directory,
@@ -321,6 +339,7 @@ (define %standard-phases
     (delete 'patch-generated-file-shebangs)
     (add-before 'unpack 'setup-go-environment setup-go-environment)
     (replace 'unpack unpack)
+    (add-after 'unpack 'fix-embed-files fix-embed-files)
     (replace 'build build)
     (replace 'check check)
     (replace 'install install)

base-commit: 0091fa2cc2ac2104d7945b585e4eaec908ca742f
-- 
Efraim Flashner   <[email-masked]>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted