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

yamllinter: raise if actual patch files are not coherent with conandata.yml #14912

Closed
wants to merge 11 commits into from
33 changes: 33 additions & 0 deletions linter/conandata_yaml_linter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import argparse
import copy
import os
from strictyaml import (
load,
Map,
Expand Down Expand Up @@ -59,10 +61,35 @@ def main():
pretty_print_yaml_validate_error(args, error) # YAML could not be parsed
return

patches_path = os.path.join(os.path.dirname(args.path), "patches")
actual_patches = []
if os.path.isdir(patches_path):
for root, _, files in os.walk(patches_path):
for f in files:
actual_patches.append(os.path.join(root[len(patches_path)+1:], f))
unused_patches = copy.copy(actual_patches)
if "patches" in parsed:
for version in parsed["patches"]:
patches = parsed["patches"][version]
for i, patch in enumerate(patches):
patch_file_name = str(patch["patch_file"])
if not patch_file_name.startswith("patches/"):
print(
f"::error file={args.path},line={type.start_line},endline={type.end_line},"
f"title=conandata.yml patch path error"
f"::'patches' should be located in `patches` subfolder"
)
else:
patch_file_name = patch_file_name[8:]
if patch_file_name in unused_patches:
unused_patches.remove(patch_file_name)
if patch_file_name not in actual_patches:
print(
f"::error file={args.path},line={patch['patch_file'].start_line},endline={patch['patch_file'].end_line},"
f"title=conandata.yml patch existence"
f"::The file `{patch_file_name}` does not exist in the `patches` folder"
)

# Individual report errors for each patch object
try:
parsed["patches"][version][i].revalidate(patch_fields)
Expand Down Expand Up @@ -94,6 +121,12 @@ def main():
" layouts (see https://docs.conan.io/en/latest/reference/conanfile/tools/layout.html) and"
" the new helper (see https://docs.conan.io/en/latest/reference/conanfile/tools/files/patches.html#conan-tools-files-apply-conandata-patches)"
)
for p in unused_patches:
print(
f"::error file={patches_path},"
f"title=patch file unused"
f"::Patch file {p} is not referenced in {args.path}"
)


def pretty_print_yaml_validate_error(args, error):
Expand Down