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

Implement test_package --build-test=missing for full control of test_package deps #14347

Merged

Conversation

memsharded
Copy link
Member

@memsharded memsharded commented Jul 21, 2023

Changelog: Feature: conan create --build-test=missing new argument to control what is being built as dependencies of the test_package folder.
Docs: conan-io/docs#3336

Close #14314
Close #14352

@memsharded memsharded added this to the 2.0.10 milestone Jul 21, 2023
@memsharded memsharded changed the title fix test_package --build=missing, now it works Implement test_package --build-test=missing for full control of test_package deps Jul 21, 2023
Copy link
Contributor

@jcar87 jcar87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this flag with a test_package like this:

    def requirements(self):
        self.requires(self.tested_reference_str)

    def build_requirements(self):
        self.tool_requires(self.tested_reference_str)

while invoking conan create in a way that results in both of these being satisfied by two different package IDs of the same reference, and this flag works perfectly fine and builds the missing reference.

However I still find it a bit counter intuitive, or perhaps it may need to be better documented

conan create . --build=missing will fail for the code below if this results in two different package IDs being required:

    def requirements(self):
        self.requires(self.tested_reference_str)

    def build_requirements(self):
        self.tool_requires(self.tested_reference_str)

But the following scenario, where:

  • foobar/123 is exported
  • it is NOT a dependency of self.tested_reference_str and only appears as a requirement of the test package
  • there is currently no package generated for it
    def requirements(self):
        self.requires(self.tested_reference_str)
        self.requires("foobar/123")

In this scenario,

conan create . --build=missing

will currently succeed (even before this PR), and will generate the missing package for foobar/1.2.3. So what is difficult to reason, on documentation alone, is why --build=missing works for some of the references required by the test package, but specifically not for the one being created. I am aware why, but perhaps it needs a clarification in the documentation.

This can create confusion as to why --build-test=missing does that --build=missing doesn't, when passed as an argument to Conan create. I only see two useful scenarios:

  • when one knows beforehand that there are multiple requirements on self.tested_reference_str
    and perhaps the more unusual but also valid:
  • when one wants conan create to force a build of the reference, rather than reuse an existing package, but still wants it to build any missing dependencies of the test_package

@memsharded
Copy link
Member Author

Thanks very much for the thorough review and testing @jcar87

I think the self.requires("foobar/123") behavior might be an overlook, you are right, it doesn't look like the most intuitive behavior, I will add some tests and check it.

@memsharded
Copy link
Member Author

I think it is working fine, adding an extra test to the PR that validates it:

    def test_build_test_package_dep(self):
        c = TestClient()
        c.save({"dep/conanfile.py": GenConanfile("dep", "0.1"),
                "pkg/conanfile.py": GenConanfile("pkg", "0.1"),
                "pkg/test_package/conanfile.py": GenConanfile().with_requires("dep/0.1")
                                                               .with_test("pass")})
        c.run("export dep")
        c.run("create pkg --build=missing", assert_error=True)
        c.assert_listed_binary({"pkg/0.1": ("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Build")})
        c.assert_listed_binary({"dep/0.1": ("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Missing"),
                                "pkg/0.1": ("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Cache")},
                               test_package=True)

This works, and raise an error because the binary is missing.
Can you please double check? Is it possible that you got the binary in the cache built in a previous command?

@memsharded memsharded marked this pull request as ready for review July 26, 2023 11:05
Copy link
Contributor

@jcar87 jcar87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I think the behaviour changes makes sense, that is --build=missing now applies only to the graph of the reference being created, and --build-test missing applies to the graph of the test_package, which may contain additional references (if the test package has them).

I think this makes sense with the premise that conan create has a premise where for the tested reference it should only build what is requested

@memsharded memsharded merged commit bc4ed4d into conan-io:release/2.0 Jul 26, 2023
@memsharded memsharded deleted the fix/test_package_build_missing branch July 26, 2023 15:04
mkmkme pushed a commit to mkmkme/conan that referenced this pull request Jul 26, 2023
…`test_package`` deps (conan-io#14347)

* fix test_package --build=missing, now it works

* wip

* removed unused .all in BuildMode

* fix unittest

* wip

* change order build_mode

* wip

* fix tests

* working

* new test

* better defaults

* minor -h improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants