Subject: QEMU 5.2.0 update - functions properly but still work in progress

From: Leo Famulari <[email-masked]>
Date: Wed, 2 Dec 2020 13:23:55 -0500

Here is a patch that updates QEMU to 5.2.0-rc4.

The big change here is that the build system has changed to use Meson
and Ninja "under the hood", although this release still uses
`./configure && make` in a superficial way.

With this patch, the qemu and qemu-minimal packages build and can boot
Guix VMs created with the `guix system` commands.

There are still two open tasks that require assistance:

1) The patch that makes Sphinx build an info manual will need to be
adapted to the meson build system. Ideally, this would be submitted
upstream.

2) The ./configure step is considered "stale" in the build phase and
thus gets run twice. You can add "--trace" to #:make-flags to trace the
Makefile and try to understand what's wrong (shown below). I'm no Make
expert but, AFAICT, there are some PHONY targets that depend on the
output of the configure step, config-host.mak, so it may be an upstream
bug. But I might be misunderstanding it. I asked on the QEMU IRC but
didn't get a useful answer.

------
starting phase `build'
GNUmakefile:10: update target 'all' due to: force
echo 'changing dir to build for make ""...'
changing dir to build for make ""...
make -C build -f Makefile 
make[1]: Entering directory '/tmp/guix-build-qemu-minimal-5.2.0-rc4.drv-0/qemu-5.2.0-rc4/build'
Makefile:109: update target 'config-host.mak' due to: /tmp/guix-build-qemu-minimal-5.2.0-rc4.drv-0/qemu-5.2.0-rc4/pc-bios
echo config-host.mak is out-of-date, running configure
config-host.mak is out-of-date, running configure
if test -f meson-private/coredata.dat; then \
  ./config.status --skip-meson; \
else \
  ./config.status && touch build.ninja.stamp; \
fi
------
From 37e261512f5b3a3e7544c31d2b001d71c547d08c Mon Sep 17 00:00:00 2001
From: Leo Famulari <[email-masked]>
Date: Sat, 28 Nov 2020 00:33:13 -0500
Subject: [PATCH] WIP: QEMU: Update to 5.2.0-rc4.

* gnu/packages/virtualization.scm (qemu): Update to 5.2.0-rc4.
[source]: TODO Update patch building the info manual.
[arguments]: Adjust the 'disable-unusable-tests' for the new Meson build
system. Generalize the 'patch-/bin/sh-references' into a 'patch-paths' phase,
and move an instance of path patching into it from the 'configure' phase.
[native-inputs]: Add ninja.
* gnu/packages/patches/qemu-build-info-manual.patch: Adjust to 5.2.0-rc4.
---
 gnu/packages/virtualization.scm | 34 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/gnu/packages/virtualization.scm b/gnu/packages/virtualization.scm
index 466e9d1ac5..e2b2508efa 100644
--- a/gnu/packages/virtualization.scm
+++ b/gnu/packages/virtualization.scm
@@ -80,6 +80,7 @@
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages nettle)
   #:use-module (gnu packages networking)
+  #:use-module (gnu packages ninja)
   #:use-module (gnu packages onc-rpc)
   #:use-module (gnu packages package-management)
   #:use-module (gnu packages perl)
@@ -132,15 +133,16 @@
 (define-public qemu
   (package
     (name "qemu")
-    (version "5.1.0")
+    (version "5.2.0-rc4")
     (source (origin
               (method url-fetch)
               (uri (string-append "https://download.qemu.org/qemu-"
                                   version ".tar.xz"))
               (sha256
                (base32
-                "1rd41wwlvp0vpialjp2czs6i3lsc338xc72l3zkbb7ixjfslw5y9"))
-              (patches (search-patches "qemu-build-info-manual.patch"))))
+                "10xsnw9sscknb6abd4h45k6gjzhqpdrvk9h8djbh7y1vh1zg76i9"))
+;              (patches (search-patches "qemu-build-info-manual.patch"))
+))
     (outputs '("out" "doc"))            ;4.7 MiB of HTML docs
     (build-system gnu-build-system)
     (arguments
@@ -188,30 +190,28 @@
                 (string-append match "9")))))
          (add-after 'unpack 'disable-unusable-tests
            (lambda _
-             (substitute* "tests/Makefile.include"
+             (substitute* "tests/meson.build"
                ;; Comment out the test-qga test, which needs /sys and
                ;; fails within the build environment.
-               (("check-unit-.* tests/test-qga" all)
+               (("tests.*test-qga.*$" all)
                 (string-append "# " all))
                ;; Comment out the test-char test, which needs networking and
                ;; fails within the build environment.
-               (("check-unit-.* tests/test-char" all)
-                (string-append "# " all)))
-             (substitute* "tests/qtest/Makefile.include"
-               ;; Disable the following test, which triggers a crash on some
-               ;; x86 CPUs (see https://issues.guix.info/43048 and
-               ;; https://bugs.launchpad.net/qemu/+bug/1896263).
-               (("check-qtest-i386-y \\+= bios-tables-test" all)
+               (("'test-char':.*$" all)
                 (string-append "# " all)))
              #t))
-         (add-after 'patch-source-shebangs 'patch-/bin/sh-references
+         (add-after 'patch-source-shebangs 'patch-embedded-shebangs
            (lambda _
              ;; Ensure the executables created by these source files reference
              ;; /bin/sh from the store so they work inside the build container.
              (substitute* '("block/cloop.c" "migration/exec.c"
                             "net/tap.c" "tests/qtest/libqtest.c")
                (("/bin/sh") (which "sh")))
+             (substitute* "tests/qemu-iotests/check"
+               (("#!/usr/bin/env python3")
+                (string-append "#!" (which "python3"))))
              #t))
+         ;; XXX ./configure is being re-run at beginning of build phase...
          (replace 'configure
            (lambda* (#:key inputs outputs (configure-flags '())
                      #:allow-other-keys)
@@ -220,14 +220,9 @@
              (let ((out (assoc-ref outputs "out")))
                (setenv "SHELL" (which "bash"))
 
-               ;; While we're at it, patch for tests.
-               (substitute* "tests/qemu-iotests/check"
-                 (("#!/usr/bin/env python3")
-                  (string-append "#!" (which "python3"))))
-
                ;; Ensure config.status gets the correct shebang off the bat.
                ;; The build system gets confused if we change it later and
-               ;; attempts to re-run the whole configury, and fails.
+               ;; attempts to re-run the whole configuration, and fails.
                (substitute* "configure"
                  (("#!/bin/sh")
                   (string-append "#!" (which "sh"))))
@@ -302,6 +297,7 @@ exec smbd $@")))
                      ("pkg-config" ,pkg-config)
                      ("python-wrapper" ,python-wrapper)
                      ("python-sphinx" ,python-sphinx)
+                     ("ninja" ,ninja)
                      ("texinfo" ,texinfo)))
     (home-page "https://www.qemu.org")
     (synopsis "Machine emulator and virtualizer")
-- 
2.29.2