>From d2d3f9d296c26ad1d4a1e17d56ae3e3361ca02d7 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Thu, 14 Aug 2014 00:03:53 +0400 Subject: [PATCH 1/2] profiles: Add 'manifest-transaction'. * guix/profiles.scm (): New record-type. (manifest-perform-transaction): New procedure. (manifest-show-transaction): New procedure. * tests/profiles.scm ("manifest-perform-transaction"): New test. --- guix/profiles.scm | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/profiles.scm | 22 +++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/guix/profiles.scm b/guix/profiles.scm index e921566..55a3348 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014 Ludovic Courtès ;;; Copyright © 2013 Nikita Karetnikov +;;; Copyright © 2014 Alex Kost ;;; ;;; This file is part of GNU Guix. ;;; @@ -18,6 +19,7 @@ ;;; along with GNU Guix. If not, see . (define-module (guix profiles) + #:use-module (guix ui) #:use-module (guix utils) #:use-module (guix records) #:use-module (guix derivations) @@ -51,6 +53,13 @@ manifest-installed? manifest-matching-entries + manifest-transaction + manifest-transaction? + manifest-transaction-install + manifest-transaction-remove + manifest-perform-transaction + manifest-show-transaction + profile-manifest package->manifest-entry profile-derivation @@ -244,6 +253,72 @@ Remove MANIFEST entries that have the same name and output as ENTRIES." ;;; +;;; Manifest transactions. +;;; + +(define-record-type* manifest-transaction + make-manifest-transaction + manifest-transaction? + (install manifest-transaction-install ; list of + (default '())) + (remove manifest-transaction-remove ; list of + (default '()))) + +(define (manifest-perform-transaction manifest transaction) + "Perform TRANSACTION on MANIFEST and return new manifest." + (let ((install (manifest-transaction-install transaction)) + (remove (manifest-transaction-remove transaction))) + (manifest-add (manifest-remove manifest remove) + install))) + +(define* (manifest-show-transaction manifest transaction #:key dry-run?) + "Display what will/would be installed/removed from MANIFEST by TRANSACTION." + ;; TODO: Report upgrades more clearly. + (let ((install (manifest-transaction-install transaction)) + (remove (manifest-matching-entries + manifest (manifest-transaction-remove transaction)))) + (match remove + ((($ name version output path _) ..1) + (let ((len (length name)) + (remove (map (cut format #f " ~a-~a\t~a\t~a" <> <> <> <>) + name version output path))) + (if dry-run? + (format (current-error-port) + (N_ "The following package would be removed:~%~{~a~%~}~%" + "The following packages would be removed:~%~{~a~%~}~%" + len) + remove) + (format (current-error-port) + (N_ "The following package will be removed:~%~{~a~%~}~%" + "The following packages will be removed:~%~{~a~%~}~%" + len) + remove)))) + (_ #f)) + (match install + ((($ name version output item _) ..1) + (let ((len (length name)) + (install (map (lambda (name version output item) + (if (package? item) + (format #f " ~a-~a\t~a" + name version output) + (format #f " ~a-~a\t~a\t~a" + name version output item))) + name version output item))) + (if dry-run? + (format (current-error-port) + (N_ "The following package would be installed:~%~{~a~%~}~%" + "The following packages would be installed:~%~{~a~%~}~%" + len) + install) + (format (current-error-port) + (N_ "The following package will be installed:~%~{~a~%~}~%" + "The following packages will be installed:~%~{~a~%~}~%" + len) + install)))) + (_ #f)))) + + +;;; ;;; Profiles. ;;; diff --git a/tests/profiles.scm b/tests/profiles.scm index b2919d7..e1f1eef 100644 --- a/tests/profiles.scm +++ b/tests/profiles.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014 Ludovic Courtès +;;; Copyright © 2014 Alex Kost ;;; ;;; This file is part of GNU Guix. ;;; @@ -26,7 +27,7 @@ #:use-module (ice-9 match) #:use-module (srfi srfi-64)) -;; Test the (guix profile) module. +;; Test the (guix profiles) module. (define %store (open-connection)) @@ -122,6 +123,25 @@ (_ #f)) (equal? m3 m4)))) +(test-assert "manifest-perform-transaction" + (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug))) + (t1 (manifest-transaction + (install (list guile-1.8.8)) + (remove (list (manifest-pattern (name "guile") + (output "debug")))))) + (t2 (manifest-transaction + (remove (list (manifest-pattern (name "guile") + (version "2.0.9") + (output #f)))))) + (m1 (manifest-perform-transaction m0 t1)) + (m2 (manifest-perform-transaction m1 t2)) + (m3 (manifest-perform-transaction m0 t2))) + (and (match (manifest-entries m1) + ((($ "guile" "1.8.8" "out")) #t) + (_ #f)) + (equal? m1 m2) + (null? (manifest-entries m3))))) + (test-assert "profile-derivation" (run-with-store %store (mlet* %store-monad -- 2.0.3