Skip to content

Commit

Permalink
Merge pull request #532 from RubenRBS/rr/patches-ensure-version-applies
Browse files Browse the repository at this point in the history
Add dangling patch checks
  • Loading branch information
uilianries authored Apr 15, 2024
2 parents 02f7384 + ccb5fd9 commit d64332c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
29 changes: 29 additions & 0 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"KB-H075": "REQUIREMENT OVERRIDE PARAMETER",
"KB-H076": "EITHER STATIC OR SHARED OF EACH LIB",
"KB-H077": "APPLE RELOCATABLE SHARED LIBS",
"KB-H078": "NO DANGLING PATCHES"
}


Expand Down Expand Up @@ -912,6 +913,34 @@ def test(out):
if match:
out.error("self.requires('package/version', override=True) is forbidden, do not force override parameter.")

@run_test("KB-H078", output)
def test(out):
conandata_path = os.path.join(export_folder_path, "conandata.yml")
conandata_yml = load_yml(conandata_path)

if not conandata_yml:
return

if 'sources' not in conandata_yml or 'patches' not in conandata_yml:
return

versions_conandata = conandata_yml['sources'].keys()
versions_patches = conandata_yml['patches'].keys()
difference = set(versions_patches) - set(versions_conandata)
if difference:
out.error("The versions {} are in 'patches' but not in 'sources'.".format(difference))

for patches in conandata_yml['patches'].values():
if not isinstance(patches, list):
# out.error("The 'patches' entry should be a list of patches.")
patches = [patches]
for patch in patches:
if 'patch_file' not in patch:
# out.error("The 'patch_file' key is required in all patches.")
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']))


@raise_if_error_output
def post_export(output, conanfile, conanfile_path, reference, **kwargs):
Expand Down
33 changes: 32 additions & 1 deletion tests/test_hooks/conan-center/test_conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,6 @@ def source(self):
output = self.conan(['export', '.', 'name/version@user/test'])
self.assertNotIn("[NO REQUIRED_CONAN_VERSION (KB-H065)] tools.get", output)


def test_no_collect_libs_warning(self):
conanfile = textwrap.dedent("""\
from conans import ConanFile
Expand All @@ -1217,3 +1216,35 @@ def package_info(self):
tools.save('conanfile.py', content=conanfile)
output = self.conan(['create', 'conanfile.py', 'name/version@user/test'])
self.assertNotIn("Lib folder doesn't exist, can't collect libraries", output)

def test_dangling_patches(self):
tools.save(os.path.join('all', 'conanfile.py'), content=self.conanfile_base.format(placeholder=''))
conandata = textwrap.dedent("""
sources:
1.0:
url: fakeurl
md5: 12323423423
patches:
"1.1":
patch_file: "patches/patch.diff"
""")

tools.save(os.path.join("all", "conandata.yml"), content=conandata)
output = self.conan(['export', 'all', 'name/version@user/test'])
self.assertIn("are in 'patches' but not in 'sources'",
output)

conandata = textwrap.dedent("""
sources:
1.0:
url: fakeurl
md5: 12323423423
patches:
"1.0":
patch_file: "patches/patch.diff"
""")

tools.save(os.path.join("all", "conandata.yml"), content=conandata)
output = self.conan(['export', 'all', 'name/version@user/test'])
self.assertIn("The patch file 'patches/patch.diff' does not exist.",
output)

0 comments on commit d64332c

Please sign in to comment.