From mboxrd@z Thu Jan 1 00:00:00 1970 From: Timothy Sample Subject: Upgrading packages with substitutes only (bug #26608) Date: Fri, 16 Jun 2017 12:28:05 -0700 Message-ID: <1497641285.3576580.1011852760.32CE7351@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLwui-0002NC-Us for guix-devel@gnu.org; Fri, 16 Jun 2017 15:28:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLwuf-0000ai-0E for guix-devel@gnu.org; Fri, 16 Jun 2017 15:28:12 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:50755) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dLwue-0000ac-M5 for guix-devel@gnu.org; Fri, 16 Jun 2017 15:28:08 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 8F13D10B9 for ; Fri, 16 Jun 2017 15:28:06 -0400 (EDT) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org Hi Guix, I=E2=80=99ve been using GuixSD for a couple of months now, and it is super cool. Thanks for all your hard work! There is one little thing, though. :) There=E2=80=99s a feature request (bug #26608) about adding an =E2=80=9C--only-substitutes=E2=80=9D flag to =E2=80=9Cguix package -u=E2=80= =9D, which would only upgrade packages that have substitutes. This sounds very useful to me, so I=E2=80= =99ve written code to implement it. It got a little harrier than I expected, so I thought I would get some feedback before actually submitting a patch. Ludo suggested to check each package using the =E2=80=9Csubstitute-paths=E2= =80=9D RPC and filter them accordingly. I did exactly this, but there was a problem. Packages were being built before my code even ran! It turns out that calling =E2=80=9Cpackage-output=E2=80=9D (or =E2=80=9Cpackage-derivati= on=E2=80=9D) to get a package=E2=80=99s output path may result in building the package. It=E2=80= =99s the grafting code that does this =E2=88=92 it needs to get a package=E2=80=99s = references, and if the daemon gives it any trouble, it tells the daemon to just build the package to figure it out. This is a real problem if you are trying to avoid building. This all happens pretty early when running =E2=80=9Cguix package -u=E2=80=9D, since it compares output paths when figu= ring out what needs upgrading. Therefore, to make it work, I introduced a flag, =E2=80=9C#:fail-on-build?= =E2=80=9D, that I threaded through a few functions that lets me try to get a package=E2=80=99s output path without resorting to building the package. The change looks like this: ---------- diff --git a/guix/grafts.scm b/guix/grafts.scm index d6b0e93e8..bcfc289a4 100644 --- a/guix/grafts.scm +++ b/guix/grafts.scm @@ -174,7 +174,7 @@ references. Call REFERENCES to get the list of references." items)))) (remove (cut member <> self) refs))) =20 -(define (references-oracle store drv) +(define (references-oracle store drv fail-on-build?) "Return a one-argument procedure that, when passed the file name of DRV's outputs or their dependencies, returns the list of references of that item. Use either local info or substitute info; build DRV if no information is @@ -186,6 +186,8 @@ available." =20 (define (references* items) (guard (c ((nix-protocol-error? c) + (when fail-on-build? + (raise c)) ;; As a last resort, build DRV and query the references of the ;; build result. =20 @@ -298,7 +300,8 @@ derivations to the corresponding set of grafts." #:key (guile (%guile-for-build)) (outputs (derivation-output-names drv)) - (system (%current-system))) + (system (%current-system)) + (fail-on-build? #f)) "Apply GRAFTS to the OUTPUTS of DRV and all their dependencies, recursively. That is, if GRAFTS apply only indirectly to DRV, graft the dependencies of DRV, and graft DRV itself to refer to those grafted dependencies." @@ -307,7 +310,7 @@ DRV, and graft DRV itself to refer to those grafted dependencies." ;; upfront to have as much parallelism as possible when querying substitute ;; info or when building DRV. (define references - (references-oracle store drv)) + (references-oracle store drv fail-on-build?)) =20 (match (run-with-state (cumulative-grafts store drv grafts references diff --git a/guix/packages.scm b/guix/packages.scm index f4967f98f..e792c348c 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -1123,7 +1123,9 @@ This is an internal procedure." =20 (define* (package-derivation store package #:optional (system (%current-system)) - #:key (graft? (%graft?))) + #:key + (graft? (%graft?)) + (fail-on-build? #f)) "Return the object of PACKAGE for SYSTEM." =20 ;; Compute the derivation and cache the result. Caching is important @@ -1144,12 +1146,15 @@ This is an internal procedure." ;; recurses anyway. (graft-derivation store drv grafts #:system system - #:guile guile)))) + #:guile guile + #:fail-on-build? fail-on-build?)))) drv)))) =20 (define* (package-cross-derivation store package target #:optional (system (%current-system)) - #:key (graft? (%graft?))) + #:key + (graft? (%graft?)) + (fail-on-build? #f)) "Cross-build PACKAGE for TARGET (a GNU triplet) from host SYSTEM (a Guix system identifying string)." (cached package (list system target graft?) @@ -1164,7 +1169,8 @@ system identifying string)." #:system system #:guile (package-derivation store (default-guile) - system #:graft? #f)))) + system #:graft? #f) + #:fail-on-build? fail-on-build?))) drv)))) =20 (define* (package-output store package diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index a6bfb03ae..19b536dd5 100644 ---------- If adding this extra parameter isn=E2=80=99t too ugly, then I will put toge= ther two patches: one with this parameter, and another that uses it to implement =E2=80=9C--only-substitutes=E2=80=9D. (And maybe a third that fix= es a very minor bug in =E2=80=9Cguix package=E2=80=9D, but that=E2=80=99s another sto= ry.) I=E2=80=99m new to Scheme programming, so this may be an atrocity of some sort that I just don=E2=80=99t know about; go easy! :) -- Tim