From cb5fd1f457cacd800f52d0e9279e43cd8fd92dc5 Mon Sep 17 00:00:00 2001 From: Daniel Richard G Date: Tue, 27 Jun 2023 04:05:25 -0400 Subject: [PATCH] Always indicate when patches are applied (#14165) Also update test_patches.py accordingly. --- conan/tools/files/patches.py | 9 ++++++--- conans/test/unittests/tools/files/test_patches.py | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/conan/tools/files/patches.py b/conan/tools/files/patches.py index 98f24a88001..e94e2ccb43f 100644 --- a/conan/tools/files/patches.py +++ b/conan/tools/files/patches.py @@ -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: @@ -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: diff --git a/conans/test/unittests/tools/files/test_patches.py b/conans/test/unittests/tools/files/test_patches.py index f48b602bfba..95da099c8e3 100644 --- a/conans/test/unittests/tools/files/test_patches.py +++ b/conans/test/unittests/tools/files/test_patches.py @@ -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): @@ -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): @@ -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