unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: Sarah Morgensen <iskarian@mgsn.dev>
To: 50493@debbugs.gnu.org
Subject: bug#50493: [PATCH 2/4] build-system/go: Initialize build cache from input packages.
Date: Sun, 19 Sep 2021 22:20:49 -0700	[thread overview]
Message-ID: <a40a0ea216c02e45f140f964552347d8ef64b4be.1632099301.git.iskarian@mgsn.dev> (raw)
In-Reply-To: <cover.1632099301.git.iskarian@mgsn.dev>

* 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.
---
 guix/build/go-build-system.scm | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index 645d2fe680..9f249b0777 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2020 Jack Hill <jackhill@jackhill.us>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
 ;;; Copyright © 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -138,9 +139,28 @@ (define* (setup-go-environment #:key inputs outputs goos goarch #:allow-other-ke
 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
 dependencies, so it should be self-contained."
-  ;; The Go cache is required starting in Go 1.12.  We don't actually use it but
-  ;; we need it to be a writable directory.
-  (setenv "GOCACHE" "/tmp/go-cache")
+  (define (search-input-directories dir)
+    (filter directory-exists?
+            (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
   ;; who need to manipulate the unpacked source code.
   (setenv "GOPATH" (getcwd))
-- 
2.33.0





  parent reply	other threads:[~2021-09-20  6:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 22:14 bug#50493: Update go-build-system to use Go 1.17 Sarah Morgensen
2021-09-09 22:37 ` Leo Famulari
2021-09-20  5:28   ` Sarah Morgensen
2021-12-14 20:11   ` Leo Famulari
2021-12-15 10:40     ` Efraim Flashner
2021-12-15 17:44       ` Leo Famulari
2021-12-15 18:03         ` Efraim Flashner
2021-12-17 22:09           ` Leo Famulari
2021-12-19  8:19             ` Efraim Flashner
2021-12-20  1:30               ` Leo Famulari
2021-12-20  2:31                 ` Leo Famulari
2021-12-24 21:35                   ` Leo Famulari
2021-09-20  5:19 ` bug#50493: [PATCH staging 0/4] build-system/go: Use go-1.17 by default Sarah Morgensen
2021-09-20  5:20   ` bug#50493: [PATCH 1/4] build-system/go: Add #:substitutable? argument Sarah Morgensen
2021-09-20  5:20   ` Sarah Morgensen [this message]
2021-09-20  5:20   ` bug#50493: [PATCH 3/4] build-system/go: Add pre-built standard library as implicit input Sarah Morgensen
2021-09-20  5:20   ` bug#50493: [PATCH 4/4] build-system/go: Use go-1.17 by default Sarah Morgensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a40a0ea216c02e45f140f964552347d8ef64b4be.1632099301.git.iskarian@mgsn.dev \
    --to=iskarian@mgsn.dev \
    --cc=50493@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).