conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.24k stars 980 forks source link

[bug] editable package fails to test out #17254

Open maichmueller opened 2 days ago

maichmueller commented 2 days ago

Describe the bug

Hi,

I have set my package into editable mode and tried to test the package with the sample test_package from the docs (https://docs.conan.io/2/tutorial/creating_packages/test_conan_packages.html) My package (not the test-one) conanfile reads:

class MimirRecipe(ConanFile):
    name = "mimir"
    version = get_version()
    package_type = "static-library"
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps"

    options = {
        "shared": [True, False],
        "fPIC": [True, False],
    }

    default_options = {
        "shared": False,
        "fPIC": True,
        "cista/*:with_fmt": True,
    }
    default_options.update({f"boost/*:without_{comp}": True for comp in BOOST_COMPS})
    for comp in ("iostreams", "random", "regex", "system"):
        default_options.update({f"boost/*:without_{comp}": False})

    def requirements(self):
        requirements = self.conan_data.get("requirements", [])
        for requirement in requirements:
            self.requires(requirement)

    def validate(self):
        # mimir requires C++20
        check_min_cppstd(self, "20")

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def layout(self):
        cmake_layout(self)

    def generate(self):
        tc = CMakeToolchain(self)
        tc.user_presets_path = False
        tc.generate()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["mimir"]     <--- is this not enough to find the lib?

My cmake setup of the lib functions as expected, here is the install log:

cmake --install build --prefix=install
-- Install configuration: "Release"
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/libmimir.a
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/cmake/mimir/mimirTargets.cmake
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/cmake/mimir/mimirTargets-release.cmake
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/include/mimir
......................................
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/include/mimir/formalism/function.hpp
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/cmake/mimir/cmake
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/cmake/mimir/cmake/utilities.cmake
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/cmake/mimir/cmake/dependencies.cmake
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/cmake/mimir/mimirConfig.cmake
-- Up-to-date: /work/rleap1/michael.aichmueller/github/mimir/install/lib/cmake/mimir/mimirConfigVersion.cmake

but it fails to test out with conan:

conan test . "mimir/[*]" ``` conan test . "mimir/[*]" ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux ======== Launching test_package ======== ======== Computing dependency graph ======== Graph root mimir/[*] (test package): /work/rleap1/michael.aichmueller/github/mimir/tests/integration/conanfile.py Requirements benchmark/1.9.0#ad992fd28f453d1f895d32b2ba576892 - Cache boost/1.86.0#cd839a2082585255010f9e82eea94c7f - Cache bzip2/1.0.8#457c272f7da34cb9c67456dd217d36c4 - Cache cista/2024.10.22#eda1c95cbe7794af648edcf809619f82 - Cache fmt/11.0.2#5c7438ef4d5d69ab106a41e460ce11f3 - Cache gtest/1.15.0#9eb07f548819215e766e41399858454f - Cache loki/0.0.6#c4a43b9e86b06a86b060ed7d90f34a7a - Cache mimir/0.1.0.dev - Editable nauty/2.8.8#f28e1ededef9f279fbf1d9a59fa21892 - Cache pybind11/2.13.6#7d301b76bc1a308a51b506dd2de145b0 - Cache range-v3/0.12.0#4c05d91d7b40e6b91b44b5345ac64408 - Cache zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache Build requirements b2/5.2.1#91bc73931a0acb655947a81569ed8b80 - Cache cmake/3.30.5#540068cc37f1d21b42b729c82d6bcb29 - Cache Resolved version ranges b2/[>=5.2 <6]: b2/5.2.1 boost/[>=1.74.0]: boost/1.86.0 cmake/[>=3.16.3 <4]: cmake/3.30.5 mimir/[*]: mimir/0.1.0.dev zlib/[>=1.2.11 <2]: zlib/1.3.1 ======== Computing necessary packages ======== fmt/11.0.2: Main binary package 'd40b5c725566ec903e3c928e9c4e6f17b04f1d30' missing fmt/11.0.2: Checking 9 compatible configurations fmt/11.0.2: Found compatible package '9a065abcb87fdca997b519cd3122b64a0d435483': compiler.cppstd=20 benchmark/1.9.0: Main binary package '359eb291b2c32efebe094b078732203ee7afa54d' missing benchmark/1.9.0: Checking 7 compatible configurations benchmark/1.9.0: Found compatible package '854ea57089d9f4ae566b7fd9f4f1573d16ecf782': compiler.cppstd=20 Requirements benchmark/1.9.0#ad992fd28f453d1f895d32b2ba576892:854ea57089d9f4ae566b7fd9f4f1573d16ecf782#6d175435a79cc018c2f27bc9b121a612 - Cache boost/1.86.0#cd839a2082585255010f9e82eea94c7f:50c9f7b2d8a1603abca068b33e2c0f78778a4b9e#8179ca9f5f8ad6d65a8dc5245433743d - Cache bzip2/1.0.8#457c272f7da34cb9c67456dd217d36c4:4530633a3406a354d9c70a71124250144067de22#9a9214178cf9d49820bac01bd07c7253 - Cache cista/2024.10.22#eda1c95cbe7794af648edcf809619f82:a1832936ceafdd5da6f5e7d9aa90cd2270ac0b76#0effc2ed056dffdc58162188b1b2c370 - Cache fmt/11.0.2#5c7438ef4d5d69ab106a41e460ce11f3:9a065abcb87fdca997b519cd3122b64a0d435483#7dd291302c7365c837104baa3a3a3206 - Cache gtest/1.15.0#9eb07f548819215e766e41399858454f:f7ae24f4eedc110c20ab741b949bc222fd459f2a#2af99b049fc858d9f4db5947c14d9ece - Cache loki/0.0.6#c4a43b9e86b06a86b060ed7d90f34a7a:08b724bd1ccff70287b8351da8544982c4d6d0a3#e4594e0ed7cd6f358ea8094bf7529573 - Cache mimir/0.1.0.dev:db571c7cedf5bd170883b805ba81fa1313e51e11 - Editable nauty/2.8.8#f28e1ededef9f279fbf1d9a59fa21892:bfac7a3a9a2e30209faf49d0b9f927f51f9103fc#620f60c8cf8b28ded596a525c90b48c5 - Cache pybind11/2.13.6#7d301b76bc1a308a51b506dd2de145b0:da39a3ee5e6b4b0d3255bfef95601890afd80709#9d289186dc0b30c7d92df3b5a8f27a74 - Cache range-v3/0.12.0#4c05d91d7b40e6b91b44b5345ac64408:da39a3ee5e6b4b0d3255bfef95601890afd80709#ecc6172c3cd6694c36d1cd98a702deb0 - Cache zlib/1.3.1#f52e03ae3d251dec704634230cd806a2:5bc851010eb7b707e5cb2e24cb8ccf0f27989fa9#1f2bf5ee2729436fb0efb04e98b58860 - Cache Build requirements Skipped binaries b2/5.2.1, cmake/3.30.5 ======== Installing packages ======== bzip2/1.0.8: Already installed! (1 of 12) fmt/11.0.2: Already installed! (2 of 12) gtest/1.15.0: Already installed! (3 of 12) nauty/2.8.8: Already installed! (4 of 12) pybind11/2.13.6: Already installed! (5 of 12) range-v3/0.12.0: Already installed! (6 of 12) zlib/1.3.1: Already installed! (7 of 12) benchmark/1.9.0: Already installed! (8 of 12) boost/1.86.0: Already installed! (9 of 12) cista/2024.10.22: Already installed! (10 of 12) loki/0.0.6: Already installed! (11 of 12) mimir/0.1.0.dev: Rewriting files of editable package 'mimir' at '/work/rleap1/michael.aichmueller/github/mimir/build/Release/generators' mimir/0.1.0.dev: Writing generators to /work/rleap1/michael.aichmueller/github/mimir/build/Release/generators mimir/0.1.0.dev: Generator 'CMakeDeps' calling 'generate()' mimir/0.1.0.dev: CMakeDeps necessary find_package() and targets for your CMakeLists.txt find_package(range-v3) find_package(GTest) find_package(pybind11) find_package(benchmark) find_package(cista) find_package(fmt) find_package(nauty) find_package(loki) find_package(Boost) target_link_libraries(... range-v3::range-v3 gtest::gtest pybind11_all_do_not_use benchmark::benchmark_main cista::cista fmt::fmt nauty::nauty loki::loki boost::boost) mimir/0.1.0.dev: Calling generate() mimir/0.1.0.dev: Generators folder: /work/rleap1/michael.aichmueller/github/mimir/build/Release/generators mimir/0.1.0.dev: CMakeToolchain generated: conan_toolchain.cmake mimir/0.1.0.dev: CMakeToolchain generated: /work/rleap1/michael.aichmueller/github/mimir/build/Release/generators/CMakePresets.json mimir/0.1.0.dev: Generating aggregated env files mimir/0.1.0.dev: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X: WARN: deprecated: 'cpp_info.names' used in: fmt/11.0.2, range-v3/0.12.0, zlib/1.3.1, boost/1.86.0, bzip2/1.0.8, pybind11/2.13.6, gtest/1.15.0 WARN: deprecated: 'cpp_info.build_modules' used in: pybind11/2.13.6, bzip2/1.0.8 WARN: deprecated: 'env_info' used in: bzip2/1.0.8, boost/1.86.0 WARN: deprecated: 'cpp_info.filenames' used in: boost/1.86.0 WARN: deprecated: 'user_info' used in: boost/1.86.0 WARN: The package created was 'mimir/0.1.0.dev' but the reference being tested is 'mimir/[*]' ======== Testing the package ======== Removing previously existing 'test_package' build folder: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/gcc-12-x86_64-gnu20-release mimir/[*] (test package): Test package build: build/gcc-12-x86_64-gnu20-release mimir/[*] (test package): Test package build folder: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/gcc-12-x86_64-gnu20-release mimir/[*] (test package): Writing generators to /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/gcc-12-x86_64-gnu20-release/generators mimir/[*] (test package): Generator 'CMakeDeps' calling 'generate()' mimir/[*] (test package): CMakeDeps necessary find_package() and targets for your CMakeLists.txt find_package(mimir) target_link_libraries(... mimir::mimir) mimir/[*] (test package): Generator 'CMakeToolchain' calling 'generate()' mimir/[*] (test package): CMakeToolchain generated: conan_toolchain.cmake mimir/[*] (test package): CMakeToolchain generated: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/gcc-12-x86_64-gnu20-release/generators/CMakePresets.json mimir/[*] (test package): CMakeToolchain generated: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/CMakeUserPresets.json mimir/[*] (test package): Generating aggregated env files mimir/[*] (test package): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] ======== Testing the package: Building ======== mimir/[*] (test package): Calling build() mimir/[*] (test package): Running CMake.configure() mimir/[*] (test package): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/work/rleap1/michael.aichmueller/github/mimir/tests/integration" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/work/rleap1/michael.aichmueller/github/mimir/tests/integration" -- Using Conan toolchain: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/gcc-12-x86_64-gnu20-release/generators/conan_toolchain.cmake -- Conan toolchain: Defining architecture flag: -m64 -- Conan toolchain: C++ Standard 20 with extensions ON -- The C compiler identification is GNU 11.4.0 -- The CXX compiler identification is GNU 11.4.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Conan: Target declared 'mimir::mimir' CMake Error at build/gcc-12-x86_64-gnu20-release/generators/cmakedeps_macros.cmake:67 (message): Library 'mimir' not found in package. If 'mimir' is a system library, declare it with 'cpp_info.system_libs' property Call Stack (most recent call first): build/gcc-12-x86_64-gnu20-release/generators/mimir-Target-release.cmake:23 (conan_package_library_targets) build/gcc-12-x86_64-gnu20-release/generators/mimirTargets.cmake:24 (include) build/gcc-12-x86_64-gnu20-release/generators/mimir-config.cmake:16 (include) CMakeLists.txt:24 (find_package) -- Configuring incomplete, errors occurred! ERROR: mimir/[*] (test package): Error in build() method, line 17 cmake.configure() ConanException: Error 1 while executing ```

If I install my lib and then run cmake on the test-project manually by providing the conan deps per prefix-path, I can get my test project to compile fine.

cmake -S . -B build ... ``` cmake -S . -B build -DCMAKE_PREFIX_PATH="$(pwd)"/../../build/conan/build/Release/generators;"$(pwd)"/../../install -DCMAKE_BUILD_TYPE=Release -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=$(pwd)/../../conan_provider.cmake -- CMake-Conan: first find_package() found. Installing dependencies with Conan -- CMake-Conan: Checking if a default profile exists /u/michael.aichmueller/.conan2/profiles/default -- CMake-Conan: cmake_system_name=Linux -- CMake-Conan: cmake_system_processor=x86_64 -- CMake-Conan: CMake compiler=GNU -- CMake-Conan: CMake compiler version=11.4.0 -- CMake-Conan: [settings] compiler=gcc -- CMake-Conan: [settings] compiler.version=11 -- CMake-Conan: Creating profile /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/conan_host_profile -- CMake-Conan: Profile: [settings] arch=x86_64 os=Linux compiler=gcc compiler.version=11 compiler.cppstd=20 compiler.libcxx=libstdc++11 build_type=Release [conf] tools.cmake.cmaketoolchain:generator=Unix Makefiles tools.build:compiler_executables={"c":"/usr/bin/cc","cpp":"/usr/bin/c++"} -- CMake-Conan: Installing single configuration Release -- CMake-Conan: conan install /work/rleap1/michael.aichmueller/github/mimir/tests/integration -of=/work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/conan --profile:host=default;--profile:host=/work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/conan_host_profile;--profile:build=default;--build=missing ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=20 compiler.libcxx=libstdc++11 compiler.version=11 os=Linux [conf] tools.build:compiler_executables={'c': '/usr/bin/cc', 'cpp': '/usr/bin/c++'} tools.cmake.cmaketoolchain:generator=Unix Makefiles Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux ======== Computing dependency graph ======== Graph root conanfile.py: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/conanfile.py ======== Computing necessary packages ======== ======== Installing packages ======== ======== Finalizing install (deploy, generators) ======== conanfile.py: Writing generators to /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/conan/build/Release/generators conanfile.py: Generator 'CMakeDeps' calling 'generate()' conanfile.py: Generator 'CMakeToolchain' calling 'generate()' conanfile.py: CMakeToolchain generated: conan_toolchain.cmake conanfile.py: CMakeToolchain: Preset 'conan-release' added to CMakePresets.json. (cmake>=3.23) cmake --preset conan-release (cmake<3.23) cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release conanfile.py: CMakeToolchain generated: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/conan/build/Release/generators/CMakePresets.json conanfile.py: CMakeToolchain generated: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/CMakeUserPresets.json conanfile.py: Generating aggregated env files conanfile.py: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] Install finished successfully -- CMake-Conan: CONAN_GENERATORS_FOLDER=/work/rleap1/michael.aichmueller/github/mimir/tests/integration/build/conan/build/Release/generators -- CMake-Conan: CONANFILE=/work/rleap1/michael.aichmueller/github/mimir/tests/integration/conanfile.py CMAKE_PREFIX_PATH: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/../../build/conan/build/Release/generators;/work/rleap1/michael.aichmueller/github/mimir/tests/integration/../../install -- CMake-Conan: find_package(Boost) found, 'conan install' already ran -- Conan: Component target declared 'Boost::diagnostic_definitions' -- Conan: Component target declared 'Boost::disable_autolinking' -- Conan: Component target declared 'Boost::dynamic_linking' -- Conan: Component target declared 'Boost::headers' -- Conan: Component target declared 'Boost::boost' -- Conan: Component target declared 'boost::_libboost' -- Conan: Component target declared 'Boost::regex' -- Conan: Component target declared 'Boost::system' -- Conan: Component target declared 'Boost::random' -- Conan: Component target declared 'Boost::iostreams' -- Conan: Target declared 'boost::boost' -- CMake-Conan: find_package(ZLIB) found, 'conan install' already ran -- Conan: Target declared 'ZLIB::ZLIB' -- CMake-Conan: find_package(BZip2) found, 'conan install' already ran -- Conan: Target declared 'BZip2::BZip2' -- Conan: Including build module from '/u/michael.aichmueller/.conan2/p/b/bzip288dca8df46971/p/lib/cmake/conan-official-bzip2-variables.cmake' -- Found Boost: /work/rleap1/michael.aichmueller/github/mimir/build/conan/build/Release/generators (found version 1.86.0) -- CMake-Conan: find_package(nauty) found, 'conan install' already ran -- Could NOT find nauty (missing: nauty_DIR) -- Conan: Target declared 'nauty::nauty' -- Found Nauty: -- CMake-Conan: find_package(loki) found, 'conan install' already ran -- Could NOT find loki (missing: loki_DIR) -- Conan: Target declared 'loki::loki' -- Found Loki: /work/rleap1/michael.aichmueller/github/mimir/build/conan/build/Release/generators (found version 0.0.6) -- CMake-Conan: find_package(fmt) found, 'conan install' already ran -- Could NOT find fmt (missing: fmt_DIR) -- Conan: Component target declared 'fmt::fmt' -- Found fmt: /work/rleap1/michael.aichmueller/github/mimir/build/conan/build/Release/generators (found version 11.0.2) -- CMake-Conan: find_package(range-v3) found, 'conan install' already ran -- Could NOT find range-v3 (missing: range-v3_DIR) -- Conan: Component target declared 'range-v3::range-v3-meta' -- Conan: Component target declared 'range-v3::range-v3-concepts' -- Conan: Target declared 'range-v3::range-v3' -- Found range-v3: /work/rleap1/michael.aichmueller/github/mimir/build/conan/build/Release/generators (found version 0.12.0) -- CMake-Conan: find_package(cista) found, 'conan install' already ran -- Could NOT find cista (missing: cista_DIR) -- Conan: Target declared 'cista::cista' -- Found cista: /work/rleap1/michael.aichmueller/github/mimir/build/conan/build/Release/generators (found version 2024.10.22) -- CMake-Conan: find_package(Threads) found, 'conan install' already ran -- Could NOT find Threads (missing: Threads_DIR) -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Found Threads: Threads_DIR-NOTFOUND (found version ) -- The following REQUIRED packages have been found: * Boost (required version >= 1.74.0) * nauty * loki * fmt * range-v3 * cista * Threads -- Found mimir: (found version 0.1.0). <--- There it is -- Configuring done (1.6s) -- Generating done (0.1s) -- Build files have been written to: /work/rleap1/michael.aichmueller/github/mimir/tests/integration/build ```

Is my cpp_info.libs configuration perhaps wrong?

How to reproduce it

No response

memsharded commented 2 days ago

Hi @maichmueller

Thanks for your feedback.

I am not sure what could be happening, but there are some things that I don't understand:

My cmake setup of the lib functions as expected, here is the install log:

There shouldn't be a install log at all. When packages are used in editable mode, they are not installed, but used from the "build" tree directly, so the package() method or cmake --install shouldn't be called at all.

conan test . "mimir/[*]"

Not sure why doing this. When the package is in editable mode, it can be enough to do a conan create .

cmake -S . -B build ...

This is confusing too, it seems to be using the cmake-conan over the test_package? The test_package is not intended to be used as a regular Conan conanfile.py, because it contains a self.requires(self.tested_reference_str) that evaluates to None if not managed by Conan.

The best to understand what could be missing is to have a fully reproducible case, with the exact commands to reproduce. Either with code in a github repo, or using a conan new cmake_lib template, which contains the equivalent to self.cpp_info.libs = ["mimir"]. Thanks for your feedback.

maichmueller commented 2 days ago

Hi @memsharded ,

I only did the manual cmake --install ... and cmake -S .... configuration commands to contrast it with the conan steps. These steps are NOT done by conan but by myself, to show that the cmake configuration of my project is working as intended!

To clarify this part, this is the dependency graph of the testpkg:

test_package --> mimir --> boost,range-v3,cista,...

I am trying to exclude a faulty cmake config on my side and show that I CAN use my project's (mimir) configuration as a cmake dependency for another consuming cmake package (without relying on its conanfile yet!). So to have the dependencies of mimir available in cmake (boost, range-v3 etc) I merely prefix the path of the conan generated deps for conan install mimir. If I didn't do this, then the call find_package(mimir) in test_package would fail to find boost and so on.

Overall, my cmake configuration (mimirConfig.cmake, mimirTargets.cmake, etc...) appears to be correct and working as can be seen in the logs of cmake -S .... How my lib is installed is also shown in the log of cmake --install ..., it is a default cmake installation. This leads me to believe that the error must lie with conan/my conanfile setup/my conan testing procedure.

Not sure why doing this. When the package is in editable mode, it can be enough to do a conan create .

Not sure what the confusing part is, I am following the conan docs on how to test: conan test test_package hello/1.0 (only replace test_package with . since i am in inside the directory and hello/1.0 with mimir/*).

Am I misunderstanding how conan editable packages work? My understanding was:

1) I declare mimir as editable conan editable add . Now conan is aware of changes in mimir. 2) NOT DONE BEFORE: Build the package conan create . (I haven't done this step before. But I just tested with calling this first, before conan test, and it doesn't change the outcome). 3) Build mimir: conan build . (inside mimir). 3) I want to see if mimir can be consumed so I use the docs' test_package conanfile and run conan test . mimir/[*]. This should proceed and work (it doesn't). Any changes made in mimir should be reflected here.

memsharded commented 2 days ago

I am trying to exclude a faulty cmake config on my side and show that I CAN use my project's (mimir) configuration as a cmake dependency for another consuming cmake package (without relying on its conanfile yet!).

That is what was confusing to me. For the conan editable flow, the CMake install functionality is not involved at all.

Lets try to do things with something that I can reproduce from my side (with COnan 2.9):

This works on my side, can you please check? Note that what you need to pass to conan test is not the version range but the actual version to test.

maichmueller commented 2 days ago

That is what was confusing to me. For the conan editable flow, the CMake install functionality is not involved at all.

I did not know this. I expected that conan would do an 'on-the-fly' install into a local build to provide the dependency to test_package. (not needing a working cmake install is actually a great feature btw)

I just tried your steps and they work for me:

conan new cmake_lib -d name=mypkg -d version=0.0.1

File saved: CMakeLists.txt
File saved: conanfile.py
File saved: include/mypkg.h
File saved: src/mypkg.cpp
File saved: test_package/CMakeLists.txt
File saved: test_package/conanfile.py
File saved: test_package/src/example.cpp

/tmp conan editable add .

Reference 'mypkg/0.0.1' in editable mode

/tmp conan build .

``` ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux ======== Computing dependency graph ======== Graph root conanfile.py (mypkg/0.0.1): /tmp/conanfile.py ======== Computing necessary packages ======== ======== Installing packages ======== ======== Installing packages ======== ======== Finalizing install (deploy, generators) ======== conanfile.py (mypkg/0.0.1): Calling generate() conanfile.py (mypkg/0.0.1): Generators folder: /tmp/build/Release/generators conanfile.py (mypkg/0.0.1): CMakeToolchain generated: conan_toolchain.cmake conanfile.py (mypkg/0.0.1): CMakeToolchain: Preset 'conan-release' added to CMakePresets.json. (cmake>=3.23) cmake --preset conan-release (cmake<3.23) cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release conanfile.py (mypkg/0.0.1): CMakeToolchain generated: /tmp/build/Release/generators/CMakePresets.json conanfile.py (mypkg/0.0.1): CMakeToolchain generated: /tmp/CMakeUserPresets.json conanfile.py (mypkg/0.0.1): Generating aggregated env files conanfile.py (mypkg/0.0.1): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] ======== Calling build() ======== conanfile.py (mypkg/0.0.1): Calling build() conanfile.py (mypkg/0.0.1): Running CMake.configure() conanfile.py (mypkg/0.0.1): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/tmp" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/tmp" -- Using Conan toolchain: /tmp/build/Release/generators/conan_toolchain.cmake -- Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC) -- Conan toolchain: Defining architecture flag: -m64 -- Conan toolchain: C++ Standard 20 with extensions ON -- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF -- The CXX compiler identification is GNU 11.4.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (0.4s) -- Generating done (0.0s) -- Build files have been written to: /tmp/build/Release conanfile.py (mypkg/0.0.1): Running CMake.build() conanfile.py (mypkg/0.0.1): RUN: cmake --build "/tmp/build/Release" -- -j20 [ 50%] Building CXX object CMakeFiles/mypkg.dir/src/mypkg.cpp.o [100%] Linking CXX static library libmypkg.a [100%] Built target mypkg ```

/tmp/test_package conan test . mypkg/0.0.1

``` ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux ======== Launching test_package ======== ======== Computing dependency graph ======== Graph root mypkg/0.0.1 (test package): /tmp/test_package/conanfile.py Requirements mypkg/0.0.1 - Editable ======== Computing necessary packages ======== Requirements mypkg/0.0.1:b93629c02b5749490253d53b27b9d540a70c35c3 - Editable ======== Installing packages ======== mypkg/0.0.1: Rewriting files of editable package 'mypkg' at '/tmp/build/Release/generators' mypkg/0.0.1: Calling generate() mypkg/0.0.1: Generators folder: /tmp/build/Release/generators mypkg/0.0.1: CMakeToolchain generated: conan_toolchain.cmake mypkg/0.0.1: CMakeToolchain generated: /tmp/build/Release/generators/CMakePresets.json mypkg/0.0.1: CMakeToolchain generated: /tmp/CMakeUserPresets.json mypkg/0.0.1: Generating aggregated env files mypkg/0.0.1: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] ======== Testing the package ======== Removing previously existing 'test_package' build folder: /tmp/test_package/build/gcc-12-x86_64-gnu20-release mypkg/0.0.1 (test package): Test package build: build/gcc-12-x86_64-gnu20-release mypkg/0.0.1 (test package): Test package build folder: /tmp/test_package/build/gcc-12-x86_64-gnu20-release mypkg/0.0.1 (test package): Writing generators to /tmp/test_package/build/gcc-12-x86_64-gnu20-release/generators mypkg/0.0.1 (test package): Generator 'CMakeDeps' calling 'generate()' mypkg/0.0.1 (test package): CMakeDeps necessary find_package() and targets for your CMakeLists.txt find_package(mypkg) target_link_libraries(... mypkg::mypkg) mypkg/0.0.1 (test package): Generator 'CMakeToolchain' calling 'generate()' mypkg/0.0.1 (test package): CMakeToolchain generated: conan_toolchain.cmake mypkg/0.0.1 (test package): CMakeToolchain generated: /tmp/test_package/build/gcc-12-x86_64-gnu20-release/generators/CMakePresets.json mypkg/0.0.1 (test package): CMakeToolchain generated: /tmp/test_package/CMakeUserPresets.json mypkg/0.0.1 (test package): Generating aggregated env files mypkg/0.0.1 (test package): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] ======== Testing the package: Building ======== mypkg/0.0.1 (test package): Calling build() mypkg/0.0.1 (test package): Running CMake.configure() mypkg/0.0.1 (test package): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/tmp/test_package" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/tmp/test_package" -- Using Conan toolchain: /tmp/test_package/build/gcc-12-x86_64-gnu20-release/generators/conan_toolchain.cmake -- Conan toolchain: Defining architecture flag: -m64 -- Conan toolchain: C++ Standard 20 with extensions ON -- The CXX compiler identification is GNU 11.4.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Conan: Target declared 'mypkg::mypkg' -- Configuring done (0.1s) -- Generating done (0.0s) -- Build files have been written to: /tmp/test_package/build/gcc-12-x86_64-gnu20-release mypkg/0.0.1 (test package): Running CMake.build() mypkg/0.0.1 (test package): RUN: cmake --build "/tmp/test_package/build/gcc-12-x86_64-gnu20-release" -- -j20 [ 50%] Building CXX object CMakeFiles/example.dir/src/example.cpp.o [100%] Linking CXX executable example [100%] Built target example ======== Testing the package: Executing test ======== mypkg/0.0.1 (test package): Running test() mypkg/0.0.1 (test package): RUN: ./example mypkg/0.0.1: Hello World Release! mypkg/0.0.1: __x86_64__ defined mypkg/0.0.1: _GLIBCXX_USE_CXX11_ABI 1 mypkg/0.0.1: __cplusplus202002 mypkg/0.0.1: __GNUC__11 mypkg/0.0.1: __GNUC_MINOR__4 mypkg/0.0.1 test_package ```

Note that what you need to pass to conan test is not the version range but the actual version to test.

It seems that this is not correct (or maybe it works as long as there is only 1 version available?)

/tmp/test_package conan test . 'mypkg/[*]'

``` ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu20 compiler.libcxx=libstdc++11 compiler.version=12 os=Linux ======== Launching test_package ======== ======== Computing dependency graph ======== Graph root mypkg/[*] (test package): /tmp/test_package/conanfile.py Requirements mypkg/0.0.1 - Editable Resolved version ranges mypkg/[*]: mypkg/0.0.1 ======== Computing necessary packages ======== Requirements mypkg/0.0.1:b93629c02b5749490253d53b27b9d540a70c35c3 - Editable ======== Installing packages ======== mypkg/0.0.1: Rewriting files of editable package 'mypkg' at '/tmp/build/Release/generators' mypkg/0.0.1: Calling generate() mypkg/0.0.1: Generators folder: /tmp/build/Release/generators mypkg/0.0.1: CMakeToolchain generated: conan_toolchain.cmake mypkg/0.0.1: CMakeToolchain generated: /tmp/build/Release/generators/CMakePresets.json mypkg/0.0.1: CMakeToolchain generated: /tmp/CMakeUserPresets.json mypkg/0.0.1: Generating aggregated env files mypkg/0.0.1: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] WARN: The package created was 'mypkg/0.0.1' but the reference being tested is 'mypkg/[*]' ======== Testing the package ======== Removing previously existing 'test_package' build folder: /tmp/test_package/build/gcc-12-x86_64-gnu20-release mypkg/[*] (test package): Test package build: build/gcc-12-x86_64-gnu20-release mypkg/[*] (test package): Test package build folder: /tmp/test_package/build/gcc-12-x86_64-gnu20-release mypkg/[*] (test package): Writing generators to /tmp/test_package/build/gcc-12-x86_64-gnu20-release/generators mypkg/[*] (test package): Generator 'CMakeDeps' calling 'generate()' mypkg/[*] (test package): CMakeDeps necessary find_package() and targets for your CMakeLists.txt find_package(mypkg) target_link_libraries(... mypkg::mypkg) mypkg/[*] (test package): Generator 'CMakeToolchain' calling 'generate()' mypkg/[*] (test package): CMakeToolchain generated: conan_toolchain.cmake mypkg/[*] (test package): CMakeToolchain generated: /tmp/test_package/build/gcc-12-x86_64-gnu20-release/generators/CMakePresets.json mypkg/[*] (test package): CMakeToolchain generated: /tmp/test_package/CMakeUserPresets.json mypkg/[*] (test package): Generating aggregated env files mypkg/[*] (test package): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] ======== Testing the package: Building ======== mypkg/[*] (test package): Calling build() mypkg/[*] (test package): Running CMake.configure() mypkg/[*] (test package): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/tmp/test_package" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/tmp/test_package" -- Using Conan toolchain: /tmp/test_package/build/gcc-12-x86_64-gnu20-release/generators/conan_toolchain.cmake -- Conan toolchain: Defining architecture flag: -m64 -- Conan toolchain: C++ Standard 20 with extensions ON -- The CXX compiler identification is GNU 11.4.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Conan: Target declared 'mypkg::mypkg' -- Configuring done (0.3s) -- Generating done (0.0s) -- Build files have been written to: /tmp/test_package/build/gcc-12-x86_64-gnu20-release mypkg/[*] (test package): Running CMake.build() mypkg/[*] (test package): RUN: cmake --build "/tmp/test_package/build/gcc-12-x86_64-gnu20-release" -- -j20 [ 50%] Building CXX object CMakeFiles/example.dir/src/example.cpp.o [100%] Linking CXX executable example [100%] Built target example ======== Testing the package: Executing test ======== mypkg/[*] (test package): Running test() mypkg/[*] (test package): RUN: ./example mypkg/0.0.1: Hello World Release! mypkg/0.0.1: __x86_64__ defined mypkg/0.0.1: _GLIBCXX_USE_CXX11_ABI 1 mypkg/0.0.1: __cplusplus202002 mypkg/0.0.1: __GNUC__11 mypkg/0.0.1: __GNUC_MINOR__4 mypkg/0.0.1 test_package ```
memsharded commented 2 days ago

I did not know this. I expected that conan would do an 'on-the-fly' install into a local build to provide the dependency to test_package. (not needing a working cmake install is actually a great feature btw)

yes, exactly, the way cmake_layout() (and other layout() implementations) is that it defines the self.cpp.source and self.cpp.build information to represent the "build-tree" information, without needing to install the artifacts.

It seems that this is not correct (or maybe it works as long as there is only 1 version available?)

yes, maybe that is the case, the recommendation would be to give it the version to test

So, if the basic cmake_lib flow works, then we would need to check what could be different. Could you please try to come up with a similar flow with your conanfile.py that reproduce your case? If it is open source, feel free to share a link so we can check.