Skip to content

Commit

Permalink
check for patches not referenced in conandata.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
ericLemanissier authored Apr 24, 2024
1 parent 0d81053 commit 9763f2e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
26 changes: 23 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,24 @@ 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 parsed["patches"]:
for patch in patches:
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)
for patch in unused_patches:
print(f"Following patch files is not referenced in conandata.yml: patches/{patch}")



@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 files 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 files is not referenced in conandata.yml: patches/patch.diff",
output)


0 comments on commit 9763f2e

Please sign in to comment.