0

I created a Ncurses conan package for some projects where I use Ncurses. I use a conanfile.py for configuration. Now I have the problem that under Centos terminfo is in /usr/lib and under Debian-based system it is in /lib.

Therefor I have to set an argument in conanfile.py depending on the distribution:

.
.
.
settings = "os", "compiler", "build_type", "arch"
.
.
.
def build(self):
    env_build = AutoToolsBuildEnvironment(self)
    env_build.configure(configure_dir="src", build=False, host=False, target=False)
    args = ["--without-debug"]
    # if debian-based
    args += ["--datadir=/lib"]
    if self.options.shared:
        args += ["--with-shared", "--without-normal"]
    env_build.configure(configure_dir="src", args=args, build=False, host=False, target=False)
    env_build.make()

How can I implement the if statement # if debian-based? What would be best practice in this case?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Thomas Sablik
  • 16,127
  • 7
  • 34
  • 62

1 Answers1

3

You can use the OSInfo helper, which is a wrapper around uname and other OS functions. In your case you would like something like:

from conans.tools import OSInfo

info = OSInfo()
if info.is_linux and info.linux_distro in ("debian", "ubuntu"):
    # your logic here
drodri
  • 5,157
  • 15
  • 21
  • As far as I understand the hash code depends in my case on the os, compiler, build_type, arch and the options. Is it possible to make it depending linux_distro? Otherwise I would build and upload the lib with ubuntu. On centos conan would generate the same hash and download the ubuntu version with wrong datadir – Thomas Sablik Apr 12 '18 at 07:23
  • 1
    Yes, it is totally possible. You need to configure your ``settings.yml`` to add there "distro" as a setting, or maybe as a subsetting of the ``os`` setting. If it is a subsetting, it will be automatically added to the hash for all recipes that declare "os" as a setting. If it is a top level setting, you need to declare setting "distro" in the recipes you want their hash to be affected by the distro. I think I'd go for the first one, with "distro" as a subsetting of "os". ``settings.yml`` can be easily shared with ``conan config install`` – drodri Apr 12 '18 at 21:45
  • 1
    For more interactive discussion, you can also write github issues, https://github.com/conan-io/conan/issues, and there is also a "conan" channel in the C++ popular CppLang slack team. – drodri Apr 12 '18 at 21:46