qemu/scripts/meson-buildoptions.py
Paolo Bonzini 61d63097be configure: prepare for auto-generated option parsing
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.

Tested-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20211007130829.632254-18-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-10-14 09:50:57 +02:00

65 lines
1.8 KiB
Python
Executable file

#! /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))
print("# This file is generated by meson-buildoptions.py, do not edit!")
print_help(options)
print_parse(options)