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

allow user patches in conandata #14576

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions conan/tools/files/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def patch(conanfile, base_path=None, patch_file=None, patch_string=None, strip=0
directory. The folder containing the sources can be customized with the self.folders attribute
in the layout(self) method.

:param conanfile: the current recipe, always pass 'self'
:param base_path: The path is a relative path to conanfile.export_sources_folder unless an
absolute path is provided.
:param patch_file: Patch file that should be applied. The path is relative to the
conanfile.source_folder unless an absolute path is provided.
:param patch_string: Patch string that should be applied.
:param strip: Number of folders to be stripped from the path.
:param output: Stream object.
:param fuzz: Should accept fuzzy patches.
:param kwargs: Extra parameters that can be added and will contribute to output information
"""
Expand Down Expand Up @@ -98,11 +98,13 @@ def apply_conandata_patches(conanfile):
entry = it.copy()
patch_file = entry.pop("patch_file")
patch_file_path = os.path.join(conanfile.export_sources_folder, patch_file)
if not "patch_description" in entry:
if "patch_description" not in entry:
entry["patch_description"] = patch_file
patch(conanfile, patch_file=patch_file_path, **entry)
elif "patch_string" in it:
patch(conanfile, **it)
elif "patch_user" in it:
pass # This will be managed directly by users, can be a command or a script execution
else:
raise ConanException("The 'conandata.yml' file needs a 'patch_file' or 'patch_string'"
" entry for every patch to be applied")
Expand Down
13 changes: 13 additions & 0 deletions conans/test/unittests/tools/files/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ def test_multiple_no_version(mock_patch_ng):
in output.getvalue()


def test_patch_user(mock_patch_ng):
output = RedirectedTestOutput()
with redirect_output(output):
conanfile = ConanFileMock()
conanfile.display_name = 'mocked/ref'
conanfile.conan_data = {'patches': [
{'patch_user': 'some replace command, the user will handle',
'myuserthings': 'other things', },
]}
apply_conandata_patches(conanfile)
# it doesn't do anything, but it doesn't crash


def test_multiple_with_version(mock_patch_ng):
output = RedirectedTestOutput()
with redirect_output(output):
Expand Down