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

Warn when using patching function and no_copy_source is True #17162

Closed

Conversation

AbrilRBS
Copy link
Member

@AbrilRBS AbrilRBS commented Oct 14, 2024

Changelog: Feature: Warn when patching files and the recipe has no_copy_source = True, which could lead to unforseen issues
Docs: Omit

Some questions remain as to:

  • Should we check that we're trying to modify something from the build() method and not the package/source one?
  • Should we check that we're modifying something inside self.source_folder?
  • Anything else I haven't thought about?

@@ -18,7 +18,7 @@ def conanfile():
with_require("base/1.0"))

conan_file += """
no_copy_sources = True
no_copy_source = True
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a typo in the test conanfile, but the behaviour is identical in these tests

@AbrilRBS AbrilRBS requested a review from memsharded October 14, 2024 13:12
@AbrilRBS AbrilRBS added this to the 2.9.0 milestone Oct 14, 2024
Copy link
Member Author

@AbrilRBS AbrilRBS left a comment

Choose a reason for hiding this comment

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

The thing is that as long as these functions are called inside the source method (For the patch case 100%, replace_in_file() also has valid use-cases inside the package method, but it's a diferent deal!), this would not be a problem

The issue arises when recipes call these methods in the build() method - CCI is almost exclusively like this, with few recipes doing it in the source() method, probably as a byproduct of old Conan 1 behaviour

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

I am not sure if I understand.
Patches and replace_in_file should be applied in general in the source() method, over the source folder. So they shouldn't warn by default.

The fact that ConanCenter patches unnecessarily in the build() method is what should be updated, most of them should patch in the source() method, as the patches are not configuration-specific.

@AbrilRBS
Copy link
Member Author

We're going with the linter approach to be released soon, as this would create many false positives for users that are following the guidelines properly, and the added complexity of inspecting the stack to check for the build method is not worth it in our opinion

@AbrilRBS AbrilRBS closed this Oct 15, 2024
@AbrilRBS AbrilRBS deleted the ar/warn-patches-no-copy-source branch October 15, 2024 14:22
@jcar87
Copy link
Contributor

jcar87 commented Oct 17, 2024

The fact that ConanCenter patches unnecessarily in the build() method is what should be updated, most of them should patch in the source() method, as the patches are not configuration-specific.

Yes - this has always been a problem.
Patches must be configuration-agnostic (or have the build system conditionals in the patch) for them to be in source() - but arguably, the patches in recipes via apply_conandata_patches() should already have this property by definition because they are not "conditionally applied".

I suppose patching in build() needs to happen when there are conditional patches (conditional on options or settings) - sometimes it's easier to do that than to create a platform-agnostic patch - however, while that may be valid - it must not happen if no_copy_sources = True

@jcar87
Copy link
Contributor

jcar87 commented Oct 17, 2024

CCI is almost exclusively like this, with few recipes doing it in the source() method, probably as a byproduct of old Conan 1 behaviour

Conan 1 documentation always advocated for doing this in the source() method as well - and the source folder is deemed immutable once the the source() method has finished, but that the contents of the source folder should be platform (including settings and options) agnostic.

Conan 2 does have that temporary copy of the source folder during build - so platform dependent changes are "safe" in the build() method. I think it's a mix of that, alongside a mentality of "the source() method should be the upstream sources, untouched" - but I think the conandata.yml already has a clear source of truth for that anyway. And for traceability purposes, having the source() method have what's actually being built, can be convenient when needed for compliance.

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

Successfully merging this pull request may close these issues.

4 participants