Skip to content

[bug] Obscure error in CMakeDeps on malformed requirement string passed to self.cpp_info.requires #18550

Description

@transegn

Describe the bug

Conan produces a cryptic "too many values to unpack (expected 2)" error

======== Testing the package ========
Removing previously existing 'test_package' build folder: /__w/1/s/packages/sim_blocks/test_package/build/gcc-11-x86_64-release
foo/1.2.3 (test package): Test package build: build/gcc-11-x86_64-release
foo/1.2.3 (test package): Test package build folder: /__w/1/s/packages/sim_blocks/test_package/build/gcc-11-x86_64-release
foo/1.2.3 (test package): Writing generators to /__w/1/s/packages/sim_blocks/test_package/build/gcc-11-x86_64-release/generators
foo/1.2.3 (test package): Generator 'CMakeDeps' calling 'generate()'
ERROR: Error in generator 'CMakeDeps': error generating context for 'foo/1.2.3': too many values to unpack (expected 2)

when self.cpp_info.requires contains malformed requirement strings with multiple :: separators. The error occurs deep in the CMakeDeps generator and doesn't clearly indicate that the issue is with malformed requirement syntax in the conanfile. A useful error pointing out the malformed string would have helped a lot with catching the underlying issue here!

Version Info:

version: 2.9.1
conan_path: /home/tom/.pyenv/versions/conan2env/bin/conan
python
  version: 3.10.12
  sys_version: 3.10.12 (main, Jul 30 2024, 13:07:00) [GCC 11.4.0]
  sys_executable: /home/tom/.pyenv/versions/3.10.12/envs/conan2env/bin/python
  is_frozen: False
  architecture: x86_64
system
  version: #63~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 22 19:00:15 UTC 2
  platform: Linux-6.8.0-60-generic-x86_64-with-glibc2.35
  system: Linux
  release: 6.8.0-60-generic
  cpu: x86_64

How to reproduce it

  1. Start from conan new cmake_exe -d name=foo -d version=1.2.3
  2. Add generators = "CMakeDeps", "CMakeToolchain" to test_package/conanfile.py
  3. Add the following the conanfile.py
    requires = "gtest/1.14.0"
    def package_info(self):
        self.cpp_info.requires = [
            "gtest::this"  # <- How we encountered bug: Missed comma here
            "is::problem"
        ]
  4. conan create .
  5. Observer error
======== Testing the package ========
foo/1.2.3 (test package): Test package build: 
foo/1.2.3 (test package): Test package build folder: ./test_package
foo/1.2.3 (test package): Writing generators to ./test_package
foo/1.2.3 (test package): Generator 'CMakeDeps' calling 'generate()'
ERROR: Error in generator 'CMakeDeps': error generating context for 'foo/1.2.3': too many values to unpack (expected 2)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions