conan-io / conan

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

[question] Set test_package_folder based on version in recipe #16478

Open lambtonr opened 2 weeks ago

lambtonr commented 2 weeks ago

What is your question?

Hi, i have a recipe with a breaking change between V1.x.x and V2.x.x the recipe is identical for both version i just wish to specify a different test package for V1 and V2. I see i can specify test_package_folder attribute, Is there a way to set this dynamically like such:


class Pkg(ConanFile):
    test_package_folder = "test_package"
...
    def config_options(self):
        if Version(self.version) < "2.0.0":
            self.test_package_folder = "test_v1_package"

Dynamically setting the test_package_folder attribute seems to have no effect.

Conan version 2.4.1

Have you read the CONTRIBUTING guide?

memsharded commented 2 weeks ago

Hi @lambtonr

Thanks for your question.

Yes, the test_package_folder is read at export time, very early, so changing it in any method will have no effect.

Have you considered doing different logic in the test_package folder based on the self.tested_reference_str value, that will contain the tested version too?

lambtonr commented 2 weeks ago

Hi @memsharded

Thanks for the advice.

i have added the following logic to my test package i dont know if this is what you intended, but it works.

conanfile.py

def generate(self):
        tc = CMakeToolchain(self)
        tc.variables["PACKAGE_V1"] = Version(self.tested_reference_str.split('/')[1].split('@')[0]) < "2.0.0"
        tc.generate()

CMakeLists.txt

if (PACKAGE_V1)
    add_executable(${PROJECT_NAME} test_v1_package.cpp)
else ()
    add_executable(${PROJECT_NAME} test_package.cpp)
endif()

Looking at this now i think it is may be better to specify a different `build_script_folder' in the 'cmake.configure()'

memsharded commented 2 weeks ago

yes, exactly something like that, using the tested_reference_str extract its version, and use it to decide what to do differently in the test_package/conanfile.py. Looks good enough to me. Depending on the amount of changes, you could do that, selecting one or other folder, sounds good too if there are too many changes in the CMakeLists.txt