meson icon indicating copy to clipboard operation
meson copied to clipboard

glib fails to configure with KeyError: Tried to access nonexistant project parent option b_vscrt.

Open tp-m opened this issue 11 months ago • 10 comments

Option refactor regression I presume.

$ git clone https://gitlab.gnome.org/GNOME/glib.git

$ cd glib

$ ~/Devel/meson/meson.py setup b
The Meson build system
Version: 1.7.99
Source dir: /tmp/glib
Build dir: /tmp/glib/b
Build type: native build
Project name: glib
Project version: 2.83.3
C compiler for the host machine: ccache cc (gcc 14.2.0 "cc (Debian 14.2.0-14) 14.2.0")
C linker for the host machine: cc ld.bfd 2.43.90.20250122
Host machine cpu family: x86_64
Host machine cpu: x86_64
Compiler for C supports arguments -std=c89: YES 
Compiler for C supports arguments -std=c99: YES 
Compiler for C supports arguments -std=c11: YES 
Compiler for C supports arguments -std=c17: YES 
C++ compiler for the host machine: ccache c++ (gcc 14.2.0 "c++ (Debian 14.2.0-14) 14.2.0")
C++ linker for the host machine: c++ ld.bfd 2.43.90.20250122
Compiler for C++ supports arguments -std=c++98: YES 
Compiler for C++ supports arguments -std=c++03: YES 
Compiler for C++ supports arguments -std=c++11: YES 
Compiler for C++ supports arguments -std=c++14: YES 
Compiler for C++ supports arguments -std=c++17: YES 
Compiler for C++ supports arguments -std=c++20: YES 
Compiler for C++ supports arguments -std=c++2b: YES 
Compiler for C++ supports arguments -std=c++latest: NO 
Checking if "building for musl libc" compiles: NO 
Program ./.gitlab-ci/thorough-test-wrapper.sh found: YES (/bin/bash /tmp/glib/./.gitlab-ci/thorough-test-wrapper.sh)
Program valgrind found: YES (/usr/bin/valgrind)
Compiler for C supports arguments -fno-strict-aliasing: YES 
Traceback (most recent call last):
  File "/home/tpm/Devel/meson/mesonbuild/mesonmain.py", line 193, in run
    return options.run_func(options)
           ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/msetup.py", line 407, in run
    app.generate()
    ~~~~~~~~~~~~^^
  File "/home/tpm/Devel/meson/mesonbuild/msetup.py", line 189, in generate
    return self._generate(env, capture, vslite_ctx)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/msetup.py", line 266, in _generate
    intr.run()
    ~~~~~~~~^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreter/interpreter.py", line 3061, in run
    super().run()
    ~~~~~~~~~~~^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 169, in run
    self.evaluate_codeblock(self.ast, start=1)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 194, in evaluate_codeblock
    raise e
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 186, in evaluate_codeblock
    self.evaluate_statement(cur)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 204, in evaluate_statement
    self.assignment(cur)
    ~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 641, in assignment
    value = self.evaluate_statement(node.value)
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 200, in evaluate_statement
    return self.function_call(cur)
           ~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 527, in function_call
    res = func(node, func_args, kwargs)
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/decorators.py", line 237, in wrapper
    return f(*nargs, **wrapped_kwargs)
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/decorators.py", line 62, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/home/tpm/Devel/meson/mesonbuild/interpreter/interpreter.py", line 1083, in func_get_option
    value_object, value = self.coredata.optstore.get_option_from_meson_file(options.OptionKey(optname, self.subproject))
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/options.py", line 1101, in get_option_from_meson_file
    (value_object, value) = self.get_value_object_and_value_for(key)
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/options.py", line 832, in get_value_object_and_value_for
    vobject = self.get_value_object_for(key)
  File "/home/tpm/Devel/meson/mesonbuild/options.py", line 826, in get_value_object_for
    raise KeyError(f'Tried to access nonexistant project parent option {parent_key}.')
KeyError: 'Tried to access nonexistant project parent option b_vscrt.'

meson.build:365:13: ERROR: Unhandled python exception

    This is a Meson bug and should be reported!

tp-m avatar Feb 15 '25 00:02 tp-m

That is caused by this line in the main meson.build

vs_crt_opt = get_option('b_vscrt')

It is unconditionally asking for that option, even though it is only defined on Windows platforms. I checked version 1.7.0 and meson configure does not list b_vscrt at all. To be fair I have no idea how this could possibly have worked before.

jpakkane avatar Feb 17 '25 18:02 jpakkane

That is caused by this line in the main meson.build

vs_crt_opt = get_option('b_vscrt')

It is unconditionally asking for that option, even though it is only defined on Windows platforms. I checked version 1.7.0 and meson configure does not list b_vscrt at all. To be fair I have no idea how this could possibly have worked before.

In 1.6.1 it returns from_buildtype which is documented as the default value.

The documentation says

The following options are available. Note that they may not be available on all platforms or with all compilers:

but does not say for each option on which platforms and with which compilers they might be available.

I am not sure if it's really reasonable to expect Meson users to just "know" what's what in this case, especially if a reasonable default value is available that was returned on Linux/with gcc before.

If it's not too much hassle we should probably add a column to the documentation with more info for each option and make this work with a warning for another release or three?

tp-m avatar Feb 17 '25 23:02 tp-m

Checking for this would be so tedious, it’s not just a question of “what is my platform”, but what are both my host and build compilers, since either of them could be msvc and enable this.

dcbaker avatar Feb 18 '25 01:02 dcbaker

If we really want to not populate these in meson 2.0 we could move to a fallback parameter, and of the fallback isn’t provided then it errors, but that’s still a breaking change and would have to go through a proper deprecation cycle

dcbaker avatar Feb 18 '25 01:02 dcbaker

@jpakkane It was intentional to allow getting b_* regardless of the platform/compiler, to make it easier to deal in meson.build.

xclaesse avatar Feb 20 '25 14:02 xclaesse

The code we used to have:

    def get_option_internal(self, optname: str) -> options.UserOption:
        key = OptionKey.from_string(optname).evolve(subproject=self.subproject)

        if not self.environment.coredata.optstore.is_project_option(key):
            for opts in [self.coredata.optstore, compilers.base_options]:
                v = opts.get(key)
                if v is None or v.yielding:
                    v = opts.get(key.as_root())
                if v is not None:
                    assert isinstance(v, options.UserOption), 'for mypy'
                    return v

Notice that it lookup into compilers.base_options that defines ALL b_ options.

xclaesse avatar Feb 20 '25 15:02 xclaesse

Fixed

bonzini avatar Feb 22 '25 08:02 bonzini

Fixed

Now it fails with

meson.build:365:13: ERROR: Option b_vscrt does not exist.

(without the python exception trace)

Is that really the expected/agreed-upon resolution?

tp-m avatar Feb 23 '25 12:02 tp-m

There were two different bugs here. The one that would fix this one is #14272 but it's not merged yet due to disagreements on how the issue should be fixed.

jpakkane avatar Feb 23 '25 17:02 jpakkane

I see this issue in AIX as well. Our glib2 CI is down. Alright. Will wait. Just want to inform. Thanks. @jpakkane

KamathForAIX avatar Feb 24 '25 10:02 KamathForAIX

Now (commit 8546e408c67a783b5b04063834eff55f3e53eaf2, optstore: remove num_options) I'm getting

raceback (most recent call last):
  File "/home/tpm/Devel/meson/mesonbuild/interpreter/interpreter.py", line 1084, in func_get_option
    value_object, value = self.coredata.optstore.get_option_from_meson_file(options.OptionKey(optname, self.subproject))
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/options.py", line 1100, in get_option_from_meson_file
    (value_object, value) = self.get_value_object_and_value_for(key)
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/options.py", line 836, in get_value_object_and_value_for
    vobject = self.get_value_object_for(key)
  File "/home/tpm/Devel/meson/mesonbuild/options.py", line 830, in get_value_object_for
    raise KeyError(f'Tried to access nonexistant project parent option {parent_key}.')
KeyError: 'Tried to access nonexistant project parent option b_vscrt.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tpm/Devel/meson/mesonbuild/mesonmain.py", line 193, in run
    return options.run_func(options)
           ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/msetup.py", line 408, in run
    app.generate()
    ~~~~~~~~~~~~^^
  File "/home/tpm/Devel/meson/mesonbuild/msetup.py", line 189, in generate
    return self._generate(env, capture, vslite_ctx)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/msetup.py", line 267, in _generate
    intr.run()
    ~~~~~~~~^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreter/interpreter.py", line 3071, in run
    super().run()
    ~~~~~~~~~~~^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 169, in run
    self.evaluate_codeblock(self.ast, start=1)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 194, in evaluate_codeblock
    raise e
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 186, in evaluate_codeblock
    self.evaluate_statement(cur)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 204, in evaluate_statement
    self.assignment(cur)
    ~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 641, in assignment
    value = self.evaluate_statement(node.value)
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 200, in evaluate_statement
    return self.function_call(cur)
           ~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/interpreterbase.py", line 527, in function_call
    res = func(node, func_args, kwargs)
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/decorators.py", line 237, in wrapper
    return f(*nargs, **wrapped_kwargs)
  File "/home/tpm/Devel/meson/mesonbuild/interpreterbase/decorators.py", line 62, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/home/tpm/Devel/meson/mesonbuild/interpreter/interpreter.py", line 1086, in func_get_option
    if self.coredata.optstore.is_base_option(optname):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/tpm/Devel/meson/mesonbuild/options.py", line 1169, in is_base_option
    return key.name.startswith('b_')
           ^^^^^^^^
AttributeError: 'str' object has no attribute 'name'

meson.build:365:13: ERROR: Unhandled python exception

    This is a Meson bug and should be reported!

fwiw.

tp-m avatar Feb 27 '25 23:02 tp-m

@tp-m: I have a feeling that 25f7e33a22967af8c8f91c46029a8fd4d5d78e78 is the culprit, can you confirm?

dcbaker avatar Feb 27 '25 23:02 dcbaker

We clearly have a testing gap here...

dcbaker avatar Feb 27 '25 23:02 dcbaker

@tp-m: I have a feeling that 25f7e33 is the culprit, can you confirm?

Yes, with that commit reverted we're back to ERROR: Option b_vscrt does not exist.

tp-m avatar Feb 27 '25 23:02 tp-m

I have a patch, hold on I'll open a PR

dcbaker avatar Feb 27 '25 23:02 dcbaker