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

check for patches not referenced in conandata.yml #536

Closed
wants to merge 3 commits into from
Closed
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
30 changes: 27 additions & 3 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,10 +922,12 @@ def test(out):
conandata_yml = load_yml(conandata_path)

if not conandata_yml:
return
conandata_yml = {}

if 'sources' not in conandata_yml or 'patches' not in conandata_yml:
return
if 'sources' not in conandata_yml:
conandata_yml['sources'] = {}
if 'patches' not in conandata_yml:
conandata_yml['patches'] = {}

versions_conandata = conandata_yml['sources'].keys()
versions_patches = conandata_yml['patches'].keys()
Expand All @@ -943,6 +945,28 @@ def test(out):
continue
if not os.path.isfile(os.path.join(export_folder_path, patch['patch_file'])):
out.error("The patch file '{}' does not exist.".format(patch['patch_file']))

patches_path = os.path.join(export_folder_path, "patches")
unused_patches: list[str] = []
if os.path.isdir(patches_path):
unused_patches.extend(
os.path.join(root[len(patches_path) + 1:], f)
for root, _, files in os.walk(patches_path) for f in files)
unused_patches.sort()
for patches in conandata_yml["patches"].values():
if not isinstance(patches, list):
continue
for patch in patches:
if 'patch_file' not in patch:
continue
patch_file_name = str(patch["patch_file"])
patch_file_name = os.path.relpath(patch_file_name) # fixes the path (double slashes for example)
patch_file_name = patch_file_name[8:]
if patch_file_name in unused_patches:
unused_patches.remove(patch_file_name)
if unused_patches:
patches_str = ", ".join(f"patches/{patch}" for patch in unused_patches)
out.error(f"Following patch file(s) are/is not referenced in conandata.yml: {patches_str}")


@raise_if_error_output
Expand Down
19 changes: 19 additions & 0 deletions tests/test_hooks/conan-center/test_conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,3 +1248,22 @@ def test_dangling_patches(self):
output = self.conan(['export', 'all', 'name/version@user/test'])
self.assertIn("The patch file 'patches/patch.diff' does not exist.",
output)

conandata = textwrap.dedent("""
sources:
1.0:
url: fakeurl
md5: 12323423423
""")

tools.save(os.path.join("all", "conandata.yml"), content=conandata)
output = self.conan(['export', 'all', 'name/version@user/test'])
self.assertNotIn("Following patch file(s) are/is not referenced in conandata.yml",
output)

tools.save(os.path.join("all", "patches", "patch.diff"), content="")
output = self.conan(['export', 'all', 'name/version@user/test'])
self.assertIn("Following patch file(s) are/is not referenced in conandata.yml: patches/patch.diff",
output)