me
/
guix
Archived
1
0
Fork 0

gexp: 'compiled-modules' gets source and parameters an environment variables.

This reduces the number of 'add-text-to-store' RPCs by 15 (out of 3336)
oin "guix build -d --no-grafts libreoffice".

* guix/gexp.scm (gexp-with-hidden-inputs): New procedure.
(compiled-modules): Use it.  Pass #:script-name.  Augment #:env-vars.
master
Ludovic Courtès 2021-03-26 10:52:24 +01:00
parent f27a7c18b6
commit 2eafeb2f3d
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 160 additions and 102 deletions

View File

@ -184,6 +184,18 @@
(set-record-type-printer! <gexp> write-gexp)
(define (gexp-with-hidden-inputs gexp inputs)
"Add INPUTS, a list of <gexp-input>, to the references of GEXP. These are
\"hidden inputs\" because they do not actually appear in the expansion of GEXP
returned by 'gexp->sexp'."
(make-gexp (append inputs (gexp-references gexp))
(gexp-self-modules gexp)
(gexp-self-extensions gexp)
(let ((extra (length inputs)))
(lambda args
(apply (gexp-proc gexp) (drop args extra))))
(gexp-location gexp)))
;;;
;;; Methods.
@ -1614,8 +1626,14 @@ TARGET, a GNU triplet."
#:system system
#:guile guile
#:module-path
module-path)))
module-path))
(extensions (mapm %store-monad
(lambda (extension)
(lower-object extension system
#:target #f))
extensions)))
(define build
(gexp-with-hidden-inputs
(gexp
(begin
(primitive-load (ungexp %utils-module)) ;for 'mkdir-p'
@ -1627,6 +1645,21 @@ TARGET, a GNU triplet."
(system base target)
(system base compile))
(define modules
(getenv "modules"))
(define total
(string->number (getenv "module count")))
(define extensions
(string-split (getenv "extensions") #\space))
(define target
(getenv "target"))
(define optimization-level
(string->number (getenv "optimization level")))
(define optimizations-for-level
(or (and=> (false-if-exception
(resolve-interface '(system base optimize)))
@ -1645,18 +1678,18 @@ TARGET, a GNU triplet."
(let* ((base (basename entry ".scm"))
(output (string-append output "/" base ".go")))
(format #t "[~2@a/~2@a] Compiling '~a'...~%"
(+ 1 processed (ungexp total))
(ungexp (* total 2))
(+ 1 processed total)
(* total 2)
entry)
(with-target (ungexp (or target (gexp %host-type)))
(with-target (or target %host-type)
(lambda ()
(compile-file entry
#:output-file output
#:opts
`(,@%auto-compilation-options
,@(optimizations-for-level
(ungexp optimization-level))))))
optimization-level)))))
(+ 1 processed))))
@ -1678,7 +1711,7 @@ TARGET, a GNU triplet."
(load-from-directory file loaded)
(begin
(format #t "[~2@a/~2@a] Loading '~a'...~%"
(+ 1 loaded) (ungexp (* 2 total))
(+ 1 loaded) (* 2 total)
file)
(save-module-excursion
(lambda ()
@ -1694,51 +1727,76 @@ TARGET, a GNU triplet."
;; Capture 'mkdir-p'.
(@ (guix build utils) mkdir-p))
;; Remove environment variables for internal consumption.
(unsetenv "modules")
(unsetenv "module count")
(unsetenv "extensions")
(unsetenv "target")
(unsetenv "optimization level")
;; Add EXTENSIONS to the search path.
(set! %load-path
(append (map (lambda (extension)
(string-append extension
"/share/guile/site/"
(effective-version)))
'((ungexp-native-splicing extensions)))
extensions)
%load-path))
(set! %load-compiled-path
(append (map (lambda (extension)
(string-append extension "/lib/guile/"
(effective-version)
"/site-ccache"))
'((ungexp-native-splicing extensions)))
extensions)
%load-compiled-path))
(set! %load-path (cons (ungexp modules) %load-path))
(set! %load-path (cons modules %load-path))
;; Above we loaded our own (guix build utils) but now we may need to
;; load a compile a different one. Thus, force a reload.
(let ((utils (string-append (ungexp modules)
(let ((utils (string-append modules
"/guix/build/utils.scm")))
(when (file-exists? utils)
(load utils)))
(mkdir (ungexp output))
(chdir (ungexp modules))
(chdir modules)
(load-from-directory ".")
(process-directory "." (ungexp output) 0))))
(process-directory "." (ungexp output) 0)))
(list (gexp-input modules))))
;; TODO: Pass MODULES as an environment variable.
(gexp->derivation name build
#:script-name "compile-modules"
#:system system
#:target target
#:guile-for-build guile
#:local-build? #t
#:env-vars
(case deprecation-warnings
`(("modules"
. ,(if (derivation? modules)
(derivation->output-path modules)
modules))
("module count" . ,(number->string total))
("extensions"
. ,(string-join
(map (match-lambda
((? derivation? drv)
(derivation->output-path drv))
((? string? str) str))
extensions)))
("optimization level"
. ,(number->string optimization-level))
,@(if target
`(("target" . ,target))
'())
,@(case deprecation-warnings
((#f)
'(("GUILE_WARN_DEPRECATED" . "no")))
((detailed)
'(("GUILE_WARN_DEPRECATED" . "detailed")))
(else
'())))))
'()))))))
;;;