From 55d1f529e1a50387d6bf7d474a3cbe3839a1f885 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 16 Jun 2015 10:28:19 +0200 Subject: gnu-maintenance: Use 'home-page' as an additional hint of "GNUness". Reported by Rastus_Vernon on IRC. Fixes 'gnu-package?' for GNUcash. * guix/gnu-maintenance.scm (gnu-package?)[gnu-home-page?]: New procedure. Use it to determine whether PACKAGE is GNU. --- guix/gnu-maintenance.scm | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'guix') diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm index 8d47cee487..ac83df40a3 100644 --- a/guix/gnu-maintenance.scm +++ b/guix/gnu-maintenance.scm @@ -192,15 +192,22 @@ network to check in GNU's database." ;; Definitely non-GNU. 'non-gnu))))) - (let ((url (and=> (package-source package) origin-uri)) - (name (package-name package))) - (case (and (string? url) (mirror-type url)) - ((gnu) #t) - ((non-gnu) #f) - (else - ;; Last resort: resort to the network. - (and (member name (map gnu-package-name (official-gnu-packages))) - #t)))))))) + (define (gnu-home-page? package) + (and=> (package-home-page package) + (lambda (url) + (and=> (uri-host (string->uri url)) + (lambda (host) + (member host '("www.gnu.org" "gnu.org"))))))) + + (or (gnu-home-page? package) + (let ((url (and=> (package-source package) origin-uri)) + (name (package-name package))) + (case (and (string? url) (mirror-type url)) + ((gnu) #t) + ((non-gnu) #f) + (else + (and (member name (map gnu-package-name (official-gnu-packages))) + #t))))))))) ;;; -- cgit v1.2.3 From 2c049216340cf25660b39b3f358ad112cbd1a798 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Wed, 17 Jun 2015 13:55:21 -0400 Subject: offload: Fix sorting bug in 'choose-build-machine'. * guix/scripts/offload.scm (choose-build-machine)[undecorate]: Return the boolean result of pred instead of the best machine+slot. --- guix/scripts/offload.scm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'guix') diff --git a/guix/scripts/offload.scm b/guix/scripts/offload.scm index e65125741f..e6be8b4465 100644 --- a/guix/scripts/offload.scm +++ b/guix/scripts/offload.scm @@ -606,9 +606,7 @@ defines a total order on machines.)" ((machine1 slot1) (match b ((machine2 slot2) - (if (pred machine1 machine2) - (list machine1 slot1) - (list machine2 slot2)))))))) + (pred machine1 machine2))))))) (let loop ((machines+slots (sort machines+slots -- cgit v1.2.3 From 84189ebc66266f03b9ca7e8b912d529886436851 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Jun 2015 10:49:29 +0200 Subject: Move 'specification->package+output' to (gnu packages). * guix/scripts/package.scm (specification->package+output): Move to... * gnu/packages.scm (specification->package+output): ... here * guix/scripts/archive.scm (guix): Adjust accordingly. --- gnu/packages.scm | 36 +++++++++++++++++++++++++++++++++++- guix/scripts/archive.scm | 4 ++-- guix/scripts/package.scm | 36 +----------------------------------- 3 files changed, 38 insertions(+), 38 deletions(-) (limited to 'guix') diff --git a/gnu/packages.scm b/gnu/packages.scm index 9eb4877be8..6e46a890bb 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -51,7 +51,8 @@ check-package-freshness - specification->package)) + specification->package + specification->package+output)) ;;; Commentary: ;;; @@ -418,3 +419,36 @@ present, return the preferred newest version." (leave (_ "~A: package not found for version ~a~%") name version) (leave (_ "~A: unknown package~%") name)))))) + +(define* (specification->package+output spec #:optional (output "out")) + "Return the package and output specified by SPEC, or #f and #f; SPEC may +optionally contain a version number and an output name, as in these examples: + + guile + guile-2.0.9 + guile:debug + guile-2.0.9:debug + +If SPEC does not specify a version number, return the preferred newest +version; if SPEC does not specify an output, return OUTPUT." + (define (ensure-output p sub-drv) + (if (member sub-drv (package-outputs p)) + sub-drv + (leave (_ "package `~a' lacks output `~a'~%") + (package-full-name p) + sub-drv))) + + (let-values (((name version sub-drv) + (package-specification->name+version+output spec output))) + (match (find-best-packages-by-name name version) + ((p) + (values p (ensure-output p sub-drv))) + ((p p* ...) + (warning (_ "ambiguous package specification `~a'~%") + spec) + (warning (_ "choosing ~a from ~a~%") + (package-full-name p) + (location->string (package-location p))) + (values p (ensure-output p sub-drv))) + (() + (leave (_ "~a: package not found~%") spec))))) diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm index ea6801a6eb..ab2fc46c31 100644 --- a/guix/scripts/archive.scm +++ b/guix/scripts/archive.scm @@ -27,6 +27,8 @@ #:use-module (guix ui) #:use-module (guix pki) #:use-module (guix pk-crypto) + #:use-module (guix scripts build) + #:use-module (gnu packages) #:use-module (ice-9 match) #:use-module (ice-9 format) #:use-module (ice-9 rdelim) @@ -34,8 +36,6 @@ #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) - #:use-module (guix scripts build) - #:use-module (guix scripts package) #:use-module (rnrs io ports) #:export (guix-archive)) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index d9f38fb8bc..56a6e2db64 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -47,8 +47,7 @@ #:use-module (gnu packages base) #:use-module (gnu packages guile) #:use-module ((gnu packages bootstrap) #:select (%bootstrap-guile)) - #:export (specification->package+output - switch-to-generation + #:export (switch-to-generation switch-to-previous-generation roll-back delete-generation @@ -324,39 +323,6 @@ similar." (primitive-_exit 0) (apply throw args))))) -(define* (specification->package+output spec #:optional (output "out")) - "Return the package and output specified by SPEC, or #f and #f; SPEC may -optionally contain a version number and an output name, as in these examples: - - guile - guile-2.0.9 - guile:debug - guile-2.0.9:debug - -If SPEC does not specify a version number, return the preferred newest -version; if SPEC does not specify an output, return OUTPUT." - (define (ensure-output p sub-drv) - (if (member sub-drv (package-outputs p)) - sub-drv - (leave (_ "package `~a' lacks output `~a'~%") - (package-full-name p) - sub-drv))) - - (let-values (((name version sub-drv) - (package-specification->name+version+output spec output))) - (match (find-best-packages-by-name name version) - ((p) - (values p (ensure-output p sub-drv))) - ((p p* ...) - (warning (_ "ambiguous package specification `~a'~%") - spec) - (warning (_ "choosing ~a from ~a~%") - (package-full-name p) - (location->string (package-location p))) - (values p (ensure-output p sub-drv))) - (() - (leave (_ "~a: package not found~%") spec))))) - (define (upgradeable? name current-version current-path) "Return #t if there's a version of package NAME newer than CURRENT-VERSION, or if the newest available version is equal to CURRENT-VERSION but would have -- cgit v1.2.3 From 39bee8a2937ea28e74b5c807962fb8bc87fe6887 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Jun 2015 21:58:04 +0200 Subject: Add 'guix edit'. * guix/scripts/edit.scm: New file. * Makefile.am (MODULES): Add it. * doc.am (SUBCOMMANDS): Add 'edit'. * doc/guix.texi (Defining Packages): Add xref to "Invoking guix edit". (Invoking guix edit): New node. * po/guix/POTFILES.in: Add it. --- Makefile.am | 1 + doc.am | 1 + doc/guix.texi | 29 ++++++++++++++++++- guix/scripts/edit.scm | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ po/guix/POTFILES.in | 1 + 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 guix/scripts/edit.scm (limited to 'guix') diff --git a/Makefile.am b/Makefile.am index c8d701b3ba..784848d364 100644 --- a/Makefile.am +++ b/Makefile.am @@ -113,6 +113,7 @@ MODULES = \ guix/scripts/import/hackage.scm \ guix/scripts/environment.scm \ guix/scripts/publish.scm \ + guix/scripts/edit.scm \ guix.scm \ $(GNU_SYSTEM_MODULES) diff --git a/doc.am b/doc.am index d4ca0fc4a5..1c52066aa0 100644 --- a/doc.am +++ b/doc.am @@ -90,6 +90,7 @@ SUBCOMMANDS := \ archive \ build \ download \ + edit \ environment \ gc \ hash \ diff --git a/doc/guix.texi b/doc/guix.texi index 1c7f4e1232..a93003d625 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -124,6 +124,7 @@ Defining Packages Utilities * Invoking guix build:: Building packages from the command line. +* Invoking guix edit:: * Invoking guix download:: Downloading a file and printing its hash. * Invoking guix hash:: Computing the cryptographic hash of a file. * Invoking guix import:: Importing package definitions. @@ -1931,7 +1932,10 @@ unavailable to the build process, possibly leading to a build failure. Once a package definition is in place, the package may actually be built using the @code{guix build} command-line -tool (@pxref{Invoking guix build}). @xref{Packaging Guidelines}, for +tool (@pxref{Invoking guix build}). You can easily jump back to the +package definition using the @command{guix edit} command +(@pxref{Invoking guix edit}). +@xref{Packaging Guidelines}, for more information on how to test package definitions, and @ref{Invoking guix lint}, for information on how to check a definition for style conformance. @@ -3261,6 +3265,7 @@ programming interface of Guix in a convenient way. @menu * Invoking guix build:: Building packages from the command line. +* Invoking guix edit:: Editing package definitions. * Invoking guix download:: Downloading a file and printing its hash. * Invoking guix hash:: Computing the cryptographic hash of a file. * Invoking guix import:: Importing package definitions. @@ -3548,6 +3553,28 @@ the parsed command-line options. @end defvr +@node Invoking guix edit +@section Invoking @command{guix edit} + +@cindex package definition, editing +So many packages, so many source files! The @command{guix edit} command +facilitates the life of packagers by pointing their editor at the source +file containing the definition of the specified packages. For instance: + +@example +guix edit gcc-4.8 vim +@end example + +@noindent +launches the program specified in the @code{EDITOR} environment variable +to edit the recipe of GCC@tie{}4.8.4 and that of Vim. + +If you are using Emacs, note that the Emacs user interface provides +similar functionality in the ``package info'' buffers created by +@kbd{M-x guix-search-by-name} and similar commands (@pxref{Emacs +Commands}). + + @node Invoking guix download @section Invoking @command{guix download} diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm new file mode 100644 index 0000000000..fc453ac38d --- /dev/null +++ b/guix/scripts/edit.scm @@ -0,0 +1,79 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 Ludovic Courtès +;;; +;;; 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 . + +(define-module (guix scripts edit) + #:use-module (guix ui) + #:use-module (guix utils) + #:use-module (guix packages) + #:use-module (gnu packages) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-37) + #:export (%editor + guix-edit)) + +(define %options + (list (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix edit"))))) + +(define (show-help) + (display (_ "Usage: guix edit PACKAGE... +Start $EDITOR to edit the definitions of PACKAGE...\n")) + (newline) + (display (_ " + -h, --help display this help and exit")) + (display (_ " + -V, --version display version information and exit")) + (newline) + (show-bug-report-information)) + +(define %editor + (make-parameter (or (getenv "EDITOR") "emacsclient"))) + +(define (search-path* path file) + "Like 'search-path' but exit if FILE is not found." + (let ((absolute-file-name (search-path path file))) + (unless absolute-file-name + ;; Shouldn't happen unless somebody fiddled with the 'location' field. + (leave (_ "file '~a' not found in search path ~s~%") + file path)) + absolute-file-name)) + + +(define (guix-edit . args) + (with-error-handling + (let* ((specs (parse-command-line args %options '(()) + #:argument-handler cons)) + (packages (map specification->package specs))) + (for-each (lambda (package) + (unless (package-location package) + (leave (_ "source location of package '~a' is unknown~%") + (package-full-name package)))) + packages) + (apply execlp (%editor) (%editor) + (append-map (lambda (package) + (let ((loc (package-location package))) + (list (string-append "+" + (number->string + (location-line loc))) + (search-path* %load-path (location-file loc))))) + packages))))) diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index 4f27f54d6c..300486b666 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in @@ -16,6 +16,7 @@ guix/scripts/authenticate.scm guix/scripts/system.scm guix/scripts/lint.scm guix/scripts/publish.scm +guix/scripts/edit.scm guix/gnu-maintenance.scm guix/ui.scm guix/http-client.scm -- cgit v1.2.3 From fcc58db68b2af59dea0cae41bc1e2df47911d588 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 18 Jun 2015 00:22:13 +0200 Subject: Add 'guix size'. * guix/scripts/size.scm: New file. * Makefile.am (MODULES): Add it. (SCM_TESTS): Add tests/size.scm. * doc.am (SUBCOMMANDS): Add 'size'. * po/guix/POTFILES.in: Add guix/scripts/size.scm. * tests/size.scm: New file. * doc/guix.texi (Packages with Multiple Outputs): Add xref to "Invoking guix size". (Invoking guix size): New node. (Invoking guix gc): Add index for "closure" and xref to the above. * doc/contributing.texi (Submitting Patches): Use @enumerate for the check list. Add item about 'guix size'. --- Makefile.am | 4 +- doc.am | 1 + doc/contributing.texi | 28 +++++- doc/guix.texi | 78 +++++++++++++++- guix/scripts/size.scm | 247 ++++++++++++++++++++++++++++++++++++++++++++++++++ po/guix/POTFILES.in | 1 + tests/size.scm | 87 ++++++++++++++++++ 7 files changed, 438 insertions(+), 8 deletions(-) create mode 100644 guix/scripts/size.scm create mode 100644 tests/size.scm (limited to 'guix') diff --git a/Makefile.am b/Makefile.am index 784848d364..9b1d31c666 100644 --- a/Makefile.am +++ b/Makefile.am @@ -114,6 +114,7 @@ MODULES = \ guix/scripts/environment.scm \ guix/scripts/publish.scm \ guix/scripts/edit.scm \ + guix/scripts/size.scm \ guix.scm \ $(GNU_SYSTEM_MODULES) @@ -192,7 +193,8 @@ SCM_TESTS = \ tests/syscalls.scm \ tests/gremlin.scm \ tests/lint.scm \ - tests/publish.scm + tests/publish.scm \ + tests/size.scm if HAVE_GUILE_JSON diff --git a/doc.am b/doc.am index 1c52066aa0..ee896c189b 100644 --- a/doc.am +++ b/doc.am @@ -100,6 +100,7 @@ SUBCOMMANDS := \ publish \ pull \ refresh \ + size \ system $(eval $(foreach subcommand,$(SUBCOMMANDS), \ diff --git a/doc/contributing.texi b/doc/contributing.texi index 536f223da4..7b16ea3539 100644 --- a/doc/contributing.texi +++ b/doc/contributing.texi @@ -203,14 +203,32 @@ standards, GNU Coding Standards}); you can check the commit history for examples. Before submitting a patch that adds or modifies a package definition, -please run @code{guix lint @var{package}}, where @var{package} is the +please run through this check list: + +@enumerate +@item +Run @code{guix lint @var{package}}, where @var{package} is the name of the new or modified package, and fix any errors it reports -(@pxref{Invoking guix lint}). In addition, please make sure the package -builds on your platform, using @code{guix build @var{package}}. You may -also want to check that dependent package (if applicable) are not -affected by the change; @code{guix refresh --list-dependent +(@pxref{Invoking guix lint}). + +@item +Make sure the package builds on your platform, using @code{guix build +@var{package}}. + +@item +Take a look at the profile reported by @command{guix size} +(@pxref{Invoking guix size}). This will allow you to notice references +to other packages unwillingly retained. It may also help determine +whether to split the package (@pxref{Packages with Multiple Outputs}), +and which optional dependencies should be used. + +@item +For important changes, check that dependent package (if applicable) are +not affected by the change; @code{guix refresh --list-dependent @var{package}} will help you do that (@pxref{Invoking guix refresh}). +@end enumerate + When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as a subject. You may use your email client or the @command{git send-mail} command. diff --git a/doc/guix.texi b/doc/guix.texi index a93003d625..a669464feb 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -124,12 +124,13 @@ Defining Packages Utilities * Invoking guix build:: Building packages from the command line. -* Invoking guix edit:: +* Invoking guix edit:: Editing package definitions. * Invoking guix download:: Downloading a file and printing its hash. * Invoking guix hash:: Computing the cryptographic hash of a file. * Invoking guix import:: Importing package definitions. * Invoking guix refresh:: Updating package definitions. * Invoking guix lint:: Finding errors in package definitions. +* Invoking guix size:: Profiling disk usage. * Invoking guix environment:: Setting up development environments. * Invoking guix publish:: Sharing substitutes. @@ -1495,7 +1496,8 @@ graphical user interfaces (GUIs). The former depend solely on the C library, whereas the latter depend on Tcl/Tk and the underlying X libraries. In this case, we leave the command-line tools in the default output, whereas the GUIs are in a separate output. This allows users -who do not need the GUIs to save space. +who do not need the GUIs to save space. The @command{guix size} command +can help find out about such situations (@pxref{Invoking guix size}). There are several such multiple-output packages in the GNU distribution. Other conventional output names include @code{lib} for libraries and @@ -1575,11 +1577,15 @@ as arguments. @item --requisites @itemx -R +@cindex closure List the requisites of the store files passed as arguments. Requisites include the store files themselves, their references, and the references of these, recursively. In other words, the returned list is the @dfn{transitive closure} of the store files. +@xref{Invoking guix size}, for a tool to profile the size of an +element's closure. + @end table Lastly, the following options allow you to check the integrity of the @@ -3271,6 +3277,7 @@ programming interface of Guix in a convenient way. * Invoking guix import:: Importing package definitions. * Invoking guix refresh:: Updating package definitions. * Invoking guix lint:: Finding errors in package definitions. +* Invoking guix size:: Profiling disk usage. * Invoking guix environment:: Setting up development environments. * Invoking guix publish:: Sharing substitutes. @end menu @@ -3974,6 +3981,73 @@ and exit. @end table +@node Invoking guix size +@section Invoking @command{guix size} + +The @command{guix size} command helps package developers profile the +disk usage of packages. It is easy to overlook the impact of an +additional dependency added to a package, or the impact of using a +single output for a package that could easily be split (@pxref{Packages +with Multiple Outputs}). These are the typical issues that +@command{guix size} can highlight. + +The command can be passed a package specification such as @code{gcc-4.8} +or @code{guile:debug}, or a file name in the store. Consider this +example: + +@example +$ guix size coreutils +store item total self +/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8% +/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6% +/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7% +/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5% +/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4% +/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1% +@end example + +@cindex closure +The store items listed here constitute the @dfn{transitive closure} of +Coreutils---i.e., Coreutils and all its dependencies, recursively---as +would be returned by: + +@example +$ guix gc -R /gnu/store/@dots{}-coreutils-8.23 +@end example + +Here the output shows 3 columns next to store items. The first column, +labeled ``total'', shows the size in mebibytes (MiB) of the closure of +the store item---that is, its own size plus the size of all its +dependencies. The next column, labeled ``self'', shows the size of the +item itself. The last column shows the ratio of the item's size to the +space occupied by all the items listed here. + +In this example, we see that the closure of Coreutils weighs in at +70@tie{}MiB, half of which is taken by libc. (That libc represents a +large fraction of the closure is not a problem @i{per se} because it is +always available on the system anyway.) + +When the package passed to @command{guix size} is available in the +store, @command{guix size} queries the daemon to determine its +dependencies, and measures its size in the store, similar to @command{du +-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU +Coreutils}). + +When the given package is @emph{not} in the store, @command{guix size} +reports information based on information about the available substitutes +(@pxref{Substitutes}). This allows it to profile disk usage of store +items that are not even on disk, only available remotely. + +A single option is available: + +@table @option + +@item --system=@var{system} +@itemx -s @var{system} +Consider packages for @var{system}---e.g., @code{x86_64-linux}. + +@end table + @node Invoking guix environment @section Invoking @command{guix environment} diff --git a/guix/scripts/size.scm b/guix/scripts/size.scm new file mode 100644 index 0000000000..41dd6043a7 --- /dev/null +++ b/guix/scripts/size.scm @@ -0,0 +1,247 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 Ludovic Courtès +;;; +;;; 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 . + +(define-module (guix scripts size) + #:use-module (guix ui) + #:use-module (guix store) + #:use-module (guix monads) + #:use-module (guix utils) + #:use-module (guix packages) + #:use-module (guix derivations) + #:use-module (gnu packages) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-11) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-37) + #:use-module (ice-9 ftw) + #:use-module (ice-9 match) + #:use-module (ice-9 format) + #:export (profile? + profile-file + profile-self-size + profile-closure-size + store-profile + + guix-size)) + +;; Size profile of a store item. +(define-record-type + (profile file self-size closure-size) + profile? + (file profile-file) ;store item + (self-size profile-self-size) ;size in bytes + (closure-size profile-closure-size)) ;size of dependencies in bytes + +(define (file-size file) + "Return the size of bytes of FILE, entering it if FILE is a directory." + (file-system-fold (const #t) + (lambda (file stat result) ;leaf + (+ (stat:size stat) result)) + (lambda (directory stat result) ;down + (+ (stat:size stat) result)) + (lambda (directory stat result) ;up + result) + (lambda (file stat result) ;skip + result) + (lambda (file stat errno result) + (format (current-error-port) + "file-size: ~a: ~a~%" file + (strerror errno)) + result) + 0 + file + lstat)) + +(define substitutable-path-info* + (store-lift substitutable-path-info)) + +(define (store-item-exists? item) + "Return #t if ITEM is in the store, and protect it from GC. Otherwise +return #f." + (lambda (store) + (add-temp-root store item) + (values (valid-path? store item) store))) + +(define (file-size* item) + "Like 'file-size', but resort to information from substitutes if ITEM is not +in the store." + (mlet %store-monad ((exists? (store-item-exists? item))) + (if exists? + (return (file-size item)) + (mlet %store-monad ((info (substitutable-path-info* (list item)))) + (match info + ((info) + ;; The nar size is an approximation, but a good one. + (return (substitutable-nar-size info))) + (() + (leave (_ "no available substitute information for '~a'~%") + item))))))) + +(define* (display-profile profile #:optional (port (current-output-port))) + "Display PROFILE, a list of PROFILE objects, to PORT." + (define MiB (expt 2 20)) + + (format port "~64a ~8a ~a\n" + (_ "store item") (_ "total") (_ "self")) + (let ((whole (reduce + 0 (map profile-self-size profile)))) + (for-each (match-lambda + (($ name self total) + (format port "~64a ~6,1f ~6,1f ~5,1f%\n" + name (/ total MiB) (/ self MiB) + (* 100. (/ self whole 1.))))) + (sort profile + (match-lambda* + ((($ _ _ total1) ($ _ _ total2)) + (> total1 total2))))))) + +(define display-profile* + (lift display-profile %store-monad)) + +(define (substitutable-requisites store item) + "Return the list of requisites of ITEM based on information available in +substitutes." + (let loop ((items (list item)) + (result '())) + (match items + (() + (delete-duplicates result)) + (items + (let ((info (substitutable-path-info store + (delete-duplicates items)))) + (loop (remove (lambda (item) ;XXX: complexity + (member item result)) + (append-map substitutable-references info)) + (append (append-map substitutable-references info) + result))))))) + +(define (requisites* item) + "Return as a monadic value the requisites of ITEMS, based either on the +information available in the local store or using information about +substitutes." + (lambda (store) + (guard (c ((nix-protocol-error? c) + (values (substitutable-requisites store item) + store))) + (values (requisites store item) store)))) + +(define (store-profile item) + "Return as a monadic value a list of objects representing the +profile of ITEM and its requisites." + (mlet* %store-monad ((refs (>>= (requisites* item) + (lambda (refs) + (return (delete-duplicates + (cons item refs)))))) + (sizes (mapm %store-monad + (lambda (item) + (>>= (file-size* item) + (lambda (size) + (return (cons item size))))) + refs))) + (define (dependency-size item) + (mlet %store-monad ((deps (requisites* item))) + (foldm %store-monad + (lambda (item total) + (return (+ (assoc-ref sizes item) total))) + 0 + (delete-duplicates (cons item deps))))) + + (mapm %store-monad + (match-lambda + ((item . size) + (mlet %store-monad ((dependencies (dependency-size item))) + (return (profile item size dependencies))))) + sizes))) + +(define* (ensure-store-item spec-or-item + #:key dry-run?) + "Return a store file name. If SPEC-OR-ITEM is a store file name, return it +as is. Otherwise, assume SPEC-OR-ITEM is a package output specification such +as \"guile:debug\" or \"gcc-4.8\" and return its store file name." + (with-monad %store-monad + (if (store-path? spec-or-item) + (return spec-or-item) + (let-values (((package output) + (specification->package+output spec-or-item))) + (mlet %store-monad ((drv (package->derivation package))) + ;; Note: we don't try building DRV like 'guix archive' does + ;; because we don't have to since we can instead rely on + ;; substitute meta-data. + (return (derivation->output-path drv output))))))) + + +;;; +;;; Options. +;;; + +(define (show-help) + (display (_ "Usage: guix size [OPTION]... PACKAGE +Report the size of PACKAGE and its dependencies.\n")) + (display (_ " + -s, --system=SYSTEM consider packages for SYSTEM--e.g., \"i686-linux\"")) + (newline) + (display (_ " + -h, --help display this help and exit")) + (display (_ " + -V, --version display version information and exit")) + (newline) + (show-bug-report-information)) + +(define %options + ;; Specifications of the command-line options. + (list (option '(#\s "system") #t #f + (lambda (opt name arg result) + (alist-cons 'system arg + (alist-delete 'system result eq?)))) + (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix size"))))) + +(define %default-options + `((system . ,(%current-system)))) + + +;;; +;;; Entry point. +;;; + +(define (guix-size . args) + (with-error-handling + (let* ((opts (parse-command-line args %options (list %default-options))) + (files (filter-map (match-lambda + (('argument . file) file) + (_ #f)) + opts)) + (system (assoc-ref opts 'system)) + (dry-run? (assoc-ref opts 'dry-run?))) + (match files + (() + (leave (_ "missing store item argument\n"))) + ((file) + (with-store store + (run-with-store store + (mlet* %store-monad ((item (ensure-store-item file)) + (profile (store-profile item))) + (display-profile* profile)) + #:system system))) + ((files ...) + (leave (_ "too many arguments\n"))))))) diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index 300486b666..247fe2cf6a 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in @@ -17,6 +17,7 @@ guix/scripts/system.scm guix/scripts/lint.scm guix/scripts/publish.scm guix/scripts/edit.scm +guix/scripts/size.scm guix/gnu-maintenance.scm guix/ui.scm guix/http-client.scm diff --git a/tests/size.scm b/tests/size.scm new file mode 100644 index 0000000000..95b99a88ef --- /dev/null +++ b/tests/size.scm @@ -0,0 +1,87 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 Ludovic Courtès +;;; +;;; 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 . + +(define-module (test-size) + #:use-module (guix store) + #:use-module (guix monads) + #:use-module (guix packages) + #:use-module (guix derivations) + #:use-module (guix gexp) + #:use-module (guix tests) + #:use-module (guix scripts size) + #:use-module (gnu packages bootstrap) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-64)) + +(define %store + (open-connection-for-tests)) + +(define-syntax-rule (test-assertm name exp) + (test-assert name + (run-with-store %store exp + #:guile-for-build (%guile-for-build)))) + + +(test-begin "size") + +(test-assertm "store-profile" + (mlet* %store-monad ((file1 (gexp->derivation "file1" + #~(symlink #$%bootstrap-guile + #$output))) + (file2 (text-file* "file2" + "the file => " file1))) + (define (matching-profile item) + (lambda (profile) + (string=? item (profile-file profile)))) + + (mbegin %store-monad + (built-derivations (list file2)) + (mlet %store-monad ((profiles (store-profile + (derivation->output-path file2))) + (guile (package->derivation %bootstrap-guile))) + (define (lookup-profile drv) + (find (matching-profile (derivation->output-path drv)) + profiles)) + + (letrec-syntax ((match* (syntax-rules (=>) + ((_ ((drv => profile) rest ...) body) + (match (lookup-profile drv) + ((? profile? profile) + (match* (rest ...) body)))) + ((_ () body) + body)))) + ;; Make sure we get all three profiles with sensible values. + (return (and (= (length profiles) 3) + (match* ((file1 => profile1) + (file2 => profile2) + (guile => profile3)) + (and (> (profile-closure-size profile2) 0) + (= (profile-closure-size profile2) + (+ (profile-self-size profile1) + (profile-self-size profile2) + (profile-self-size profile3)))))))))))) + +(test-end "size") + + +(exit (= (test-runner-fail-count (test-runner-current)) 0)) + +;;; Local Variables: +;;; eval: (put 'match* 'scheme-indent-function 1) +;;; End: -- cgit v1.2.3