From: Thomas Huth <thuth@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH 23/24] configure: prepare for auto-generated option parsing
Date: Thu, 7 Oct 2021 18:53:53 +0200 [thread overview]
Message-ID: <a1bdcb8f-8f37-a375-465b-a1bd0cc47d30@redhat.com> (raw)
In-Reply-To: <20211007130829.632254-18-pbonzini@redhat.com>
On 07/10/2021 15.08, Paolo Bonzini wrote:
> Prepare the configure script and Makefile for automatically generated
> help and parsing.
>
> Because we need to run the script to generate the full help, we
> cannot rely on the user supplying the path to a Python interpreter
> with --python; therefore, the introspection output is parsed into
> shell functions and stored in scripts/. The converter is written
> in Python as standard for QEMU, and this commit contains a stub.
Looks like a good approach to me! I've just got two questions below...
> diff --git a/configure b/configure
> index d2f754d5d1..d979476e03 100755
> --- a/configure
> +++ b/configure
> @@ -789,6 +789,18 @@ fi
>
> werror=""
>
> +. $source_path/scripts/meson-buildoptions.sh
> +
> +meson_options=
> +meson_option_parse() {
> + meson_options="$meson_options $(_meson_option_parse "$@")"
> + if test $? -eq 1; then
> + echo "ERROR: unknown option $1"
> + echo "Try '$0 --help' for more information"
> + exit 1
> + fi
> +}
Why the detour via this wrapper and $(_meson_option_parse) ? Couldn't you
simply add the stuff directly to $meson_options in _meson_option_parse() ?
> for opt do
> optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
> case "$opt" in
> @@ -1548,6 +1560,8 @@ for opt do
> ;;
> --disable-slirp-smbd) slirp_smbd=no
> ;;
> + --enable-* | --disable-*) meson_option_parse "$opt" "$optarg"
> + ;;
> *)
> echo "ERROR: unknown option $opt"
> echo "Try '$0 --help' for more information"
> @@ -1802,11 +1816,9 @@ Advanced options (experts only):
> enable plugins via shared library loading
> --disable-containers don't use containers for cross-building
> --gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
> -
> -Optional features, enabled with --enable-FEATURE and
> -disabled with --disable-FEATURE, default is enabled if available
> -(unless built with --without-default-features):
> -
> +EOF
> + meson_options_help
> +cat << EOF
> system all system emulation targets
> user supported user emulation targets
> linux-user all linux usermode emulation targets
> @@ -4487,7 +4499,8 @@ if test "$skip_meson" = no; then
> mv $cross config-meson.cross
>
> rm -rf meson-private meson-info meson-logs
> - NINJA=$ninja $meson setup \
> + run_meson() {
> + NINJA=$ninja $meson setup \
> --prefix "$prefix" \
> --libdir "$libdir" \
> --libexecdir "$libexecdir" \
> @@ -4532,9 +4545,9 @@ if test "$skip_meson" = no; then
> -Dpa=$pa -Daudio_drv_list=$audio_drv_list -Dtcg_interpreter=$tcg_interpreter \
> -Dtrace_backends=$trace_backends -Dtrace_file=$trace_file -Dlinux_aio=$linux_aio \
> -Dnetmap=$netmap -Dvde=$vde \
> - $cross_arg \
> - "$PWD" "$source_path"
> -
> + "$@" $cross_arg "$PWD" "$source_path"
> + }
> + eval run_meson $meson_options
> if test "$?" -ne 0 ; then
> error_exit "meson setup failed"
> fi
> diff --git a/scripts/meson-buildoptions.py b/scripts/meson-buildoptions.py
> new file mode 100755
> index 0000000000..8948c296b7
> --- /dev/null
> +++ b/scripts/meson-buildoptions.py
> @@ -0,0 +1,63 @@
> +#! /usr/bin/env python3
> +
> +# Generate configure command line options handling code, based on Meson's
> +# user build options introspection data
> +#
> +# Copyright (C) 2021 Red Hat, Inc.
> +#
> +# Author: Paolo Bonzini <pbonzini@redhat.com>
> +#
> +# This program 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 2, or (at your option)
> +# any later version.
> +#
> +# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
> +
> +import json
> +import textwrap
> +import shlex
> +import sys
> +
> +def sh_print(line=""):
> + print(' printf "%s\\n"', shlex.quote(line))
> +
> +
> +def load_options(json):
> + json = [
> + x
> + for x in json
> + if x["section"] == "user"
> + and ":" not in x["name"]
> + and x["name"] not in SKIP_OPTIONS
> + ]
> + return sorted(json, key=lambda x: x["name"])
> +
> +
> +def print_help(options):
> + print("meson_options_help() {")
> + sh_print()
> + sh_print("Optional features, enabled with --enable-FEATURE and")
> + sh_print("disabled with --disable-FEATURE, default is enabled if available")
> + sh_print("(unless built with --without-default-features):")
> + sh_print()
> + print("}")
> +
> +
> +def print_parse(options):
> + print("_meson_option_parse() {")
> + print(" case $1 in")
> + print(" *) return 1 ;;")
> + print(" esac")
> + print("}")
> +
> +
> +options = load_options(json.load(sys.stdin))
Could you maybe print a header line first, à la:
# This file is generated by meson-buildoptions.py, do not edit!
?
> +print_help(options)
> +print_parse(options)
> diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
> new file mode 100644
> index 0000000000..3be3058a6c
> --- /dev/null
> +++ b/scripts/meson-buildoptions.sh
> @@ -0,0 +1,12 @@
> +meson_options_help() {
> + printf "%s\n" ''
> + printf "%s\n" 'Optional features, enabled with --enable-FEATURE and'
> + printf "%s\n" 'disabled with --disable-FEATURE, default is enabled if available'
> + printf "%s\n" '(unless built with --without-default-features):'
> + printf "%s\n" ''
> +}
> +_meson_option_parse() {
> + case $1 in
> + *) return 1 ;;
> + esac
> +}
>
Tested-by: Thomas Huth <thuth@redhat.com>
next prev parent reply other threads:[~2021-10-07 16:56 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-07 13:06 [PATCH 00/24] configure->meson queue for 6.2 Paolo Bonzini
2021-10-07 13:06 ` [PATCH 01/24] configure: remove --oss-lib Paolo Bonzini
2021-10-07 17:32 ` Thomas Huth
2021-10-07 20:42 ` Marc-André Lureau
2021-10-08 9:19 ` Paolo Bonzini
2021-10-07 13:06 ` [PATCH 02/24] audio: remove CONFIG_AUDIO_WIN_INT Paolo Bonzini
2021-10-07 20:42 ` Marc-André Lureau
2021-10-07 13:06 ` [PATCH 03/24] configure, meson: move audio driver detection to Meson Paolo Bonzini
2021-10-07 20:42 ` Marc-André Lureau
2021-10-07 13:06 ` [PATCH 04/24] meson: define symbols for all available audio drivers Paolo Bonzini
2021-10-07 13:06 ` [PATCH 05/24] configure: add command line options for " Paolo Bonzini
2021-10-07 20:42 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 06/24] kconfig: split CONFIG_SPARSE_MEM from fuzzing Paolo Bonzini
2021-10-07 13:48 ` Philippe Mathieu-Daudé
2021-10-07 20:42 ` Marc-André Lureau
2021-10-08 3:08 ` Alexander Bulekov
2021-10-07 13:08 ` [PATCH 07/24] configure, meson: move fuzzing configuration to Meson Paolo Bonzini
2021-10-08 3:10 ` Alexander Bulekov
2021-10-07 13:08 ` [PATCH 08/24] trace: simple: pass trace_file unmodified to config-host.h Paolo Bonzini
2021-10-07 20:42 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 09/24] trace: move configuration from configure to Meson Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 10/24] configure, meson: move CONFIG_HOST_DSOSUF " Paolo Bonzini
2021-10-07 13:44 ` Philippe Mathieu-Daudé
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 11/24] configure, meson: get HOST_WORDS_BIGENDIAN via the machine object Paolo Bonzini
2021-10-07 13:45 ` Philippe Mathieu-Daudé
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 12/24] configure, meson: remove CONFIG_GCOV from config-host.mak Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 13/24] configure, meson: move remaining HAVE_* compiler tests to Meson Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 14/24] configure, meson: move pthread_setname_np checks " Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 15/24] configure, meson: move libaio check to meson.build Paolo Bonzini
2021-10-07 19:24 ` Richard Henderson
2021-10-08 8:30 ` Paolo Bonzini
2021-10-08 8:47 ` Marc-André Lureau
2021-10-08 9:15 ` Paolo Bonzini
2021-10-07 13:08 ` [PATCH 16/24] configure, meson: move vde detection to meson Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 17/24] configure, meson: move netmap " Paolo Bonzini
2021-10-07 17:55 ` Thomas Huth
2021-10-07 13:08 ` [PATCH 18/24] configure, meson: move Spice configure handling " Paolo Bonzini
2021-10-07 13:08 ` [PATCH 19/24] configure: remove obsolete Solaris ar check Paolo Bonzini
2021-10-07 18:19 ` Thomas Huth
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 20/24] configure, meson: move more compiler checks to Meson Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 21/24] configure: remove deprecated --{enable, disable}-git-update Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 22/24] configure: accept "internal" for --enable-capstone/slirp/fdt Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-07 13:08 ` [PATCH 23/24] configure: prepare for auto-generated option parsing Paolo Bonzini
2021-10-07 16:53 ` Thomas Huth [this message]
2021-10-08 8:42 ` Paolo Bonzini
2021-10-07 13:08 ` [PATCH 24/24] configure: automatically parse command line for meson -D options Paolo Bonzini
2021-10-07 20:41 ` Marc-André Lureau
2021-10-08 8:43 ` Paolo Bonzini
2021-10-08 8:46 ` Marc-André Lureau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a1bdcb8f-8f37-a375-465b-a1bd0cc47d30@redhat.com \
--to=thuth@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).