From 0d046587107a56467cf2027799ac79ce8c203ce0 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 26 Dec 2020 22:59:52 +0100 Subject: utils: Remove 'compressed-output-port'. This procedure was unused except in one test. * guix/utils.scm (compressed-port): Remove. * tests/utils.scm (test-compression/decompression): Rewrite to use 'compressed-output-port' instead. --- tests/utils.scm | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'tests/utils.scm') diff --git a/tests/utils.scm b/tests/utils.scm index 009e2121ab..c278b2a277 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2014 Eric Bavier ;;; Copyright © 2016 Mathieu Lirzin ;;; @@ -182,19 +182,34 @@ skip these tests." method) (let ((data (call-with-input-file (search-path %load-path "guix.scm") get-bytevector-all))) - (let*-values (((compressed pids1) - (compressed-port method (open-bytevector-input-port data))) - ((decompressed pids2) - (decompressed-port method compressed))) - (and (every (compose zero? cdr waitpid) - (pk 'pids method (append pids1 pids2))) - (let ((result (get-bytevector-all decompressed))) - (pk 'len method - (if (bytevector? result) - (bytevector-length result) - result) - (bytevector-length data)) - (equal? result data)))))) + (call-with-temporary-output-file + (lambda (output port) + (close-port port) + (let*-values (((compressed pids) + ;; Note: 'compressed-output-port' only supports file + ;; ports. + (compressed-output-port method + (open-file output "w0")))) + (put-bytevector compressed data) + (close-port compressed) + (and (every (compose zero? cdr waitpid) + (pk 'pids method pids)) + (let*-values (((decompressed pids) + (decompressed-port method + (open-bytevector-input-port + (call-with-input-file output + get-bytevector-all)))) + ((result) + (get-bytevector-all decompressed))) + (close-port decompressed) + (pk 'len method + (if (bytevector? result) + (bytevector-length result) + result) + (bytevector-length data)) + (and (every (compose zero? cdr waitpid) + (pk 'pids method pids)) + (equal? result data))))))))) (false-if-exception (delete-file temp-file)) (unless (run?) (test-skip 1)) -- cgit v1.2.3 From db0cecdf6b2f2b8f9c5a3cebe8fc60e79a692be0 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 26 Dec 2020 23:01:05 +0100 Subject: utils: Support zstd compression via Guile-zstd. * guix/utils.scm (lzip-port): Return a single value. (zstd-port): New procedure. (decompressed-port, compressed-output-port): Add 'zstd' case. * tests/utils.scm (test-compression/decompression): Test 'zstd' when the (zstd) module is available. --- guix/utils.scm | 12 +++++++++++- tests/utils.scm | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'tests/utils.scm') diff --git a/guix/utils.scm b/guix/utils.scm index c321ad9943..f8b05e7e80 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -210,7 +210,13 @@ buffered data is lost." "Return the lzip port produced by calling PROC (a symbol) on PORT and ARGS. Raise an error if lzlib support is missing." (let ((make-port (module-ref (resolve-interface '(lzlib)) proc))) - (values (make-port port) '()))) + (make-port port))) + +(define (zstd-port proc port . args) + "Return the zstd port produced by calling PROC (a symbol) on PORT and ARGS. +Raise an error if zstd support is missing." + (let ((make-port (module-ref (resolve-interface '(zstd)) proc))) + (make-port port))) (define (decompressed-port compression input) "Return an input port where INPUT is decompressed according to COMPRESSION, @@ -222,6 +228,8 @@ a symbol such as 'xz." ('gzip (filtered-port `(,%gzip "-dc") input)) ('lzip (values (lzip-port 'make-lzip-input-port input) '())) + ('zstd (values (zstd-port 'make-zstd-input-port input) + '())) (_ (error "unsupported compression scheme" compression)))) (define (call-with-decompressed-port compression port proc) @@ -281,6 +289,8 @@ program--e.g., '(\"--fast\")." ('gzip (filtered-output-port `(,%gzip "-c" ,@options) output)) ('lzip (values (lzip-port 'make-lzip-output-port output) '())) + ('zstd (values (zstd-port 'make-zstd-output-port output) + '())) (_ (error "unsupported compression scheme" compression)))) (define* (call-with-compressed-output-port compression port proc diff --git a/tests/utils.scm b/tests/utils.scm index c278b2a277..9bce446d98 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -228,8 +228,10 @@ skip these tests." get-bytevector-all))))) (for-each test-compression/decompression - '(gzip xz lzip) - (list (const #t) (const #t) (const #t))) + `(gzip xz lzip zstd) + (list (const #t) (const #t) (const #t) + (lambda () + (resolve-module '(zstd) #t #f #:ensure #f)))) ;; This is actually in (guix store). (test-equal "store-path-package-name" -- cgit v1.2.3 From 579506e272cf68649ec68ad8a976a17426ea630c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 10 Jan 2021 11:53:43 +0100 Subject: utils: Add 'version-unique-prefix'. * guix/utils.scm (version-unique-prefix): New procedure. * tests/utils.scm ("version-unique-prefix"): New test. --- guix/utils.scm | 35 ++++++++++++++++++++++++++++++++++- tests/utils.scm | 8 +++++++- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'tests/utils.scm') diff --git a/guix/utils.scm b/guix/utils.scm index f8b05e7e80..a85e2f495c 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2013, 2014, 2015 Mark H Weaver ;;; Copyright © 2014 Eric Bavier ;;; Copyright © 2014 Ian Denhardt @@ -88,6 +88,7 @@ version-major+minor+point version-major+minor version-major + version-unique-prefix guile-version>? version-prefix? string-replace-substring @@ -589,6 +590,38 @@ minor version numbers from version-string." "Return the major version number as string from the version-string." (version-prefix version-string 1)) +(define (version-unique-prefix version versions) + "Return the shortest version prefix to unambiguously identify VERSION among +VERSIONS. For example: + + (version-unique-prefix \"2.0\" '(\"3.0\" \"2.0\")) + => \"2\" + + (version-unique-prefix \"2.2\" '(\"3.0.5\" \"2.0.9\" \"2.2.7\")) + => \"2.2\" + + (version-unique-prefix \"27.1\" '(\"27.1\")) + => \"\" +" + (define not-dot + (char-set-complement (char-set #\.))) + + (define other-versions + (delete version versions)) + + (let loop ((prefix '()) + (components (string-tokenize version not-dot))) + (define prefix-str + (string-join prefix ".")) + + (if (any (cut string-prefix? prefix-str <>) other-versions) + (match components + ((head . tail) + (loop `(,@prefix ,head) tail)) + (() + version)) + prefix-str))) + (define (version>? a b) "Return #t when A denotes a version strictly newer than B." (eq? '> (version-compare a b))) diff --git a/tests/utils.scm b/tests/utils.scm index 9bce446d98..62ec7e8b4c 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2014 Eric Bavier ;;; Copyright © 2016 Mathieu Lirzin ;;; @@ -78,6 +78,12 @@ (not (version-prefix? "4.1" "4.16.2")) (not (version-prefix? "4.1" "4")))) +(test-equal "version-unique-prefix" + '("2" "2.2" "") + (list (version-unique-prefix "2.0" '("3.0" "2.0")) + (version-unique-prefix "2.2" '("3.0.5" "2.0.9" "2.2.7")) + (version-unique-prefix "27.1" '("27.1")))) + (test-equal "string-tokenize*" '(("foo") ("foo" "bar" "baz") -- cgit v1.2.3