build-system/go: Initialize build cache from input packages.

* guix/build/go-build-system.com (setup-go-environment): Set GOCACHE to
a location within the build directory.  Union "/var/cache/go/build"
input directories to initialize the cache.  Generate "trim.txt" within
the cache, with the current time.

Signed-off-by: Leo Famulari <leo@famulari.name>
This commit is contained in:
Sarah Morgensen 2021-09-19 22:20:49 -07:00 committed by Leo Famulari
parent d0050ea8ad
commit c90f73f816
No known key found for this signature in database
GPG Key ID: 2646FA30BACA7F08
1 changed files with 23 additions and 3 deletions

View File

@ -5,6 +5,7 @@
;;; Copyright © 2020 Jack Hill <jackhill@jackhill.us> ;;; Copyright © 2020 Jack Hill <jackhill@jackhill.us>
;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net> ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
;;; Copyright © 2020, 2021 Efraim Flashner <efraim@flashner.co.il> ;;; Copyright © 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -138,9 +139,28 @@ of the package being built and its dependencies, and GOBIN, which determines
where executables (\"commands\") are installed to. This phase is sometimes used where executables (\"commands\") are installed to. This phase is sometimes used
by packages that use (guix build-system gnu) but have a handful of Go by packages that use (guix build-system gnu) but have a handful of Go
dependencies, so it should be self-contained." dependencies, so it should be self-contained."
;; The Go cache is required starting in Go 1.12. We don't actually use it but (define (search-input-directories dir)
;; we need it to be a writable directory. (filter directory-exists?
(setenv "GOCACHE" "/tmp/go-cache") (map (match-lambda
((name . directory)
(string-append directory "/" dir)))
inputs)))
;; Seed the Go build cache with the build caches from input packages.
(let ((cache (string-append (getcwd) "/go-build")))
(setenv "GOCACHE" cache)
(union-build cache
(search-input-directories "/var/cache/go/build")
;; Creating all directories isn't that bad, because there are
;; only ever 256 of them.
#:create-all-directories? #t
#:log-port (%make-void-port "w"))
;; Tell Go that the cache was recently trimmed, so it doesn't try to.
(call-with-output-file (string-append cache "/trim.txt")
(lambda (port)
(format port "~a" (current-time)))))
;; Using the current working directory as GOPATH makes it easier for packagers ;; Using the current working directory as GOPATH makes it easier for packagers
;; who need to manipulate the unpacked source code. ;; who need to manipulate the unpacked source code.
(setenv "GOPATH" (getcwd)) (setenv "GOPATH" (getcwd))