Subject: [PATCH v2 1/2] gnu: move meson to (gnu packages meson).

From: Vivien Kraus <[email-masked]>
Date: Fri, 6 Jan 2023 22:04:48 +0100

* gnu/packages/meson.scm: New file with meson.
* gnu/packages/build-tools.scm (meson-0.63, meson-0.60 meson-0.59 meson
meson-python): Move to (gnu packages meson).
* gnu/packages/freedesktop.scm, gnu/packages/geo.scm, gnu/packages/gnome.scm,
gnu/packages/package-management.scm, gnu/packages/python-science.scm,
gnu/packages/syndication.scm, gnu/packages/virtualization.scm: import (gnu
packages meson).
* guix/build-system/meson.scm (default-meson): get it from (gnu packages meson).
---
 gnu/local.mk                        |   1 +
 gnu/packages/build-tools.scm        | 169 ++---------------------
 gnu/packages/freedesktop.scm        |   3 +-
 gnu/packages/geo.scm                |   1 +
 gnu/packages/gnome.scm              |   1 +
 gnu/packages/meson.scm              | 204 ++++++++++++++++++++++++++++
 gnu/packages/package-management.scm |   1 +
 gnu/packages/python-science.scm     |   1 +
 gnu/packages/syndication.scm        |   1 +
 gnu/packages/virtualization.scm     |   1 +
 guix/build-system/meson.scm         |   2 +-
 11 files changed, 224 insertions(+), 161 deletions(-)
 create mode 100644 gnu/packages/meson.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 325bdd570a..ccf225efbb 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -419,6 +419,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/medical.scm			\
   %D%/packages/mercury.scm			\
   %D%/packages/mes.scm				\
+  %D%/packages/meson.scm			\
   %D%/packages/messaging.scm			\
   %D%/packages/minetest.scm			\
   %D%/packages/mingw.scm			\
diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index 6c1350c44f..e61db21325 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -1,10 +1,10 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2017, 2018 Ricardo Wurmus <[email-masked]>
-;;; Copyright © 2017 Corentin Bocquillon <[email-masked]>
-;;; Copyright © 2017–2021 Tobias Geerinckx-Rice <[email-masked]>
+;;; Copyright © 2017 Ricardo Wurmus <[email-masked]>
+;;; Copyright © 2017 Oleg Pykhalov <[email-masked]>
 ;;; Copyright © 2018 Fis Trivial <[email-masked]>
 ;;; Copyright © 2018 Tomáš Čech <[email-masked]>
-;;; Copyright © 2018, 2020 Marius Bakke <[email-masked]>
+;;; Copyright © 2018-2022 Tobias Geerinckx-Rice <[email-masked]>
+;;; Copyright © 2018-2022 Marius Bakke <[email-masked]>
 ;;; Copyright © 2018 Alex Vong <[email-masked]>
 ;;; Copyright © 2019, 2020 Brett Gilio <[email-masked]>
 ;;; Copyright © 2019 Jonathan Brielmaier <[email-masked]>
@@ -12,9 +12,14 @@
 ;;; Copyright © 2020 Yuval Kogman <[email-masked]>
 ;;; Copyright © 2020 Jakub Kądziołka <[email-masked]>
 ;;; Copyright © 2020 Efraim Flashner <[email-masked]>
+;;; Copyright © 2020 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2020 Raghav Gururajan <[email-masked]>
 ;;; Copyright © 2021 qblade <[email-masked]>
-;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Léo Le Bouter <[email-masked]>
+;;; Copyright © 2021, 2022 Greg Hogan <[email-masked]>
+;;; Copyright © 2021 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2022 Juliana Sims <[email-masked]>
+;;; Copyright © 2022 Maxim Cournoyer <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -273,160 +278,6 @@ (define-public gn
       ;; X11 license.
       (license (list license:bsd-3 license:x11)))))
 
-(define-public meson-0.63
-  (package
-    (name "meson")
-    (version "0.63.2")
-    (source (origin
-              (method url-fetch)
-              (uri (string-append "https://github.com/mesonbuild/meson/"
-                                  "releases/download/" version  "/meson-"
-                                  version ".tar.gz"))
-              (sha256
-               (base32
-                "1gwba75z47m2hv3w08gw8sgqgbknjr7rj1qwr510bgknxwbjy8hn"))))
-    (build-system python-build-system)
-    (arguments
-     `(;; FIXME: Tests require many additional inputs and patching many
-       ;; hard-coded file system locations in "run_unittests.py".
-       #:tests? #f
-       #:phases (modify-phases %standard-phases
-                  ;; Meson calls the various executables in out/bin through the
-                  ;; Python interpreter, so we cannot use the shell wrapper.
-                  (replace 'wrap
-                    (lambda* (#:key outputs inputs #:allow-other-keys)
-                      (let ((python-version
-                             (python-version (assoc-ref inputs "python")))
-                            (output (assoc-ref outputs "out")))
-                        (substitute* (string-append output "/bin/meson")
-                          (("# EASY-INSTALL-ENTRY-SCRIPT")
-                           (format #f "\
-import sys
-sys.path.insert(0, '~a/lib/python~a/site-packages')
-# EASY-INSTALL-ENTRY-SCRIPT"
-                                   output python-version)))))))))
-    (inputs (list python-wrapper ninja))
-    (home-page "https://mesonbuild.com/")
-    (synopsis "Build system designed to be fast and user-friendly")
-    (description
-     "The Meson build system is focused on user-friendliness and speed.
-It can compile code written in C, C++, Fortran, Java, Rust, and other
-languages.  Meson provides features comparable to those of the
-Autoconf/Automake/make combo.  Build specifications, also known as @dfn{Meson
-files}, are written in a custom domain-specific language (@dfn{DSL}) that
-resembles Python.")
-    (license license:asl2.0)))
-
-(define-public meson-0.60
-  (package
-    (inherit meson-0.63)
-    (version "0.60.3")
-    (source (origin
-              (method url-fetch)
-              (uri (string-append "https://github.com/mesonbuild/meson/"
-                                  "releases/download/" version  "/meson-"
-                                  version ".tar.gz"))
-              (sha256
-               (base32
-                "13mrrizg4vl6n5k7fz6amyafnn3i097dcarr552qc0ca6nlmzjl7"))
-              (patches (search-patches
-                        "meson-allow-dirs-outside-of-prefix.patch"))))))
-
-;;; This older Meson variant is kept for now for gtkmm and others that may
-;;; have problems with 0.60.
-(define-public meson-0.59
-  (package
-    (inherit meson-0.60)
-    (version "0.59.4")
-    (source (origin
-              (method url-fetch)
-              (uri (string-append "https://github.com/mesonbuild/meson/"
-                                  "releases/download/" version  "/meson-"
-                                  version ".tar.gz"))
-              (sha256
-               (base32
-                "117cm8794h291lca1wljz1pwnzidgbvrpg3mw3np6ksma368hyd7"))
-              (patches (search-patches
-                        "meson-allow-dirs-outside-of-prefix.patch"))))))
-
-;; TODO: Bump this in the next rebuild cycle.
-(define-public meson meson-0.60)
-
-(define-public meson-python
-  (package
-    (name "meson-python")
-    (version "0.8.1")
-    (source (origin
-              (method url-fetch)
-              (uri (pypi-uri "meson_python" version))
-              (sha256
-               (base32
-                "0k2yn0iws1n184sdznzmfw4xgbqgq5cn02hpc7m0xdaxryj1ybs4"))))
-    (build-system python-build-system)
-    (arguments
-     (list #:phases
-           #~(modify-phases %standard-phases
-               (add-after 'unpack 'avoid-ninja-dependency
-                 (lambda _
-                   ;; Avoid dependency on the "ninja" PyPI distribution,
-                   ;; which is a meta-package that simply downloads and
-                   ;; installs ninja from the web ...
-                   (substitute* "pyproject.toml"
-                     (("'ninja',")
-                      ""))))
-               (replace 'build
-                 (lambda _
-                   ;; ZIP does not support timestamps before 1980.
-                   (setenv "SOURCE_DATE_EPOCH" "315532800")
-                   (invoke "python" "-m" "build" "--wheel" "--no-isolation" ".")))
-               (replace 'install
-                 (lambda _
-                   (let ((whl (car (find-files "dist" "\\.whl$"))))
-                     (invoke "pip" "--no-cache-dir" "--no-input"
-                             "install" "--no-deps" "--prefix" #$output whl))))
-               (replace 'check
-                 (lambda* (#:key tests? #:allow-other-keys)
-                   (when tests?
-                     (invoke "pytest" "-vv" "tests" "-k"
-                             (string-append
-                              "not "
-                              ;; These tests require a git checkout.
-                              (string-join '("test_contents_unstaged"
-                                             "test_no_pep621"
-                                             "test_pep621"
-                                             "test_dynamic_version"
-                                             "test_contents"
-                                             "test_contents_subdirs")
-                                           " and not ")))))))))
-    (propagated-inputs
-     (list meson-0.63                   ;>=0.62 required
-           ninja
-           ;; XXX: python-meson forcefully sets the RUNPATH of binaries
-           ;; for vendoring purposes, and uses PatchELF for that(!).  This
-           ;; functionality is not useful in Guix, but removing this
-           ;; dependency is tricky.  There is discussion upstream about making
-           ;; it optional, but for now we'll just carry it:
-           ;; https://github.com/FFY00/meson-python/issues/125
-           patchelf
-           python-colorama
-           python-pyproject-metadata
-           python-tomli
-           python-wheel))
-    (native-inputs
-     (list python-pypa-build
-           python-wheel
-
-           ;; For tests.
-           pkg-config
-           python-gitpython
-           python-pytest
-           python-pytest-mock))
-    (home-page "https://github.com/FFY00/mesonpy")
-    (synopsis "Meson-based build backend for Python")
-    (description
-     "meson-python is a PEP 517 build backend for Meson projects.")
-    (license license:expat)))
-
 (define-public premake4
   (package
     (name "premake")
diff --git a/gnu/packages/freedesktop.scm b/gnu/packages/freedesktop.scm
index 515d9b9cea..b442ec8ab7 100644
--- a/gnu/packages/freedesktop.scm
+++ b/gnu/packages/freedesktop.scm
@@ -103,8 +103,9 @@ (define-module (gnu packages freedesktop)
   #:use-module (gnu packages libunwind)
   #:use-module (gnu packages libusb)
   #:use-module (gnu packages linux)
-  #:use-module (gnu packages man)
   #:use-module (gnu packages m4)
+  #:use-module (gnu packages man)
+  #:use-module (gnu packages meson)
   #:use-module (gnu packages networking)
   #:use-module (gnu packages nss)
   #:use-module (gnu packages package-management)
diff --git a/gnu/packages/geo.scm b/gnu/packages/geo.scm
index 2185af7a98..5fbe6f8dd7 100644
--- a/gnu/packages/geo.scm
+++ b/gnu/packages/geo.scm
@@ -99,6 +99,7 @@ (define-module (gnu packages geo)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages lua)
   #:use-module (gnu packages maths)
+  #:use-module (gnu packages meson)
   #:use-module (gnu packages multiprecision)
   #:use-module (gnu packages pcre)
   #:use-module (gnu packages pdf)
diff --git a/gnu/packages/gnome.scm b/gnu/packages/gnome.scm
index 47a0f237fe..3774b9af9f 100644
--- a/gnu/packages/gnome.scm
+++ b/gnu/packages/gnome.scm
@@ -162,6 +162,7 @@ (define-module (gnu packages gnome)
   #:use-module (gnu packages mail)
   #:use-module (gnu packages man)
   #:use-module (gnu packages markup)
+  #:use-module (gnu packages meson)
   #:use-module (gnu packages messaging)
   #:use-module (gnu packages mp3)
   #:use-module (gnu packages multiprecision)
diff --git a/gnu/packages/meson.scm b/gnu/packages/meson.scm
new file mode 100644
index 0000000000..c42e13cf2a
--- /dev/null
+++ b/gnu/packages/meson.scm
@@ -0,0 +1,204 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2017 Corentin Bocquillon <[email-masked]>
+;;; Copyright © 2017, 2018, 2021 Tobias Geerinckx-Rice <[email-masked]>
+;;; Copyright © 2017 Peter Mikkelsen <[email-masked]>
+;;; Copyright © 2018-2022 Marius Bakke <[email-masked]>
+;;; Copyright © 2018 Ricardo Wurmus <[email-masked]>
+;;; Copyright © 2018 Brett Gilio <[email-masked]>
+;;; Copyright © 2020 Alexandros Theodotou <[email-masked]>
+;;; Copyright © 2021, 2022 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Efraim Flashner <[email-masked]>
+;;; Copyright © 2021 Sou Bunnbu (宋文武) <[email-masked]>
+;;; Copyright © 2021 Kaelyn Takata <[email-masked]>
+;;; Copyright © 2021 Mathieu Othacehe <[email-masked]>
+;;; Copyright © 2021 Vivien Kraus <[email-masked]>
+;;; Copyright © 2021 Ludovic Courtès <[email-masked]>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages meson)
+  #:use-module (ice-9 optargs)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system python)
+  #:use-module (guix download)
+  #:use-module (guix gexp)
+  #:use-module (guix git-download)
+  #:use-module (guix modules)
+  #:use-module (guix packages)
+  #:use-module (guix utils)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages check)
+  #:use-module (gnu packages elf)
+  #:use-module (gnu packages ninja)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-build)
+  #:use-module (gnu packages python-xyz)
+  #:use-module (gnu packages version-control))
+
+(define-public meson-0.63
+  (package
+    (name "meson")
+    (version "0.63.2")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://github.com/mesonbuild/meson/"
+                                  "releases/download/" version  "/meson-"
+                                  version ".tar.gz"))
+              (sha256
+               (base32
+                "1gwba75z47m2hv3w08gw8sgqgbknjr7rj1qwr510bgknxwbjy8hn"))))
+    (build-system python-build-system)
+    (arguments
+     `(;; FIXME: Tests require many additional inputs and patching many
+       ;; hard-coded file system locations in "run_unittests.py".
+       #:tests? #f
+       #:phases (modify-phases %standard-phases
+                  ;; Meson calls the various executables in out/bin through the
+                  ;; Python interpreter, so we cannot use the shell wrapper.
+                  (replace 'wrap
+                    (lambda* (#:key outputs inputs #:allow-other-keys)
+                      (let ((python-version
+                             (python-version (assoc-ref inputs "python")))
+                            (output (assoc-ref outputs "out")))
+                        (substitute* (string-append output "/bin/meson")
+                          (("# EASY-INSTALL-ENTRY-SCRIPT")
+                           (format #f "\
+import sys
+sys.path.insert(0, '~a/lib/python~a/site-packages')
+# EASY-INSTALL-ENTRY-SCRIPT"
+                                   output python-version)))))))))
+    (inputs (list python-wrapper ninja))
+    (home-page "https://mesonbuild.com/")
+    (synopsis "Build system designed to be fast and user-friendly")
+    (description
+     "The Meson build system is focused on user-friendliness and speed.
+It can compile code written in C, C++, Fortran, Java, Rust, and other
+languages.  Meson provides features comparable to those of the
+Autoconf/Automake/make combo.  Build specifications, also known as @dfn{Meson
+files}, are written in a custom domain-specific language (@dfn{DSL}) that
+resembles Python.")
+    (license license:asl2.0)))
+
+(define-public meson-0.60
+  (package
+    (inherit meson-0.63)
+    (version "0.60.3")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://github.com/mesonbuild/meson/"
+                                  "releases/download/" version  "/meson-"
+                                  version ".tar.gz"))
+              (sha256
+               (base32
+                "13mrrizg4vl6n5k7fz6amyafnn3i097dcarr552qc0ca6nlmzjl7"))
+              (patches (search-patches
+                        "meson-allow-dirs-outside-of-prefix.patch"))))))
+
+;;; This older Meson variant is kept for now for gtkmm and others that may
+;;; have problems with 0.60.
+(define-public meson-0.59
+  (package
+    (inherit meson-0.60)
+    (version "0.59.4")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://github.com/mesonbuild/meson/"
+                                  "releases/download/" version  "/meson-"
+                                  version ".tar.gz"))
+              (sha256
+               (base32
+                "117cm8794h291lca1wljz1pwnzidgbvrpg3mw3np6ksma368hyd7"))
+              (patches (search-patches
+                        "meson-allow-dirs-outside-of-prefix.patch"))))))
+
+;; TODO: Bump this in the next rebuild cycle.
+(define-public meson meson-0.60)
+
+(define-public meson-python
+  (package
+    (name "meson-python")
+    (version "0.8.1")
+    (source (origin
+              (method url-fetch)
+              (uri (pypi-uri "meson_python" version))
+              (sha256
+               (base32
+                "0k2yn0iws1n184sdznzmfw4xgbqgq5cn02hpc7m0xdaxryj1ybs4"))))
+    (build-system python-build-system)
+    (arguments
+     (list #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'unpack 'avoid-ninja-dependency
+                 (lambda _
+                   ;; Avoid dependency on the "ninja" PyPI distribution,
+                   ;; which is a meta-package that simply downloads and
+                   ;; installs ninja from the web ...
+                   (substitute* "pyproject.toml"
+                     (("'ninja',")
+                      ""))))
+               (replace 'build
+                 (lambda _
+                   ;; ZIP does not support timestamps before 1980.
+                   (setenv "SOURCE_DATE_EPOCH" "315532800")
+                   (invoke "python" "-m" "build" "--wheel" "--no-isolation" ".")))
+               (replace 'install
+                 (lambda _
+                   (let ((whl (car (find-files "dist" "\\.whl$"))))
+                     (invoke "pip" "--no-cache-dir" "--no-input"
+                             "install" "--no-deps" "--prefix" #$output whl))))
+               (replace 'check
+                 (lambda* (#:key tests? #:allow-other-keys)
+                   (when tests?
+                     (invoke "pytest" "-vv" "tests" "-k"
+                             (string-append
+                              "not "
+                              ;; These tests require a git checkout.
+                              (string-join '("test_contents_unstaged"
+                                             "test_no_pep621"
+                                             "test_pep621"
+                                             "test_dynamic_version"
+                                             "test_contents"
+                                             "test_contents_subdirs")
+                                           " and not ")))))))))
+    (propagated-inputs
+     (list meson-0.63                   ;>=0.62 required
+           ninja
+           ;; XXX: python-meson forcefully sets the RUNPATH of binaries
+           ;; for vendoring purposes, and uses PatchELF for that(!).  This
+           ;; functionality is not useful in Guix, but removing this
+           ;; dependency is tricky.  There is discussion upstream about making
+           ;; it optional, but for now we'll just carry it:
+           ;; https://github.com/FFY00/meson-python/issues/125
+           patchelf
+           python-colorama
+           python-pyproject-metadata
+           python-tomli
+           python-wheel))
+    (native-inputs
+     (list python-pypa-build
+           python-wheel
+
+           ;; For tests.
+           pkg-config
+           python-gitpython
+           python-pytest
+           python-pytest-mock))
+    (home-page "https://github.com/FFY00/mesonpy")
+    (synopsis "Meson-based build backend for Python")
+    (description
+     "meson-python is a PEP 517 build backend for Meson projects.")
+    (license license:expat)))
diff --git a/gnu/packages/package-management.scm b/gnu/packages/package-management.scm
index 2ffaa12247..8a992b8cb1 100644
--- a/gnu/packages/package-management.scm
+++ b/gnu/packages/package-management.scm
@@ -84,6 +84,7 @@ (define-module (gnu packages package-management)
   #:use-module (gnu packages lua)
   #:use-module (gnu packages man)
   #:use-module (gnu packages markup)
+  #:use-module (gnu packages meson)
   #:use-module (gnu packages nettle)
   #:use-module (gnu packages networking)
   #:use-module (gnu packages ninja)
diff --git a/gnu/packages/python-science.scm b/gnu/packages/python-science.scm
index dab044d9f7..ebdcadad2c 100644
--- a/gnu/packages/python-science.scm
+++ b/gnu/packages/python-science.scm
@@ -52,6 +52,7 @@ (define-module (gnu packages python-science)
   #:use-module (gnu packages image-processing)
   #:use-module (gnu packages machine-learning)
   #:use-module (gnu packages maths)
+  #:use-module (gnu packages meson)
   #:use-module (gnu packages mpi)
   #:use-module (gnu packages pcre)
   #:use-module (gnu packages perl)
diff --git a/gnu/packages/syndication.scm b/gnu/packages/syndication.scm
index 506245fd17..fd327fb27f 100644
--- a/gnu/packages/syndication.scm
+++ b/gnu/packages/syndication.scm
@@ -51,6 +51,7 @@ (define-module (gnu packages syndication)
   #:use-module (gnu packages gstreamer)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages kde-frameworks)
+  #:use-module (gnu packages meson)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages pretty-print)
diff --git a/gnu/packages/virtualization.scm b/gnu/packages/virtualization.scm
index 64a26edb02..f3cb521599 100644
--- a/gnu/packages/virtualization.scm
+++ b/gnu/packages/virtualization.scm
@@ -96,6 +96,7 @@ (define-module (gnu packages virtualization)
   #:use-module (gnu packages libusb)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages m4)
+  #:use-module (gnu packages meson)
   #:use-module (gnu packages multiprecision)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages nettle)
diff --git a/guix/build-system/meson.scm b/guix/build-system/meson.scm
index 9fee6c4570..440577ddb8 100644
--- a/guix/build-system/meson.scm
+++ b/guix/build-system/meson.scm
@@ -124,7 +124,7 @@ (define (default-ninja)
 (define (default-meson)
   "Return the default meson package."
   ;; Lazily resolve the binding to avoid a circular dependency.
-  (let ((module (resolve-interface '(gnu packages build-tools))))
+  (let ((module (resolve-interface '(gnu packages meson))))
     (module-ref module 'meson)))
 
 (define* (lower name
-- 
2.38.1