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.

540 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`".
4 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`".
4 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`".
4 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`".
4 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`".
4 years ago
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 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. #:use-module (guix profiles)
  33. #:use-module (guix describe)
  34. #:use-module (guix deprecation)
  35. #:use-module (ice-9 vlist)
  36. #:use-module (ice-9 match)
  37. #:use-module (ice-9 binary-ports)
  38. #:autoload (system base compile) (compile)
  39. #:use-module (srfi srfi-1)
  40. #:use-module (srfi srfi-11)
  41. #:use-module (srfi srfi-26)
  42. #:use-module (srfi srfi-34)
  43. #:use-module (srfi srfi-35)
  44. #:use-module (srfi srfi-39)
  45. #:export (search-patch
  46. search-patches
  47. search-auxiliary-file
  48. %patch-path
  49. %auxiliary-files-path
  50. %package-module-path
  51. %default-package-module-path
  52. fold-packages
  53. fold-available-packages
  54. find-newest-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 and auxiliary files
  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 %auxiliary-files-path
  76. (make-parameter
  77. (map (cut string-append <> "/gnu/packages/aux-files")
  78. %load-path)))
  79. (define (search-auxiliary-file file-name)
  80. "Search the auxiliary FILE-NAME. Return #f if not found."
  81. (search-path (%auxiliary-files-path) file-name))
  82. (define (search-patch file-name)
  83. "Search the patch FILE-NAME. Raise an error if not found."
  84. (or (search-path (%patch-path) file-name)
  85. (raise (condition
  86. (&message (message (format #f (G_ "~a: patch not found")
  87. file-name)))))))
  88. (define-syntax-rule (search-patches file-name ...)
  89. "Return the list of absolute file names corresponding to each
  90. FILE-NAME found in %PATCH-PATH."
  91. (list (search-patch file-name) ...))
  92. (define %distro-root-directory
  93. ;; Absolute file name of the module hierarchy. Since (gnu packages …) might
  94. ;; live in a directory different from (guix), try to get the best match.
  95. (letrec-syntax ((dirname* (syntax-rules ()
  96. ((_ file)
  97. (dirname file))
  98. ((_ file head tail ...)
  99. (dirname (dirname* file tail ...)))))
  100. (try (syntax-rules ()
  101. ((_ (file things ...) rest ...)
  102. (match (search-path %load-path file)
  103. (#f
  104. (try rest ...))
  105. (absolute
  106. (dirname* absolute things ...))))
  107. ((_)
  108. #f))))
  109. (try ("gnu/packages/base.scm" gnu/ packages/)
  110. ("gnu/packages.scm" gnu/)
  111. ("guix.scm"))))
  112. (define %default-package-module-path
  113. ;; Default search path for package modules.
  114. `((,%distro-root-directory . "gnu/packages")))
  115. (define (cache-is-authoritative?)
  116. "Return true if the pre-computed package cache is authoritative. It is not
  117. authoritative when entries have been added via GUIX_PACKAGE_PATH or '-L'
  118. flags."
  119. (equal? (%package-module-path)
  120. (append %default-package-module-path
  121. (package-path-entries))))
  122. (define %package-module-path
  123. ;; Search path for package modules. Each item must be either a directory
  124. ;; name or a pair whose car is a directory and whose cdr is a sub-directory
  125. ;; to narrow the search.
  126. (let*-values (((not-colon)
  127. (char-set-complement (char-set #\:)))
  128. ((environment)
  129. (string-tokenize (or (getenv "GUIX_PACKAGE_PATH") "")
  130. not-colon))
  131. ((channels-scm channels-go)
  132. (package-path-entries)))
  133. ;; Automatically add channels and items from $GUIX_PACKAGE_PATH to Guile's
  134. ;; search path. For historical reasons, $GUIX_PACKAGE_PATH goes to the
  135. ;; front; channels go to the back so that they don't override Guix' own
  136. ;; modules.
  137. (set! %load-path
  138. (append environment %load-path channels-scm))
  139. (set! %load-compiled-path
  140. (append environment %load-compiled-path channels-go))
  141. (make-parameter
  142. (append environment
  143. %default-package-module-path
  144. channels-scm))))
  145. (define %patch-path
  146. ;; Define it after '%package-module-path' so that '%load-path' contains user
  147. ;; directories, allowing patches in $GUIX_PACKAGE_PATH to be found.
  148. (make-parameter
  149. (map (lambda (directory)
  150. (if (string=? directory %distro-root-directory)
  151. (string-append directory "/gnu/packages/patches")
  152. directory))
  153. %load-path)))
  154. ;; This procedure is used by Emacs-Guix up to 0.5.1.1, so keep it for now.
  155. ;; See <https://github.com/alezost/guix.el/issues/30>.
  156. (define-deprecated find-newest-available-packages
  157. find-packages-by-name
  158. (mlambda ()
  159. "Return a vhash keyed by package names, and with
  160. associated values of the form
  161. (newest-version newest-package ...)
  162. where the preferred package is listed first."
  163. (fold-packages (lambda (p r)
  164. (let ((name (package-name p))
  165. (version (package-version p)))
  166. (match (vhash-assoc name r)
  167. ((_ newest-so-far . pkgs)
  168. (case (version-compare version newest-so-far)
  169. ((>) (vhash-cons name `(,version ,p) r))
  170. ((=) (vhash-cons name `(,version ,p ,@pkgs) r))
  171. ((<) r)))
  172. (#f (vhash-cons name `(,version ,p) r)))))
  173. vlist-null)))
  174. (define (fold-available-packages proc init)
  175. "Fold PROC over the list of available packages. For each available package,
  176. PROC is called along these lines:
  177. (PROC NAME VERSION RESULT
  178. #:outputs OUTPUTS
  179. #:location LOCATION
  180. )
  181. PROC can use #:allow-other-keys to ignore the bits it's not interested in.
  182. When a package cache is available, this procedure does not actually load any
  183. package module."
  184. (define cache
  185. (load-package-cache (current-profile)))
  186. (if (and cache (cache-is-authoritative?))
  187. (vhash-fold (lambda (name vector result)
  188. (match vector
  189. (#(name version module symbol outputs
  190. supported? deprecated?
  191. file line column)
  192. (proc name version result
  193. #:outputs outputs
  194. #:location (and file
  195. (location file line column))
  196. #:supported? supported?
  197. #:deprecated? deprecated?))))
  198. init
  199. cache)
  200. (fold-packages (lambda (package result)
  201. (proc (package-name package)
  202. (package-version package)
  203. result
  204. #:outputs (package-outputs package)
  205. #:location (package-location package)
  206. #:supported?
  207. (->bool (supported-package? package))
  208. #:deprecated?
  209. (->bool
  210. (package-superseded package))))
  211. init)))
  212. (define* (fold-packages proc init
  213. #:optional
  214. (modules (all-modules (%package-module-path)
  215. #:warn
  216. warn-about-load-error))
  217. #:key (select? (negate hidden-package?)))
  218. "Call (PROC PACKAGE RESULT) for each available package defined in one of
  219. MODULES that matches SELECT?, using INIT as the initial value of RESULT. It
  220. is guaranteed to never traverse the same package twice."
  221. (fold-module-public-variables (lambda (object result)
  222. (if (and (package? object) (select? object))
  223. (proc object result)
  224. result))
  225. init
  226. modules))
  227. (define %package-cache-file
  228. ;; Location of the package cache.
  229. "/lib/guix/package.cache")
  230. (define load-package-cache
  231. (mlambda (profile)
  232. "Attempt to load the package cache. On success return a vhash keyed by
  233. package names. Return #f on failure."
  234. (match profile
  235. (#f #f)
  236. (profile
  237. (catch 'system-error
  238. (lambda ()
  239. (define lst
  240. (load-compiled (string-append profile %package-cache-file)))
  241. (fold (lambda (item vhash)
  242. (match item
  243. (#(name version module symbol outputs
  244. supported? deprecated?
  245. file line column)
  246. (vhash-cons name item vhash))))
  247. vlist-null
  248. lst))
  249. (lambda args
  250. (if (= ENOENT (system-error-errno args))
  251. #f
  252. (apply throw args))))))))
  253. (define find-packages-by-name/direct ;bypass the cache
  254. (let ((packages (delay
  255. (fold-packages (lambda (p r)
  256. (vhash-cons (package-name p) p r))
  257. vlist-null)))
  258. (version>? (lambda (p1 p2)
  259. (version>? (package-version p1) (package-version p2)))))
  260. (lambda* (name #:optional version)
  261. "Return the list of packages with the given NAME. If VERSION is not #f,
  262. then only return packages whose version is prefixed by VERSION, sorted in
  263. decreasing version order."
  264. (let ((matching (sort (vhash-fold* cons '() name (force packages))
  265. version>?)))
  266. (if version
  267. (filter (lambda (package)
  268. (version-prefix? version (package-version package)))
  269. matching)
  270. matching)))))
  271. (define (cache-lookup cache name)
  272. "Lookup package NAME in CACHE. Return a list sorted in increasing version
  273. order."
  274. (define (package-version<? v1 v2)
  275. (version>? (vector-ref v2 1) (vector-ref v1 1)))
  276. (sort (vhash-fold* cons '() name cache)
  277. package-version<?))
  278. (define* (find-packages-by-name name #:optional version)
  279. "Return the list of packages with the given NAME. If VERSION is not #f,
  280. then only return packages whose version is prefixed by VERSION, sorted in
  281. decreasing version order."
  282. (define cache
  283. (load-package-cache (current-profile)))
  284. (if (and (cache-is-authoritative?) cache)
  285. (match (cache-lookup cache name)
  286. (#f #f)
  287. ((#(_ versions modules symbols _ _ _ _ _ _) ...)
  288. (fold (lambda (version* module symbol result)
  289. (if (or (not version)
  290. (version-prefix? version version*))
  291. (cons (module-ref (resolve-interface module)
  292. symbol)
  293. result)
  294. result))
  295. '()
  296. versions modules symbols)))
  297. (find-packages-by-name/direct name version)))
  298. (define* (find-package-locations name #:optional version)
  299. "Return a list of version/location pairs corresponding to each package
  300. matching NAME and VERSION."
  301. (define cache
  302. (load-package-cache (current-profile)))
  303. (if (and cache (cache-is-authoritative?))
  304. (match (cache-lookup cache name)
  305. (#f '())
  306. ((#(name versions modules symbols outputs
  307. supported? deprecated?
  308. files lines columns) ...)
  309. (fold (lambda (version* file line column result)
  310. (if (and file
  311. (or (not version)
  312. (version-prefix? version version*)))
  313. (alist-cons version* (location file line column)
  314. result)
  315. result))
  316. '()
  317. versions files lines columns)))
  318. (map (lambda (package)
  319. (cons (package-version package) (package-location package)))
  320. (find-packages-by-name/direct name version))))
  321. (define (find-best-packages-by-name name version)
  322. "If version is #f, return the list of packages named NAME with the highest
  323. version numbers; otherwise, return the list of packages named NAME and at
  324. VERSION."
  325. (if version
  326. (find-packages-by-name name version)
  327. (match (find-packages-by-name name)
  328. (()
  329. '())
  330. ((matches ...)
  331. ;; Return the subset of MATCHES with the higher version number.
  332. (let ((highest (package-version (first matches))))
  333. (take-while (lambda (p)
  334. (string=? (package-version p) highest))
  335. matches))))))
  336. ;; Prevent Guile 3 from inlining this procedure so we can mock it in tests.
  337. (set! find-best-packages-by-name find-best-packages-by-name)
  338. (define (generate-package-cache directory)
  339. "Generate under DIRECTORY a cache of all the available packages.
  340. The primary purpose of the cache is to speed up package lookup by name such
  341. that we don't have to traverse and load all the package modules, thereby also
  342. reducing the memory footprint."
  343. (define cache-file
  344. (string-append directory %package-cache-file))
  345. (define (expand-cache module symbol variable result+seen)
  346. (match (false-if-exception (variable-ref variable))
  347. ((? package? package)
  348. (match result+seen
  349. ((result . seen)
  350. (if (or (vhash-assq package seen)
  351. (hidden-package? package))
  352. (cons result seen)
  353. (cons (cons `#(,(package-name package)
  354. ,(package-version package)
  355. ,(module-name module)
  356. ,symbol
  357. ,(package-outputs package)
  358. ,(->bool (supported-package? package))
  359. ,(->bool (package-superseded package))
  360. ,@(let ((loc (package-location package)))
  361. (if loc
  362. `(,(location-file loc)
  363. ,(location-line loc)
  364. ,(location-column loc))
  365. '(#f #f #f))))
  366. result)
  367. (vhash-consq package #t seen))))))
  368. (_
  369. result+seen)))
  370. (define exp
  371. (first
  372. (fold-module-public-variables* expand-cache
  373. (cons '() vlist-null)
  374. (all-modules (%package-module-path)
  375. #:warn
  376. warn-about-load-error))))
  377. (mkdir-p (dirname cache-file))
  378. (call-with-output-file cache-file
  379. (lambda (port)
  380. ;; Store the cache as a '.go' file. This makes loading fast and reduces
  381. ;; heap usage since some of the static data is directly mmapped.
  382. (put-bytevector port
  383. (compile `'(,@exp)
  384. #:to 'bytecode
  385. #:opts '(#:to-file? #t)))))
  386. cache-file)
  387. (define %sigint-prompt
  388. ;; The prompt to jump to upon SIGINT.
  389. (make-prompt-tag "interruptible"))
  390. (define (call-with-sigint-handler thunk handler)
  391. "Call THUNK and return its value. Upon SIGINT, call HANDLER with the signal
  392. number in the context of the continuation of the call to this function, and
  393. return its return value."
  394. (call-with-prompt %sigint-prompt
  395. (lambda ()
  396. (sigaction SIGINT
  397. (lambda (signum)
  398. (sigaction SIGINT SIG_DFL)
  399. (abort-to-prompt %sigint-prompt signum)))
  400. (dynamic-wind
  401. (const #t)
  402. thunk
  403. (cut sigaction SIGINT SIG_DFL)))
  404. (lambda (k signum)
  405. (handler signum))))
  406. ;;;
  407. ;;; Package specification.
  408. ;;;
  409. (define* (%find-package spec name version)
  410. (match (find-best-packages-by-name name version)
  411. ((pkg . pkg*)
  412. (unless (null? pkg*)
  413. (warning (G_ "ambiguous package specification `~a'~%") spec)
  414. (warning (G_ "choosing ~a@~a from ~a~%")
  415. (package-name pkg) (package-version pkg)
  416. (location->string (package-location pkg))))
  417. (match (package-superseded pkg)
  418. ((? package? new)
  419. (info (G_ "package '~a' has been superseded by '~a'~%")
  420. (package-name pkg) (package-name new))
  421. new)
  422. (#f
  423. pkg)))
  424. (x
  425. (if version
  426. (leave (G_ "~A: package not found for version ~a~%") name version)
  427. (leave (G_ "~A: unknown package~%") name)))))
  428. (define (specification->package spec)
  429. "Return a package matching SPEC. SPEC may be a package name, or a package
  430. name followed by an at-sign and a version number. If the version number is not
  431. present, return the preferred newest version."
  432. (let-values (((name version) (package-name->name+version spec)))
  433. (%find-package spec name version)))
  434. (define (specification->location spec)
  435. "Return the location of the highest-numbered package matching SPEC, a
  436. specification such as \"guile@2\" or \"emacs\"."
  437. (let-values (((name version) (package-name->name+version spec)))
  438. (match (find-package-locations name version)
  439. (()
  440. (if version
  441. (leave (G_ "~A: package not found for version ~a~%") name version)
  442. (leave (G_ "~A: unknown package~%") name)))
  443. (lst
  444. (let* ((highest (match lst (((version . _) _ ...) version)))
  445. (locations (take-while (match-lambda
  446. ((version . location)
  447. (string=? version highest)))
  448. lst)))
  449. (match locations
  450. (((version . location) . rest)
  451. (unless (null? rest)
  452. (warning (G_ "ambiguous package specification `~a'~%") spec)
  453. (warning (G_ "choosing ~a@~a from ~a~%")
  454. name version
  455. (location->string location)))
  456. location)))))))
  457. (define* (specification->package+output spec #:optional (output "out"))
  458. "Return the package and output specified by SPEC, or #f and #f; SPEC may
  459. optionally contain a version number and an output name, as in these examples:
  460. guile
  461. guile@2.0.9
  462. guile:debug
  463. guile@2.0.9:debug
  464. If SPEC does not specify a version number, return the preferred newest
  465. version; if SPEC does not specify an output, return OUTPUT.
  466. When OUTPUT is false and SPEC does not specify any output, return #f as the
  467. output."
  468. (let-values (((name version sub-drv)
  469. (package-specification->name+version+output spec output)))
  470. (match (%find-package spec name version)
  471. (#f
  472. (values #f #f))
  473. (package
  474. (if (or (and (not output) (not sub-drv))
  475. (member sub-drv (package-outputs package)))
  476. (values package sub-drv)
  477. (leave (G_ "package `~a' lacks output `~a'~%")
  478. (package-full-name package)
  479. sub-drv))))))
  480. (define (specifications->manifest specs)
  481. "Given SPECS, a list of specifications such as \"emacs@25.2\" or
  482. \"guile:debug\", return a profile manifest."
  483. ;; This procedure exists mostly so users of 'guix package -m' don't have to
  484. ;; fiddle with multiple-value returns.
  485. (packages->manifest
  486. (map (compose list specification->package+output) specs)))