all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob fea5d130c33cea1bf879cfc8f92135ba71dc22cc 6898 bytes (raw)
name: guix/scripts/manifest.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guix scripts manifest)
  #:use-module (guix ui)
  #:use-module ((guix diagnostics) #:select (location))
  #:use-module (guix scripts environment)
  #:use-module (guix transformations)
  #:use-module (guix scripts)
  #:use-module (guix packages)
  #:use-module (guix profiles)
  #:autoload   (gnu packages) (specifications->manifest
                               specification->package
                               package-unique-version-prefix)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-37)
  #:use-module (srfi srfi-71)
  #:use-module (ice-9 match)
  #:autoload   (ice-9 pretty-print) (pretty-print)
  #:export (guix-manifest))

(define (show-help)
  (display (G_ "Usage: guix manifest [OPTION] SPECS...
Print a manifest corresponding to the given package SPECS.\n"))
  (newline)

  (display (G_ "
  -D, --development      include the development inputs of the next package"))
  (display (G_ "
  -m, --manifest=FILE    create environment with the manifest from FILE"))

  (newline)
  (show-transformation-options-help)
  (newline)
  (display (G_ "
  -h, --help             display this help and exit"))
  (display (G_ "
  -V, --version          display version information and exit"))
  (newline)
  (show-bug-report-information))

(define %options
  ;; Specification of the command-line options.
  (cons* (option '(#\h "help") #f #f
                 (lambda args
                   (show-help)
                   (exit 0)))
         (option '(#\V "version") #f #f
                 (lambda args
                   (show-version-and-exit "guix manifest")))

         (option '(#\D "development") #f #f
                 (lambda (opt name arg result)
                   (alist-cons 'development? #t result)))
         (option '(#\m "manifest") #t #f
                 (lambda (opt name arg result)
                   (alist-cons 'manifest arg result)))

         %transformation-options))

(define %default-options
  ;; Default option alist.
  '())

(define (load-manifest file)                      ;TODO: factorize
  "Load the user-profile manifest (Scheme code) from FILE and return it."
  (let ((user-module (make-user-module '((guix profiles) (gnu)))))
    (load* file user-module)))

(define (manifest-entry-version-prefix entry)
  "Search among all the versions of ENTRY's package that are available, and
return the shortest unambiguous version prefix for this package."
  (package-unique-version-prefix (manifest-entry-name entry)
                                 (manifest-entry-version entry)))

(define (manifest->code* manifest extra-manifests)
  "Like 'manifest->code', but insert a 'concatenate-manifests' call that
concatenates MANIFESTS, a list of expressions."
  (if (null? (manifest-entries manifest))
      (match extra-manifests
        ((one) one)
        (lst   `(concatenate-manifests ,@extra-manifests)))
      (match (manifest->code manifest
                             #:entry-package-version
                             manifest-entry-version-prefix)
        (('begin exp ... last)
         `(begin
            ,@exp
            ,(match extra-manifests
               (() last)
               (_  `(concatenate-manifests
                     (list ,last ,@extra-manifests)))))))))

\f
(define-command (guix-manifest . args)
  (category development)
  (synopsis "turn command-line arguments into a manifest")

  (define (manifest-lift proc)
    (lambda (entry)
      (match (manifest-entry-item entry)
        ((? package? p)
         (manifest-entry
           (inherit (package->manifest-entry (proc p)))
           (output (manifest-entry-output entry))))
        (_
         entry))))

  (define (handle-argument arg result)
    (if (assoc-ref result 'development?)
        (alist-cons 'development-inputs arg
                    (alist-delete 'development? result))
        (alist-cons 'argument arg result)))

  (with-error-handling
    (let* ((opts (parse-command-line args %options (list %default-options)
                                     #:build-options? #f
                                     #:argument-handler handle-argument))
           (transform (options->transformation opts))
           (specs     (reverse
                       (filter-map (match-lambda
                                     (('argument . spec) spec)
                                     (_ #f))
                                   opts)))
           (extras    (reverse
                       (filter-map (match-lambda
                                     (('development-inputs . spec)
                                      ;; Make sure SPEC is valid.
                                      (specification->package spec)

                                      ;; XXX: This is an approximation:
                                      ;; transformation options are not
                                      ;; applied.
                                      `(package->development-manifest
                                        (specification->package ,spec)))
                                     (_ #f))
                                   opts)))
           (manifest  (concatenate-manifests
                       (cons (map-manifest-entries
                              (manifest-lift transform)
                              (specifications->manifest specs))
                             (filter-map (match-lambda
                                           (('manifest . file)
                                            (load-manifest file))
                                           (_ #f))
                                         opts)))))
      (display (G_ "\
;; What follows is a \"manifest\" equivalent to the command line you gave.
;; You can store it in a file that you may then pass to any 'guix' command
;; that accepts a '--manifest' (or '-m') option.\n"))
      (match (manifest->code* manifest extras)
        (('begin exp ...)
         (for-each (lambda (exp)
                     (newline)
                     (pretty-print exp))
                   exp))
        (exp
         (pretty-print exp))))))

debug log:

solving fea5d130c3 ...
found fea5d130c3 in https://yhetil.org/guix/20220314215146.24490-2-ludo@gnu.org/

applying [1/1] https://yhetil.org/guix/20220314215146.24490-2-ludo@gnu.org/
diff --git a/guix/scripts/manifest.scm b/guix/scripts/manifest.scm
new file mode 100644
index 0000000000..fea5d130c3

Checking patch guix/scripts/manifest.scm...
Applied patch guix/scripts/manifest.scm cleanly.

index at:
100644 fea5d130c33cea1bf879cfc8f92135ba71dc22cc	guix/scripts/manifest.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.