conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Set test_package_folder based on version in recipe

Open lambtonr opened this issue 1 year ago • 3 comments

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?

  • [X] I've read the CONTRIBUTING guide

lambtonr avatar Jun 13 '24 17:06 lambtonr

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?

memsharded avatar Jun 13 '24 17:06 memsharded

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()'

lambtonr avatar Jun 13 '24 18:06 lambtonr

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

memsharded avatar Jun 13 '24 18:06 memsharded

Hi @lambtonr

Any further feedback or question here? Can the issue be closed? Thanks!

memsharded avatar Sep 02 '24 09:09 memsharded

Hi @memsharded

This issue can be closed, Many Thanks!

lambtonr avatar Sep 03 '24 16:09 lambtonr

Thanks for the feedback!

memsharded avatar Sep 03 '24 16:09 memsharded