qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com
Subject: [PATCH v2 15/34] meson-buildoptions: add support for string options
Date: Sat, 23 Apr 2022 14:51:32 +0200	[thread overview]
Message-ID: <20220423125151.27821-16-pbonzini@redhat.com> (raw)
In-Reply-To: <20220423125151.27821-1-pbonzini@redhat.com>

Allow using the buildoptions.json file for more options, namely anything
that is not a boolean or multiple-choice.

The mapping between configure and meson is messy for string options,
so allow configure to use to something other than the name in
meson_options.txt.  This will come in handy anyway for builtin
Meson options such as b_lto or b_coverage.

Tested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 meson_options.txt             |  2 +-
 scripts/meson-buildoptions.py | 65 ++++++++++++++++++++++++++++++-----
 scripts/meson-buildoptions.sh |  6 ++--
 3 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/meson_options.txt b/meson_options.txt
index cf18663833..415fcc448e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -11,7 +11,7 @@ option('qemu_firmwarepath', type : 'string', value : '',
 option('smbd', type : 'string', value : '',
        description: 'Path to smbd for slirp networking')
 option('sphinx_build', type : 'string', value : '',
-       description: 'Use specified sphinx-build [$sphinx_build] for building document (default to be empty)')
+       description: 'Use specified sphinx-build for building document')
 option('iasl', type : 'string', value : '',
        description: 'Path to ACPI disassembler')
 option('default_devices', type : 'boolean', value : true,
diff --git a/scripts/meson-buildoptions.py b/scripts/meson-buildoptions.py
index 693be7b966..4af8d6e732 100755
--- a/scripts/meson-buildoptions.py
+++ b/scripts/meson-buildoptions.py
@@ -38,6 +38,11 @@
     "trace_file",
 }
 
+OPTION_NAMES = {
+    "malloc": "enable-malloc",
+    "trace_backends": "enable-trace-backends",
+}
+
 BUILTIN_OPTIONS = {
     "strip",
 }
@@ -75,7 +80,7 @@ def help_line(left, opt, indent, long):
     right = f'{opt["description"]}'
     if long:
         value = value_to_help(opt["value"])
-        if value != "auto":
+        if value != "auto" and value != "":
             right += f" [{value}]"
     if "choices" in opt and long:
         choices = "/".join(sorted(opt["choices"]))
@@ -96,6 +101,18 @@ def allow_arg(opt):
     return not (set(opt["choices"]) <= {"auto", "disabled", "enabled"})
 
 
+# Return whether the option (a dictionary) can be used without
+# arguments.  Booleans can only be used without arguments;
+# combos require an argument if they accept neither "enabled"
+# nor "disabled"
+def require_arg(opt):
+    if opt["type"] == "boolean":
+        return False
+    if opt["type"] != "combo":
+        return True
+    return not ({"enabled", "disabled"}.intersection(opt["choices"]))
+
+
 def filter_options(json):
     if ":" in json["name"]:
         return False
@@ -110,20 +127,48 @@ def load_options(json):
     return sorted(json, key=lambda x: x["name"])
 
 
+def cli_option(opt):
+    name = opt["name"]
+    if name in OPTION_NAMES:
+        return OPTION_NAMES[name]
+    return name.replace("_", "-")
+
+
+def cli_help_key(opt):
+    key = cli_option(opt)
+    if require_arg(opt):
+        return key
+    if opt["type"] == "boolean" and opt["value"]:
+        return f"disable-{key}"
+    return f"enable-{key}"
+
+
+def cli_metavar(opt):
+    if opt["type"] == "string":
+        return "VALUE"
+    if opt["type"] == "array":
+        return "CHOICES"
+    return "CHOICE"
+
+
 def print_help(options):
     print("meson_options_help() {")
-    for opt in options:
-        key = opt["name"].replace("_", "-")
+    for opt in sorted(options, key=cli_help_key):
+        key = cli_help_key(opt)
         # The first section includes options that have an arguments,
         # and booleans (i.e., only one of enable/disable makes sense)
-        if opt["type"] == "boolean":
-            left = f"--disable-{key}" if opt["value"] else f"--enable-{key}"
+        if require_arg(opt):
+            metavar = cli_metavar(opt)
+            left = f"--{key}={metavar}"
+            help_line(left, opt, 27, True)
+        elif opt["type"] == "boolean":
+            left = f"--{key}"
             help_line(left, opt, 27, False)
         elif allow_arg(opt):
             if opt["type"] == "combo" and "enabled" in opt["choices"]:
-                left = f"--enable-{key}[=CHOICE]"
+                left = f"--{key}[=CHOICE]"
             else:
-                left = f"--enable-{key}=CHOICE"
+                left = f"--{key}=CHOICE"
             help_line(left, opt, 27, True)
 
     sh_print()
@@ -142,9 +187,11 @@ def print_parse(options):
     print("_meson_option_parse() {")
     print("  case $1 in")
     for opt in options:
-        key = opt["name"].replace("_", "-")
+        key = cli_option(opt)
         name = opt["name"]
-        if opt["type"] == "boolean":
+        if require_arg(opt):
+            print(f'    --{key}=*) quote_sh "-D{name}=$2" ;;')
+        elif opt["type"] == "boolean":
             print(f'    --enable-{key}) printf "%s" -D{name}=true ;;')
             print(f'    --disable-{key}) printf "%s" -D{name}=false ;;')
         else:
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index a269534394..5a06b7915c 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -1,5 +1,7 @@
 # This file is generated by meson-buildoptions.py, do not edit!
 meson_options_help() {
+  printf "%s\n" '  --disable-coroutine-pool coroutine freelist (better performance)'
+  printf "%s\n" '  --disable-install-blobs  install provided firmware blobs'
   printf "%s\n" '  --enable-block-drv-whitelist-in-tools'
   printf "%s\n" '                           use block whitelist also in tools instead of only'
   printf "%s\n" '                           QEMU'
@@ -8,7 +10,6 @@ meson_options_help() {
   printf "%s\n" '                           (choices: auto/disabled/enabled/internal/system)'
   printf "%s\n" '  --enable-cfi             Control-Flow Integrity (CFI)'
   printf "%s\n" '  --enable-cfi-debug       Verbose errors in case of CFI violation'
-  printf "%s\n" '  --disable-coroutine-pool coroutine freelist (better performance)'
   printf "%s\n" '  --enable-debug-mutex     mutex debugging support'
   printf "%s\n" '  --enable-debug-stack-usage'
   printf "%s\n" '                           measure coroutine stack usage'
@@ -16,7 +17,6 @@ meson_options_help() {
   printf "%s\n" '                           (choices: auto/disabled/enabled/internal/system)'
   printf "%s\n" '  --enable-fuzzing         build fuzzing targets'
   printf "%s\n" '  --enable-gprof           QEMU profiling with gprof'
-  printf "%s\n" '  --disable-install-blobs  install provided firmware blobs'
   printf "%s\n" '  --enable-malloc=CHOICE   choose memory allocator to use [system] (choices:'
   printf "%s\n" '                           jemalloc/system/tcmalloc)'
   printf "%s\n" '  --enable-module-upgrades try to load modules from alternate paths for'
@@ -29,7 +29,7 @@ meson_options_help() {
   printf "%s\n" '                           (choices: auto/disabled/enabled/internal/system)'
   printf "%s\n" '  --enable-strip           Strip targets on install'
   printf "%s\n" '  --enable-tcg-interpreter TCG with bytecode interpreter (slow)'
-  printf "%s\n" '  --enable-trace-backends=CHOICE'
+  printf "%s\n" '  --enable-trace-backends=CHOICES'
   printf "%s\n" '                           Set available tracing backends [log] (choices:'
   printf "%s\n" '                           dtrace/ftrace/log/nop/simple/syslog/ust)'
   printf "%s\n" ''
-- 
2.35.1




  parent reply	other threads:[~2022-04-23 13:11 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-23 12:51 [PATCH v2 00/34] Misc meson conversions for QEMU 7.1 Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 01/34] meson: show final set of compiler flags Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 02/34] configure: remove dead code Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 03/34] qga: wixl: get path to sysroot from pkg-config as intended Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 04/34] configure: pc-bios/qemu-icon.bmp does not exist Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 05/34] configure: gcov should not exclude fortify-source Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 06/34] configure: move --enable/--disable-debug-info to second option parsing pass Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 07/34] configure, meson: move OpenGL check to meson Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 08/34] meson, configure: move RDMA options " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 09/34] meson, configure: move keyctl test " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 10/34] meson, configure: move usbfs " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 11/34] meson, configure: move libgio " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 12/34] meson: remove CONFIG_XEN_PCI_PASSTHROUGH from config-target.h Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 13/34] meson, configure: move --enable-module-upgrades to meson Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 14/34] meson, configure: move Xen detection " Paolo Bonzini
2022-04-23 12:51 ` Paolo Bonzini [this message]
2022-04-23 12:51 ` [PATCH v2 16/34] configure, meson: move iasl " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 17/34] configure: move Windows flags " Paolo Bonzini
2022-04-24 12:33   ` Marc-André Lureau
2022-04-23 12:51 ` [PATCH v2 18/34] configure: switch string options to automatic parsing Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 19/34] meson, configure: move --tls-priority to meson Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 20/34] meson, configure: move bdrv whitelists " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 21/34] meson, configure: move --with-pkgversion, CONFIG_STAMP " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 22/34] meson, configure: move --interp-prefix " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 23/34] meson: always combine directories with prefix Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 24/34] configure: switch directory options to automatic parsing Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 25/34] meson: pass more options directly as -D Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 26/34] configure: omit options with default values from meson command line Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 27/34] meson, virtio: place all virtio-pci devices under virtio_pci_ss Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 28/34] configure: simplify vhost-net-{user, vdpa} configuration Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 29/34] build: move vhost-vsock configuration to Kconfig Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 30/34] build: move vhost-scsi " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 31/34] build: move vhost-user-fs " Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 32/34] meson: create have_vhost_* variables Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 33/34] meson: use have_vhost_* variables to pick sources Paolo Bonzini
2022-04-23 12:51 ` [PATCH v2 34/34] configure, meson: move vhost options to Meson Paolo Bonzini

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=20220423125151.27821-16-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=marcandre.lureau@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).