From 98b4a19a536ddb9f75611deaa272ae5661c5df4d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 13 Sep 2018 17:24:58 +0200 Subject: [PATCH 1/9] build: meson: support $DESTDIR in installation script Adapt the meson post-installation script to handle the $DESTDIR variable supplied by user to specify the installation target directory. While at it, convert the script to shell because it seems simpler to me. --- Makefile.am | 2 +- meson.build | 2 +- meson_post_install.py | 46 ------------------------------------- tools/meson-post-install.sh | 44 +++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 48 deletions(-) delete mode 100644 meson_post_install.py create mode 100755 tools/meson-post-install.sh diff --git a/Makefile.am b/Makefile.am index 3f81c38925..13c07612fc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5040,7 +5040,6 @@ EXTRA_DIST += \ valgrind.suppressions \ meson.build \ meson_options.txt \ - meson_post_install.py \ config.h.meson \ config-extra.h.meson \ docs/meson.build \ @@ -5081,6 +5080,7 @@ EXTRA_DIST += \ tools/check-exports.sh \ tools/create-exports-NetworkManager.sh \ tools/debug-helper.py \ + tools/meson-post-install.sh \ tools/run-nm-test.sh \ tools/test-networkmanager-service.py \ tools/test-sudo-wrapper.sh \ diff --git a/meson.build b/meson.build index 7c7ef7ecc5..239e6744b6 100644 --- a/meson.build +++ b/meson.build @@ -895,7 +895,7 @@ configure_file( ) meson.add_install_script( - 'meson_post_install.py', + join_paths('tools', 'meson-post-install.sh'), nm_datadir, nm_bindir, nm_pkgconfdir, diff --git a/meson_post_install.py b/meson_post_install.py deleted file mode 100644 index 16dbc42b95..0000000000 --- a/meson_post_install.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -if not os.environ.get('DESTDIR'): - datadir = sys.argv[1] - bindir = sys.argv[2] - pkgconfdir = sys.argv[3] - pkglibdir = sys.argv[4] - localstatedir = sys.argv[5] - - completions_dir = os.path.join(datadir, 'bash-completion', 'completions') - os.rename(os.path.join(completions_dir, 'nmcli-completion'), os.path.join(completions_dir, 'nmcli')) - - nmtui_alias = ['nmtui-connect', 'nmtui-edit', 'nmtui-hostname'] - src = os.path.join(bindir, 'nmtui') - [os.symlink(src, os.path.join(bindir, dst)) - for dst in nmtui_alias] - - dst_dirs = [ - os.path.join(pkgconfdir, 'conf.d'), - os.path.join(pkgconfdir, 'system-connections'), - os.path.join(pkgconfdir, 'dispatcher.d', 'no-wait.d'), - os.path.join(pkgconfdir, 'dispatcher.d', 'pre-down.d'), - os.path.join(pkgconfdir, 'dispatcher.d', 'pre-up.d'), - os.path.join(pkgconfdir, 'dnsmasq.d'), - os.path.join(pkgconfdir, 'dnsmasq-shared.d'), - os.path.join(pkglibdir, 'conf.d'), - os.path.join(pkglibdir, 'VPN'), - os.path.join(localstatedir, 'lib', 'NetworkManager') - ] - [os.makedirs(dst_dir) - for dst_dir in dst_dirs - if not os.path.exists(dst_dir)] - - if sys.argv[6] == 'install_docs': - mandir = sys.argv[7] - - src = os.path.join(mandir, 'man1', 'nmtui.1') - [os.symlink(src, os.path.join(mandir, 'man1', dst + '.1')) - for dst in nmtui_alias] - - src = os.path.join(mandir, 'man5', 'NetworkManager.conf.5') - dst = os.path.join(mandir, 'man5', 'nm-system-settings.conf.5') - os.symlink(src, dst) diff --git a/tools/meson-post-install.sh b/tools/meson-post-install.sh new file mode 100755 index 0000000000..fd21941bbd --- /dev/null +++ b/tools/meson-post-install.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +datadir=$1 +bindir=$2 +pkgconfdir=$3 +pkglibdir=$4 +localstatedir=$5 + +[ -n "$DESTDIR" ] && DESTDIR=${DESTDIR%%/}/ + +if [ -f "${DESTDIR}${datadir}/bash-completion/completions/nmcli-completion" ]; then + mv "${DESTDIR}${datadir}/bash-completion/completions/nmcli-completion" \ + "${DESTDIR}${datadir}/bash-completion/completions/nmcli" +fi + +if [ -x "${DESTDIR}${bindir}/nmtui" ]; then + for alias in nmtui-connect nmtui-edit nmtui-hostname; do + ln -sf nmtui "${DESTDIR}${bindir}/$alias" + done +fi + +for dir in "${pkgconfdir}/conf.d" \ + "${pkgconfdir}/system-connections" \ + "${pkgconfdir}/dispatcher.d/no-wait.d" \ + "${pkgconfdir}/dispatcher.d/pre-down.d" \ + "${pkgconfdir}/dispatcher.d/pre-up.d" \ + "${pkgconfdir}/dnsmasq.d" \ + "${pkgconfdir}/dnsmasq-shared.d" \ + "${pkgconfdir}/conf.d" \ + "${pkgconfdir}/VPN" \ + "${localstatedir}/lib/NetworkManager"; do + mkdir -p "${DESTDIR}${dir}" +done + +if [ "$6" = install_docs ]; then + mandir=$7 + + for alias in nmtui-connect nmtui-edit nmtui-hostname; do + ln -f "${DESTDIR}${mandir}/man1/nmtui.1" "${DESTDIR}${mandir}/man1/${alias}.1" + done + + ln -f "${DESTDIR}${mandir}/man5/NetworkManager.conf.5" "${DESTDIR}${mandir}/man5/nm-system-settings.conf" +fi + From 37954c91bd1a9a44cf7e21ca5019c959b84a722a Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 14 Sep 2018 15:33:47 +0200 Subject: [PATCH 2/9] build: meson: check vapi prerequisites and allow autodetection Turn the vapi option into a combo that allows autodetection and check whether all prerequisites are satisfied (including introspection support) when vapi is explicitly enabled. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/28 --- meson.build | 25 +++++++++++++++++++++---- meson_options.txt | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 239e6744b6..2850d75a9d 100644 --- a/meson.build +++ b/meson.build @@ -711,11 +711,27 @@ auto_support_src = 'int main() { int a = 0; __auto_type b = a; return b + a; };' config_h.set10('_NM_CC_SUPPORT_AUTO_TYPE', cc.compiles(auto_support_src)) # Vala bindings -enable_vapi = get_option('vapi') -if enable_vapi +vapi_opt = get_option('vapi') +if vapi_opt == 'false' + enable_vapi = false +else vala_req_version = '>= 0.17.1.24' - assert(add_languages('vala', required: false), 'vala is required to build. Use -Dvapi=false to disable it') - assert(meson.get_compiler('vala').version().version_compare(vala_req_version), 'vala ' + vala_req_version + ' is required to build. Use -Dvapi=false to disable it') + enable_vapi = true + + if not enable_introspection + assert(vapi_opt != 'true', 'vala api require GObject introspection. Use -Dvapi=false to disable it') + enable_vapi = false + endif + + if enable_vapi and not add_languages('vala', required: false) + assert(vapi_opt != 'true', 'vala is required to build. Use -Dvapi=false to disable it') + enable_vapi = false + endif + + if enable_vapi and not meson.get_compiler('vala').version().version_compare(vala_req_version) + assert(vapi_opt != 'true', 'vala ' + vala_req_version + ' is required to build. Use -Dvapi=false to disable it') + enable_vapi = false + endif endif # Tests, utilities and documentation @@ -978,4 +994,5 @@ output += ' JSON validation for libnm: ' + enable_json_validation.to_string() + output += ' crypto: ' + crypto + ' (have-gnutls: ' + crypto_gnutls_dep.found().to_string() + ', have-nss: ' + crypto_nss_dep.found().to_string() + ')\n' output += ' sanitizers: ' + get_option('b_sanitize') + '\n' output += ' Mozilla Public Suffix List: ' + enable_libpsl.to_string() + '\n' +output += ' vapi: ' + enable_vapi.to_string() + '\n' message(output) diff --git a/meson_options.txt b/meson_options.txt index ee205601c3..1e7f886d27 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -62,7 +62,7 @@ option('config_dhcp_default', type: 'combo', choices: ['dhcpcanon', 'dhclient', # miscellaneous option('introspection', type: 'boolean', value: true, description: 'Enable introspection for this build') -option('vapi', type: 'boolean', value: true, description: 'build Vala bindings') +option('vapi', type : 'combo', choices : ['auto', 'true', 'false'], description: 'build Vala bindings') option('docs', type: 'boolean', value: false, description: 'use to build documentation') option('tests', type: 'combo', choices: ['yes', 'no', 'root'], value: 'yes', description: 'Build NetworkManager tests') option('more_asserts', type: 'string', value: 'all', description: 'Enable more assertions for debugging (0 = none, 100 = all, default: all)') From c8636449b3cf68d3ba8446dcef3f6dbecf48c3e4 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 14 Sep 2018 17:41:09 +0200 Subject: [PATCH 3/9] build: meson: man files depend on common.ent --- man/meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/man/meson.build b/man/meson.build index 044ddcaba4..929431668e 100644 --- a/man/meson.build +++ b/man/meson.build @@ -10,7 +10,7 @@ common_conf.set('NM_CONFIG_DEFAULT_MAIN_DHCP', config_dhcp_default) common = 'common.ent' -configure_file( +common_ent_file = configure_file( input: common + '.in', output: common, configuration: common_conf @@ -58,6 +58,7 @@ foreach man: mans input: input, output: output, command: xsltproc_options + [docbook_xls, '@INPUT@'], + depend_files: common_ent_file, install: true, install_dir: join_paths(nm_mandir, 'man' + man[1]) ) From c06a6aec1a969dcb5ec2e2ce8ecfe270cfdedeba Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 14 Sep 2018 17:41:36 +0200 Subject: [PATCH 4/9] build: meson: gtk-doc needs common.ent --- man/meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/man/meson.build b/man/meson.build index 929431668e..41fbf583a6 100644 --- a/man/meson.build +++ b/man/meson.build @@ -47,6 +47,8 @@ if enable_ovs mans += [['nm-openvswitch', '7']] endif +content_files += join_paths(meson.current_build_dir(), 'common.ent') + foreach man: mans input = man[0] + '.xml' content_files += join_paths(meson.current_source_dir(), input) From 6da369252a7b76cbbe38254ee9dd55cfc66723bd Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 14 Sep 2018 18:14:46 +0200 Subject: [PATCH 5/9] docs: include openvswitch(7) man page only when ovs is enabled --- docs/api/Makefile.am | 6 +++++- docs/api/network-manager-docs.xml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/api/Makefile.am b/docs/api/Makefile.am index 1f388b99ec..2baf40562f 100644 --- a/docs/api/Makefile.am +++ b/docs/api/Makefile.am @@ -89,11 +89,15 @@ content_files = \ $(top_builddir)/man/nmcli-examples.xml \ $(top_builddir)/man/nm-settings.xml \ $(top_builddir)/man/nm-settings-keyfile.xml \ - $(top_builddir)/man/nm-openvswitch.xml \ version.xml \ ../../COPYING \ $(NULL) + +if WITH_OPENVSWITCH +content_files += $(top_builddir)/man/nm-openvswitch.xml +endif + if CONFIG_PLUGIN_IFCFG_RH content_files += $(top_builddir)/man/nm-settings-ifcfg-rh.xml endif diff --git a/docs/api/network-manager-docs.xml b/docs/api/network-manager-docs.xml index 457ec0ac29..ec2712474b 100644 --- a/docs/api/network-manager-docs.xml +++ b/docs/api/network-manager-docs.xml @@ -78,7 +78,7 @@ - + From 19a718bc13824eae925ece55d04ebc07cd00cf62 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 18 Sep 2018 10:14:09 +0200 Subject: [PATCH 6/9] build: meson: fix computing NM exported symbols The script didn't include all the symbols needed by plugins because libNetworkManager.a, as built by meson, doesn't include symbols from other static libraries that are linked in. Since we used libNetworkManager.a to know which symbols are potentiall available from NM, the result was an incomplete list. Unfortunately, the only way to include the whole static library is to create a dependency object and use 'link_whole', but this is only available in meson >= 0.46. Since 'link_whole' is available for executables in meson >= 0.40, create a fake executable and use that to enumerate symbols. Also add tests to check that plugins can be loaded correctly. Fixes: dfa2a2b40c866bf7a5484b72639464c31b80e7da --- src/meson.build | 27 +++++++++++++++++++++++++- tools/create-exports-NetworkManager.sh | 7 ++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/meson.build b/src/meson.build index f46366a904..0a66647c25 100644 --- a/src/meson.build +++ b/src/meson.build @@ -252,11 +252,27 @@ subdir('settings/plugins') create_exports_networkmanager = join_paths(meson.source_root(), 'tools', 'create-exports-NetworkManager.sh') symbol_map_name = 'NetworkManager.ver' +# libNetworkManager.a, as built by meson doesn't contain all symbols +# from libNetworkManagerBase.a and other static libraries, unless we +# add dependencies with link_whole, only supported in meson >= 0.46. +# Create an executable with full symbols that we use in place of the +# library to enumerate the symbols. +network_manager_sym = executable( + 'nm-full-symbols', + 'main.c', + c_args: nm_cflags, + link_args: '-Wl,--no-gc-sections', + dependencies: nm_deps, + link_whole: [libnetwork_manager, libnetwork_manager_base, libnm_core], + install: false, +) + +# this uses symbols from nm-full-symbols instead of libNetworkManager.a ver_script = custom_target( symbol_map_name, input: meson.source_root(), output: symbol_map_name, - depends: [ libnetwork_manager, core_plugins ], + depends: [ network_manager_sym, core_plugins ], command: [create_exports_networkmanager, '--called-from-build', '@INPUT@'] ) @@ -273,3 +289,12 @@ network_manager = executable( install: true, install_dir: nm_sbindir ) + +if enable_tests + foreach plugin : core_plugins + test ('sym/' + plugin.full_path().split('/')[-1], + network_manager, + args: '--version', + env: ['LD_BIND_NOW=1', 'LD_PRELOAD=' + plugin.full_path()]) + endforeach +endif diff --git a/tools/create-exports-NetworkManager.sh b/tools/create-exports-NetworkManager.sh index 7d359005b7..1462501ee3 100755 --- a/tools/create-exports-NetworkManager.sh +++ b/tools/create-exports-NetworkManager.sh @@ -35,7 +35,12 @@ call_nm() { } get_symbols_nm () { - call_nm ./src/${libs}libNetworkManager.a | + if [ -z "$from_meson" ]; then + base=./src/.libs/libNetworkManager.a + else + base=./src/nm-full-symbols + fi + call_nm "$base" | sed -n 's/^[tTDGRBS] //p' | _sort } From 84701c049cfed8a8cf8a841100b6ce8b6be0d46e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 18 Sep 2018 14:56:59 +0200 Subject: [PATCH 7/9] build: meson: GTK documentation requires introspection --- meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 2850d75a9d..8d6fa031f0 100644 --- a/meson.build +++ b/meson.build @@ -864,11 +864,10 @@ if enable_qt endif enable_docs = get_option('docs') + if enable_docs + assert(enable_introspection, '-Ddocs=true requires -Dintrospection=true') subdir('man') - - #assert(enable_introspection, '-Dgtk_doc=true requires -Dintrospection=true') - subdir('docs') endif From 5af7d46be49b581319e92296931f30af714d3c6d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 18 Sep 2018 15:10:39 +0200 Subject: [PATCH 8/9] travis: disable gtk-doc for meson builds Introspection can't be enabled on travis due to a GLib bug [1]. Therefore, gtk-doc must be disabled as well. [1] https://bugzilla.gnome.org/show_bug.cgi?id=774368 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1149c8b830..6a0a3d89cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -97,7 +97,7 @@ script: -D introspection=false \ -D qt=false \ -D crypto=$CRYPTO \ - -D docs=true \ + -D docs=false \ \ -D libnm_glib=true \ -D iwd=true \ From 470c5c0a82a546b9dd294693f8aba0f11a51048f Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 19 Sep 2018 13:34:55 +0200 Subject: [PATCH 9/9] initrd: enable meson builds --- src/initrd/meson.build | 32 +++++++++++++++++++++++++++++ src/initrd/tests/meson.build | 39 ++++++++++++++++++------------------ src/meson.build | 1 + 3 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 src/initrd/meson.build diff --git a/src/initrd/meson.build b/src/initrd/meson.build new file mode 100644 index 0000000000..66e825d535 --- /dev/null +++ b/src/initrd/meson.build @@ -0,0 +1,32 @@ +sources = files( + 'nmi-cmdline-reader.c', + 'nmi-ibft-reader.c' +) + +nm_cflags = ['-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_DAEMON'] + +libnmi_core = static_library( + 'nmi-core', + c_args: nm_cflags, + sources: sources, + include_directories: src_inc, + dependencies: nm_core_dep, +) + +name = 'nm-initrd-generator' +executable( + name, + name + '.c', + c_args: nm_cflags, + include_directories: src_inc, + dependencies: [ nm_core_dep ], + link_with: [libnetwork_manager_base, libnmi_core], + link_args: ldflags_linker_script_binary, + link_depends: linker_script_binary, + install: true, + install_dir: nm_libexecdir, +) + +if enable_tests + subdir('tests') +endif diff --git a/src/initrd/tests/meson.build b/src/initrd/tests/meson.build index 0e74ea8d9e..6b316d4ed4 100644 --- a/src/initrd/tests/meson.build +++ b/src/initrd/tests/meson.build @@ -1,22 +1,23 @@ -test_unit = 'test-ibft' - -test_ibft_dir = meson.current_source_dir() - -cflags = [ - '-DTEST_IBFT_DIR="@0@"'.format(test_ibft_dir), - '-DTEST_SCRATCH_DIR="@0@"'.format(test_ibft_dir) +test_units = [ + 'test-ibft-reader', + 'test-cmdline-reader', ] -exe = executable( - test_unit, - test_unit + '.c', - dependencies: test_nm_dep, - c_args: cflags, - link_with: libnmi_ibft_core -) +cflags = [ + '-DTEST_INITRD_DIR="@0@"'.format(meson.current_source_dir()), +] -test( - 'ibft/' + test_unit, - test_script, - args: test_args + [exe.full_path()] -) +foreach test_unit : test_units + exe = executable( + test_unit, + test_unit + '.c', + dependencies: test_nm_dep, + c_args: cflags, + link_with: libnmi_core + ) + test( + 'initrd/' + test_unit, + test_script, + args: test_args + [exe.full_path()] + ) +endforeach diff --git a/src/meson.build b/src/meson.build index 0a66647c25..87c576714d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -245,6 +245,7 @@ if enable_ppp endif subdir('devices') +subdir('initrd') subdir('settings/plugins') # NetworkManager binary