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

[question] editable mode breaks CMakeDeps/CMakeToolchain #12840

Closed
ghost opened this issue Jan 4, 2023 · 10 comments
Closed

[question] editable mode breaks CMakeDeps/CMakeToolchain #12840

ghost opened this issue Jan 4, 2023 · 10 comments

Comments

@ghost
Copy link

ghost commented Jan 4, 2023

Environment details

  • Operating System+version: macOS 12.6.2
  • Compiler+version: Apple clang 13.1.6
  • Conan version: 1.56.0
  • Python version: 3.8.9

Steps to reproduce

  1. Create a producer with conan new producer/1.0 -s
  2. Change it to use CMakeToolchain and overall Conan 2.0 compatible. The contents of all files in my producer result can be found here
  3. Create a consumer project in the separate directory. Having a directory with a single conanfile.txt will be enough. My consumer conanfile.txt can be found here
  4. Make your producer an editable dependency: conan editable add ../producer/ producer/1.0
  5. Install dependency with conan install . -u -pr:h default -pr:b default --build missing -if conan-editable-cmake

The last step fails with internal Conan error and Python stack trace

Logs

❯ conan install . -u -pr:h default -pr:b default --build missing -if conan-editable-cmake
Configuration (profile_host):
[settings]
arch=armv8
arch_build=armv8
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
os_build=Macos
[options]
[build_requires]
[env]

Configuration (profile_build):
[settings]
arch=armv8
arch_build=armv8
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
os_build=Macos
[options]
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    producer/1.0 from user folder - Editable
Packages
    producer/1.0:f7023de70d0bfc63077b5172ade69e4423b9047c - Editable

Installing (downloading, building) binaries...
producer/1.0: Rewriting files of editable package 'producer' at '/Users/kovimi/Developer/conan-xcode-bug/producer/build/generators'
producer/1.0: Generator 'CMakeToolchain' calling 'generate()'
producer/1.0: Preset 'release' added to CMakePresets.json. Invoke it manually using 'cmake --preset release'
producer/1.0: If your CMake version is not compatible with CMakePresets (<3.19) call cmake like: 'cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/Users/kovimi/Developer/conan-xcode-bug/producer/build/generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release'
producer/1.0: Aggregating env generators
producer/1.0: Generated toolchain
producer/1.0: Generated conan.lock
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: ERROR: Traceback (most recent call last):
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/templates/__init__.py", line 42, in render
    context = self.context
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/templates/target_data.py", line 28, in context
    global_cpp = self._get_global_cpp_cmake()
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/templates/target_data.py", line 152, in _get_global_cpp_cmake
    return _TargetDataContext(global_cppinfo, pfolder_var_name, self._root_folder)
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/templates/target_data.py", line 256, in __init__
    self.include_paths = join_paths(cpp_info.includedirs)
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/templates/target_data.py", line 230, in join_paths
    assert os.path.isabs(p), "{} is not absolute".format(p)
AssertionError: include is not absolute

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conans/client/generators/__init__.py", line 187, in write_generators
    generator.generate()
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/cmakedeps.py", line 47, in generate
    generator_files = self.content
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/cmakedeps.py", line 89, in content
    self._generate_files(require, dep, ret, find_module_mode=False)
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/cmakedeps.py", line 102, in _generate_files
    ret[data_target.filename] = data_target.render()
  File "/Users/kovimi/.local/pipx/venvs/conan/lib/python3.8/site-packages/conan/tools/cmake/cmakedeps/templates/__init__.py", line 44, in render
    raise ConanException("error generating context for '{}': {}".format(self.conanfile, e))
conans.errors.ConanException: error generating context for 'producer/1.0': include is not absolute

ERROR: Error in generator 'CMakeDeps': error generating context for 'producer/1.0': include is not absolute
@memsharded
Copy link
Member

As commented in the other issue, please try the producer with the conan new producer/0.1 -m=cmake_lib template instead, and let us know. Thanks!

@ghost
Copy link
Author

ghost commented Jan 4, 2023

You're right, -m=cmake_lib fixed the issue. Thanks!
However, this got me curious. It seems that me specifying bindirs and includedirs broke things, because the paths were relative. What is the proper way of specifying them?

@ghost ghost changed the title [bug] editable mode breaks CMakeDeps/CMakeToolchain [question] editable mode breaks CMakeDeps/CMakeToolchain Jan 4, 2023
@memsharded
Copy link
Member

However, this got me curious. It seems that me specifying bindirs and includedirs broke things, because the paths were relative. What is the proper way of specifying them?

The proper way is in the layout() method. Inside cmake_layout() call there is a default configuration, but you can create your own layout too, or customize existing. You might want to read https://docs.conan.io/en/latest/developing_packages/package_layout.html#package-layout for clarification

@ghost
Copy link
Author

ghost commented Jan 4, 2023

Thanks for super quick response!
One thing is still confusing, though. How can I mix this layout method with the components descriped here: https://docs.conan.io/en/latest/creating_packages/package_information.html#package-information-components ?

My understanding is that my project is likely broken because it contains multiple components and therefore I do specify libdirs and includedirs for those components

@memsharded
Copy link
Member

Yes, components layouts can also be defined in the layout() method:

def layout(self):
     self.cpp.source.components["foo"].includedirs = ["my_include_foo"]
     self.cpp.build.components["foo"].libdirs= ["my_lib_foo"]
     ...

It seems there are no explicit examples for this in the docs, but it relies on dcoumenting that cpp.build and cpp.source are cpp_info objects, and the same syntax applies. Are you specifying components in the layout()?

@ghost
Copy link
Author

ghost commented Jan 4, 2023

No, I'm specifying them in package_info as shown here: https://docs.conan.io/en/latest/creating_packages/package_information.html#package-information-components

And the original conanfile.py contained:

    def package_info(self):
        producer = self.cpp_info.components["producer"]
        producer.libs = ["producer"]
        producer.libdirs = ["lib"]
        producer.includedirs = ["include"]

I assumed it was superfluous, but harmless. But it seems that it can change the paths in generated files.

@memsharded
Copy link
Member

That could be the issue. If you want that package to be in editable, you need to define the equivalent to that in the layout() method, to define the location of the components artifacts while in editable mode.

@ghost
Copy link
Author

ghost commented Jan 4, 2023

I see. Thanks, I'll try to do that! That's probably something worth mentioning in the docs..

@ghost
Copy link
Author

ghost commented Feb 22, 2023

Closing this, as there's no issue in Conan per se. Rather a small unclarity caused by lack of information in the docs. Thanks for help! :)

@ghost ghost closed this as completed Feb 22, 2023
@memsharded
Copy link
Member

Thanks! We hope that the 2.0 docs will provide more clarity about this, we will try to add some more examples in https://docs.conan.io/2/tutorial/developing_packages/package_layout.html

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

No branches or pull requests

1 participant