scripts: ci: guideline_check: support other repos

Support running this check against other repositories.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2023-12-10 16:04:57 +10:00 committed by Carles Cufí
parent a40a8a5f49
commit ac78b97820

View file

@ -11,13 +11,6 @@ from unidiff import PatchSet
if "ZEPHYR_BASE" not in os.environ:
exit("$ZEPHYR_BASE environment variable undefined.")
repository_path = os.environ['ZEPHYR_BASE']
sh_special_args = {
'_tty_out': False,
'_cwd': repository_path
}
coccinelle_scripts = ["/scripts/coccinelle/reserved_names.cocci",
"/scripts/coccinelle/same_identifier.cocci",
#"/scripts/coccinelle/identifier_length.cocci",
@ -38,7 +31,9 @@ def parse_coccinelle(contents: str, violations: dict):
def parse_args():
parser = argparse.ArgumentParser(
description="Check if change requires full twister", allow_abbrev=False)
description="Check commits against Cocccinelle rules", allow_abbrev=False)
parser.add_argument('-r', "--repository", required=False,
help="Path to repository")
parser.add_argument('-c', '--commits', default=None,
help="Commit range in the form: a..b")
parser.add_argument("-o", "--output", required=False,
@ -51,6 +46,16 @@ def main():
if not args.commits:
exit("missing commit range")
if args.repository is None:
repository_path = os.environ['ZEPHYR_BASE']
else:
repository_path = args.repository
sh_special_args = {
'_tty_out': False,
'_cwd': repository_path
}
# pylint does not like the 'sh' library
# pylint: disable=too-many-function-args,unexpected-keyword-arg
commit = sh.git("diff", args.commits, **sh_special_args)