From patchwork Thu Jan 7 09:09:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 26256 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B8B5327BC0F; Thu, 7 Jan 2021 09:10:22 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D0CDA27BC0E for ; Thu, 7 Jan 2021 09:10:20 +0000 (GMT) Received: from localhost ([::1]:45218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxRJD-0007AP-UC for patchwork@mira.cbaines.net; Thu, 07 Jan 2021 04:10:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxRIw-000796-GV for guix-patches@gnu.org; Thu, 07 Jan 2021 04:10:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kxRIw-0004Ny-3k for guix-patches@gnu.org; Thu, 07 Jan 2021 04:10:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kxRIv-000442-UT for guix-patches@gnu.org; Thu, 07 Jan 2021 04:10:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45710] [PATCH] transformations: Add '--with-latest'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 07 Jan 2021 09:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45710 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45710@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.161001055715552 (code B ref -1); Thu, 07 Jan 2021 09:10:01 +0000 Received: (at submit) by debbugs.gnu.org; 7 Jan 2021 09:09:17 +0000 Received: from localhost ([127.0.0.1]:46306 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxRIC-00042h-8T for submit@debbugs.gnu.org; Thu, 07 Jan 2021 04:09:16 -0500 Received: from lists.gnu.org ([209.51.188.17]:39264) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxRI9-00042Y-ST for submit@debbugs.gnu.org; Thu, 07 Jan 2021 04:09:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxRI9-00072H-Me for guix-patches@gnu.org; Thu, 07 Jan 2021 04:09:13 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:52122) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxRI8-00043L-JC; Thu, 07 Jan 2021 04:09:12 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=43924 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kxRI8-0007aP-2M; Thu, 07 Jan 2021 04:09:12 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 7 Jan 2021 10:09:04 +0100 Message-Id: <20210107090904.23753-1-ludo@gnu.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/upstream.scm (upstream-source-compiler): New procedure. (%updaters): Set! it. * guix/transformations.scm (transform-package-latest): New procedure. (%transformations): Add 'with-latest'. (%transformation-options, show-transformation-options-help/detailed): Add '--with-latest'. * tests/transformations.scm ("options->transformation, with-latest"): New test. * doc/guix.texi (Package Transformation Options): Document it. --- doc/guix.texi | 31 +++++++++++++++++++++++++ guix/transformations.scm | 49 +++++++++++++++++++++++++++++++++++++-- guix/upstream.scm | 28 ++++++++++++++++++++-- tests/transformations.scm | 19 ++++++++++++++- 4 files changed, 122 insertions(+), 5 deletions(-) Hi! This was a very tempting hack and I think it can prove useful when you want to quickly try things out, at your own risk. Thoughts? Ludo’. diff --git a/doc/guix.texi b/doc/guix.texi index 0f6e95a65a..cefdb3e3ef 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10376,6 +10376,37 @@ guix build coreutils --with-patch=glibc=./glibc-frob.patch In this example, glibc itself as well as everything that leads to Coreutils in the dependency graph is rebuilt. +@cindex upstream, latest version +@item --with-latest=@var{package} +So you like living on the bleeding edge? This option is for you! It +replaces occurrences of @var{package} in the dependency graph with its +latest upstream version, as reported by @command{guix refresh} +(@pxref{Invoking guix refresh}). + +It does so by determining the latest upstream release of @var{package} +(if possible), downloading it, and authenticating it @emph{if} it comes +with an OpenPGP signature. + +As an example, the command below builds Guix against the latest version +of Guile-JSON: + +@example +guix build guix --with-latest=guile-json +@end example + +There are limitations. First, in cases where the tool cannot or does +not know how to authenticate source code, you are at risk of running +malicious code; a warning is emitted in this case. Second, this option +simply changes the source used in the existing package definitions, +which is not always sufficient: there might be additional dependencies +that need to be added, patches to apply, and more generally the quality +assurance work that Guix developers normally do will be missing. + +You've been warned! In all the other cases, it's a snappy way to stay +on top. We encourage you to submit patches updating the actual package +definitions once you have successfully tested an upgrade +(@pxref{Contributing}). + @cindex test suite, skipping @item --without-tests=@var{package} Build @var{package} without running its tests. This can be useful in diff --git a/guix/transformations.scm b/guix/transformations.scm index 2385d3231e..4e9260350c 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -25,6 +25,9 @@ #:autoload (guix download) (download-to-store) #:autoload (guix git-download) (git-reference? git-reference-url) #:autoload (guix git) (git-checkout git-checkout? git-checkout-url) + #:autoload (guix upstream) (package-latest-release* + upstream-source-version + upstream-source-signature-urls) #:use-module (guix utils) #:use-module (guix memoization) #:use-module (guix gexp) @@ -511,6 +514,42 @@ additional patches." (rewrite obj) obj))) +(define (transform-package-latest specs) + "Return a procedure that rewrites package graphs such that those in SPECS +are replaced by their latest upstream version." + (define (package-with-latest-upstream p) + (let ((source (package-latest-release* p))) + (cond ((not source) + (warning + (G_ "could not determine latest upstream release of '~a'~%") + (package-name p)) + p) + ((string=? (upstream-source-version source) + (package-version p)) + p) + (else + (unless (pair? (upstream-source-signature-urls source)) + (warning (G_ "cannot authenticate source of '~a', version ~a~%") + (package-name p) + (upstream-source-version source))) + + ;; TODO: Take 'upstream-source-input-changes' into account. + (package + (inherit p) + (version (upstream-source-version source)) + (source source)))))) + + (define rewrite + (package-input-rewriting/spec + (map (lambda (spec) + (cons spec package-with-latest-upstream)) + specs))) + + (lambda (obj) + (if (package? obj) + (rewrite obj) + obj))) + (define %transformations ;; Transformations that can be applied to things to build. The car is the ;; key used in the option alist, and the cdr is the transformation @@ -525,7 +564,8 @@ additional patches." (with-c-toolchain . ,transform-package-toolchain) (with-debug-info . ,transform-package-with-debug-info) (without-tests . ,transform-package-tests) - (with-patch . ,transform-package-patches))) + (with-patch . ,transform-package-patches) + (with-latest . ,transform-package-latest))) (define (transformation-procedure key) "Return the transformation procedure associated with KEY, a symbol such as @@ -567,6 +607,8 @@ additional patches." (parser 'without-tests)) (option '("with-patch") #t #f (parser 'with-patch)) + (option '("with-latest") #t #f + (parser 'with-latest)) (option '("help-transform") #f #f (lambda _ @@ -598,6 +640,9 @@ additional patches." (display (G_ " --with-patch=PACKAGE=FILE add FILE to the list of patches of PACKAGE")) + (display (G_ " + --with-latest=PACKAGE + use the latest upstream release of PACKAGE")) (display (G_ " --with-c-toolchain=PACKAGE=TOOLCHAIN build PACKAGE and its dependents with TOOLCHAIN")) diff --git a/guix/upstream.scm b/guix/upstream.scm index a8ed1d81cd..accd8967d8 100644 --- a/guix/upstream.scm +++ b/guix/upstream.scm @@ -31,8 +31,8 @@ #:use-module (guix base32) #:use-module (guix gexp) #:use-module (guix store) - #:use-module ((guix derivations) - #:select (built-derivations derivation->output-path)) + #:use-module ((guix derivations) #:select (built-derivations derivation->output-path)) + #:autoload (gcrypt hash) (port-sha256) #:use-module (guix monads) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) @@ -248,6 +248,9 @@ correspond to the same version." '() (importer-modules)))) +;; Tests need to mock this variable so mark it as "non-declarative". +(set! %updaters %updaters) + (define* (lookup-updater package #:optional (updaters (force %updaters))) "Return an updater among UPDATERS that matches PACKAGE, or #f if none of @@ -351,6 +354,27 @@ values: 'interactive' (default), 'always', and 'never'." data url) #f))))))) +(define-gexp-compiler (upstream-source-compiler (source ) + system target) + "Download SOURCE from its first URL and lower it as a fixed-output +derivation that would fetch it." + (mlet* %store-monad ((url -> (first (upstream-source-urls source))) + (signature + -> (and=> (upstream-source-signature-urls source) + first)) + (tarball ((store-lift download-tarball) url signature))) + (unless tarball + (raise (formatted-message (G_ "failed to fetch source from '~a'") + url))) + + ;; Instead of returning TARBALL, return a fixed-output derivation that + ;; would be able to re-download it. In practice, since TARBALL is already + ;; in the store, no extra download will happen, but having the derivation + ;; in store improves provenance tracking. + (let ((hash (call-with-input-file tarball port-sha256))) + (url-fetch url 'sha256 hash (store-path-package-name tarball) + #:system system)))) + (define (find2 pred lst1 lst2) "Like 'find', but operate on items from both LST1 and LST2. Return two values: the item from LST1 and the item from LST2 that match PRED." diff --git a/tests/transformations.scm b/tests/transformations.scm index 9053deba41..7877029486 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2016, 2017, 2019, 2020 Ludovic Courtès +;;; Copyright © 2016, 2017, 2019, 2020, 2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -30,6 +30,7 @@ #:use-module (guix ui) #:use-module (guix utils) #:use-module (guix git) + #:use-module (guix upstream) #:use-module (gnu packages) #:use-module (gnu packages base) #:use-module (gnu packages busybox) @@ -396,6 +397,22 @@ (map local-file-file (origin-patches (package-source dep))))))))) +(test-equal "options->transformation, with-latest" + "42.0" + (mock ((guix upstream) %updaters + (delay (list (upstream-updater + (name 'dummy) + (pred (const #t)) + (description "") + (latest (const (upstream-source + (package "foo") + (version "42.0") + (urls '("http://example.org"))))))))) + (let* ((p (dummy-package "foo" (version "1.0"))) + (t (options->transformation + `((with-latest . "foo"))))) + (package-version (t p))))) + (test-end) ;;; Local Variables: