meson icon indicating copy to clipboard operation
meson copied to clipboard

interpreter/mesonmain: Add build_options method

Open amyspark opened this issue 3 years ago • 6 comments

👋

This PR proposes adding a method, meson.build_options(), that allows meson.build to introspect on the changed options. It works by merely exposing the same set of data that is logged by MesonApp._generate.

Fixes #10898

amyspark avatar Oct 18 '22 22:10 amyspark

Would setup_options be a better function name? Not sure

tristan957 avatar Oct 18 '22 23:10 tristan957

It's missing doc and release notes, but I like the feature. I expect some people will want to get all options instead of just user defined options, but that can always be done later with a new kwargs.

Maybe we should return as an array of strings instead, I'm a bit afraid that people will pass that to some command lines, and escaping will be wrong.

xclaesse avatar Oct 19 '22 08:10 xclaesse

Maybe we should return as an array of strings instead, I'm a bit afraid that people will pass that to some command lines, and escaping will be wrong.

Absolutely positively under no circumstances ever.

In fact, this is a general reason why I'm uncomfortable with the feature in the first place -- it can be abused to attempt to use this to semantically parse it, when the only IMO valid use is as prose data e.g. formatted into a visually displayable string

I'd still be willing to add it as a feature because I agree that people do end up needing it. But we need to avoid the temptation to allow people to misuse it.

In fact, I wouldn't be sad if this didn't return a string at all, but only a confdata.set_quoted string guaranteed to be usable as a C string but probably nowhere else. The problem then becomes that people want to do the same thing in e.g. scipy.show_config()...

So we will probably just have to leave it as one long string, and leave people to use it correctly on the honor system.

If they despite that go ahead and use it in command lines with wrong quoting, then the appropriate solution is to scold them for using it in command lines, and tell them that we're sorry it took that long to break, we'll make sure to change the internal implementation details of that string on a regular basis in order to teach them a lesson about relying on it in the future. /s

We have actual API for checking options, taking something that was designed for human readability instead is pretty wrong.

eli-schwartz avatar Oct 19 '22 08:10 eli-schwartz

setup_options

@tristan957 It's inconsistent with https://github.com/mesonbuild/meson/blob/212af2b278f6cd58b17cabbff4883b5258601a6c/mesonbuild/msetup.py#L196

In fact, I wouldn't be sad if this didn't return a string at all, but only a confdata.set_quoted string guaranteed to be usable as a C string but probably nowhere else. The problem then becomes that people want to do the same thing in e.g. scipy.show_config()...

@eli-schwartz At present, use of set_quoted is required, I've made no attempt to escape any special characters.

It's missing doc and release notes, but I like the feature. I expect some people will want to get all options instead of just user defined options, but that can always be done later with a new kwargs.

@xclaesse Just added the relevant docs.

amyspark avatar Oct 28 '22 16:10 amyspark

Codecov Report

Merging #10930 (1239556) into master (b2473b6) will increase coverage by 2.97%. The diff coverage is n/a.

:exclamation: Current head 1239556 differs from pull request most recent head 5a91ded. Consider uploading reports for the commit 5a91ded to get more accurate results

@@            Coverage Diff             @@
##           master   #10930      +/-   ##
==========================================
+ Coverage   65.81%   68.79%   +2.97%     
==========================================
  Files         414      207     -207     
  Lines       90654    45340   -45314     
  Branches    20126     9379   -10747     
==========================================
- Hits        59665    31191   -28474     
+ Misses      26476    11752   -14724     
+ Partials     4513     2397    -2116     
Impacted Files Coverage Δ
utils/posix.py 80.95% <0.00%> (-19.05%) :arrow_down:
interpreter/mesonmain.py 96.53% <0.00%> (-0.62%) :arrow_down:
compilers/mixins/gnu.py 82.32% <0.00%> (-0.29%) :arrow_down:
modules/python.py 69.76% <0.00%> (-0.22%) :arrow_down:
mesonbuild/build.py
mesonbuild/compilers/mixins/gnu.py
mesonbuild/interpreter/mesonmain.py
mesonbuild/utils/posix.py
mesonbuild/compilers/mixins/clike.py
mesonbuild/templates/cstemplates.py
... and 201 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov[bot] avatar Oct 28 '22 17:10 codecov[bot]

(The doc changes can be grouped together with the commit adding the functionality.)

eli-schwartz avatar Nov 14 '22 00:11 eli-schwartz

I suppose this will have to be updated for whatever the next release will be, but any chance this could make it in? I'm actually looking exactly for this feature.

Dudemanguy avatar Jan 13 '23 18:01 Dudemanguy

@tristan957 @jpakkane please let me know if this can be merged?

amyspark avatar Jan 20 '23 21:01 amyspark

I am not someone that can click merge.

tristan957 avatar Jan 20 '23 22:01 tristan957

@amyspark: sorry gentle ping in case you didn't see my review earlier. I'm not someone who can merge this, but as far as I know there's literally only a one line change needed.

Dudemanguy avatar Feb 10 '23 16:02 Dudemanguy