mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-31 06:46:50 +01:00
build/go: Replace symlinks with a copy of the file.
* 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
This commit is contained in:
parent
63c558d62a
commit
922d017081
3 changed files with 41 additions and 2 deletions
|
@ -132,6 +132,8 @@ Copyright @copyright{} 2024 Denis 'GNUtoo' Carikli@*
|
|||
Copyright @copyright{} 2024 Fabio Natali@*
|
||||
Copyright @copyright{} 2024 Arnaud Daby-Seesaram@*
|
||||
Copyright @copyright{} 2024 Nigko Yerden@*
|
||||
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
|
||||
|
@ -9588,6 +9590,11 @@ the test binary. Build, test and test binary flags can be provided as
|
|||
@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
|
||||
|
|
|
@ -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 builder
|
|||
#: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 %outputs
|
|||
#: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
|
||||
|
|
|
@ -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 (search-input-directories dir)
|
|||
(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)
|
||||
|
|
Loading…
Reference in a new issue