unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#73299] [PATCH v2 1/3] build/go: Replace symlinks with a copy of the file.
       [not found] <cover.1726516329.git.sharlatanus@gmail.com>
@ 2024-09-16 20:10 ` Sharlatan Hellseher
  2024-09-26 13:22   ` Maxim Cournoyer
  2024-09-16 20:10 ` [bug#73299] [PATCH v2 2/3] gnu: go-github-com-prometheus-statsd-exporter: Remove redundant phase Sharlatan Hellseher
  2024-09-16 20:10 ` [bug#73299] [PATCH v2 3/3] gnu: go-github-com-golang-protobuf: " Sharlatan Hellseher
  2 siblings, 1 reply; 4+ messages in thread
From: Sharlatan Hellseher @ 2024-09-16 20:10 UTC (permalink / raw)
  To: 73299
  Cc: Sharlatan Hellseher, Efraim Flashner, Florian Pelz,
	Katherine Cox-Buday, Ludovic Courtès, Maxim Cournoyer,
	Sharlatan Hellseher

From: Efraim Flashner <efraim@flashner.co.il>

* guix/build/go-build-system.scm (fix-embed-files): New procedure.
(%standard-phases): Add 'fix-embed-files after 'unpack.
* guix/build-system/go.scm (#:embed-files): New key parameter.
* doc/guix.texi: (go-build-system): Document a new key.

Co-authored-by: Sharlatan Hellseher <sharlatanus@gmail.com>
Change-Id: I27bc46fa1a3f4675ff73b6cba4ef5c3d177c22b1
---
 doc/guix.texi                  |  8 ++++++++
 guix/build-system/go.scm       |  6 ++++++
 guix/build/go-build-system.scm | 30 ++++++++++++++++++++++++++++--
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 4abe258af0..e780bde6cf 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -130,6 +130,9 @@
 Copyright @copyright{} 2024 Dariqq@*
 Copyright @copyright{} 2024 Denis 'GNUtoo' Carikli@*
 Copyright @copyright{} 2024 Fabio Natali@*
+Copyright @copyright{} 2024 Troy Figiel@*
+Copyright @copyright{} 2024 Sharlatan Hellseher@*
+
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -9580,6 +9583,11 @@ Build Systems
 @code{#:test-flags} parameter, default is @code{'()}.  See @code{go help
 test} and @code{go help testflag} for more details.
 
+The key @code{#:embed-files}, default is @code{'()}, provides a list of
+future embedded files or regexps matching files.  They will be copied to
+build directory after @code{unpack} phase.  See
+@url{https://pkg.go.dev/embed} for more details.
+
 @end defvar
 
 @defvar glib-or-gtk-build-system
diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm
index e6e8b84e48..97581a14c6 100644
--- a/guix/build-system/go.scm
+++ b/guix/build-system/go.scm
@@ -6,6 +6,8 @@
 ;;; Copyright © 2021, 2023 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
 ;;; Copyright © 2024 Christina O'Donnell <cdo@mutix.org>
+;;; Copyright © 2024 Troy Figiel <troy@troyfigiel.com>
+;;; Copyright © 2024 Sharlatan Hellseher <sharlatanus@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -197,6 +199,7 @@ (define* (go-build name inputs
                    (outputs '("out"))
                    (search-paths '())
                    (install-source? #t)
+                   (embed-files ''())
                    (import-path "")
                    (unpack-path "")
                    (build-flags ''())
@@ -226,6 +229,7 @@ (define* (go-build name inputs
                     #:substitutable? #$substitutable?
                     #:goarch #$goarch
                     #:goos #$goos
+                    #:embed-files #$embed-files
                     #:search-paths '#$(sexp->gexp
                                        (map search-path-specification->sexp
                                             search-paths))
@@ -264,6 +268,7 @@ (define* (go-cross-build name
                          (system (%current-system))
                          (goarch (first (go-target target)))
                          (goos (last (go-target target)))
+                         (embed-files ''())
                          (guile #f)
                          (imported-modules %go-build-system-modules)
                          (modules '((guix build go-build-system)
@@ -297,6 +302,7 @@ (define* (go-cross-build name
                     #:target #$target
                     #:goarch #$goarch
                     #:goos #$goos
+                    #:embed-files #$embed-files
                     #:inputs %build-target-inputs
                     #:native-inputs %build-host-inputs
                     #:search-paths '#$(map search-path-specification->sexp
diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index 3f0f5700a1..14cb5ae687 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -4,10 +4,12 @@
 ;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Jack Hill <jackhill@jackhill.us>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
-;;; Copyright © 2020, 2021, 2023 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2020, 2021, 2023, 2024 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
 ;;; Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech>
 ;;; Copyright © 2024 Picnoir <picnoir@alternativebit.fr>
+;;; Copyright © 2024 Troy Figiel <troy@troyfigiel.com>
+;;; Copyright © 2024 Sharlatan Hellseher <sharlatanus@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -28,8 +30,9 @@ (define-module (guix build go-build-system)
   #:use-module ((guix build gnu-build-system) #:prefix gnu:)
   #:use-module (guix build union)
   #:use-module (guix build utils)
-  #:use-module (ice-9 match)
+  #:use-module (ice-9 format)
   #:use-module (ice-9 ftw)
+  #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
   #:use-module (rnrs io ports)
   #:use-module (rnrs bytevectors)
@@ -201,6 +204,28 @@ (define* (setup-go-environment #:key inputs outputs goos goarch #:allow-other-ke
     (delete-file-recursively tmpdir))
   #t)
 
+(define* (fix-embed-files #:key embed-files #:allow-other-keys)
+  "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. Take
+a list of files or regexps matching files from EMBED-FILES paramter, failover
+to 'editions_defaults.binpb' which is a part of <github.com/golang/protobuf>."
+  ;; see details in Golang source:
+  ;;
+  ;; - URL: <https://github.com/golang/go/blob/>
+  ;; - commit: 82c14346d89ec0eeca114f9ca0e88516b2cda454
+  ;; - file: src/cmd/go/internal/load/pkg.go#L2059
+  (let ((embed-files (format #f "^(~{~a|~}~a)$"
+                             embed-files
+                             "editions_defaults.binpb")))
+    (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" embed-files))))
+
 (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 +346,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)
-- 
2.46.0





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#73299] [PATCH v2 2/3] gnu: go-github-com-prometheus-statsd-exporter: Remove redundant phase.
       [not found] <cover.1726516329.git.sharlatanus@gmail.com>
  2024-09-16 20:10 ` [bug#73299] [PATCH v2 1/3] build/go: Replace symlinks with a copy of the file Sharlatan Hellseher
@ 2024-09-16 20:10 ` Sharlatan Hellseher
  2024-09-16 20:10 ` [bug#73299] [PATCH v2 3/3] gnu: go-github-com-golang-protobuf: " Sharlatan Hellseher
  2 siblings, 0 replies; 4+ messages in thread
From: Sharlatan Hellseher @ 2024-09-16 20:10 UTC (permalink / raw)
  To: 73299; +Cc: Sharlatan Hellseher

* gnu/packages/prometheus.scm (go-github-com-prometheus-statsd-exporter)
[arguments]: <#:phases>: Remove 'fix-embed-files and relay on standard
one.

Change-Id: I1bc965c65bcd40fcaef7d0ace9943a01ef08bdd3
---
 gnu/packages/prometheus.scm | 24 +-----------------------
 1 file changed, 1 insertion(+), 23 deletions(-)

diff --git a/gnu/packages/prometheus.scm b/gnu/packages/prometheus.scm
index fe2fa18e95..a81932f62b 100644
--- a/gnu/packages/prometheus.scm
+++ b/gnu/packages/prometheus.scm
@@ -572,29 +572,7 @@ (define-public go-github-com-prometheus-statsd-exporter
     (arguments
      (list
       #:import-path "github.com/prometheus/statsd_exporter"
-      #:phases
-      #~(modify-phases %standard-phases
-          ;; TODO: Implement it in go-build-system.
-          ;;
-          ;; This happens due to 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
-          (add-before 'build 'fix-embed-files
-            (lambda _
-              (for-each (lambda (file)
-                          (let ((file-store-path (readlink file)))
-                            (delete-file file)
-                            (copy-recursively file-store-path file)))
-                        (find-files "src" (string-append
-                                           ".*(editions_defaults.binpb"
-                                           "|landing_page.css"
-                                           "|landing_page.html)$"))))))))
+      #:embed-files #~(list "landing_page.css" "landing_page.html")))
     (native-inputs
      (list go-github-com-stvp-go-udp-testing))
     (propagated-inputs
-- 
2.46.0





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#73299] [PATCH v2 3/3] gnu: go-github-com-golang-protobuf: Remove redundant phase.
       [not found] <cover.1726516329.git.sharlatanus@gmail.com>
  2024-09-16 20:10 ` [bug#73299] [PATCH v2 1/3] build/go: Replace symlinks with a copy of the file Sharlatan Hellseher
  2024-09-16 20:10 ` [bug#73299] [PATCH v2 2/3] gnu: go-github-com-prometheus-statsd-exporter: Remove redundant phase Sharlatan Hellseher
@ 2024-09-16 20:10 ` Sharlatan Hellseher
  2 siblings, 0 replies; 4+ messages in thread
From: Sharlatan Hellseher @ 2024-09-16 20:10 UTC (permalink / raw)
  To: 73299; +Cc: Sharlatan Hellseher

* gnu/packages/packages/golang-build.scm (go-github-com-golang-protobuf)
[arguments]: <#:phases>: Remove 'fix-embed-files and relay on standard
one.

Change-Id: Ife4d86e8072588d562364534a66d41ff01851361
---
 gnu/packages/golang-build.scm | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/gnu/packages/golang-build.scm b/gnu/packages/golang-build.scm
index 8fdd652b63..7049acf8c2 100644
--- a/gnu/packages/golang-build.scm
+++ b/gnu/packages/golang-build.scm
@@ -103,24 +103,6 @@ (define-public go-github-com-golang-protobuf
       #:import-path "github.com/golang/protobuf"
       #:phases
       #~(modify-phases %standard-phases
-          ;; TODO: Implement it in go-build-system.
-          ;;
-          ;; This happens due to 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
-          (add-after 'unpack 'fix-embed-files
-            (lambda _
-              (for-each (lambda (file)
-                          (let ((file-store-path (readlink file)))
-                            (delete-file file)
-                            (copy-recursively file-store-path file)))
-                        (find-files "src" ".*(editions_defaults.binpb)$"))))
           ;; XXX: Workaround for go-build-system's lack of Go modules
           ;; support.
           (delete 'build)
-- 
2.46.0





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#73299] [PATCH v2 1/3] build/go: Replace symlinks with a copy of the file.
  2024-09-16 20:10 ` [bug#73299] [PATCH v2 1/3] build/go: Replace symlinks with a copy of the file Sharlatan Hellseher
@ 2024-09-26 13:22   ` Maxim Cournoyer
  0 siblings, 0 replies; 4+ messages in thread
From: Maxim Cournoyer @ 2024-09-26 13:22 UTC (permalink / raw)
  To: Sharlatan Hellseher
  Cc: Katherine Cox-Buday, Ludovic Courtès, Florian Pelz, 73299,
	Efraim Flashner

Hi Sharlatan,

Some small nitpicks below:

Sharlatan Hellseher <sharlatanus@gmail.com> writes:

> From: Efraim Flashner <efraim@flashner.co.il>
>
> * guix/build/go-build-system.scm (fix-embed-files): New procedure.
> (%standard-phases): Add 'fix-embed-files after 'unpack.
> * guix/build-system/go.scm (#:embed-files): New key parameter.
> * doc/guix.texi: (go-build-system): Document a new key.
>
> Co-authored-by: Sharlatan Hellseher <sharlatanus@gmail.com>
> Change-Id: I27bc46fa1a3f4675ff73b6cba4ef5c3d177c22b1
> ---
>  doc/guix.texi                  |  8 ++++++++
>  guix/build-system/go.scm       |  6 ++++++
>  guix/build/go-build-system.scm | 30 ++++++++++++++++++++++++++++--
>  3 files changed, 42 insertions(+), 2 deletions(-)
>
> diff --git a/doc/guix.texi b/doc/guix.texi
> index 4abe258af0..e780bde6cf 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -130,6 +130,9 @@
>  Copyright @copyright{} 2024 Dariqq@*
>  Copyright @copyright{} 2024 Denis 'GNUtoo' Carikli@*
>  Copyright @copyright{} 2024 Fabio Natali@*
> +Copyright @copyright{} 2024 Troy Figiel@*

Is this accurate?  Should another Co-authored-by: git trailer be added
for them?

[...]

[...]

> diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
> index 3f0f5700a1..14cb5ae687 100644
> --- a/guix/build/go-build-system.scm
> +++ b/guix/build/go-build-system.scm
> @@ -4,10 +4,12 @@
>  ;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
>  ;;; Copyright © 2020 Jack Hill <jackhill@jackhill.us>
>  ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
> -;;; Copyright © 2020, 2021, 2023 Efraim Flashner <efraim@flashner.co.il>
> +;;; Copyright © 2020, 2021, 2023, 2024 Efraim Flashner <efraim@flashner.co.il>
>  ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
>  ;;; Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech>
>  ;;; Copyright © 2024 Picnoir <picnoir@alternativebit.fr>
> +;;; Copyright © 2024 Troy Figiel <troy@troyfigiel.com>
> +;;; Copyright © 2024 Sharlatan Hellseher <sharlatanus@gmail.com>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -28,8 +30,9 @@ (define-module (guix build go-build-system)
>    #:use-module ((guix build gnu-build-system) #:prefix gnu:)
>    #:use-module (guix build union)
>    #:use-module (guix build utils)
> -  #:use-module (ice-9 match)
> +  #:use-module (ice-9 format)
>    #:use-module (ice-9 ftw)
> +  #:use-module (ice-9 match)
>    #:use-module (srfi srfi-1)
>    #:use-module (rnrs io ports)
>    #:use-module (rnrs bytevectors)
> @@ -201,6 +204,28 @@ (define* (setup-go-environment #:key inputs outputs goos goarch #:allow-other-ke
>      (delete-file-recursively tmpdir))
>    #t)
>  
> +(define* (fix-embed-files #:key embed-files #:allow-other-keys)
> +  "Golang can't determine the valid directory of the module of embed file
                                                                 ^ *an* embed file
                                                                 or
                                                                 embed fileS

I typically prefer 'cannot' vs can't and likewise for 'do not' vs
doesn't, etc., which I feel reads more "formal".

> +which is symlinked during setup environment phase, but easy resolved after

easy resolved -> easily resolved

> +coping file from the store to the build directory of the current package. Take

coping file -> copying the file; missing double space before 'Take'.

> +a list of files or regexps matching files from EMBED-FILES paramter, failover

paramter -> parameter

> +to 'editions_defaults.binpb' which is a part of <github.com/golang/protobuf>."

> +  ;; see details in Golang source:

Please use fully punctuated sentences for standalone comments; e.g. :
"For the details, consult the Golang source:"

> +  ;;
> +  ;; - URL: <https://github.com/golang/go/blob/>
> +  ;; - commit: 82c14346d89ec0eeca114f9ca0e88516b2cda454
> +  ;; - file: src/cmd/go/internal/load/pkg.go#L2059

You could use github's raw URL for the file, which doesn't require any
javascript to be viewed.

That's it!  Thank you for working on improving Go on Guix.

-- 
Maxim




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-26 15:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1726516329.git.sharlatanus@gmail.com>
2024-09-16 20:10 ` [bug#73299] [PATCH v2 1/3] build/go: Replace symlinks with a copy of the file Sharlatan Hellseher
2024-09-26 13:22   ` Maxim Cournoyer
2024-09-16 20:10 ` [bug#73299] [PATCH v2 2/3] gnu: go-github-com-prometheus-statsd-exporter: Remove redundant phase Sharlatan Hellseher
2024-09-16 20:10 ` [bug#73299] [PATCH v2 3/3] gnu: go-github-com-golang-protobuf: " Sharlatan Hellseher

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).