Subject: [bug#34007] [PATCH 2/5] maint: Remove 'cond-expand' forms for Guile 2.0.

From: Ludovic Courtès <[email-masked]>
Date: Mon, 7 Jan 2019 11:48:54 +0100

Note: Leave 'cond-expand' forms used in the build-side modules that can
run on %BOOTSTRAP-GUILE, which is currently Guile 2.0.

* guix/build/compile.scm: Move 'use-modules' clause from 'cond-expand'
to 'define-module' form.
(%default-optimizations): Remove 'cond-expand'.
* guix/build/download.scm (tls-wrap): Remove 'cond-expand'.
* guix/build/syscalls.scm: Remove 'cond-expand' form around
'%set-automatic-finalization-enabled?!' and
'without-automatic-finalization'.
* guix/inferior.scm (port->inferior): Remove 'cond-expand'.
* guix/scripts/pack.scm (wrapped-package)[build]: Remove 'cond-expand'.
* guix/status.scm (build-event-output-port): Remove 'cond-expand'.
* guix/store.scm (open-inet-socket): Remove 'cond-expand'.
* guix/ui.scm (install-locale): Remove 'cond-expand'.
* tests/status.scm ("current-build-output-port, UTF-8 + garbage"):
Remove 'cond-expand'.
* tests/store.scm ("current-build-output-port, UTF-8 + garbage"):
Remove 'cond-expand'.
---
 guix/build/compile.scm  | 18 +++++--------
 guix/build/download.scm |  6 ++---
 guix/build/syscalls.scm | 56 ++++++++++++++++++-----------------------
 guix/inferior.scm       |  6 ++---
 guix/scripts/pack.scm   |  6 ++---
 guix/status.scm         |  6 ++---
 guix/store.scm          |  7 +-----
 guix/ui.scm             |  5 ----
 tests/status.scm        |  6 ++---
 tests/store.scm         |  6 ++---
 10 files changed, 43 insertions(+), 79 deletions(-)

diff --git a/guix/build/compile.scm b/guix/build/compile.scm
index 5a1363556a..215489f136 100644
--- a/guix/build/compile.scm
+++ b/guix/build/compile.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014, 2016, 2017, 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2013, 2014, 2016, 2017, 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2015 Taylan Ulrich Bayırlı/Kammer <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -26,28 +26,22 @@
   #:use-module (system base message)
   #:use-module (guix modules)
   #:use-module (guix build utils)
+  #:use-module (language tree-il optimize)
+  #:use-module (language cps optimize)
   #:export (%default-optimizations
             %lightweight-optimizations
             compile-files))
 
 ;;; Commentary:
 ;;;
-;;; Support code to compile Guile code as efficiently as possible (both with
-;;; Guile 2.0 and 2.2).
+;;; Support code to compile Guile code as efficiently as possible (with 2.2).
 ;;;
 ;;; Code:
 
-(cond-expand
-  (guile-2.2 (use-modules (language tree-il optimize)
-                          (language cps optimize)))
-  (else #f))
-
 (define %default-optimizations
   ;; Default optimization options (equivalent to -O2 on Guile 2.2).
-  (cond-expand
-    (guile-2.2 (append (tree-il-default-optimization-options)
-                       (cps-default-optimization-options)))
-    (else '())))
+  (append (tree-il-default-optimization-options)
+          (cps-default-optimization-options)))
 
 (define %lightweight-optimizations
   ;; Lightweight optimizations (like -O0, but with partial evaluation).
diff --git a/guix/build/download.scm b/guix/build/download.scm
index 54163849a2..199702a679 100644
--- a/guix/build/download.scm
+++ b/guix/build/download.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2015 Mark H Weaver <[email-masked]>
 ;;; Copyright © 2017 Tobias Geerinckx-Rice <[email-masked]>
 ;;;
@@ -314,9 +314,7 @@ host name without trailing dot."
 
       ;; Write HTTP requests line by line rather than byte by byte:
       ;; <https://bugs.gnu.org/22966>.  This is possible with Guile >= 2.2.
-      (cond-expand
-        (guile-2.2 (setvbuf record 'line))
-        (else #f))
+      (setvbuf record 'line)
 
       record)))
 
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 56a689f667..d75c11ada7 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2015 David Thompson <[email-masked]>
 ;;; Copyright © 2015 Mark H Weaver <[email-masked]>
 ;;; Copyright © 2017 Mathieu Othacehe <[email-masked]>
@@ -699,39 +699,31 @@ mounted at FILE."
 (define CLONE_NEWPID         #x20000000)
 (define CLONE_NEWNET         #x40000000)
 
-(cond-expand
-  (guile-2.2
-   (define %set-automatic-finalization-enabled?!
-     ;; When using a statically-linked Guile, for instance in the initrd, we
-     ;; cannot resolve this symbol, but most of the time we don't need it
-     ;; anyway.  Thus, delay it.
-     (let ((proc (delay
-                   (pointer->procedure int
-                                       (dynamic-func
-                                        "scm_set_automatic_finalization_enabled"
-                                        (dynamic-link))
-                                       (list int)))))
-       (lambda (enabled?)
-         "Switch on or off automatic finalization in a separate thread.
+(define %set-automatic-finalization-enabled?!
+  ;; When using a statically-linked Guile, for instance in the initrd, we
+  ;; cannot resolve this symbol, but most of the time we don't need it
+  ;; anyway.  Thus, delay it.
+  (let ((proc (delay
+                (pointer->procedure int
+                                    (dynamic-func
+                                     "scm_set_automatic_finalization_enabled"
+                                     (dynamic-link))
+                                    (list int)))))
+    (lambda (enabled?)
+      "Switch on or off automatic finalization in a separate thread.
 Turning finalization off shuts down the finalization thread as a side effect."
-         (->bool ((force proc) (if enabled? 1 0))))))
+      (->bool ((force proc) (if enabled? 1 0))))))
 
-   (define-syntax-rule (without-automatic-finalization exp)
-     "Turn off automatic finalization within the dynamic extent of EXP."
-     (let ((enabled? #t))
-       (dynamic-wind
-         (lambda ()
-           (set! enabled? (%set-automatic-finalization-enabled?! #f)))
-         (lambda ()
-           exp)
-         (lambda ()
-           (%set-automatic-finalization-enabled?! enabled?))))))
-
-  (else
-   (define-syntax-rule (without-automatic-finalization exp)
-     ;; Nothing to do here: Guile 2.0 does not have a separate finalization
-     ;; thread.
-     exp)))
+(define-syntax-rule (without-automatic-finalization exp)
+  "Turn off automatic finalization within the dynamic extent of EXP."
+  (let ((enabled? #t))
+    (dynamic-wind
+      (lambda ()
+        (set! enabled? (%set-automatic-finalization-enabled?! #f)))
+      (lambda ()
+        exp)
+      (lambda ()
+        (%set-automatic-finalization-enabled?! enabled?)))))
 
 ;; The libc interface to sys_clone is not useful for Scheme programs, so the
 ;; low-level system call is wrapped instead.  The 'syscall' function is
diff --git a/guix/inferior.scm b/guix/inferior.scm
index 973bd5264e..a6e6d2f16e 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -137,9 +137,7 @@ it's an old Guix."
   "Given PIPE, an input/output port, return an inferior that talks over PIPE.
 PIPE is closed with CLOSE when 'close-inferior' is called on the returned
 inferior."
-  (cond-expand
-    ((and guile-2 (not guile-2.2)) #t)
-    (else (setvbuf pipe 'line)))
+  (setvbuf pipe 'line)
 
   (match (read pipe)
     (('repl-version 0 rest ...)
diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm
index 98b06971bd..e137fb136a 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2015, 2017, 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2015, 2017, 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2017, 2018 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2018 Konrad Hinsen <[email-masked]>
 ;;; Copyright © 2018 Chris Marusich <[email-masked]>
@@ -553,9 +553,7 @@ please email '~a'~%")
                       "run.c" "-o" result)
               (delete-file "run.c")))
 
-          (setvbuf (current-output-port)
-                   (cond-expand (guile-2.2 'line)
-                                (else      _IOLBF)))
+          (setvbuf (current-output-port) 'line)
 
           ;; Link the top-level files of PACKAGE so that search paths are
           ;; properly defined in PROFILE/etc/profile.
diff --git a/guix/status.scm b/guix/status.scm
index d4fc4ca16e..1a7cb313ea 100644
--- a/guix/status.scm
+++ b/guix/status.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2017, 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2017, 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2018 Ricardo Wurmus <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -636,9 +636,7 @@ The second return value is a thunk to retrieve the current state."
 
   ;; The build port actually receives Unicode strings.
   (set-port-encoding! port "UTF-8")
-  (cond-expand
-    ((and guile-2 (not guile-2.2)) #t)
-    (else (setvbuf port 'line)))
+  (setvbuf port 'line)
   (values port (lambda () %state)))
 
 (define (call-with-status-report on-event thunk)
diff --git a/guix/store.scm b/guix/store.scm
index 042dfab67f..1883829231 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2018 Jan Nieuwenhuizen <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -404,11 +404,6 @@
 (define (open-inet-socket host port)
   "Connect to the Unix-domain socket at HOST:PORT and return it.  Raise a
 '&nix-connection-error' upon error."
-  ;; Define 'TCP_NODELAY' on Guile 2.0.  The value is the same on all GNU
-  ;; systems.
-  (cond-expand (guile-2.2 #t)
-               (else      (define TCP_NODELAY 1)))
-
   (let ((sock (with-fluids ((%default-port-encoding #f))
                 ;; This trick allows use of the `scm_c_read' optimization.
                 (socket PF_UNIX SOCK_STREAM 0))))
diff --git a/guix/ui.scm b/guix/ui.scm
index 4c31246920..f542cd3e3f 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -427,11 +427,6 @@ report them in a user-friendly way."
     (lambda _
       (setlocale LC_ALL ""))
     (lambda args
-      (cond-expand
-        ;; Guile 2.2 already emits a warning, so let's not add a second one.
-        (guile-2.2 #t)
-        (else (warning (G_ "failed to install locale: ~a~%")
-                       (strerror (system-error-errno args)))))
       (display-hint (G_ "Consider installing the @code{glibc-utf8-locales} or
 @code{glibc-locales} package and defining @code{GUIX_LOCPATH}, along these
 lines:
diff --git a/tests/status.scm b/tests/status.scm
index 99abb41c8b..08a3153218 100644
--- a/tests/status.scm
+++ b/tests/status.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -125,9 +125,7 @@
 
 (test-equal "current-build-output-port, UTF-8 + garbage"
   ;; What about a mixture of UTF-8 + garbage?
-  (let ((replacement (cond-expand
-                      ((and guile-2 (not guile-2.2)) "?")
-                      (else "�"))))
+  (let ((replacement "�"))
     `((build-log #f ,(string-append "garbage: " replacement "lambda: λ\n"))))
   (let-values (((port get-status) (build-event-output-port cons '())))
     (display "garbage: " port)
diff --git a/tests/store.scm b/tests/store.scm
index 3ff526cdcf..5ff9308d7d 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -444,9 +444,7 @@
                      (package-derivation %store %bootstrap-guile))))
             (guard (c ((nix-protocol-error? c) #t))
               (build-derivations %store (list d))))))))
-   (cond-expand
-     (guile-2.2 "garbage: �lambda: λ")
-     (else      "garbage: ?lambda: λ"))))
+   "garbage: �lambda: λ"))
 
 (test-assert "log-file, derivation"
   (let* ((b (add-text-to-store %store "build" "echo $foo > $out" '()))
-- 
2.20.1