diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2023-01-21 15:04:09 -0500 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2023-02-19 21:13:23 -0500 |
| commit | 598f4c509bbfec2b983a8ee246cce0a0fe45ec7f (patch) | |
| tree | 1bf799843929f714428c27eb2325c255a92793f3 /tests | |
| parent | ac1d530d56c1a259630c8873b2281033878a4acb (diff) | |
pack: Add RPM format.
* guix/rpm.scm: New file.
* guix/scripts/pack.scm (rpm-archive): New procedure.
(%formats): Register it.
(show-formats): Add it.
(guix-pack): Register supported extra-options for the rpm format.
* tests/pack.scm (rpm-for-tests): New variable.
("rpm archive can be installed/uninstalled"): New test.
* tests/rpm.scm: New test.
* doc/guix.texi (Invoking guix pack): Document it.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/pack.scm | 57 | ||||
| -rw-r--r-- | tests/rpm.scm | 86 |
2 files changed, 142 insertions, 1 deletions
diff --git a/tests/pack.scm b/tests/pack.scm index a02924b7d20..734ae1c69b6 100644 --- a/tests/pack.scm +++ b/tests/pack.scm | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net> | 3 | ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net> |
| 4 | ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> | 4 | ;;; Copyright © 2021, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
| 5 | ;;; | 5 | ;;; |
| 6 | ;;; This file is part of GNU Guix. | 6 | ;;; This file is part of GNU Guix. |
| 7 | ;;; | 7 | ;;; |
| @@ -28,13 +28,16 @@ | |||
| 28 | #:use-module (guix tests) | 28 | #:use-module (guix tests) |
| 29 | #:use-module (guix gexp) | 29 | #:use-module (guix gexp) |
| 30 | #:use-module (guix modules) | 30 | #:use-module (guix modules) |
| 31 | #:use-module (guix utils) | ||
| 31 | #:use-module (gnu packages) | 32 | #:use-module (gnu packages) |
| 32 | #:use-module ((gnu packages base) #:select (glibc-utf8-locales)) | 33 | #:use-module ((gnu packages base) #:select (glibc-utf8-locales)) |
| 33 | #:use-module (gnu packages bootstrap) | 34 | #:use-module (gnu packages bootstrap) |
| 35 | #:use-module ((gnu packages package-management) #:select (rpm)) | ||
| 34 | #:use-module ((gnu packages compression) #:select (squashfs-tools)) | 36 | #:use-module ((gnu packages compression) #:select (squashfs-tools)) |
| 35 | #:use-module ((gnu packages debian) #:select (dpkg)) | 37 | #:use-module ((gnu packages debian) #:select (dpkg)) |
| 36 | #:use-module ((gnu packages guile) #:select (guile-sqlite3)) | 38 | #:use-module ((gnu packages guile) #:select (guile-sqlite3)) |
| 37 | #:use-module ((gnu packages gnupg) #:select (guile-gcrypt)) | 39 | #:use-module ((gnu packages gnupg) #:select (guile-gcrypt)) |
| 40 | #:use-module ((gnu packages linux) #:select (fakeroot)) | ||
| 38 | #:use-module (srfi srfi-64)) | 41 | #:use-module (srfi srfi-64)) |
| 39 | 42 | ||
| 40 | (define %store | 43 | (define %store |
| @@ -59,6 +62,17 @@ | |||
| 59 | 62 | ||
| 60 | (define %ar-bootstrap %bootstrap-binutils) | 63 | (define %ar-bootstrap %bootstrap-binutils) |
| 61 | 64 | ||
| 65 | ;;; This is a variant of the RPM package configured so that its database can | ||
| 66 | ;;; be created on a writable location readily available inside the build | ||
| 67 | ;;; container ("/tmp"). | ||
| 68 | (define rpm-for-tests | ||
| 69 | (package | ||
| 70 | (inherit rpm) | ||
| 71 | (arguments (substitute-keyword-arguments (package-arguments rpm) | ||
| 72 | ((#:configure-flags flags '()) | ||
| 73 | #~(cons "--localstatedir=/tmp" | ||
| 74 | (delete "--localstatedir=/var" #$flags))))))) | ||
| 75 | |||
| 62 | 76 | ||
| 63 | (test-begin "pack") | 77 | (test-begin "pack") |
| 64 | 78 | ||
| @@ -356,6 +370,47 @@ | |||
| 356 | (assert (file-exists? "triggers")) | 370 | (assert (file-exists? "triggers")) |
| 357 | 371 | ||
| 358 | (mkdir #$output)))))) | 372 | (mkdir #$output)))))) |
| 373 | (built-derivations (list check)))) | ||
| 374 | |||
| 375 | (unless store (test-skip 1)) | ||
| 376 | (test-assertm "rpm archive can be installed/uninstalled" store | ||
| 377 | (mlet* %store-monad | ||
| 378 | ((guile (set-guile-for-build (default-guile))) | ||
| 379 | (profile (profile-derivation (packages->manifest | ||
| 380 | (list %bootstrap-guile)) | ||
| 381 | #:hooks '() | ||
| 382 | #:locales? #f)) | ||
| 383 | (rpm-pack (rpm-archive "rpm-pack" profile | ||
| 384 | #:compressor %gzip-compressor | ||
| 385 | #:symlinks '(("/bin/guile" -> "bin/guile")) | ||
| 386 | #:extra-options '(#:relocatable? #t))) | ||
| 387 | (check | ||
| 388 | (gexp->derivation "check-rpm-pack" | ||
| 389 | (with-imported-modules (source-module-closure | ||
| 390 | '((guix build utils))) | ||
| 391 | #~(begin | ||
| 392 | (use-modules (guix build utils)) | ||
| 393 | |||
| 394 | (define fakeroot #+(file-append fakeroot "/bin/fakeroot")) | ||
| 395 | (define rpm #+(file-append rpm-for-tests "/bin/rpm")) | ||
| 396 | (mkdir-p "/tmp/lib/rpm") | ||
| 397 | |||
| 398 | ;; Install the RPM package. This causes RPM to validate the | ||
| 399 | ;; signatures, header as well as the file digests, which | ||
| 400 | ;; makes it a rather thorough test. | ||
| 401 | (mkdir "test-prefix") | ||
| 402 | (invoke fakeroot rpm "--install" | ||
| 403 | (string-append "--prefix=" (getcwd) "/test-prefix") | ||
| 404 | #$rpm-pack) | ||
| 405 | |||
| 406 | ;; Invoke the installed Guile command. | ||
| 407 | (invoke "./test-prefix/bin/guile" "--version") | ||
| 408 | |||
| 409 | ;; Uninstall the RPM package. | ||
| 410 | (invoke fakeroot rpm "--erase" "guile-bootstrap") | ||
| 411 | |||
| 412 | ;; Required so the above is run. | ||
| 413 | (mkdir #$output)))))) | ||
| 359 | (built-derivations (list check))))) | 414 | (built-derivations (list check))))) |
| 360 | 415 | ||
| 361 | (test-end) | 416 | (test-end) |
diff --git a/tests/rpm.scm b/tests/rpm.scm new file mode 100644 index 00000000000..f40b36fe603 --- /dev/null +++ b/tests/rpm.scm | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (test-rpm) | ||
| 20 | #:use-module (guix rpm) | ||
| 21 | #:use-module (rnrs bytevectors) | ||
| 22 | #:use-module (srfi srfi-1) | ||
| 23 | #:use-module (srfi srfi-26) | ||
| 24 | #:use-module (srfi srfi-64) | ||
| 25 | #:use-module (srfi srfi-71)) | ||
| 26 | |||
| 27 | ;; For white-box testing. | ||
| 28 | (define-syntax-rule (expose-internal name) | ||
| 29 | (define name (@@ (guix rpm) name))) | ||
| 30 | |||
| 31 | (expose-internal RPMTAG_ARCH) | ||
| 32 | (expose-internal RPMTAG_LICENSE) | ||
| 33 | (expose-internal RPMTAG_NAME) | ||
| 34 | (expose-internal RPMTAG_OS) | ||
| 35 | (expose-internal RPMTAG_RELEASE) | ||
| 36 | (expose-internal RPMTAG_SUMMARY) | ||
| 37 | (expose-internal RPMTAG_VERSION) | ||
| 38 | (expose-internal header-entry-count) | ||
| 39 | (expose-internal header-entry-tag) | ||
| 40 | (expose-internal header-entry-value) | ||
| 41 | (expose-internal header-entry?) | ||
| 42 | (expose-internal make-header) | ||
| 43 | (expose-internal make-header-entry) | ||
| 44 | (expose-internal make-header-index+data) | ||
| 45 | |||
| 46 | (test-begin "rpm") | ||
| 47 | |||
| 48 | (test-equal "lead must be 96 bytes long" | ||
| 49 | 96 | ||
| 50 | (length (generate-lead "hello-2.12.1"))) | ||
| 51 | |||
| 52 | (define header-entries | ||
| 53 | (list (make-header-entry RPMTAG_NAME 1 "hello") | ||
| 54 | (make-header-entry RPMTAG_VERSION 1 "2.12.1") | ||
| 55 | (make-header-entry RPMTAG_RELEASE 1 "0") | ||
| 56 | (make-header-entry RPMTAG_SUMMARY 1 | ||
| 57 | "Hello, GNU world: An example GNU package") | ||
| 58 | (make-header-entry RPMTAG_LICENSE 1 "GPL 3 or later") | ||
| 59 | (make-header-entry RPMTAG_OS 1 "Linux") | ||
| 60 | (make-header-entry RPMTAG_ARCH 1 "x86_64"))) | ||
| 61 | |||
| 62 | (define expected-header-index-length | ||
| 63 | (* 16 (length header-entries))) ;16 bytes per index entry | ||
| 64 | |||
| 65 | (define expected-header-data-length | ||
| 66 | (+ (length header-entries) ;to account for null bytes | ||
| 67 | (fold + 0 (map (compose string-length (cut header-entry-value <>)) | ||
| 68 | header-entries)))) | ||
| 69 | |||
| 70 | (let ((index data (make-header-index+data header-entries))) | ||
| 71 | (test-equal "header index" | ||
| 72 | expected-header-index-length | ||
| 73 | (length index)) | ||
| 74 | |||
| 75 | ;; This test depends on the fact that only STRING entries are used, and that | ||
| 76 | ;; they are composed of single byte characters and the delimiting null byte. | ||
| 77 | (test-equal "header data" | ||
| 78 | expected-header-data-length | ||
| 79 | (length data))) | ||
| 80 | |||
| 81 | (test-equal "complete header section" | ||
| 82 | (+ 16 ;leading magic + count bytes | ||
| 83 | expected-header-index-length expected-header-data-length) | ||
| 84 | (length (make-header header-entries))) | ||
| 85 | |||
| 86 | (test-end) | ||
