Mirror of GNU Guix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

531 lines
21 KiB

ui: Rename '_' to 'G_'. This avoids collisions with '_' when the latter is used as a 'match' pattern for instance. See <https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>. * guix/ui.scm: Rename '_' to 'G_'. * po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly. * build-aux/compile-all.scm (warnings): Remove 'format'. * gnu/packages.scm, gnu/services.scm, gnu/services/shepherd.scm, gnu/system.scm, gnu/system/shadow.scm, guix/gnupg.scm, guix/http-client.scm, guix/import/cpan.scm, guix/import/elpa.scm, guix/import/pypi.scm, guix/nar.scm, guix/scripts.scm, guix/scripts/archive.scm, guix/scripts/authenticate.scm, guix/scripts/build.scm, guix/scripts/challenge.scm, guix/scripts/container.scm, guix/scripts/container/exec.scm, guix/scripts/copy.scm, guix/scripts/download.scm, guix/scripts/edit.scm, guix/scripts/environment.scm, guix/scripts/gc.scm, guix/scripts/graph.scm, guix/scripts/hash.scm, guix/scripts/import.scm, guix/scripts/import/cpan.scm, guix/scripts/import/cran.scm, guix/scripts/import/crate.scm, guix/scripts/import/elpa.scm, guix/scripts/import/gem.scm, guix/scripts/import/gnu.scm, guix/scripts/import/hackage.scm, guix/scripts/import/nix.scm, guix/scripts/import/pypi.scm, guix/scripts/import/stackage.scm, guix/scripts/lint.scm, guix/scripts/offload.scm, guix/scripts/pack.scm, guix/scripts/package.scm, guix/scripts/perform-download.scm, guix/scripts/publish.scm, guix/scripts/pull.scm, guix/scripts/refresh.scm, guix/scripts/size.scm, guix/scripts/substitute.scm, guix/scripts/system.scm, guix/ssh.scm, guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
5 years ago
ui: Rename '_' to 'G_'. This avoids collisions with '_' when the latter is used as a 'match' pattern for instance. See <https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>. * guix/ui.scm: Rename '_' to 'G_'. * po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly. * build-aux/compile-all.scm (warnings): Remove 'format'. * gnu/packages.scm, gnu/services.scm, gnu/services/shepherd.scm, gnu/system.scm, gnu/system/shadow.scm, guix/gnupg.scm, guix/http-client.scm, guix/import/cpan.scm, guix/import/elpa.scm, guix/import/pypi.scm, guix/nar.scm, guix/scripts.scm, guix/scripts/archive.scm, guix/scripts/authenticate.scm, guix/scripts/build.scm, guix/scripts/challenge.scm, guix/scripts/container.scm, guix/scripts/container/exec.scm, guix/scripts/copy.scm, guix/scripts/download.scm, guix/scripts/edit.scm, guix/scripts/environment.scm, guix/scripts/gc.scm, guix/scripts/graph.scm, guix/scripts/hash.scm, guix/scripts/import.scm, guix/scripts/import/cpan.scm, guix/scripts/import/cran.scm, guix/scripts/import/crate.scm, guix/scripts/import/elpa.scm, guix/scripts/import/gem.scm, guix/scripts/import/gnu.scm, guix/scripts/import/hackage.scm, guix/scripts/import/nix.scm, guix/scripts/import/pypi.scm, guix/scripts/import/stackage.scm, guix/scripts/lint.scm, guix/scripts/offload.scm, guix/scripts/pack.scm, guix/scripts/package.scm, guix/scripts/perform-download.scm, guix/scripts/publish.scm, guix/scripts/pull.scm, guix/scripts/refresh.scm, guix/scripts/size.scm, guix/scripts/substitute.scm, guix/scripts/system.scm, guix/ssh.scm, guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
5 years ago
ui: Rename '_' to 'G_'. This avoids collisions with '_' when the latter is used as a 'match' pattern for instance. See <https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>. * guix/ui.scm: Rename '_' to 'G_'. * po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly. * build-aux/compile-all.scm (warnings): Remove 'format'. * gnu/packages.scm, gnu/services.scm, gnu/services/shepherd.scm, gnu/system.scm, gnu/system/shadow.scm, guix/gnupg.scm, guix/http-client.scm, guix/import/cpan.scm, guix/import/elpa.scm, guix/import/pypi.scm, guix/nar.scm, guix/scripts.scm, guix/scripts/archive.scm, guix/scripts/authenticate.scm, guix/scripts/build.scm, guix/scripts/challenge.scm, guix/scripts/container.scm, guix/scripts/container/exec.scm, guix/scripts/copy.scm, guix/scripts/download.scm, guix/scripts/edit.scm, guix/scripts/environment.scm, guix/scripts/gc.scm, guix/scripts/graph.scm, guix/scripts/hash.scm, guix/scripts/import.scm, guix/scripts/import/cpan.scm, guix/scripts/import/cran.scm, guix/scripts/import/crate.scm, guix/scripts/import/elpa.scm, guix/scripts/import/gem.scm, guix/scripts/import/gnu.scm, guix/scripts/import/hackage.scm, guix/scripts/import/nix.scm, guix/scripts/import/pypi.scm, guix/scripts/import/stackage.scm, guix/scripts/lint.scm, guix/scripts/offload.scm, guix/scripts/pack.scm, guix/scripts/package.scm, guix/scripts/perform-download.scm, guix/scripts/publish.scm, guix/scripts/pull.scm, guix/scripts/refresh.scm, guix/scripts/size.scm, guix/scripts/substitute.scm, guix/scripts/system.scm, guix/ssh.scm, guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
5 years ago
ui: Rename '_' to 'G_'. This avoids collisions with '_' when the latter is used as a 'match' pattern for instance. See <https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>. * guix/ui.scm: Rename '_' to 'G_'. * po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly. * build-aux/compile-all.scm (warnings): Remove 'format'. * gnu/packages.scm, gnu/services.scm, gnu/services/shepherd.scm, gnu/system.scm, gnu/system/shadow.scm, guix/gnupg.scm, guix/http-client.scm, guix/import/cpan.scm, guix/import/elpa.scm, guix/import/pypi.scm, guix/nar.scm, guix/scripts.scm, guix/scripts/archive.scm, guix/scripts/authenticate.scm, guix/scripts/build.scm, guix/scripts/challenge.scm, guix/scripts/container.scm, guix/scripts/container/exec.scm, guix/scripts/copy.scm, guix/scripts/download.scm, guix/scripts/edit.scm, guix/scripts/environment.scm, guix/scripts/gc.scm, guix/scripts/graph.scm, guix/scripts/hash.scm, guix/scripts/import.scm, guix/scripts/import/cpan.scm, guix/scripts/import/cran.scm, guix/scripts/import/crate.scm, guix/scripts/import/elpa.scm, guix/scripts/import/gem.scm, guix/scripts/import/gnu.scm, guix/scripts/import/hackage.scm, guix/scripts/import/nix.scm, guix/scripts/import/pypi.scm, guix/scripts/import/stackage.scm, guix/scripts/lint.scm, guix/scripts/offload.scm, guix/scripts/pack.scm, guix/scripts/package.scm, guix/scripts/perform-download.scm, guix/scripts/publish.scm, guix/scripts/pull.scm, guix/scripts/refresh.scm, guix/scripts/size.scm, guix/scripts/substitute.scm, guix/scripts/system.scm, guix/ssh.scm, guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
5 years ago
ui: Rename '_' to 'G_'. This avoids collisions with '_' when the latter is used as a 'match' pattern for instance. See <https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>. * guix/ui.scm: Rename '_' to 'G_'. * po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly. * build-aux/compile-all.scm (warnings): Remove 'format'. * gnu/packages.scm, gnu/services.scm, gnu/services/shepherd.scm, gnu/system.scm, gnu/system/shadow.scm, guix/gnupg.scm, guix/http-client.scm, guix/import/cpan.scm, guix/import/elpa.scm, guix/import/pypi.scm, guix/nar.scm, guix/scripts.scm, guix/scripts/archive.scm, guix/scripts/authenticate.scm, guix/scripts/build.scm, guix/scripts/challenge.scm, guix/scripts/container.scm, guix/scripts/container/exec.scm, guix/scripts/copy.scm, guix/scripts/download.scm, guix/scripts/edit.scm, guix/scripts/environment.scm, guix/scripts/gc.scm, guix/scripts/graph.scm, guix/scripts/hash.scm, guix/scripts/import.scm, guix/scripts/import/cpan.scm, guix/scripts/import/cran.scm, guix/scripts/import/crate.scm, guix/scripts/import/elpa.scm, guix/scripts/import/gem.scm, guix/scripts/import/gnu.scm, guix/scripts/import/hackage.scm, guix/scripts/import/nix.scm, guix/scripts/import/pypi.scm, guix/scripts/import/stackage.scm, guix/scripts/lint.scm, guix/scripts/offload.scm, guix/scripts/pack.scm, guix/scripts/package.scm, guix/scripts/perform-download.scm, guix/scripts/publish.scm, guix/scripts/pull.scm, guix/scripts/refresh.scm, guix/scripts/size.scm, guix/scripts/substitute.scm, guix/scripts/system.scm, guix/ssh.scm, guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
5 years ago
ui: Rename '_' to 'G_'. This avoids collisions with '_' when the latter is used as a 'match' pattern for instance. See <https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00464.html>. * guix/ui.scm: Rename '_' to 'G_'. * po/guix/Makevars (XGETTEXT_OPTIONS): Adjust accordingly. * build-aux/compile-all.scm (warnings): Remove 'format'. * gnu/packages.scm, gnu/services.scm, gnu/services/shepherd.scm, gnu/system.scm, gnu/system/shadow.scm, guix/gnupg.scm, guix/http-client.scm, guix/import/cpan.scm, guix/import/elpa.scm, guix/import/pypi.scm, guix/nar.scm, guix/scripts.scm, guix/scripts/archive.scm, guix/scripts/authenticate.scm, guix/scripts/build.scm, guix/scripts/challenge.scm, guix/scripts/container.scm, guix/scripts/container/exec.scm, guix/scripts/copy.scm, guix/scripts/download.scm, guix/scripts/edit.scm, guix/scripts/environment.scm, guix/scripts/gc.scm, guix/scripts/graph.scm, guix/scripts/hash.scm, guix/scripts/import.scm, guix/scripts/import/cpan.scm, guix/scripts/import/cran.scm, guix/scripts/import/crate.scm, guix/scripts/import/elpa.scm, guix/scripts/import/gem.scm, guix/scripts/import/gnu.scm, guix/scripts/import/hackage.scm, guix/scripts/import/nix.scm, guix/scripts/import/pypi.scm, guix/scripts/import/stackage.scm, guix/scripts/lint.scm, guix/scripts/offload.scm, guix/scripts/pack.scm, guix/scripts/package.scm, guix/scripts/perform-download.scm, guix/scripts/publish.scm, guix/scripts/pull.scm, guix/scripts/refresh.scm, guix/scripts/size.scm, guix/scripts/substitute.scm, guix/scripts/system.scm, guix/ssh.scm, guix/upstream.scm: Use 'G_' instead of '_'. Most of this change was obtained by running: "sed -i -e's/(_ "/(G_ "/g' `find -name \*.scm`".
5 years ago
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
  5. ;;; Copyright © 2016, 2017 Alex Kost <alezost@gmail.com>
  6. ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (gnu packages)
  23. #:use-module (guix packages)
  24. #:use-module (guix ui)
  25. #:use-module (guix utils)
  26. #:use-module (guix discovery)
  27. #:use-module (guix memoization)
  28. #:use-module ((guix build utils)
  29. #:select ((package-name->name+version
  30. . hyphen-separated-name->name+version)
  31. mkdir-p))
  32. #:autoload (guix profiles) (packages->manifest)
  33. #:use-module (guix describe)
  34. #:use-module (ice-9 vlist)
  35. #:use-module (ice-9 match)
  36. #:autoload (ice-9 binary-ports) (put-bytevector)
  37. #:autoload (system base compile) (compile)
  38. #:use-module (srfi srfi-1)
  39. #:use-module (srfi srfi-11)
  40. #:use-module (srfi srfi-26)
  41. #:use-module (srfi srfi-34)
  42. #:use-module (srfi srfi-35)
  43. #:use-module (srfi srfi-39)
  44. #:export (search-patch
  45. search-patches
  46. search-auxiliary-file
  47. search-bootstrap-binary
  48. %patch-path
  49. %auxiliary-files-path
  50. %bootstrap-binaries-path
  51. %package-module-path
  52. %default-package-module-path
  53. fold-packages
  54. fold-available-packages
  55. find-packages-by-name
  56. find-package-locations
  57. find-best-packages-by-name
  58. specification->package
  59. specification->package+output
  60. specification->location
  61. specifications->manifest
  62. generate-package-cache))
  63. ;;; Commentary:
  64. ;;;
  65. ;;; General utilities for the software distribution---i.e., the modules under
  66. ;;; (gnu packages ...).
  67. ;;;
  68. ;;; Code:
  69. ;; By default, we store patches, auxiliary files and bootstrap binaries
  70. ;; alongside Guile modules. This is so that these extra files can be
  71. ;; found without requiring a special setup, such as a specific
  72. ;; installation directory and an extra environment variable. One
  73. ;; advantage of this setup is that everything just works in an
  74. ;; auto-compilation setting.
  75. (define %bootstrap-binaries-path
  76. (make-parameter
  77. (map (cut string-append <> "/gnu/packages/bootstrap")
  78. %load-path)))
  79. (define %auxiliary-files-path
  80. (make-parameter
  81. (map (cut string-append <> "/gnu/packages/aux-files")
  82. %load-path)))
  83. (define (search-auxiliary-file file-name)
  84. "Search the auxiliary FILE-NAME. Return #f if not found."
  85. (search-path (%auxiliary-files-path) file-name))
  86. (define (search-patch file-name)
  87. "Search the patch FILE-NAME. Raise an error if not found."
  88. (or (search-path (%patch-path) file-name)
  89. (raise (condition
  90. (&message (message (format #f (G_ "~a: patch not found")
  91. file-name)))))))
  92. (define-syntax-rule (search-patches file-name ...)
  93. "Return the list of absolute file names corresponding to each
  94. FILE-NAME found in %PATCH-PATH."
  95. (list (search-patch file-name) ...))
  96. (define (search-bootstrap-binary file-name system)
  97. "Search the bootstrap binary FILE-NAME for SYSTEM. Raise an error if not
  98. found."
  99. (or (search-path (%bootstrap-binaries-path)
  100. (string-append system "/" file-name))
  101. (raise (condition
  102. (&message
  103. (message
  104. (format #f (G_ "could not find bootstrap binary '~a' \
  105. for system '~a'")
  106. file-name system)))))))
  107. (define %distro-root-directory
  108. ;; Absolute file name of the module hierarchy. Since (gnu packages …) might
  109. ;; live in a directory different from (guix), try to get the best match.
  110. (letrec-syntax ((dirname* (syntax-rules ()
  111. ((_ file)
  112. (dirname file))
  113. ((_ file head tail ...)
  114. (dirname (dirname* file tail ...)))))
  115. (try (syntax-rules ()
  116. ((_ (file things ...) rest ...)
  117. (match (search-path %load-path file)
  118. (#f
  119. (try rest ...))
  120. (absolute
  121. (dirname* absolute things ...))))
  122. ((_)
  123. #f))))
  124. (try ("gnu/packages/base.scm" gnu/ packages/)
  125. ("gnu/packages.scm" gnu/)
  126. ("guix.scm"))))
  127. (define %default-package-module-path
  128. ;; Default search path for package modules.
  129. `((,%distro-root-directory . "gnu/packages")))
  130. (define (cache-is-authoritative?)
  131. "Return true if the pre-computed package cache is authoritative. It is not
  132. authoritative when entries have been added via GUIX_PACKAGE_PATH or '-L'
  133. flags."
  134. (equal? (%package-module-path)
  135. (append %default-package-module-path
  136. (package-path-entries))))
  137. (define %package-module-path
  138. ;; Search path for package modules. Each item must be either a directory
  139. ;; name or a pair whose car is a directory and whose cdr is a sub-directory
  140. ;; to narrow the search.
  141. (let*-values (((not-colon)
  142. (char-set-complement (char-set #\:)))
  143. ((environment)
  144. (string-tokenize (or (getenv "GUIX_PACKAGE_PATH") "")
  145. not-colon))
  146. ((channels-scm channels-go)
  147. (package-path-entries)))
  148. ;; Automatically add channels and items from $GUIX_PACKAGE_PATH to Guile's
  149. ;; search path. For historical reasons, $GUIX_PACKAGE_PATH goes to the
  150. ;; front; channels go to the back so that they don't override Guix' own
  151. ;; modules.
  152. (set! %load-path
  153. (append environment %load-path channels-scm))
  154. (set! %load-compiled-path
  155. (append environment %load-compiled-path channels-go))
  156. (make-parameter
  157. (append environment
  158. %default-package-module-path
  159. channels-scm))))
  160. (define %patch-path
  161. ;; Define it after '%package-module-path' so that '%load-path' contains user
  162. ;; directories, allowing patches in $GUIX_PACKAGE_PATH to be found.
  163. (make-parameter
  164. (map (lambda (directory)
  165. (if (string=? directory %distro-root-directory)
  166. (string-append directory "/gnu/packages/patches")
  167. directory))
  168. %load-path)))
  169. (define (fold-available-packages proc init)
  170. "Fold PROC over the list of available packages. For each available package,
  171. PROC is called along these lines:
  172. (PROC NAME VERSION RESULT
  173. #:outputs OUTPUTS
  174. #:location LOCATION
  175. )
  176. PROC can use #:allow-other-keys to ignore the bits it's not interested in.
  177. When a package cache is available, this procedure does not actually load any
  178. package module."
  179. (define cache
  180. (load-package-cache (current-profile)))
  181. (if (and cache (cache-is-authoritative?))
  182. (vhash-fold (lambda (name vector result)
  183. (match vector
  184. (#(name version module symbol outputs
  185. supported? deprecated?
  186. file line column)
  187. (proc name version result
  188. #:outputs outputs
  189. #:location (and file
  190. (location file line column))
  191. #:supported? supported?
  192. #:deprecated? deprecated?))))
  193. init
  194. cache)
  195. (fold-packages (lambda (package result)
  196. (proc (package-name package)
  197. (package-version package)
  198. result
  199. #:outputs (package-outputs package)
  200. #:location (package-location package)
  201. #:supported?
  202. (->bool
  203. (member (%current-system)
  204. (package-supported-systems package)))
  205. #:deprecated?
  206. (->bool
  207. (package-superseded package))))
  208. init)))
  209. (define* (fold-packages proc init
  210. #:optional
  211. (modules (all-modules (%package-module-path)
  212. #:warn
  213. warn-about-load-error))
  214. #:key (select? (negate hidden-package?)))
  215. "Call (PROC PACKAGE RESULT) for each available package defined in one of
  216. MODULES that matches SELECT?, using INIT as the initial value of RESULT. It
  217. is guaranteed to never traverse the same package twice."
  218. (fold-module-public-variables (lambda (object result)
  219. (if (and (package? object) (select? object))
  220. (proc object result)
  221. result))
  222. init
  223. modules))
  224. (define %package-cache-file
  225. ;; Location of the package cache.
  226. "/lib/guix/package.cache")
  227. (define load-package-cache
  228. (mlambda (profile)
  229. "Attempt to load the package cache. On success return a vhash keyed by
  230. package names. Return #f on failure."
  231. (match profile
  232. (#f #f)
  233. (profile
  234. (catch 'system-error
  235. (lambda ()
  236. (define lst
  237. (load-compiled (string-append profile %package-cache-file)))
  238. (fold (lambda (item vhash)
  239. (match item
  240. (#(name version module symbol outputs
  241. supported? deprecated?
  242. file line column)
  243. (vhash-cons name item vhash))))
  244. vlist-null
  245. lst))
  246. (lambda args
  247. (if (= ENOENT (system-error-errno args))
  248. #f
  249. (apply throw args))))))))
  250. (define find-packages-by-name/direct ;bypass the cache
  251. (let ((packages (delay
  252. (fold-packages (lambda (p r)
  253. (vhash-cons (package-name p) p r))
  254. vlist-null)))
  255. (version>? (lambda (p1 p2)
  256. (version>? (package-version p1) (package-version p2)))))
  257. (lambda* (name #:optional version)
  258. "Return the list of packages with the given NAME. If VERSION is not #f,
  259. then only return packages whose version is prefixed by VERSION, sorted in
  260. decreasing version order."
  261. (let ((matching (sort (vhash-fold* cons '() name (force packages))
  262. version>?)))
  263. (if version
  264. (filter (lambda (package)
  265. (version-prefix? version (package-version package)))
  266. matching)
  267. matching)))))
  268. (define (cache-lookup cache name)
  269. "Lookup package NAME in CACHE. Return a list sorted in increasing version
  270. order."
  271. (define (package-version<? v1 v2)
  272. (version>? (vector-ref v2 1) (vector-ref v1 1)))
  273. (sort (vhash-fold* cons '() name cache)
  274. package-version<?))
  275. (define* (find-packages-by-name name #:optional version)
  276. "Return the list of packages with the given NAME. If VERSION is not #f,
  277. then only return packages whose version is prefixed by VERSION, sorted in
  278. decreasing version order."
  279. (define cache
  280. (load-package-cache (current-profile)))
  281. (if (and (cache-is-authoritative?) cache)
  282. (match (cache-lookup cache name)
  283. (#f #f)
  284. ((#(_ versions modules symbols _ _ _ _ _ _) ...)
  285. (fold (lambda (version* module symbol result)
  286. (if (or (not version)
  287. (version-prefix? version version*))
  288. (cons (module-ref (resolve-interface module)
  289. symbol)
  290. result)
  291. result))
  292. '()
  293. versions modules symbols)))
  294. (find-packages-by-name/direct name version)))
  295. (define* (find-package-locations name #:optional version)
  296. "Return a list of version/location pairs corresponding to each package
  297. matching NAME and VERSION."
  298. (define cache
  299. (load-package-cache (current-profile)))
  300. (if (and cache (cache-is-authoritative?))
  301. (match (cache-lookup cache name)
  302. (#f '())
  303. ((#(name versions modules symbols outputs
  304. supported? deprecated?
  305. files lines columns) ...)
  306. (fold (lambda (version* file line column result)
  307. (if (and file
  308. (or (not version)
  309. (version-prefix? version version*)))
  310. (alist-cons version* (location file line column)
  311. result)
  312. result))
  313. '()
  314. versions files lines columns)))
  315. (map (lambda (package)
  316. (cons (package-version package) (package-location package)))
  317. (find-packages-by-name/direct name version))))
  318. (define (find-best-packages-by-name name version)
  319. "If version is #f, return the list of packages named NAME with the highest
  320. version numbers; otherwise, return the list of packages named NAME and at
  321. VERSION."
  322. (if version
  323. (find-packages-by-name name version)
  324. (match (find-packages-by-name name)
  325. (()
  326. '())
  327. ((matches ...)
  328. ;; Return the subset of MATCHES with the higher version number.
  329. (let ((highest (package-version (first matches))))
  330. (take-while (lambda (p)
  331. (string=? (package-version p) highest))
  332. matches))))))
  333. (define (generate-package-cache directory)
  334. "Generate under DIRECTORY a cache of all the available packages.
  335. The primary purpose of the cache is to speed up package lookup by name such
  336. that we don't have to traverse and load all the package modules, thereby also
  337. reducing the memory footprint."
  338. (define cache-file
  339. (string-append directory %package-cache-file))
  340. (define (expand-cache module symbol variable result+seen)
  341. (match (false-if-exception (variable-ref variable))
  342. ((? package? package)
  343. (match result+seen
  344. ((result . seen)
  345. (if (or (vhash-assq package seen)
  346. (hidden-package? package))
  347. (cons result seen)
  348. (cons (cons `#(,(package-name package)
  349. ,(package-version package)
  350. ,(module-name module)
  351. ,symbol
  352. ,(package-outputs package)
  353. ,(->bool
  354. (member (%current-system)
  355. (package-supported-systems package)))
  356. ,(->bool (package-superseded package))
  357. ,@(let ((loc (package-location package)))
  358. (if loc
  359. `(,(location-file loc)
  360. ,(location-line loc)
  361. ,(location-column loc))
  362. '(#f #f #f))))
  363. result)
  364. (vhash-consq package #t seen))))))
  365. (_
  366. result+seen)))
  367. (define exp
  368. (first
  369. (fold-module-public-variables* expand-cache
  370. (cons '() vlist-null)
  371. (all-modules (%package-module-path)
  372. #:warn
  373. warn-about-load-error))))
  374. (mkdir-p (dirname cache-file))
  375. (call-with-output-file cache-file
  376. (lambda (port)
  377. ;; Store the cache as a '.go' file. This makes loading fast and reduces
  378. ;; heap usage since some of the static data is directly mmapped.
  379. (put-bytevector port
  380. (compile `'(,@exp)
  381. #:to 'bytecode
  382. #:opts '(#:to-file? #t)))))
  383. cache-file)
  384. (define %sigint-prompt
  385. ;; The prompt to jump to upon SIGINT.
  386. (make-prompt-tag "interruptible"))
  387. (define (call-with-sigint-handler thunk handler)
  388. "Call THUNK and return its value. Upon SIGINT, call HANDLER with the signal
  389. number in the context of the continuation of the call to this function, and
  390. return its return value."
  391. (call-with-prompt %sigint-prompt
  392. (lambda ()
  393. (sigaction SIGINT
  394. (lambda (signum)
  395. (sigaction SIGINT SIG_DFL)
  396. (abort-to-prompt %sigint-prompt signum)))
  397. (dynamic-wind
  398. (const #t)
  399. thunk
  400. (cut sigaction SIGINT SIG_DFL)))
  401. (lambda (k signum)
  402. (handler signum))))
  403. ;;;
  404. ;;; Package specification.
  405. ;;;
  406. (define* (%find-package spec name version)
  407. (match (find-best-packages-by-name name version)
  408. ((pkg . pkg*)
  409. (unless (null? pkg*)
  410. (warning (G_ "ambiguous package specification `~a'~%") spec)
  411. (warning (G_ "choosing ~a@~a from ~a~%")
  412. (package-name pkg) (package-version pkg)
  413. (location->string (package-location pkg))))
  414. (match (package-superseded pkg)
  415. ((? package? new)
  416. (info (G_ "package '~a' has been superseded by '~a'~%")
  417. (package-name pkg) (package-name new))
  418. new)
  419. (#f
  420. pkg)))
  421. (x
  422. (if version
  423. (leave (G_ "~A: package not found for version ~a~%") name version)
  424. (leave (G_ "~A: unknown package~%") name)))))
  425. (define (specification->package spec)
  426. "Return a package matching SPEC. SPEC may be a package name, or a package
  427. name followed by an at-sign and a version number. If the version number is not
  428. present, return the preferred newest version."
  429. (let-values (((name version) (package-name->name+version spec)))
  430. (%find-package spec name version)))
  431. (define (specification->location spec)
  432. "Return the location of the highest-numbered package matching SPEC, a
  433. specification such as \"guile@2\" or \"emacs\"."
  434. (let-values (((name version) (package-name->name+version spec)))
  435. (match (find-package-locations name version)
  436. (()
  437. (if version
  438. (leave (G_ "~A: package not found for version ~a~%") name version)
  439. (leave (G_ "~A: unknown package~%") name)))
  440. (lst
  441. (let* ((highest (match lst (((version . _) _ ...) version)))
  442. (locations (take-while (match-lambda
  443. ((version . location)
  444. (string=? version highest)))
  445. lst)))
  446. (match locations
  447. (((version . location) . rest)
  448. (unless (null? rest)
  449. (warning (G_ "ambiguous package specification `~a'~%") spec)
  450. (warning (G_ "choosing ~a@~a from ~a~%")
  451. name version
  452. (location->string location)))
  453. location)))))))
  454. (define* (specification->package+output spec #:optional (output "out"))
  455. "Return the package and output specified by SPEC, or #f and #f; SPEC may
  456. optionally contain a version number and an output name, as in these examples:
  457. guile
  458. guile@2.0.9
  459. guile:debug
  460. guile@2.0.9:debug
  461. If SPEC does not specify a version number, return the preferred newest
  462. version; if SPEC does not specify an output, return OUTPUT."
  463. (let-values (((name version sub-drv)
  464. (package-specification->name+version+output spec output)))
  465. (match (%find-package spec name version)
  466. (#f
  467. (values #f #f))
  468. (package
  469. (if (member sub-drv (package-outputs package))
  470. (values package sub-drv)
  471. (leave (G_ "package `~a' lacks output `~a'~%")
  472. (package-full-name package)
  473. sub-drv))))))
  474. (define (specifications->manifest specs)
  475. "Given SPECS, a list of specifications such as \"emacs@25.2\" or
  476. \"guile:debug\", return a profile manifest."
  477. ;; This procedure exists mostly so users of 'guix package -m' don't have to
  478. ;; fiddle with multiple-value returns.
  479. (packages->manifest
  480. (map (compose list specification->package+output) specs)))