Skip to content

Commit

Permalink
Always indicate when patches are applied (#14165)
Browse files Browse the repository at this point in the history
Also update test_patches.py accordingly.
  • Loading branch information
iskunk committed Jun 28, 2023
1 parent b43eb83 commit cb5fd1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions conan/tools/files/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def patch(conanfile, base_path=None, patch_file=None, patch_string=None, strip=0
:param kwargs: Extra parameters that can be added and will contribute to output information
"""

patch_type = kwargs.get('patch_type')
patch_type = kwargs.get('patch_type') or ("file" if patch_file else "string")
patch_description = kwargs.get('patch_description')

if patch_type or patch_description:
Expand Down Expand Up @@ -96,8 +96,11 @@ def apply_conandata_patches(conanfile):
if "patch_file" in it:
# The patch files are located in the root src
entry = it.copy()
patch_file = os.path.join(conanfile.export_sources_folder, entry.pop("patch_file"))
patch(conanfile, patch_file=patch_file, **entry)
patch_file = entry.pop("patch_file")
patch_file_path = os.path.join(conanfile.export_sources_folder, patch_file)
if not "patch_description" in entry:
entry["patch_description"] = patch_file
patch(conanfile, patch_file=patch_file_path, **entry)
elif "patch_string" in it:
patch(conanfile, **it)
else:
Expand Down
10 changes: 7 additions & 3 deletions conans/test/unittests/tools/files/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_single_patch_description(mock_patch_ng):
conanfile = ConanFileMock()
conanfile.display_name = 'mocked/ref'
patch(conanfile, patch_file='patch-file', patch_description='patch_description')
assert 'mocked/ref: Apply patch: patch_description\n' == output.getvalue()
assert 'mocked/ref: Apply patch (file): patch_description\n' == output.getvalue()


def test_single_patch_extra_fields(mock_patch_ng):
Expand Down Expand Up @@ -173,8 +173,10 @@ def test_multiple_no_version(mock_patch_ng):
'patch_description': 'Needed to build with modern clang compilers.'}
]}
apply_conandata_patches(conanfile)
assert 'mocked/ref: Apply patch (file): patches/0001-buildflatbuffers-cmake.patch\n' \
in output.getvalue()
assert 'mocked/ref: Apply patch (backport): Needed to build with modern clang compilers.\n' \
== output.getvalue()
in output.getvalue()


def test_multiple_with_version(mock_patch_ng):
Expand Down Expand Up @@ -210,8 +212,10 @@ def test_multiple_with_version(mock_patch_ng):

conanfile.version = "1.11.0"
apply_conandata_patches(conanfile)
assert 'mocked/ref: Apply patch (file): patches/0001-buildflatbuffers-cmake.patch\n' \
in output.getvalue()
assert 'mocked/ref: Apply patch (backport): Needed to build with modern clang compilers.\n' \
== output.getvalue()
in output.getvalue()

# Ensure the function is not mutating the `conan_data` structure
assert conanfile.conan_data == conandata_contents

0 comments on commit cb5fd1f

Please sign in to comment.