[PATCH 03/11] build: introduce bare minimum use of meson as a build system

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch is the first baby step in an incremental conversion
to use meson. Initially all it does is take responsibilty for
creating the dist tarball.

No attempt is made to integrate into autotools at this stage.
Eventually meson will be the primary build system and autotools
will be invoked by meson automatically for building gnulib.
To start with though, the build process will require invoking
both automake and meson. Since meson only supports
builddir != srcdir, automake must be invoked this way too:

   mkdir build
   cd build
   ../configure
   make
   cd ..
   meson build
   ninja -C build

Though in reality the meson/ninja step here is a no-op,
it is enough to start the integration process.

In terms of making a release the steps are the same, but the
last command must be followed by "ninja -C build dist"

The dist tarball we generate is slightly different from what
we previously built. meson's default is to merely bundle the
result of 'git archive' with all submodules. We do not want
the .gnulib submodule though as that is far too large. We
just want the subset of gnulib installed by bootstrap. We
can't simply copy the gnulib/ directory though, as we need
the autotools integration too and bootstrap runs autoreconf.

The upshot is that we purge .gnulib and copy a whitelist of
files that were seen to be created by bootstrap in a Fedora
30 host. By the end of the series, when gnulib is the only
thing using autotools, we can isolate everything from
bootstrap in a private sub-dir and simplify the dist.

In addition to the gnulib / autotools pieces, we add the
AUTHORS, NEWS and libvirt.spec files.

What this looses compared to previous tarballs is any
files that were listed as EXTRA_DIST, which were not
source controlled in git. This is negligible and any
such files are easily built.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 build-aux/dist.py | 133 ++++++++++++++++++++++++++++++++++++++++++++++
 libvirt.spec.in   |   8 +++
 meson.build       |  22 ++++++++
 3 files changed, 163 insertions(+)
 create mode 100755 build-aux/dist.py
 create mode 100644 meson.build

diff --git a/build-aux/dist.py b/build-aux/dist.py
new file mode 100755
index 0000000000..306d8d91bc
--- /dev/null
+++ b/build-aux/dist.py
@@ -0,0 +1,133 @@
+#!/usr/bin/env python3
+
+from __future__ import print_function
+
+import os
+import os.path
+import time
+import shutil
+import subprocess
+import sys
+
+if len(sys.argv) != 3:
+   print("syntax: %s SOURCE-ROOT BUILD-ROOT", sys.argv[0])
+   sys.exit(1)
+
+srcroot = sys.argv[1]
+buildroot = sys.argv[2]
+distdir = os.environ["MESON_DIST_ROOT"]
+
+# We don't want to bundle the entire of gnulib.
+# Bundling only the stuff we need is not as simple
+# as just grabbing the gnulib/ subdir though. The
+# bootstrap script is intertwined into autoreconf
+# with specific ordering needs. Thus we must
+# bundle the result from autoreconf + bootstrap
+gnulibmod = os.path.join(distdir, ".gnulib")
+shutil.rmtree(gnulibmod)
+
+autotools = {
+   "/": [
+      "GNUmakefile",
+      "INSTALL",
+      "Makefile.in",
+      "aclocal.m4",
+      "config.h.in",
+      "configure",
+      "maint.mk",
+   ],
+   "/build-aux": [
+      ".gitignore",
+      "compile",
+      "config.guess",
+      "config.rpath",
+      "config.sub",
+      "depcomp",
+      "gitlog-to-changelog",
+      "install-sh",
+      "ltmain.sh",
+      "missing",
+      "mktempd",
+      "test-driver",
+      "useless-if-before-free",
+      "vc-list-files",
+   ],
+   "/docs": [
+      "Makefile.in",
+   ],
+   "/examples": [
+      "Makefile.in",
+   ],
+   "/gnulib": None,
+   "/include/libvirt": [
+      "Makefile.in",
+   ],
+   "/m4": None,
+   "/po": [
+      "Makefile.in",
+   ],
+   "/src": [
+      "Makefile.in",
+   ],
+   "/tests": [
+      "Makefile.in",
+   ],
+   "/tools": [
+      "Makefile.in",
+   ],
+}
+
+for dirname in autotools.keys():
+   srcdir = os.path.join(srcroot, *dirname[1:].split("/"))
+   dstdir = os.path.join(distdir, *dirname[1:].split("/"))
+
+   if autotools[dirname] is None:
+      shutil.rmtree(dstdir)
+      shutil.copytree(srcdir, dstdir)
+   else:
+      os.makedirs(dstdir, exist_ok=True)
+      for filename in autotools[dirname]:
+         srcfile = os.path.join(srcdir, filename)
+         dstfile = os.path.join(dstdir, filename)
+
+         shutil.copyfile(srcfile, dstfile)
+         shutil.copymode(srcfile, dstfile)
+
+# Files created by meson using 'git clone' get a
+# timestamp from time we run 'ninja dist'. The
+# autotools files we're copying, get a time from
+# time we copy them. When 'make' runs later it
+# will think 'configure' is out of date and try
+# to recreate it. We hack around this by setting
+# all files to the same timestamp
+now = time.time()
+for dirname, subdirs, files in os.walk(distdir):
+   for filename in files:
+      dstfile = os.path.join(dirname, filename)
+      os.utime(dstfile, (now, now))
+
+
+# Some auto-generated files we want to include
+extra_dist = [
+   "libvirt.spec",
+   "NEWS"
+]
+for filename in extra_dist:
+   filesrc = os.path.join(buildroot, filename)
+   filedst = os.path.join(distdir, filename)
+
+   shutil.copyfile(filesrc, filedst)
+
+authors = subprocess.check_output(["git", "log", "--pretty=format:%aN <%aE>"])
+authorlist = sorted(set(authors.decode("utf8").split("\n")))
+
+authorssrc = os.path.join(srcroot, "AUTHORS.in")
+authorsdst = os.path.join(distdir, "AUTHORS")
+with open(authorssrc, "r") as src, open(authorsdst, "w") as dst:
+   for line in src:
+      if line.find("#contributorslist#") != -1:
+         for name in authorlist:
+            print(name, file=dst)
+      else:
+         print(line, end='', file=dst)
+
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 20d4c0444b..9e33504e01 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -254,6 +254,7 @@ BuildRequires: gettext-devel
 BuildRequires: libtool
 BuildRequires: /usr/bin/pod2man
 %endif
+BuildRequires: meson
 BuildRequires: gcc
 BuildRequires: git
 %if 0%{?fedora} || 0%{?rhel} > 7
@@ -1224,6 +1225,9 @@ cd %{_vpath_builddir}
            --with-init-script=systemd \
            %{?arg_login_shell}
 make %{?_smp_mflags} V=1
+cd ..
+%meson
+%meson_build
 
 %install
 rm -fr %{buildroot}
@@ -1232,6 +1236,8 @@ export SOURCE_DATE_EPOCH=$(stat --printf='%Y' %{_specdir}/%{name}.spec)
 
 cd %{_vpath_builddir}
 %make_install %{?_smp_mflags} SYSTEMD_UNIT_DIR=%{_unitdir} V=1
+cd ..
+%meson_install
 
 rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
 rm -f $RPM_BUILD_ROOT%{_libdir}/*.a
@@ -1318,6 +1324,8 @@ then
   cat test-suite.log || true
   exit 1
 fi
+cd ../..
+%meson_test
 
 %post libs
 %if 0%{?rhel} == 7
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000000..31428dba9b
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,22 @@
+project(
+  'libvirt',
+  'c',
+  version: '5.8.0',
+  license: 'LGPLv2+',
+  default_options: [
+    'buildtype=debugoptimized',
+    'c_std=gnu99',
+  ],
+  meson_version: '>= 0.49.0'
+)
+
+prefix = get_option('prefix')
+bin_dir = get_option('bindir')
+lib_dir = get_option('libdir')
+sys_conf_dir = get_option('sysconfdir')
+data_dir = get_option('datadir')
+local_state_dir = get_option('localstatedir')
+pkg_data_dir = data_dir / meson.project_name()
+pkg_doc_dir = data_dir / 'doc' / meson.project_name() + '-' + meson.project_version()
+
+meson.add_dist_script('build-aux' / 'dist.py', meson.source_root(), meson.build_root())
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux