Automatically convert configure options to meson build options
Subsystems (2)
cover Automatically convert configure options to meson build options
Right now meson_options.txt lists less than a dozen options, but about 40 more could come as configure tests are converted and moved to meson.build. Each option needs code in configure to parse it and pass the option down to Meson as a -D command-line argument; in addition the default must be duplicated between configure and meson_options.txt.
This series tries to remove the code duplication by passing unknown --enable and --disable options to a Python program, and using Meson's introspection support to match those to meson_options.txt
The disadvantages are:
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
- we now need Python to generate the full help, so if Python is missing we can only print a partial message and direct the user to specify the interpreter with --python. It would be possible to fix this by rewriting the script in Perl (at least on Fedora, JSON::PP is always installed if Perl is, because it's a dependency for CPAN; I'd have to check Ubuntu and the BSDs), or if we want to write it as a Bourne shell script, to further massage the introspection output into for example TAB-separated values.
Opinions are welcome on whether this is worthwhile and how to solve the above doubts.
Paolo
Paolo Bonzini (3):
configure: quote command line arguments in config.status
configure: early test for Python
configure: automatically parse command line for meson -D options
Makefile | 6 ++ configure | 107 ++++++++----------- docs/devel/build-system.rst | 35 +------ meson-buildoptions.json | 130 ++++++++++++++++++++++++ scripts/configure-parse-buildoptions.py | 94 +++++++++++++++++ 5 files changed, 280 insertions(+), 92 deletions(-) create mode 100644 meson-buildoptions.json create mode 100644 scripts/configure-parse-buildoptions.py
Signature · 1 line
2.26.2
PATCH 1/3 configure: quote command line arguments in config.status
--- configure | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
configure +5 -1
@@ -89,6 +89,10 @@ printf " '%s'" "$0" "$@" >> config.log echo >> config.log echo "#" >> config.log +quote_sh() { + printf "'%s'" "$(echo "$1" | sed "s,','\\',")" +} + print_error() { (echo echo "ERROR: $1"
@@ -8061,7 +8065,7 @@ preserve_env WINDRES printf "exec" >>config.status for i in "$0" "$@"; do - test "$i" = --skip-meson || printf " '%s'" "$i" >>config.status + test "$i" = --skip-meson || printf " %s" "$(quote_sh $i)" >>config.status done echo ' "$@"' >>config.status chmod +x config.status
Signature · 1 line
2.26.2
Re: [PATCH 1/3] configure: quote command line arguments in config.status
Quoted 10 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- configure | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)configure +0
-0
configure printf " '%s'" "$0" "$@" >> config.log · line 93
Quoted 5 lines
configure +2
-0@@ -89,6 +89,10 @@ printf " '%s'" "$0" "$@" >> config.log echo >> config.log echo "#" >> config.log +quote_sh() { + printf "'%s'" "$(echo "$1" | sed "s,','\\',")"
This is unsafe if $1 starts with - or contains \. Better is using printf. It also eats any trailing newlines in $1, although that may be less of a concern.
configure preserve_env WINDRES · line 8068
Quoted 11 lines
configure +3
-1+} + print_error() { (echo echo "ERROR: $1"@@ -8061,7 +8065,7 @@ preserve_env WINDRES printf "exec" >>config.status for i in "$0" "$@"; do - test "$i" = --skip-meson || printf " '%s'" "$i" >>config.status + test "$i" = --skip-meson || printf " %s" "$(quote_sh $i)" >>config.status
And this unquoted use of $i is wrong.
Quoted 4 lines
configure +0
-0done echo ' "$@"' >>config.status chmod +x config.status
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 2/3 configure: early test for Python
In reply to Paolo Bonzini--- configure | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
configure +17 -13
@@ -1631,6 +1631,23 @@ for opt do esac done +if test -n "$python" +then + # Preserve python version since some functionality is dependent on it + python_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null) + + # Suppress writing compiled files + python="$python -B" + + # Note that if the Python conditional here evaluates True we will exit + # with status 1 which is a shell 'false' value. + if ! $python -c 'import sys; sys.exit(sys.version_info < (3,5))'; then + print_error "Cannot use '$python', Python >= 3.5 is required." \ + "Use --python=/path/to/python to specify a supported Python." + python= + fi +fi + firmwarepath="${firmwarepath:-$prefix/share/qemu-firmware}" libdir="${libdir:-$prefix/lib}" libexecdir="${libexecdir:-$prefix/libexec}"
@@ -1962,19 +1979,6 @@ then error_exit "Python not found. Use --python=/path/to/python" fi -# Note that if the Python conditional here evaluates True we will exit -# with status 1 which is a shell 'false' value. -if ! $python -c 'import sys; sys.exit(sys.version_info < (3,5))'; then - error_exit "Cannot use '$python', Python >= 3.5 is required." \ - "Use --python=/path/to/python to specify a supported Python." -fi - -# Preserve python version since some functionality is dependent on it -python_version=$($python -c 'import sys; print("%d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2]))' 2>/dev/null) - -# Suppress writing compiled files -python="$python -B" - if test -z "$meson"; then if test "$explicit_python" = no && has meson && version_ge "$(meson --version)" 0.55.1; then meson=meson
Signature · 1 line
2.26.2
PATCH 3/3 configure: automatically parse command line for meson -D options
In reply to Paolo Bonzini--- Makefile | 6 ++ configure | 71 +++++-------- docs/devel/build-system.rst | 35 +------ meson-buildoptions.json | 130 ++++++++++++++++++++++++ scripts/configure-parse-buildoptions.py | 94 +++++++++++++++++ 5 files changed, 258 insertions(+), 78 deletions(-) create mode 100644 meson-buildoptions.json create mode 100644 scripts/configure-parse-buildoptions.py
Makefile +6 -0
@@ -80,6 +80,12 @@ ifneq ($(MESON),) Makefile.mtest: build.ninja scripts/mtest2make.py $(MESON) introspect --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@ -include Makefile.mtest + +# jq is used to keep the result stable +meson-buildoptions.json: meson_options.txt + $(MESON) introspect --buildoptions . | \ + jq 'map(select(.section == "user")) | sort_by(.name)' \ + > $(SRC_PATH)/meson-buildoptions.json endif Makefile: .git-submodule-status
configure +24 -48
166 lines not on this page · raw message
docs/devel/build-system.rst +5 -30
@@ -52,12 +52,6 @@ following tasks: - Add a Meson build option to meson_options.txt. - - Add support to the command line arg parser to handle any new - `--enable-XXX`/`--disable-XXX` flags required by the feature. - - - Add information to the help output message to report on the new - feature flag. - - Add code to perform the actual feature check. - Add code to include the feature status in `config-host.h`
@@ -66,30 +60,6 @@ following tasks: upon completion. -Taking the probe for SDL2_Image as an example, we have the following pieces -in configure:: - - # Initial variable state - sdl_image=auto - - ..snip.. - - # Configure flag processing - --disable-sdl-image) sdl_image=disabled - ;; - --enable-sdl-image) sdl_image=enabled - ;; - - ..snip.. - - # Help output feature message - sdl-image SDL Image support for icons - - ..snip.. - - # Meson invocation - -Dsdl_image=$sdl_image - In meson_options.txt:: option('sdl', type : 'feature', value : 'auto',
@@ -108,6 +78,11 @@ In meson.build:: # Summary summary_info += {'SDL image support': sdl_image.found()} +The configure script automatically converts command line options to +Meson options as long as the `meson-buildoptions.json` file in the +root source directory is up-to-date. You can simply type +`make meson-buildoptions.json` to update it; the `jq` program +is needed. Helper functions
meson-buildoptions.json new file +130 -0
130 lines not on this page · raw message
scripts/configure-parse-buildoptions.py new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH 3/3] configure: automatically parse command line for meson -D options
Quoted 16 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- Makefile | 6 ++ configure | 71 +++++-------- docs/devel/build-system.rst | 35 +------ meson-buildoptions.json | 130 ++++++++++++++++++++++++ scripts/configure-parse-buildoptions.py | 94 +++++++++++++++++ 5 files changed, 258 insertions(+), 78 deletions(-)create mode 100644 meson-buildoptions.json create mode 100644
scripts/configure-parse-buildoptions.pyMakefile +0
-0
Makefile ifneq ($(MESON),) · line 88
Quoted 9 lines
Makefile +6
-0@@ -80,6 +80,12 @@ ifneq ($(MESON),) Makefile.mtest: build.ninja scripts/mtest2make.py $(MESON) introspect --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@ -include Makefile.mtest + +# jq is used to keep the result stable +meson-buildoptions.json: meson_options.txt + $(MESON) introspect --buildoptions . | \ + jq 'map(select(.section == "user")) | sort_by(.name)' \ + > $(SRC_PATH)/meson-buildoptions.json
Are we guaranteed to have jq on the system? This appears to be the first use of it in qemu.git.
Makefile In meson.build:: · line 85
Quoted 9 lines
Makefile +5
-0@@ -108,6 +78,11 @@ In meson.build:: # Summary summary_info += {'SDL image support': sdl_image.found()} +The configure script automatically converts command line options to +Meson options as long as the `meson-buildoptions.json` file in the +root source directory is up-to-date. You can simply type +`make meson-buildoptions.json` to update it; the `jq` program +is needed.
Oh, you're using it for an optional step, that most people don't have to run, but where a developer needing to regenerate things can be likely to understand how to get it.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 21 lines · Paolo Bonzini
Right now meson_options.txt lists less than a dozen options, but about 40 more could come as configure tests are converted and moved to meson.build. Each option needs code in configure to parse it and pass the option down to Meson as a -D command-line argument; in addition the default must be duplicated between configure and meson_options.txt.
This series tries to remove the code duplication by passing unknown --enable and --disable options to a Python program, and using Meson's introspection support to match those to meson_options.txt
The disadvantages are:
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
Quoted 9 lines
- we now need Python to generate the full help, so if Python is missing we can only print a partial message and direct the user to specify the interpreter with --python. It would be possible to fix this by rewriting the script in Perl (at least on Fedora,
JSON::PPis always installed if Perl is, because it's a dependency for CPAN; I'd have to check Ubuntu and the BSDs), or if we want to write it as a Bourne shell script, to further massage the introspection output into for example TAB-separated values.
I am confusing about this? we were converting configure to meson, and python is a
force dependencies, why we need rewrite the script in Perl? If we wanna build qemu, the first thing
we need to install is python+meson, so there is no need convert to Perl or bash script.
And perl/bash will incur msys2/mingw user, the ideal way is we only depends on python+meson to building qemu
Quoted 25 lines
Opinions are welcome on whether this is worthwhile and how to solve the above doubts.
Paolo
Paolo Bonzini (3):
configure: quote command line arguments in config.status
configure: early test for Python
configure: automatically parse command line for meson -D optionsMakefile | 6 ++ configure | 107 ++++++++----------- docs/devel/build-system.rst | 35 +------ meson-buildoptions.json | 130 ++++++++++++++++++++++++ scripts/configure-parse-buildoptions.py | 94 +++++++++++++++++ 5 files changed, 280 insertions(+), 92 deletions(-) create mode 100644 meson-buildoptions.json create mode 100644 scripts/configure-parse-buildoptions.py--
2.26.2
Signature · 6 lines
此致
礼
罗勇刚
Yours
sincerely,
Yonggang LuoQuoted 7 lines · 罗勇刚(Yonggang Luo)
I am confusing about this? we were converting configure to meson, and python is a force dependencies, why we need rewrite the script in Perl? If we wanna build qemu, the first thing we need to install is python+meson, so there is no need convert to Perl or bash script. And perl/bash will incur msys2/mingw user, the ideal way is we only depends on python+meson to building qemu
The main issue is that the Python interpreter is any of python, python3, python3.5. Furthermore Meson's shebang python is not necessarily the first "python3" in the path.
Perl is pretty much always "/usr/bin/env perl". Note that Perl is already needed to run "make check". When/if it will be possible to only build QEMU with python+meson there will be no configure script anymore, so Perl is a reasonable choice for parsing the configure command line options. It wasn't my first choice, in fact this series includes a Python implementation, but it does have some advantages.
Paolo
Quoted 21 lines · Paolo Bonzini
Right now meson_options.txt lists less than a dozen options, but about 40 more could come as configure tests are converted and moved to meson.build. Each option needs code in configure to parse it and pass the option down to Meson as a -D command-line argument; in addition the default must be duplicated between configure and meson_options.txt.
This series tries to remove the code duplication by passing unknown --enable and --disable options to a Python program, and using Meson's introspection support to match those to meson_options.txt
The disadvantages are:
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
Quoted 8 lines
- we now need Python to generate the full help, so if Python is missing we can only print a partial message and direct the user to specify the interpreter with --python. It would be possible to fix this by rewriting the script in Perl (at least on Fedora,
JSON::PPis always installed if Perl is, because it's a dependency for CPAN; I'd have to check Ubuntu and the BSDs), or if we want to write it as a Bourne shell script, to further massage the introspection output into for example TAB-separated values.
IMHO we should stay as far away from Perl as possible, and I say this as someone who enjoys writing Perl scripts ! Perl is a significant barrier to entry for potential contributors, because it just doesn't have the wide knowledge base that it did in the past. You can expect most people to have some familiarity with Python, or be able to pick it up fairly easily in a way that just isn't possible in Perl.
As for shell, we have a never ending stream of bugs due to the wide range of different shell impls which make portable coding very hard.
In general I think our overall goal should be to focus on getting down to use of a single scripting language in QEMU, and that language clearly has to be python3. We shouldn't introduce any new usage of Perl or Shell in QEMU IMHO. Even if we think the usage will only be short term temporary workaround, short term hacks in QEMU have a habit of living for years longer than we expect.
Quoted 2 lines
Opinions are welcome on whether this is worthwhile and how to solve the above doubts.
IIUC, the motivation of this series is just to remove some duplication of defaults / args, nothing more than that ?
If correct, then I'd say it probably isn't worth the hassle. I'd say we should focus effort on just converting more of configure to meson, as quickly as practical, and not try to add much more magic that's only relevant for the transition time.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 10 lines · Daniel P. Berrangé
IMHO we should stay as far away from Perl as possible, and I say this as someone who enjoys writing Perl scripts ! Perl is a significant barrier to entry for potential contributors, because it just doesn't have the wide knowledge base that it did in the past. You can expect most people to have some familiarity with Python, or be able to pick it up fairly easily in a way that just isn't possible in Perl.
As for shell, we have a never ending stream of bugs due to the wide range of different shell impls which make portable coding very hard.
Quoted 6 lines
In general I think our overall goal should be to focus on getting down to use of a single scripting language in QEMU, and that language clearly has to be python3. We shouldn't introduce any new usage of Perl or Shell in QEMU IMHO. Even if we think the usage will only be short term temporary workaround, short term hacks in QEMU have a habit of living for years longer than we expect.
I totally agree. This would not be a short term workaround, I expect it to stay for years; I don't expect the transition of the configure script to Meson to be very short.
This can be both a pro and a con. On one hand it means this is "more magic" that is here to stay. On the other hand it makes transition patches smaller and easier to review.
I agree that in principle all scripting should be Python. On the other hand Perl is quite suitable for "configure tasks that are too complicated for shell" and are not going to be rewritten in Meson down the road. And I say that as someone who has written exactly 3 serious Perl programs in his life, two of which are part of QEMU. :)
In this case shell scripting could also be a plausible alternative; I didn't try only because I first tried the obvious choice of Python.
Or we can just decide that an incomplete help below a "please use --python" error is good enough.
Quoted 5 lines
Quoted 2 lines
Opinions are welcome on whether this is worthwhile and how to solve the above doubts.
IIUC, the motivation of this series is just to remove some duplication of defaults / args, nothing more than that ?
Yes, though it's quite some duplication: right now an option needs
- a default in configure
- command line parsing in configure
- a Meson -D argument in configure
- an help message in configure
- a declaration (including default and help) in meson_options.txt
so this patch reduces an option from 8-9 lines to 2.
There are a couple secondary goals too. First, making sure all the policy is in meson_options.txt and not configure; this avoids surprises when/if we can start invoking meson directly. Second, removing variables completely from the configure script gives a better idea of interdependencies between the configure tests.
Thanks,
Paolo
Quoted 3 lines
I'd say we should focus effort on just converting more of configure to meson, as quickly as practical, and not try to add much more magic that's only relevant for the transition time.
Quoted 8 lines · Paolo Bonzini
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
Does this add a build dependency on jq? Is it possible to use a Python script or even a command-line one-liner instead?
Quoted 11 lines · Stefan Hajnoczi
Quoted 8 lines · Paolo Bonzini
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
Quoted 2 lines
Does this add a build dependency on jq? Is it possible to use a Python script or even a command-line one-liner instead?
What's jq stands for, is that a perl script?
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
Quoted 12 lines · 罗勇刚(Yonggang Luo)
Quoted 11 lines · Stefan Hajnoczi
Quoted 8 lines · Paolo Bonzini
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
Quoted 3 lines
Quoted 2 lines
Does this add a build dependency on jq? Is it possible to use a Python script or even a command-line one-liner instead?
What's jq stands for, is that a perl script?
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Paolo Bonzini
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
Quoted 2 lines
Does this add a build dependency on jq? Is it possible to use a Python script or even a command-line one-liner instead?
No, only developers need jq and only if they add configure options. Using Python would certainly be possible, though probably it wouldn't be a one-liner as for jq.
Paolo
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · Paolo Bonzini
- because we parse command-line options before meson is available, the introspection output is stored in the source tree. The output is slightly modified using the "jq" tool in order to ensure that it's stable and that modifications to meson_buildoptions.txt do not cause horrible conflicts. This is the main reason for the unattractive diffstat (the number of JSON lines added is higher than the number of configure lines removed, though of course the latter are code that must be maintained manually and the former is not).
Quoted 6 lines
Quoted 2 lines
Does this add a build dependency on jq? Is it possible to use a Python script or even a command-line one-liner instead?
No, only developers need jq and only if they add configure options. Using Python would certainly be possible, though probably it wouldn't be a one-liner as for jq.
I see. Avoiding the dependency would be nice but only if the alternative is reasonable.
Stefan
Quoted 5 lines · Stefan Hajnoczi
Quoted 3 lines
No, only developers need jq and only if they add configure options. Using Python would certainly be possible, though probably it wouldn't be a one-liner as for jq.
I see. Avoiding the dependency would be nice but only if the alternative is reasonable.
I guess this counts as reasonable:
python3 -c 'import json, sys; print(
json.dumps(sorted([x for x in json.loads(sys.stdin.read())
if x["section"] == "user"], key=lambda x: x["name"]),
indent=2))'Paolo