2017-08-10 11:34:14 +08:00
|
|
|
#!/usr/bin/env python3
|
2019-04-06 21:08:09 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2017-08-10 11:34:14 +08:00
|
|
|
|
|
|
|
# A script to generate a list of boards that have changed or added and create an
|
2019-06-19 02:45:40 +08:00
|
|
|
# arguments file for sanitycheck to allow running more tests for those boards.
|
2017-08-10 11:34:14 +08:00
|
|
|
|
|
|
|
import re, os
|
|
|
|
import sh
|
|
|
|
import logging
|
|
|
|
import argparse
|
2019-04-19 20:11:59 +08:00
|
|
|
import glob
|
2017-08-10 11:34:14 +08:00
|
|
|
|
|
|
|
if "ZEPHYR_BASE" not in os.environ:
|
|
|
|
logging.error("$ZEPHYR_BASE environment variable undefined.\n")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
logger = None
|
|
|
|
|
|
|
|
repository_path = os.environ['ZEPHYR_BASE']
|
|
|
|
sh_special_args = {
|
|
|
|
'_tty_out': False,
|
|
|
|
'_cwd': repository_path
|
|
|
|
}
|
|
|
|
|
|
|
|
def init_logs():
|
|
|
|
log_lev = os.environ.get('LOG_LEVEL', None)
|
|
|
|
level = logging.INFO
|
|
|
|
global logger
|
|
|
|
|
|
|
|
if log_lev == "DEBUG":
|
|
|
|
level = logging.DEBUG
|
|
|
|
elif log_lev == "ERROR":
|
|
|
|
level = logging.ERROR
|
|
|
|
|
|
|
|
console = logging.StreamHandler()
|
|
|
|
format = logging.Formatter('%(levelname)-8s: %(message)s')
|
|
|
|
console.setFormatter(format)
|
|
|
|
logger = logging.getLogger('')
|
|
|
|
logger.addHandler(console)
|
|
|
|
logger.setLevel(level)
|
|
|
|
|
|
|
|
logging.debug("Log init completed")
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Generate a sanitycheck argument for for boards "
|
|
|
|
" that have changed")
|
|
|
|
parser.add_argument('-c', '--commits', default=None,
|
|
|
|
help="Commit range in the form: a..b")
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
boards = set()
|
2019-04-19 20:11:59 +08:00
|
|
|
all_boards = set()
|
2017-08-10 11:34:14 +08:00
|
|
|
|
|
|
|
args = parse_args()
|
|
|
|
if not args.commits:
|
|
|
|
exit(1)
|
|
|
|
|
2019-09-03 19:06:05 +08:00
|
|
|
# pylint does not like the 'sh' library
|
|
|
|
# pylint: disable=too-many-function-args,unexpected-keyword-arg
|
|
|
|
commit = sh.git("diff", "--name-only", args.commits, **sh_special_args)
|
2017-08-10 11:34:14 +08:00
|
|
|
files = commit.split("\n")
|
|
|
|
|
|
|
|
for f in files:
|
2019-02-10 03:59:48 +08:00
|
|
|
if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"):
|
|
|
|
continue
|
2019-03-22 04:38:03 +08:00
|
|
|
p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f)
|
2017-08-10 11:34:14 +08:00
|
|
|
if p and p.groups():
|
|
|
|
boards.add(p.group(1))
|
|
|
|
|
2019-04-19 20:11:59 +08:00
|
|
|
for b in boards:
|
|
|
|
suboards = glob.glob("boards/*/%s/*.yaml" %(b))
|
|
|
|
for subboard in suboards:
|
|
|
|
name = os.path.splitext(os.path.basename(subboard))[0]
|
|
|
|
if name:
|
|
|
|
all_boards.add(name)
|
|
|
|
|
|
|
|
if all_boards:
|
|
|
|
print("-p\n%s" %("\n-p\n".join(all_boards)))
|
2017-08-10 11:34:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|