Git Product home page Git Product logo

Comments (5)

memsharded avatar memsharded commented on June 27, 2024 1

Hi @PauloCarvalhoRJ

Thanks for your question.

if self.settings.os == "Linux":

Yes, this will return True for all Linux OSs, because this is the os=Linux that is defined in the profile file or in command line argument. This is irrespective of the current OS Conan is running, the Conan recipes must be as independent of the current system as possible. If in some case the current "build" settings are necessary, coming from the "build" profile (--profile:build or --settings:build), then recipes might access it too, but this is rarely needed and typically only for some packages like packages wrapping a compiler or a build tool.

Note also that no conditionals can be used in the source() method, as it should be independent of the inputs.

from conan.

memsharded avatar memsharded commented on June 27, 2024 1

Thanks for the answer. In the ideal world, I totally agree that a recipe should be OS-invariant

Not a recipe. Recipes have lots of things that are not invariant. It is only the source() method of the recipe that should be invariant.

if self.settings.distro in ("debian", "ubuntu"):

yes, definitely, a recipe can use this, as long as it defines the distro custom setting as first level setting. But this will typically not be the most recommended approach. The most correct approach in most cases is to add distro as a subsetting of os Linux setting, so the above would be more like:

if self.settings.os == "Linux" and str(self.settings.os.distro) in ("ubuntu", ...)

Note the str() to be able to do the in operator.

This can be perfectly use in many methods of the recipe, just not in the source() one.

from conan.

memsharded avatar memsharded commented on June 27, 2024 1

Happy to help!

from conan.

PauloCarvalhoRJ avatar PauloCarvalhoRJ commented on June 27, 2024

Hello, @memsharded ,

Thanks for the answer. In the ideal world, I totally agree that a recipe should be OS-invariant. However, unfortunately, this is often not the case, especially when you are tasked with building legacy software which are even sensitive to Linux distro. By the way, following your rationale, can recipe code like

from conans.tools import OSInfo
...
info = OSInfo()
if info.is_linux and info.linux_distro in ("debian", "ubuntu"):
   ...

be replaced with

     if self.settings.distro in ("debian", "ubuntu"):
        ...

, provided I have distro=debian (or ubuntu) in the profile file set in the --profile:<profile_name> option?

thanks again,

PC

from conan.

PauloCarvalhoRJ avatar PauloCarvalhoRJ commented on June 27, 2024

Thank you for the informative answers. That helped me a lot.

from conan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.