Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Anas Nashif | 3ae5262 | 2019-04-06 09:08:09 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: Apache-2.0 |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 3 | |
| 4 | # A script to generate a list of boards that have changed or added and create an |
Anas Nashif | f2cb20c | 2019-06-18 14:45:40 -0400 | [diff] [blame] | 5 | # arguments file for sanitycheck to allow running more tests for those boards. |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 6 | |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 7 | import re, os |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 8 | import sh |
| 9 | import logging |
| 10 | import argparse |
Anas Nashif | 924987d | 2019-04-19 08:11:59 -0400 | [diff] [blame] | 11 | import glob |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 12 | |
| 13 | if "ZEPHYR_BASE" not in os.environ: |
| 14 | logging.error("$ZEPHYR_BASE environment variable undefined.\n") |
| 15 | exit(1) |
| 16 | |
| 17 | logger = None |
| 18 | |
| 19 | repository_path = os.environ['ZEPHYR_BASE'] |
| 20 | sh_special_args = { |
| 21 | '_tty_out': False, |
| 22 | '_cwd': repository_path |
| 23 | } |
| 24 | |
| 25 | def init_logs(): |
| 26 | log_lev = os.environ.get('LOG_LEVEL', None) |
| 27 | level = logging.INFO |
| 28 | global logger |
| 29 | |
| 30 | if log_lev == "DEBUG": |
| 31 | level = logging.DEBUG |
| 32 | elif log_lev == "ERROR": |
| 33 | level = logging.ERROR |
| 34 | |
| 35 | console = logging.StreamHandler() |
| 36 | format = logging.Formatter('%(levelname)-8s: %(message)s') |
| 37 | console.setFormatter(format) |
| 38 | logger = logging.getLogger('') |
| 39 | logger.addHandler(console) |
| 40 | logger.setLevel(level) |
| 41 | |
| 42 | logging.debug("Log init completed") |
| 43 | |
| 44 | def parse_args(): |
| 45 | parser = argparse.ArgumentParser( |
| 46 | description="Generate a sanitycheck argument for for boards " |
| 47 | " that have changed") |
| 48 | parser.add_argument('-c', '--commits', default=None, |
| 49 | help="Commit range in the form: a..b") |
| 50 | return parser.parse_args() |
| 51 | |
| 52 | def main(): |
| 53 | boards = set() |
Anas Nashif | 924987d | 2019-04-19 08:11:59 -0400 | [diff] [blame] | 54 | all_boards = set() |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 55 | |
| 56 | args = parse_args() |
| 57 | if not args.commits: |
| 58 | exit(1) |
| 59 | |
| 60 | commit = sh.git("diff","--name-only", args.commits, **sh_special_args) |
| 61 | files = commit.split("\n") |
| 62 | |
| 63 | for f in files: |
Anas Nashif | 115b811 | 2019-02-09 14:59:48 -0500 | [diff] [blame] | 64 | if f.endswith(".rst") or f.endswith(".png") or f.endswith(".jpg"): |
| 65 | continue |
Ulf Magnusson | a449c98 | 2019-03-21 21:38:03 +0100 | [diff] [blame] | 66 | p = re.match(r"^boards\/[^/]+\/([^/]+)\/", f) |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 67 | if p and p.groups(): |
| 68 | boards.add(p.group(1)) |
| 69 | |
Anas Nashif | 924987d | 2019-04-19 08:11:59 -0400 | [diff] [blame] | 70 | for b in boards: |
| 71 | suboards = glob.glob("boards/*/%s/*.yaml" %(b)) |
| 72 | for subboard in suboards: |
| 73 | name = os.path.splitext(os.path.basename(subboard))[0] |
| 74 | if name: |
| 75 | all_boards.add(name) |
| 76 | |
| 77 | if all_boards: |
| 78 | print("-p\n%s" %("\n-p\n".join(all_boards))) |
Anas Nashif | c1cafb1 | 2017-08-09 23:34:14 -0400 | [diff] [blame] | 79 | |
| 80 | |
| 81 | |
| 82 | if __name__ == "__main__": |
| 83 | main() |