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

conanfile options and None #11451

Closed
fittyCent opened this issue Jun 13, 2022 · 5 comments
Closed

conanfile options and None #11451

fittyCent opened this issue Jun 13, 2022 · 5 comments

Comments

@fittyCent
Copy link

None seems to come in as a string 'None' when default_options is involved. In the folllowing conanfile, issue-line is satisfied and the contents of the if-statement is executed even when my profile file doesn't contain options.configuration. If i change that line to if self.options.configuration != 'None', it works as expected (not going into the if-statement if configuration is None).

My conanfile.py

class SetupConan(ConanFile):
    name = 'foo'
    version = '0.1.0'
    settings = 'arch', 'os', 'build_type', 'compiler'
    options = {'configuration': 'ANY' }
    default_options = {'configuration': None}

    def requirements(self):
        self.requires('libcurl/7.83.1')

    def generate(self):
        ms = MSBuildDeps(self)
        if self.options.configuration is not None:   # <---- issue-line: also doesn't work with != None
            ms.configuration = self.options.configuration
        ms.generate()

    def layout(self):
        self.folders.generators = 'conan'

Environment Details (include every applicable attribute)

  • windows 10
  • msvs 2019
  • 1.49
  • 3.10.5
@memsharded
Copy link
Member

If you want to allow None (not defined, please better write the option as options = {"configuration": [None, "ANY"]}

@fittyCent
Copy link
Author

Did this and the execution still went into the if statement:

class SetupConan(ConanFile):
    name = 'foo'
    version = '0.1.0'
    settings = 'arch', 'os', 'build_type', 'compiler'
    options = {'configuration': [ None, 'ANY' ]}
    default_options = {'configuration': None}

    def requirements(self):
        self.requires('libcurl/7.83.1')

    def generate(self):
        ms = MSBuildDeps(self)
        if self.options.configuration is not None:   # <---- issue-line: also doesn't work with != None
            ms.configuration = self.options.configuration
        ms.generate()

    def layout(self):
        self.folders.generators = 'conan'

The conan_libcurl.props file shows this when ran against a profile that doesn't contain options (only contains settings):

<Import Condition="'$(Configuration)' == 'None' And '$(Platform)' == 'x64'" Project="conan_libcurl_none_x64.props"/>

@memsharded
Copy link
Member

Have you tried with if self.options.configuration:? The options object has some magic in it to allow the dynamic attributtes, but that also means that sometimes it cannot be treated as pure Python objects as is not None.

@fittyCent
Copy link
Author

if self.options.configuration: worked.

One note is if I did options = {'configuration': [ None, 'ANY' ]}, I could only set configuration, the ANY option doesn't work because it would only allow 'None' or 'ANY' strings as options.

So to get this all working the way I need to:

  • options = {'configuration': 'ANY' }
  • if self.options.configuration:

@memsharded
Copy link
Member

good point @fittyCent

This was my mistake. There was an issue with exactly this, that has been recently fixed in #11449, and will be in next 1.50 release.

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

No branches or pull requests

2 participants