conan icon indicating copy to clipboard operation
conan copied to clipboard

Did version_range resolving get error answer?

Open liao-zhihan opened this issue 1 year ago • 6 comments

Hi all, feel lucky to use Conan(version 1.38.0) such a good tool to manage my C++ library and APP. But I got some problem these day.

I am building an APP, and there are three Conan packages used for this APP, called lib_C, lib_E, lib_D. lib_C is depend on the lib_E and lib_D, and the conanfile.py of lib_C is below, where I use version_range to manage the library:

from conans import ConanFile, tools
import os


class PackageConan(ConanFile):
  settings = ()

  revision_mode = "scm"
  scm = {
        "type": "git",
        "url": "xxx/lib_C",
        "revision": "auto"
  }
  url = 'xxx/lib_C'

  license = 'aaa'
  description = 'bbb'
  settings = 'os', 'compiler', 'build_type', 'arch'
  generators = 'cmake'

  requires = ("lib_D/[0.0.0> <0.1.0]@lzh/stable",
              "lib_E/[0.1.0>= <0.2.0]@lzh/stable")

  build_requires = ()

  def imports(self):
    pass

  def package(self):
    source_dir = os.environ.get('PACKAGE_SOURCE_DIR')
    build_dir = os.environ.get('PACKAGE_BUILD_DIR')
    install_dir = os.environ.get('PACKAGE_INSTALL_DIR')
    self.copy('*',
              dst='include',
              src='{}/include'.format(install_dir),
              symlinks=True)
    self.copy('*', dst='lib', src='{}/lib'.format(install_dir), symlinks=True)

  def package_id(self):
    self.info.requires.minor_mode()

  def package_info(self):
    self.cpp_info.libs = tools.collect_libs(self)

And there are two Conan remotes in my system, called them conan-stable, conan-dev (the priority of conan-stable is higher than conan-dev). And the available version of lib_E in conan-stable is such below: image

however, in conan-dev is: image

Based on the environment, I am creating the lockfile of lib_C, and expect to get the 0.1.0 version of lib_E in the lockfile,but when I run the command:

conan lock create conanfile.py --lockfile-out=dep_base.lock --update --base

the output of this command is below: image

As you can see from this picture, Conan only try to solve version from conan-stable, but not conan-dev, thus got a wrong version of lib_E which should be 0.1.0. And, in my opinion, it should search from conan-dev, since there is not any version in conan-stable satisfy the range [0.1.0>= <0.2.0]. But if I change the require from "lib_E/[0.1.0>= <0.2.0]@lzh/stable" to "lib_E/0.1.0@lzh/stable", it works well.

Is there some mistake in my project or Conan?

liao-zhihan avatar Jul 28 '22 05:07 liao-zhihan

I got REVISION_MODE enabled.

liao-zhihan avatar Jul 28 '22 06:07 liao-zhihan

I guess that maybe I can pass a "lockfile" generated by lib_E (version 0.1.0) to the lib_C, then force lib_C to use the 0.1.0 version of lib_E. But I think passing a "lockfile" between different repos is really annoyed, especially these repos are maintained by many developers.

liao-zhihan avatar Jul 28 '22 07:07 liao-zhihan

Hi @liao-zhihan

Are you sure your requires are correct? I see [0.0.0> <0.1.0]@lzh/stable", but that looks weird, probably should be [>0.0.0 <0.1.0]@lzh/stable"

memsharded avatar Jul 28 '22 08:07 memsharded

Thx for quick reply, I will try this immediately.

liao-zhihan avatar Jul 28 '22 09:07 liao-zhihan

Hi @liao-zhihan

Are you sure your requires are correct? I see [0.0.0> <0.1.0]@lzh/stable", but that looks weird, probably should be [>0.0.0 <0.1.0]@lzh/stable"

I change it to

requires = ("lib_D/[>0.0.0 <0.1.0]@lzh/stable",
                   "lib_E/[>=0.1.0 <0.2.0]@lzh/stable")

But it got output: image

liao-zhihan avatar Jul 28 '22 12:07 liao-zhihan

@memsharded I got the answer in https://github.com/conan-io/conan/issues/3113 this seems a problem in Conan 1.x, I will try other method. thx!

liao-zhihan avatar Jul 28 '22 13:07 liao-zhihan