summaryrefslogtreecommitdiff
path: root/guix/packages.scm
diff options
context:
space:
mode:
authorMarius Bakke <mbakke@fastmail.com>2019-03-23 23:16:55 +0100
committerMarius Bakke <mbakke@fastmail.com>2019-03-23 23:16:55 +0100
commit8c14f7f8a7ab0722bf4c9f92fd28ae85514d564f (patch)
treeadc5d29e9c2dcda5befa0ca81f1af8df23294947 /guix/packages.scm
parent2f33a7321e5e37d37f57c229c8079cb4ffd10834 (diff)
parent3374e9207f5244c20402a3c5513fe562140fef47 (diff)
Merge branch 'staging' into core-updates
Diffstat (limited to 'guix/packages.scm')
-rw-r--r--guix/packages.scm38
1 files changed, 38 insertions, 0 deletions
diff --git a/guix/packages.scm b/guix/packages.scm
index 1893539aab..a961dc3973 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -102,6 +102,7 @@
package-transitive-supported-systems
package-mapping
package-input-rewriting
+ package-input-rewriting/spec
package-source-derivation
package-derivation
package-cross-derivation
@@ -871,6 +872,43 @@ package and returns its new name after rewrite."
(package-mapping rewrite (cut assq <> replacements)))
+(define (package-input-rewriting/spec replacements)
+ "Return a procedure that, given a package, applies the given REPLACEMENTS to
+all the package graph (excluding implicit inputs). REPLACEMENTS is a list of
+spec/procedures pair; each spec is a package specification such as \"gcc\" or
+\"guile@2\", and each procedure takes a matching package and returns a
+replacement for that package."
+ (define table
+ (fold (lambda (replacement table)
+ (match replacement
+ ((spec . proc)
+ (let-values (((name version)
+ (package-name->name+version spec)))
+ (vhash-cons name (list version proc) table)))))
+ vlist-null
+ replacements))
+
+ (define (find-replacement package)
+ (vhash-fold* (lambda (item proc)
+ (or proc
+ (match item
+ ((#f proc)
+ proc)
+ ((version proc)
+ (and (version-prefix? version
+ (package-version package))
+ proc)))))
+ #f
+ (package-name package)
+ table))
+
+ (define (rewrite package)
+ (match (find-replacement package)
+ (#f package)
+ (proc (proc package))))
+
+ (package-mapping rewrite find-replacement))
+
(define-syntax-rule (package/inherit p overrides ...)
"Like (package (inherit P) OVERRIDES ...), except that the same
transformation is done to the package replacement, if any. P must be a bare