Subject: [bug#49672] [PATCH 9/9] gnu: Use existing target helpers from ‘(guix utils)’

From: Thiago Jung Bauermann <[email-masked]>
Date: Tue, 20 Jul 2021 22:00:43 -0300

These are equivalent to existing code and shouldn't lead to any behaviour
change. The objective of the change is to make the code easier to read.

* gnu/packages/algebra.scm (fftwf)[arguments]<#:configure-flags>: Use
‘target-arm32?’.
* gnu/packages/boost.scm (boost)[arguments]<#:make-flags>: Use
‘target-arm32?’ and ‘target-aarch64?’.
* gnu/packages/bootloaders.scm (grub)[arguments]<#:tests>: Use
‘target-arm?’.
(vboot-utils)[arguments]<#:make-flags>: Use ‘target-arm32?’.
* gnu/packages/ci.scm (cuirass)[arguments]<#:tests>: Use ‘target-aarch64?’.
* gnu/packages/firmware.scm (ovmf-aarch64)[native-inputs]: Use ‘target-aarch64?’.
[arguments]<#:phases>: Likewise.
* gnu/packages/gstreamer.scm (gst-plugins-base)[propagated-inputs]: Use
‘target-arm32?’.
(gst-plugins-bad)[arguments]<#:phases>: Likewise.
* gnu/packages/java.scm (jamvm-1-bootstrap)[arguments]<#:phases>: Use
‘target-aarch64?’.
[native-inputs]: Likewise.
* gnu/packages/linux.scm (proot)[arguments]<#:tests>: Use ‘target-arm?’.
* gnu/packages/multiprecision.scm (qd)[arguments]<#:configure-flags>: Use
‘target-aarch64?’.
* gnu/packages/php.scm (php)[arguments]<#:phases>: Use ‘target-arm32?’.
* gnu/packages/python.scm (python-3.8)[arguments]<#:phases>: Use ‘target-arm?’.
[native-inputs]: Likewise.
* gnu/packages/syncthing.scm (go-github-com-rcrowley-go-metrics)[arguments]
<#:tests>: Use ‘target-aarch64?’.
* gnu/packages/valgrind.scm (valgrind)[arguments]<#:make-flags>: Use
‘target-powerpc?’.
* gnu/packages/web.scm (rapidjson)[arguments]<#:phases>: Use ‘target-aarch64?’.
---
 gnu/packages/algebra.scm        |  3 +--
 gnu/packages/boost.scm          |  4 ++--
 gnu/packages/bootloaders.scm    |  9 ++-------
 gnu/packages/ci.scm             |  6 ++----
 gnu/packages/firmware.scm       |  4 ++--
 gnu/packages/gstreamer.scm      |  6 ++----
 gnu/packages/java.scm           |  6 ++----
 gnu/packages/linux.scm          |  4 +---
 gnu/packages/multiprecision.scm |  4 +---
 gnu/packages/php.scm            |  3 +--
 gnu/packages/python.scm         | 26 ++++++++++----------------
 gnu/packages/syncthing.scm      |  4 ++--
 gnu/packages/valgrind.scm       |  4 ++--
 gnu/packages/web.scm            |  3 +--
 14 files changed, 31 insertions(+), 55 deletions(-)

diff --git a/gnu/packages/algebra.scm b/gnu/packages/algebra.scm
index 533b1f09e023..f51bd69a4230 100644
--- a/gnu/packages/algebra.scm
+++ b/gnu/packages/algebra.scm
@@ -802,8 +802,7 @@ cosine/ sine transforms or DCT/DST).")
      (substitute-keyword-arguments (package-arguments fftw)
        ((#:configure-flags fftw-configure-flags)
         `(cons* "--enable-single"
-                ,@(if (string-prefix? "arm" (or (%current-target-system)
-                                                (%current-system)))
+                ,@(if (target-arm32?)
                       ;; fftw supports NEON on 32-bit ARM only when compiled
                       ;; for single-precision, so add it here.
                       '("--enable-neon")
diff --git a/gnu/packages/boost.scm b/gnu/packages/boost.scm
index e05a3c32fe11..67d452e925e1 100644
--- a/gnu/packages/boost.scm
+++ b/gnu/packages/boost.scm
@@ -108,11 +108,11 @@
                      "binary-format=elf"
                      "target-os=linux"
                      ,@(cond
-                        ((string-prefix? "arm" (%current-target-system))
+                        ((target-arm32?)
                          '("abi=aapcs"
                            "address-model=32"
                            "architecture=arm"))
-                        ((string-prefix? "aarch64" (%current-target-system))
+                        ((target-aarch64?)
                          '("abi=aapcs"
                            "address-model=64"
                            "architecture=arm"))
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 669574468bd2..6912cffa38be 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -173,10 +173,7 @@
                           "test_unset"))
                       #t)))
        ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling.
-       #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system)
-                                                           (%current-system)))
-                               '("arm" "aarch64"))
-                          (%current-target-system)))))
+       #:tests? ,(not (or (target-arm?) (%current-target-system)))))
     (inputs
      `(("gettext" ,gettext-minimal)
 
@@ -988,9 +985,7 @@ to Novena upstream, does not load u-boot.img from the first partition.")
                           ;; "armv7l", the value of `uname -m`, and will not
                           ;; match ${ARCH}, which will make the tests require
                           ;; QEMU for testing.
-                          ,@(if (string-prefix? "arm"
-                                                (or (%current-target-system)
-                                                    (%current-system)))
+                          ,@(if (target-arm32?)
                                 '("HOST_ARCH=arm")
                                 '())
                           (string-append "DESTDIR=" (assoc-ref %outputs "out")))
diff --git a/gnu/packages/ci.scm b/gnu/packages/ci.scm
index 0bcde0fad515..bddc1e8386c2 100644
--- a/gnu/packages/ci.scm
+++ b/gnu/packages/ci.scm
@@ -27,7 +27,7 @@
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix git-download)
-  #:use-module (guix download)
+  #:use-module (guix utils)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages base)
   #:use-module (gnu packages boost)
@@ -97,9 +97,7 @@
          #:configure-flags '("--localstatedir=/var") ;for /var/log/cuirass
          ;; XXX: HTTP tests fail on aarch64 due to Fibers errors, disable them
          ;; on that architecture for now.
-         #:tests? ,(let ((s (or (%current-target-system)
-                                (%current-system))))
-                     (not (string-prefix? "aarch64" s)))
+         #:tests? ,(not (target-aarch64?))
          #:parallel-tests? #f
          #:phases
          (modify-phases %standard-phases
diff --git a/gnu/packages/firmware.scm b/gnu/packages/firmware.scm
index ebcb89923cee..b569bc288949 100644
--- a/gnu/packages/firmware.scm
+++ b/gnu/packages/firmware.scm
@@ -398,7 +398,7 @@ Virtual Machines.  OVMF contains a sample UEFI firmware for QEMU and KVM.")
     (name "ovmf-aarch64")
     (native-inputs
      `(,@(package-native-inputs ovmf)
-       ,@(if (not (string-prefix? "aarch64" (%current-system)))
+       ,@(if (not (target-aarch64? (%current-system)))
            `(("cross-gcc" ,(cross-gcc "aarch64-linux-gnu"))
              ("cross-binutils" ,(cross-binutils "aarch64-linux-gnu")))
            '())))
@@ -408,7 +408,7 @@ Virtual Machines.  OVMF contains a sample UEFI firmware for QEMU and KVM.")
         `(modify-phases ,phases
            (add-before 'configure 'set-env
              (lambda _
-               ,@(if (not (string-prefix? "aarch64" (%current-system)))
+               ,@(if (not (target-aarch64? (%current-system)))
                      `((setenv "GCC49_AARCH64_PREFIX" "aarch64-linux-gnu-"))
                      '())
                #t))
diff --git a/gnu/packages/gstreamer.scm b/gnu/packages/gstreamer.scm
index 3047773e0f07..488417c39773 100644
--- a/gnu/packages/gstreamer.scm
+++ b/gnu/packages/gstreamer.scm
@@ -539,8 +539,7 @@ This package provides the core library and elements.")
        ;; XXX: Do not enable Orc optimizations on ARM systems because
        ;; it leads to two test failures.
        ;; https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/683
-       ,@(if (string-prefix? "arm" (or (%current-target-system)
-                                       (%current-system)))
+       ,@(if (target-arm32?)
              '()
              `(("orc" ,orc)))))         ;required by gstreamer-audio-1.0.pc
     (inputs
@@ -691,8 +690,7 @@ model to base your own plug-in on, here it is.")
      `(#:phases
        (modify-phases %standard-phases
          ,@%common-gstreamer-phases
-         ,@(if (string-prefix? "arm" (or (%current-target-system)
-                                         (%current-system)))
+         ,@(if (target-arm32?)
                ;; Disable test that fails on ARMv7.
                ;; https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1188
                `((add-after 'unpack 'disable-asfmux-test
diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm
index 1c62f5d358e2..5b5d5afed945 100644
--- a/gnu/packages/java.scm
+++ b/gnu/packages/java.scm
@@ -315,8 +315,7 @@ language.")
              "--enable-runtime-reloc-checks"
              "--enable-ffi")
        #:phases
-       ,(if (string-prefix? "aarch64" (or (%current-target-system)
-                                          (%current-system)))
+       ,(if (target-aarch64?)
             ;; Makefiles and the configure script need to be regenerated to
             ;; incorporate support for AArch64.
             '(modify-phases %standard-phases
@@ -330,8 +329,7 @@ language.")
        ("zip" ,zip)
        ("zlib" ,zlib)))
     (native-inputs
-     (if (string-prefix? "aarch64" (or (%current-target-system)
-                                       (%current-system)))
+     (if (target-aarch64?)
          ;; Additional packages needed for autoreconf.
          `(("autoconf" ,autoconf)
            ("automake" ,automake)
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 0d695950d101..c6b7c0a403ef 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -6890,9 +6890,7 @@ userspace queueing component and the logging subsystem.")
      ;; Disable the test suite on ARM platforms, as there are too many
      ;; failures to keep track of (see for example:
      ;; https://github.com/proot-me/proot/issues/263).
-     `(#:tests? ,(not (string-match "^(arm|aarch64)"
-                                    (or (%current-target-system)
-                                        (%current-system))))
+     `(#:tests? ,(not (target-arm?))
        #:make-flags '("-C" "src")
        #:phases (modify-phases %standard-phases
                   (add-after 'unpack 'patch-sources
diff --git a/gnu/packages/multiprecision.scm b/gnu/packages/multiprecision.scm
index 733e6548b992..53b1e3c55ca7 100644
--- a/gnu/packages/multiprecision.scm
+++ b/gnu/packages/multiprecision.scm
@@ -235,9 +235,7 @@ error.  Additionally, iRRAM uses the concept of multi-valued functions.")
     (arguments
      `(#:configure-flags `("--disable-enable_fma" ;weird :/
                            "--enable-shared"
-                           ,,@(if (string-prefix? "aarch64"
-                                                  (or (%current-target-system)
-                                                      (%current-system)))
+                           ,,@(if (target-aarch64?)
                                   ;; XXX: The qd_test test fails numerical
                                   ;; accuracy checks for 'dd_real::exp()' on
                                   ;; aarch64 with GCC 5.4 at -O2.  Disabling
diff --git a/gnu/packages/php.scm b/gnu/packages/php.scm
index 597494e8a94f..36a4527aad67 100644
--- a/gnu/packages/php.scm
+++ b/gnu/packages/php.scm
@@ -177,8 +177,7 @@
              (substitute* "ext/standard/tests/streams/bug60602.phpt"
                (("'ls'") (string-append "'" (which "ls") "'")))
 
-             ,@(if (string-prefix? "arm" (or (%current-target-system)
-                                             (%current-system)))
+             ,@(if (target-arm32?)
                    ;; Drop tests known to fail on armhf.
                    '((for-each delete-file
                               (list
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index e694321e173e..c1a486b9f21f 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -488,16 +488,13 @@ data types.")
                  #t)))
            ;; XXX: Apply patch on ARM platforms only to avoid a full rebuild.
            ;; Remove this phase in the next rebuild cycle.
-           ,@(let ((system (or (%current-target-system)
-                               (%current-system))))
-               (if (any (cute string-prefix? <> system)
-                        '("arm" "aarch64"))
-                   '((add-after 'unpack 'apply-alignment-patch
-                       (lambda* (#:key native-inputs inputs #:allow-other-keys)
-                        (invoke "patch" "-p1" "--force" "--input"
-                                (assoc-ref (or native-inputs inputs)
-                                           "arm-alignment.patch")))))
-                   '()))))))
+           ,@(if (target-arm?)
+                 '((add-after 'unpack 'apply-alignment-patch
+                     (lambda* (#:key native-inputs inputs #:allow-other-keys)
+                       (invoke "patch" "-p1" "--force" "--input"
+                               (assoc-ref (or native-inputs inputs)
+                                          "arm-alignment.patch")))))
+                 '())))))
     (native-inputs
      `(("tzdata" ,tzdata-for-tests)
 
@@ -505,12 +502,9 @@ data types.")
        ;; it causes a test failure when building 32-bit Python on a
        ;; 64-bit kernel.  See <https://bugs.python.org/issue36515>.
        ;; TODO: make this a regular patch in the next rebuild cycle.
-       ,@(let ((system (or (%current-target-system)
-                           (%current-system))))
-           (if (any (cute string-prefix? <> system)
-                    '("arm" "aarch64"))
-               `(("arm-alignment.patch" ,(search-patch "python-3-arm-alignment.patch")))
-               '()))
+       ,@(if (target-arm?)
+             `(("arm-alignment.patch" ,(search-patch "python-3-arm-alignment.patch")))
+             '())
 
        ,@(if (%current-target-system)
              `(("python3" ,this-package))
diff --git a/gnu/packages/syncthing.scm b/gnu/packages/syncthing.scm
index 5cb8449e448e..b23fcea24096 100644
--- a/gnu/packages/syncthing.scm
+++ b/gnu/packages/syncthing.scm
@@ -30,6 +30,7 @@
   #:use-module (guix download)
   #:use-module (guix git-download)
   #:use-module (guix licenses)
+  #:use-module (guix utils)
   #:use-module (gnu packages)
   #:use-module (gnu packages freedesktop)
   #:use-module (gnu packages glib)
@@ -568,8 +569,7 @@ higher-level API for doing so.")
       (arguments
        ;; Arbitrary precision tests are known to be broken on aarch64, ppc64le
        ;; and s390x. See: https://github.com/rcrowley/go-metrics/issues/249
-       `(#:tests? ,(not (string-prefix? "aarch64" (or (%current-target-system)
-                                                      (%current-system))))
+       `(#:tests? ,(not (target-aarch64?))
          #:import-path "github.com/rcrowley/go-metrics"))
       (propagated-inputs
        `(("go-github-com-stathat-go" ,go-github-com-stathat-go)))
diff --git a/gnu/packages/valgrind.scm b/gnu/packages/valgrind.scm
index 4036bd461bc5..24b422c2c52c 100644
--- a/gnu/packages/valgrind.scm
+++ b/gnu/packages/valgrind.scm
@@ -26,6 +26,7 @@
   #:use-module (guix download)
   #:use-module (guix build-system gnu)
   #:use-module (guix licenses)
+  #:use-module (guix utils)
   #:use-module (gnu packages gdb)
   #:use-module (gnu packages perl)
   #:use-module (gnu packages))
@@ -50,8 +51,7 @@
     (outputs '("doc"                              ;16 MB
                "out"))
     (arguments
-     `(,@(if (string-prefix? "powerpc" (or (%current-target-system)
-                                           (%current-system)))
+     `(,@(if (target-powerpc?)
            `(#:make-flags '("CFLAGS+=-maltivec"))
            '())
        #:phases
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index b00c9aa3db5b..a6812699d77b 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -1322,8 +1322,7 @@ current version of any major web browser.")
                   #t))))
     (build-system cmake-build-system)
     (arguments
-     (if (string-prefix? "aarch64" (or (%current-target-system)
-                                       (%current-system)))
+     (if (target-aarch64?)
          '(#:phases
            (modify-phases %standard-phases
              (add-after 'unpack 'patch-aarch-march-detection