Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MesonToolchain] Showing a warning message if raw options are used #14692

Conversation

franramirez688
Copy link
Contributor

@franramirez688 franramirez688 commented Sep 7, 2023

Changelog: Feature: MesonToolchain shows a warning message if any options are used directly.
Docs: conan-io/docs#3381
Closes: #14453

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this hasn't been released yet, just remove the Changelog in both PRs

@franramirez688 franramirez688 changed the title [MesonToolchain] Revert check if raw options [MesonToolchain] Reverts check if raw options. Showing a warning message instead. Sep 7, 2023
@franramirez688
Copy link
Contributor Author

If this hasn't been released yet, just remove the Changelog in both PRs

Keeping only the feature about showing the warning message

@franramirez688 franramirez688 changed the title [MesonToolchain] Reverts check if raw options. Showing a warning message instead. [MesonToolchain] Showing a warning message if raw options are used Sep 7, 2023
@czoido czoido merged commit b2b7eac into conan-io:release/2.0 Sep 7, 2023
@SpaceIm
Copy link
Contributor

SpaceIm commented Sep 18, 2023

Is it expected that boolean options display this warning?

In dav1d recipe, there is this warning now:

WARN: deprecated: Please, do not use a Conan option value directly. Convert 'options.assembly' into a valid Pythondata type, e.g, bool(self.options.shared)
WARN: deprecated: Please, do not use a Conan option value directly. Convert 'options.with_tools' into a valid Pythondata type, e.g, bool(self.options.shared)

Though, in recipe, there is:

    options = {
        "shared": [True, False],
        "fPIC": [True, False],
        "bit_depth": ["all", 8, 16],
        "with_tools": [True, False],
        "assembly": [True, False],
        "with_avx512": [True, False],
    }
    default_options = {
        "shared": False,
        "fPIC": True,
        "bit_depth": "all",
        "with_tools": True,
        "assembly": True,
        "with_avx512": False,
    }

    (...)

    def generate(self):
        env = VirtualBuildEnv(self)
        env.generate()

        tc = MesonToolchain(self)
        tc.project_options["enable_tests"] = False
        tc.project_options["enable_asm"] = self.options.assembly
        if Version(self.version) < "1.0.0":
            tc.project_options["enable_avx512"] = self.options.get_safe("with_avx512", False)
        tc.project_options["enable_tools"] = self.options.with_tools
        if self.options.bit_depth == "all":
            tc.project_options["bitdepths"] = "8,16"
        else:
            tc.project_options["bitdepths"] = str(self.options.bit_depth)
        tc.generate()

So why this warning? I though that boolean values were properly converted, unlike string. I don't understand why there can't be an automated conversion of PackageOption like in CMakeToolchain which has:

            elif isinstance(value, _PackageOption):
                if str(value).lower() in ["true", "false", "none"]:
                    cache_variables[name] = "ON" if bool(value) else "OFF"
                elif str(value).isdigit():
                    cache_variables[name] = int(value)
                else:
                    cache_variables[name] = str(value)

I would have expected such fix for #14453, to get consistent behavior of toolchains.

@memsharded
Copy link
Member

Yes, it is expected. The options have to be explicitly converted to bool(self.options.xxx) if desired that Meson treats them as booleans. Right now it is working by luck, because being mapped as strings and meson accepts the casing.

@SpaceIm
Copy link
Contributor

SpaceIm commented Sep 18, 2023

But why this inconsistency between CMakeToolchain and MesonToolchain? CMakeToolchain converts PackageOption evaluated as boolean or digits or string to their CMake format, but not MesonToolchain. It's weird.

@SpaceIm
Copy link
Contributor

SpaceIm commented Sep 18, 2023

I see that @RubenRBS had the same concern #14633 (review)

@franramirez688
Copy link
Contributor Author

But why this inconsistency between CMakeToolchain and MesonToolchain? CMakeToolchain converts PackageOption evaluated as boolean or digits or string to their CMake format, but not MesonToolchain. It's weird.

Indeed, I agree with both of you @SpaceIm and @RubenRBS. The thing is that I don't see the point of converting anything like CMakeToolchain is doing under the hood. Actually, it's doing that only for cache_variables and not for the rest of the variables so that's the weirdest thing. IMHO, we should not convert anything at all, and we should manage those conversions through the internal _PackageOption class instead somehow. Also, I cannot prune that conversion from CMakeToolchain because of likely breaking changes. It's clear that it's a limitation of this class for now, and we should solve it in the future.

@franramirez688
Copy link
Contributor Author

Related issue: #14590

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants