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] Set test_package_folder based on version in recipe #16478

Open
1 task done
lambtonr opened this issue Jun 13, 2024 · 3 comments
Open
1 task done

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

lambtonr opened this issue Jun 13, 2024 · 3 comments
Assignees

Comments

@lambtonr
Copy link

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?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Jun 13, 2024
@memsharded
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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

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

2 participants