Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 3 | # |
| 4 | # Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
| 5 | # |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 6 | |
| 7 | """ |
| 8 | Move config options from headers to defconfig files. |
| 9 | |
Simon Glass | 5c72c0e | 2021-07-21 21:35:51 -0600 | [diff] [blame] | 10 | See doc/develop/moveconfig.rst for documentation. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 11 | """ |
| 12 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 13 | from argparse import ArgumentParser |
Markus Klotzbuecher | b3192f4 | 2020-02-12 20:46:44 +0100 | [diff] [blame] | 14 | import asteval |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 15 | import collections |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 16 | from contextlib import ExitStack |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 17 | import copy |
Masahiro Yamada | f2f6981 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 18 | import difflib |
Simon Glass | 84067a5 | 2021-12-18 08:09:45 -0700 | [diff] [blame] | 19 | import doctest |
Masahiro Yamada | c8e1b10 | 2016-05-19 15:52:07 +0900 | [diff] [blame] | 20 | import filecmp |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 21 | import fnmatch |
Masahiro Yamada | 0dbc9b5 | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 22 | import glob |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 23 | import multiprocessing |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 24 | import os |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 25 | import queue |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 26 | import re |
| 27 | import shutil |
| 28 | import subprocess |
| 29 | import sys |
| 30 | import tempfile |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 31 | import threading |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 32 | import time |
Simon Glass | 84067a5 | 2021-12-18 08:09:45 -0700 | [diff] [blame] | 33 | import unittest |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 34 | |
Simon Glass | 0ede00f | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 35 | from buildman import bsettings |
| 36 | from buildman import kconfiglib |
| 37 | from buildman import toolchain |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 38 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 39 | SHOW_GNU_MAKE = 'scripts/show-gnu-make' |
| 40 | SLEEP_TIME=0.03 |
| 41 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 42 | STATE_IDLE = 0 |
| 43 | STATE_DEFCONFIG = 1 |
| 44 | STATE_AUTOCONF = 2 |
Joe Hershberger | 96464ba | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 45 | STATE_SAVEDEFCONFIG = 3 |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 46 | |
| 47 | ACTION_MOVE = 0 |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 48 | ACTION_NO_ENTRY = 1 |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 49 | ACTION_NO_ENTRY_WARN = 2 |
| 50 | ACTION_NO_CHANGE = 3 |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 51 | |
| 52 | COLOR_BLACK = '0;30' |
| 53 | COLOR_RED = '0;31' |
| 54 | COLOR_GREEN = '0;32' |
| 55 | COLOR_BROWN = '0;33' |
| 56 | COLOR_BLUE = '0;34' |
| 57 | COLOR_PURPLE = '0;35' |
| 58 | COLOR_CYAN = '0;36' |
| 59 | COLOR_LIGHT_GRAY = '0;37' |
| 60 | COLOR_DARK_GRAY = '1;30' |
| 61 | COLOR_LIGHT_RED = '1;31' |
| 62 | COLOR_LIGHT_GREEN = '1;32' |
| 63 | COLOR_YELLOW = '1;33' |
| 64 | COLOR_LIGHT_BLUE = '1;34' |
| 65 | COLOR_LIGHT_PURPLE = '1;35' |
| 66 | COLOR_LIGHT_CYAN = '1;36' |
| 67 | COLOR_WHITE = '1;37' |
| 68 | |
Simon Glass | f3b8e64 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 69 | AUTO_CONF_PATH = 'include/config/auto.conf' |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 70 | CONFIG_DATABASE = 'moveconfig.db' |
Simon Glass | f3b8e64 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 71 | |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 72 | CONFIG_LEN = len('CONFIG_') |
Simon Glass | f3b8e64 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 73 | |
Markus Klotzbuecher | b237d35 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 74 | SIZES = { |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 75 | 'SZ_1': 0x00000001, 'SZ_2': 0x00000002, |
| 76 | 'SZ_4': 0x00000004, 'SZ_8': 0x00000008, |
| 77 | 'SZ_16': 0x00000010, 'SZ_32': 0x00000020, |
| 78 | 'SZ_64': 0x00000040, 'SZ_128': 0x00000080, |
| 79 | 'SZ_256': 0x00000100, 'SZ_512': 0x00000200, |
| 80 | 'SZ_1K': 0x00000400, 'SZ_2K': 0x00000800, |
| 81 | 'SZ_4K': 0x00001000, 'SZ_8K': 0x00002000, |
| 82 | 'SZ_16K': 0x00004000, 'SZ_32K': 0x00008000, |
| 83 | 'SZ_64K': 0x00010000, 'SZ_128K': 0x00020000, |
| 84 | 'SZ_256K': 0x00040000, 'SZ_512K': 0x00080000, |
| 85 | 'SZ_1M': 0x00100000, 'SZ_2M': 0x00200000, |
| 86 | 'SZ_4M': 0x00400000, 'SZ_8M': 0x00800000, |
| 87 | 'SZ_16M': 0x01000000, 'SZ_32M': 0x02000000, |
| 88 | 'SZ_64M': 0x04000000, 'SZ_128M': 0x08000000, |
| 89 | 'SZ_256M': 0x10000000, 'SZ_512M': 0x20000000, |
| 90 | 'SZ_1G': 0x40000000, 'SZ_2G': 0x80000000, |
| 91 | 'SZ_4G': 0x100000000 |
Markus Klotzbuecher | b237d35 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Simon Glass | b8d11da | 2022-02-08 11:49:45 -0700 | [diff] [blame] | 94 | RE_REMOVE_DEFCONFIG = re.compile(r'(.*)_defconfig') |
| 95 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 96 | ### helper functions ### |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 97 | def check_top_directory(): |
| 98 | """Exit if we are not at the top of source directory.""" |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 99 | for fname in 'README', 'Licenses': |
| 100 | if not os.path.exists(fname): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 101 | sys.exit('Please run at the top of source directory.') |
| 102 | |
Masahiro Yamada | bd63e5b | 2016-05-19 15:51:54 +0900 | [diff] [blame] | 103 | def check_clean_directory(): |
| 104 | """Exit if the source tree is not clean.""" |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 105 | for fname in '.config', 'include/config': |
| 106 | if os.path.exists(fname): |
Masahiro Yamada | bd63e5b | 2016-05-19 15:51:54 +0900 | [diff] [blame] | 107 | sys.exit("source tree is not clean, please run 'make mrproper'") |
| 108 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 109 | def get_make_cmd(): |
| 110 | """Get the command name of GNU Make. |
| 111 | |
| 112 | U-Boot needs GNU Make for building, but the command name is not |
| 113 | necessarily "make". (for example, "gmake" on FreeBSD). |
| 114 | Returns the most appropriate command name on your system. |
| 115 | """ |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 116 | with subprocess.Popen([SHOW_GNU_MAKE], stdout=subprocess.PIPE) as proc: |
| 117 | ret = proc.communicate() |
| 118 | if proc.returncode: |
| 119 | sys.exit('GNU Make not found') |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 120 | return ret[0].rstrip() |
| 121 | |
Simon Glass | 25f978c | 2017-06-01 19:38:58 -0600 | [diff] [blame] | 122 | def get_matched_defconfig(line): |
| 123 | """Get the defconfig files that match a pattern |
| 124 | |
| 125 | Args: |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 126 | line (str): Path or filename to match, e.g. 'configs/snow_defconfig' or |
Simon Glass | 25f978c | 2017-06-01 19:38:58 -0600 | [diff] [blame] | 127 | 'k2*_defconfig'. If no directory is provided, 'configs/' is |
| 128 | prepended |
| 129 | |
| 130 | Returns: |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 131 | list of str: a list of matching defconfig files |
Simon Glass | 25f978c | 2017-06-01 19:38:58 -0600 | [diff] [blame] | 132 | """ |
| 133 | dirname = os.path.dirname(line) |
| 134 | if dirname: |
| 135 | pattern = line |
| 136 | else: |
| 137 | pattern = os.path.join('configs', line) |
| 138 | return glob.glob(pattern) + glob.glob(pattern + '_defconfig') |
| 139 | |
Masahiro Yamada | 0dbc9b5 | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 140 | def get_matched_defconfigs(defconfigs_file): |
Simon Glass | ee4e61b | 2017-06-01 19:38:59 -0600 | [diff] [blame] | 141 | """Get all the defconfig files that match the patterns in a file. |
| 142 | |
| 143 | Args: |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 144 | defconfigs_file (str): File containing a list of defconfigs to process, |
| 145 | or '-' to read the list from stdin |
Simon Glass | ee4e61b | 2017-06-01 19:38:59 -0600 | [diff] [blame] | 146 | |
| 147 | Returns: |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 148 | list of str: A list of paths to defconfig files, with no duplicates |
Simon Glass | ee4e61b | 2017-06-01 19:38:59 -0600 | [diff] [blame] | 149 | """ |
Masahiro Yamada | 0dbc9b5 | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 150 | defconfigs = [] |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 151 | with ExitStack() as stack: |
| 152 | if defconfigs_file == '-': |
| 153 | inf = sys.stdin |
| 154 | defconfigs_file = 'stdin' |
| 155 | else: |
| 156 | inf = stack.enter_context(open(defconfigs_file, encoding='utf-8')) |
| 157 | for i, line in enumerate(inf): |
| 158 | line = line.strip() |
| 159 | if not line: |
| 160 | continue # skip blank lines silently |
| 161 | if ' ' in line: |
| 162 | line = line.split(' ')[0] # handle 'git log' input |
| 163 | matched = get_matched_defconfig(line) |
| 164 | if not matched: |
| 165 | print(f"warning: {defconfigs_file}:{i + 1}: no defconfig matched '{line}'", |
| 166 | file=sys.stderr) |
Masahiro Yamada | 0dbc9b5 | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 167 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 168 | defconfigs += matched |
Masahiro Yamada | 0dbc9b5 | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 169 | |
| 170 | # use set() to drop multiple matching |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 171 | return [defconfig[len('configs') + 1:] for defconfig in set(defconfigs)] |
Masahiro Yamada | 0dbc9b5 | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 172 | |
Masahiro Yamada | 684c306 | 2016-07-25 19:15:28 +0900 | [diff] [blame] | 173 | def get_all_defconfigs(): |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 174 | """Get all the defconfig files under the configs/ directory. |
| 175 | |
| 176 | Returns: |
| 177 | list of str: List of paths to defconfig files |
| 178 | """ |
Masahiro Yamada | 684c306 | 2016-07-25 19:15:28 +0900 | [diff] [blame] | 179 | defconfigs = [] |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 180 | for (dirpath, _, filenames) in os.walk('configs'): |
Masahiro Yamada | 684c306 | 2016-07-25 19:15:28 +0900 | [diff] [blame] | 181 | dirpath = dirpath[len('configs') + 1:] |
| 182 | for filename in fnmatch.filter(filenames, '*_defconfig'): |
| 183 | defconfigs.append(os.path.join(dirpath, filename)) |
| 184 | |
| 185 | return defconfigs |
| 186 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 187 | def color_text(color_enabled, color, string): |
| 188 | """Return colored string.""" |
| 189 | if color_enabled: |
Masahiro Yamada | 1d08556 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 190 | # LF should not be surrounded by the escape sequence. |
| 191 | # Otherwise, additional whitespace or line-feed might be printed. |
| 192 | return '\n'.join([ '\033[' + color + 'm' + s + '\033[0m' if s else '' |
| 193 | for s in string.split('\n') ]) |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 194 | return string |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 195 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 196 | def show_diff(alines, blines, file_path, color_enabled): |
Masahiro Yamada | f2f6981 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 197 | """Show unidified diff. |
| 198 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 199 | Args: |
| 200 | alines (list of str): A list of lines (before) |
| 201 | blines (list of str): A list of lines (after) |
| 202 | file_path (str): Path to the file |
| 203 | color_enabled (bool): Display the diff in color |
Masahiro Yamada | f2f6981 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 204 | """ |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 205 | diff = difflib.unified_diff(alines, blines, |
Masahiro Yamada | f2f6981 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 206 | fromfile=os.path.join('a', file_path), |
| 207 | tofile=os.path.join('b', file_path)) |
| 208 | |
| 209 | for line in diff: |
Alper Nebi Yasak | 6c928c6 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 210 | if line.startswith('-') and not line.startswith('--'): |
| 211 | print(color_text(color_enabled, COLOR_RED, line)) |
| 212 | elif line.startswith('+') and not line.startswith('++'): |
| 213 | print(color_text(color_enabled, COLOR_GREEN, line)) |
Masahiro Yamada | e9ea122 | 2016-07-25 19:15:26 +0900 | [diff] [blame] | 214 | else: |
Alper Nebi Yasak | 6c928c6 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 215 | print(line) |
Masahiro Yamada | f2f6981 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 216 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 217 | def extend_matched_lines(lines, matched, pre_patterns, post_patterns, |
| 218 | extend_pre, extend_post): |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 219 | """Extend matched lines if desired patterns are found before/after already |
| 220 | matched lines. |
| 221 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 222 | Args: |
| 223 | lines (list of str): list of lines handled. |
| 224 | matched (list of int): list of line numbers that have been already |
| 225 | matched (will be updated by this function) |
| 226 | pre_patterns (list of re.Pattern): list of regular expression that should |
| 227 | be matched as preamble |
| 228 | post_patterns (list of re.Pattern): list of regular expression that should |
| 229 | be matched as postamble |
| 230 | extend_pre (bool): Add the line number of matched preamble to the matched |
| 231 | list |
| 232 | extend_post (bool): Add the line number of matched postamble to the |
| 233 | matched list |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 234 | """ |
| 235 | extended_matched = [] |
| 236 | |
| 237 | j = matched[0] |
| 238 | |
| 239 | for i in matched: |
| 240 | if i == 0 or i < j: |
| 241 | continue |
| 242 | j = i |
| 243 | while j in matched: |
| 244 | j += 1 |
| 245 | if j >= len(lines): |
| 246 | break |
| 247 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 248 | for pat in pre_patterns: |
| 249 | if pat.search(lines[i - 1]): |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 250 | break |
| 251 | else: |
| 252 | # not matched |
| 253 | continue |
| 254 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 255 | for pat in post_patterns: |
| 256 | if pat.search(lines[j]): |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 257 | break |
| 258 | else: |
| 259 | # not matched |
| 260 | continue |
| 261 | |
| 262 | if extend_pre: |
| 263 | extended_matched.append(i - 1) |
| 264 | if extend_post: |
| 265 | extended_matched.append(j) |
| 266 | |
| 267 | matched += extended_matched |
| 268 | matched.sort() |
| 269 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 270 | def confirm(args, prompt): |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 271 | """Ask the user to confirm something |
| 272 | |
| 273 | Args: |
| 274 | args (Namespace ): program arguments |
| 275 | |
| 276 | Returns: |
| 277 | bool: True to confirm, False to cancel/stop |
| 278 | """ |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 279 | if not args.yes: |
Chris Packham | 85edfc1 | 2017-05-02 21:30:46 +1200 | [diff] [blame] | 280 | while True: |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 281 | choice = input(f'{prompt} [y/n]: ') |
Chris Packham | 85edfc1 | 2017-05-02 21:30:46 +1200 | [diff] [blame] | 282 | choice = choice.lower() |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 283 | print(choice) |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 284 | if choice in ('y', 'n'): |
Chris Packham | 85edfc1 | 2017-05-02 21:30:46 +1200 | [diff] [blame] | 285 | break |
| 286 | |
| 287 | if choice == 'n': |
| 288 | return False |
| 289 | |
| 290 | return True |
| 291 | |
Simon Glass | 2fd85bd | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 292 | def write_file(fname, data): |
| 293 | """Write data to a file |
| 294 | |
| 295 | Args: |
| 296 | fname (str): Filename to write to |
| 297 | data (list of str): Lines to write (with or without trailing newline); |
| 298 | or str to write |
| 299 | """ |
| 300 | with open(fname, 'w', encoding='utf-8') as out: |
| 301 | if isinstance(data, list): |
| 302 | for line in data: |
| 303 | print(line.rstrip('\n'), file=out) |
| 304 | else: |
| 305 | out.write(data) |
| 306 | |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 307 | def read_file(fname, as_lines=True, skip_unicode=False): |
| 308 | """Read a file and return the contents |
| 309 | |
| 310 | Args: |
| 311 | fname (str): Filename to read from |
| 312 | as_lines: Return file contents as a list of lines |
| 313 | skip_unicode (bool): True to report unicode errors and continue |
| 314 | |
| 315 | Returns: |
| 316 | iter of str: List of ;ines from the file with newline removed; str if |
| 317 | as_lines is False with newlines intact; or None if a unicode error |
| 318 | occurred |
| 319 | |
| 320 | Raises: |
| 321 | UnicodeDecodeError: Unicode error occurred when reading |
| 322 | """ |
| 323 | with open(fname, encoding='utf-8') as inf: |
| 324 | try: |
| 325 | if as_lines: |
| 326 | return [line.rstrip('\n') for line in inf.readlines()] |
| 327 | else: |
| 328 | return inf.read() |
| 329 | except UnicodeDecodeError as e: |
| 330 | if not skip_unicode: |
Simon Glass | 68a0b71 | 2022-02-11 13:23:22 -0700 | [diff] [blame] | 331 | raise |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 332 | print("Failed on file %s': %s" % (fname, e)) |
| 333 | return None |
| 334 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 335 | def cleanup_empty_blocks(header_path, args): |
Chris Packham | 4d9dbb1 | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 336 | """Clean up empty conditional blocks |
| 337 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 338 | Args: |
| 339 | header_path (str): path to the cleaned file. |
| 340 | args (Namespace): program arguments |
Chris Packham | 4d9dbb1 | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 341 | """ |
| 342 | pattern = re.compile(r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*', flags=re.M) |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 343 | data = read_file(header_path, as_lines=False, skip_unicode=True) |
| 344 | if data is None: |
| 345 | return |
Chris Packham | 4d9dbb1 | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 346 | |
| 347 | new_data = pattern.sub('\n', data) |
| 348 | |
| 349 | show_diff(data.splitlines(True), new_data.splitlines(True), header_path, |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 350 | args.color) |
Chris Packham | 4d9dbb1 | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 351 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 352 | if args.dry_run: |
Chris Packham | 4d9dbb1 | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 353 | return |
| 354 | |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 355 | if new_data != data: |
| 356 | write_file(header_path, new_data) |
Chris Packham | 4d9dbb1 | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 357 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 358 | def cleanup_one_header(header_path, patterns, args): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 359 | """Clean regex-matched lines away from a file. |
| 360 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 361 | Args: |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 362 | header_path: path to the cleaned file. |
| 363 | patterns: list of regex patterns. Any lines matching to these |
| 364 | patterns are deleted. |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 365 | args (Namespace): program arguments |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 366 | """ |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 367 | lines = read_file(header_path, skip_unicode=True) |
| 368 | if lines is None: |
| 369 | return |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 370 | |
| 371 | matched = [] |
| 372 | for i, line in enumerate(lines): |
Alper Nebi Yasak | 6c928c6 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 373 | if i - 1 in matched and lines[i - 1].endswith('\\'): |
Masahiro Yamada | a3a779f | 2016-07-25 19:15:27 +0900 | [diff] [blame] | 374 | matched.append(i) |
| 375 | continue |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 376 | for pattern in patterns: |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 377 | if pattern.search(line): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 378 | matched.append(i) |
| 379 | break |
| 380 | |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 381 | if not matched: |
| 382 | return |
| 383 | |
| 384 | # remove empty #ifdef ... #endif, successive blank lines |
Alper Nebi Yasak | 6c928c6 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 385 | pattern_if = re.compile(r'#\s*if(def|ndef)?\b') # #if, #ifdef, #ifndef |
| 386 | pattern_elif = re.compile(r'#\s*el(if|se)\b') # #elif, #else |
| 387 | pattern_endif = re.compile(r'#\s*endif\b') # #endif |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 388 | pattern_blank = re.compile(r'^\s*$') # empty line |
| 389 | |
| 390 | while True: |
| 391 | old_matched = copy.copy(matched) |
| 392 | extend_matched_lines(lines, matched, [pattern_if], |
| 393 | [pattern_endif], True, True) |
| 394 | extend_matched_lines(lines, matched, [pattern_elif], |
| 395 | [pattern_elif, pattern_endif], True, False) |
| 396 | extend_matched_lines(lines, matched, [pattern_if, pattern_elif], |
| 397 | [pattern_blank], False, True) |
| 398 | extend_matched_lines(lines, matched, [pattern_blank], |
| 399 | [pattern_elif, pattern_endif], True, False) |
| 400 | extend_matched_lines(lines, matched, [pattern_blank], |
| 401 | [pattern_blank], True, False) |
| 402 | if matched == old_matched: |
| 403 | break |
| 404 | |
Masahiro Yamada | f2f6981 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 405 | tolines = copy.copy(lines) |
| 406 | |
| 407 | for i in reversed(matched): |
| 408 | tolines.pop(i) |
| 409 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 410 | show_diff(lines, tolines, header_path, args.color) |
Masahiro Yamada | 8ba1f5d | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 411 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 412 | if args.dry_run: |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 413 | return |
| 414 | |
Simon Glass | 2fd85bd | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 415 | write_file(header_path, tolines) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 416 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 417 | def cleanup_headers(configs, args): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 418 | """Delete config defines from board headers. |
| 419 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 420 | Args: |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 421 | configs: A list of CONFIGs to remove. |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 422 | args (Namespace): program arguments |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 423 | """ |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 424 | if not confirm(args, 'Clean up headers?'): |
Chris Packham | 85edfc1 | 2017-05-02 21:30:46 +1200 | [diff] [blame] | 425 | return |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 426 | |
| 427 | patterns = [] |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 428 | for config in configs: |
Alper Nebi Yasak | 6c928c6 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 429 | patterns.append(re.compile(r'#\s*define\s+%s\b' % config)) |
| 430 | patterns.append(re.compile(r'#\s*undef\s+%s\b' % config)) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 431 | |
Joe Hershberger | 60727f5 | 2015-05-19 13:21:21 -0500 | [diff] [blame] | 432 | for dir in 'include', 'arch', 'board': |
| 433 | for (dirpath, dirnames, filenames) in os.walk(dir): |
Masahiro Yamada | dc6de50 | 2016-07-25 19:15:22 +0900 | [diff] [blame] | 434 | if dirpath == os.path.join('include', 'generated'): |
| 435 | continue |
Joe Hershberger | 60727f5 | 2015-05-19 13:21:21 -0500 | [diff] [blame] | 436 | for filename in filenames: |
Simon Glass | a38cc17 | 2020-08-11 11:23:34 -0600 | [diff] [blame] | 437 | if not filename.endswith(('~', '.dts', '.dtsi', '.bin', |
Trevor Woerner | dc514d7 | 2021-03-15 12:01:33 -0400 | [diff] [blame] | 438 | '.elf','.aml','.dat')): |
Chris Packham | 4d9dbb1 | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 439 | header_path = os.path.join(dirpath, filename) |
Tom Rini | 02b5670 | 2019-11-10 21:19:37 -0500 | [diff] [blame] | 440 | # This file contains UTF-16 data and no CONFIG symbols |
| 441 | if header_path == 'include/video_font_data.h': |
| 442 | continue |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 443 | cleanup_one_header(header_path, patterns, args) |
| 444 | cleanup_empty_blocks(header_path, args) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 445 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 446 | def cleanup_whitelist(configs, args): |
Chris Packham | ca43834 | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 447 | """Delete config whitelist entries |
| 448 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 449 | Args: |
Chris Packham | ca43834 | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 450 | configs: A list of CONFIGs to remove. |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 451 | args (Namespace): program arguments |
Chris Packham | ca43834 | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 452 | """ |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 453 | if not confirm(args, 'Clean up whitelist entries?'): |
Chris Packham | ca43834 | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 454 | return |
| 455 | |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 456 | lines = read_file(os.path.join('scripts', 'config_whitelist.txt')) |
Chris Packham | ca43834 | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 457 | |
| 458 | lines = [x for x in lines if x.strip() not in configs] |
| 459 | |
Simon Glass | 2fd85bd | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 460 | write_file(os.path.join('scripts', 'config_whitelist.txt'), lines) |
Chris Packham | ca43834 | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 461 | |
Chris Packham | f90df59 | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 462 | def find_matching(patterns, line): |
| 463 | for pat in patterns: |
| 464 | if pat.search(line): |
| 465 | return True |
| 466 | return False |
| 467 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 468 | def cleanup_readme(configs, args): |
Chris Packham | f90df59 | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 469 | """Delete config description in README |
| 470 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 471 | Args: |
Chris Packham | f90df59 | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 472 | configs: A list of CONFIGs to remove. |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 473 | args (Namespace): program arguments |
Chris Packham | f90df59 | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 474 | """ |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 475 | if not confirm(args, 'Clean up README?'): |
Chris Packham | f90df59 | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 476 | return |
| 477 | |
| 478 | patterns = [] |
| 479 | for config in configs: |
| 480 | patterns.append(re.compile(r'^\s+%s' % config)) |
| 481 | |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 482 | lines = read_file('README') |
Chris Packham | f90df59 | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 483 | |
| 484 | found = False |
| 485 | newlines = [] |
| 486 | for line in lines: |
| 487 | if not found: |
| 488 | found = find_matching(patterns, line) |
| 489 | if found: |
| 490 | continue |
| 491 | |
| 492 | if found and re.search(r'^\s+CONFIG', line): |
| 493 | found = False |
| 494 | |
| 495 | if not found: |
| 496 | newlines.append(line) |
| 497 | |
Simon Glass | 2fd85bd | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 498 | write_file('README', newlines) |
Chris Packham | f90df59 | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 499 | |
Markus Klotzbuecher | b237d35 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 500 | def try_expand(line): |
| 501 | """If value looks like an expression, try expanding it |
| 502 | Otherwise just return the existing value |
| 503 | """ |
| 504 | if line.find('=') == -1: |
| 505 | return line |
| 506 | |
| 507 | try: |
Markus Klotzbuecher | b3192f4 | 2020-02-12 20:46:44 +0100 | [diff] [blame] | 508 | aeval = asteval.Interpreter( usersyms=SIZES, minimal=True ) |
Markus Klotzbuecher | b237d35 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 509 | cfg, val = re.split("=", line) |
| 510 | val= val.strip('\"') |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 511 | if re.search(r'[*+-/]|<<|SZ_+|\(([^\)]+)\)', val): |
Markus Klotzbuecher | b3192f4 | 2020-02-12 20:46:44 +0100 | [diff] [blame] | 512 | newval = hex(aeval(val)) |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 513 | print('\tExpanded expression %s to %s' % (val, newval)) |
Markus Klotzbuecher | b237d35 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 514 | return cfg+'='+newval |
| 515 | except: |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 516 | print('\tFailed to expand expression in %s' % line) |
Markus Klotzbuecher | b237d35 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 517 | |
| 518 | return line |
| 519 | |
Chris Packham | ca43834 | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 520 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 521 | ### classes ### |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 522 | class Progress: |
| 523 | |
| 524 | """Progress Indicator""" |
| 525 | |
| 526 | def __init__(self, total): |
| 527 | """Create a new progress indicator. |
| 528 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 529 | Args: |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 530 | total: A number of defconfig files to process. |
| 531 | """ |
| 532 | self.current = 0 |
| 533 | self.total = total |
| 534 | |
| 535 | def inc(self): |
| 536 | """Increment the number of processed defconfig files.""" |
| 537 | |
| 538 | self.current += 1 |
| 539 | |
| 540 | def show(self): |
| 541 | """Display the progress.""" |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 542 | print(' %d defconfigs out of %d\r' % (self.current, self.total), end=' ') |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 543 | sys.stdout.flush() |
| 544 | |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 545 | |
| 546 | class KconfigScanner: |
| 547 | """Kconfig scanner.""" |
| 548 | |
| 549 | def __init__(self): |
| 550 | """Scan all the Kconfig files and create a Config object.""" |
| 551 | # Define environment variables referenced from Kconfig |
| 552 | os.environ['srctree'] = os.getcwd() |
| 553 | os.environ['UBOOTVERSION'] = 'dummy' |
| 554 | os.environ['KCONFIG_OBJDIR'] = '' |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 555 | self.conf = kconfiglib.Kconfig() |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 556 | |
| 557 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 558 | class KconfigParser: |
| 559 | |
| 560 | """A parser of .config and include/autoconf.mk.""" |
| 561 | |
| 562 | re_arch = re.compile(r'CONFIG_SYS_ARCH="(.*)"') |
| 563 | re_cpu = re.compile(r'CONFIG_SYS_CPU="(.*)"') |
| 564 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 565 | def __init__(self, configs, args, build_dir): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 566 | """Create a new parser. |
| 567 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 568 | Args: |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 569 | configs: A list of CONFIGs to move. |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 570 | args (Namespace): program arguments |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 571 | build_dir: Build directory. |
| 572 | """ |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 573 | self.configs = configs |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 574 | self.args = args |
Masahiro Yamada | 1f16992 | 2016-05-19 15:52:00 +0900 | [diff] [blame] | 575 | self.dotconfig = os.path.join(build_dir, '.config') |
| 576 | self.autoconf = os.path.join(build_dir, 'include', 'autoconf.mk') |
Masahiro Yamada | 07913d1 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 577 | self.spl_autoconf = os.path.join(build_dir, 'spl', 'include', |
| 578 | 'autoconf.mk') |
Simon Glass | f3b8e64 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 579 | self.config_autoconf = os.path.join(build_dir, AUTO_CONF_PATH) |
Masahiro Yamada | 5da4f85 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 580 | self.defconfig = os.path.join(build_dir, 'defconfig') |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 581 | |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 582 | def get_arch(self): |
| 583 | """Parse .config file and return the architecture. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 584 | |
| 585 | Returns: |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 586 | Architecture name (e.g. 'arm'). |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 587 | """ |
| 588 | arch = '' |
| 589 | cpu = '' |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 590 | for line in read_file(self.dotconfig): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 591 | m = self.re_arch.match(line) |
| 592 | if m: |
| 593 | arch = m.group(1) |
| 594 | continue |
| 595 | m = self.re_cpu.match(line) |
| 596 | if m: |
| 597 | cpu = m.group(1) |
| 598 | |
Masahiro Yamada | 90ed6cb | 2016-05-19 15:51:53 +0900 | [diff] [blame] | 599 | if not arch: |
| 600 | return None |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 601 | |
| 602 | # fix-up for aarch64 |
| 603 | if arch == 'arm' and cpu == 'armv8': |
| 604 | arch = 'aarch64' |
| 605 | |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 606 | return arch |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 607 | |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 608 | def parse_one_config(self, config, dotconfig_lines, autoconf_lines): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 609 | """Parse .config, defconfig, include/autoconf.mk for one config. |
| 610 | |
| 611 | This function looks for the config options in the lines from |
| 612 | defconfig, .config, and include/autoconf.mk in order to decide |
| 613 | which action should be taken for this defconfig. |
| 614 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 615 | Args: |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 616 | config: CONFIG name to parse. |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 617 | dotconfig_lines: lines from the .config file. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 618 | autoconf_lines: lines from the include/autoconf.mk file. |
| 619 | |
| 620 | Returns: |
| 621 | A tupple of the action for this defconfig and the line |
| 622 | matched for the config. |
| 623 | """ |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 624 | not_set = '# %s is not set' % config |
| 625 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 626 | for line in autoconf_lines: |
| 627 | line = line.rstrip() |
| 628 | if line.startswith(config + '='): |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 629 | new_val = line |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 630 | break |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 631 | else: |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 632 | new_val = not_set |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 633 | |
Markus Klotzbuecher | b237d35 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 634 | new_val = try_expand(new_val) |
| 635 | |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 636 | for line in dotconfig_lines: |
| 637 | line = line.rstrip() |
| 638 | if line.startswith(config + '=') or line == not_set: |
| 639 | old_val = line |
| 640 | break |
| 641 | else: |
| 642 | if new_val == not_set: |
| 643 | return (ACTION_NO_ENTRY, config) |
| 644 | else: |
| 645 | return (ACTION_NO_ENTRY_WARN, config) |
| 646 | |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 647 | # If this CONFIG is neither bool nor trisate |
| 648 | if old_val[-2:] != '=y' and old_val[-2:] != '=m' and old_val != not_set: |
| 649 | # tools/scripts/define2mk.sed changes '1' to 'y'. |
| 650 | # This is a problem if the CONFIG is int type. |
| 651 | # Check the type in Kconfig and handle it correctly. |
| 652 | if new_val[-2:] == '=y': |
| 653 | new_val = new_val[:-1] + '1' |
| 654 | |
Masahiro Yamada | 5030159 | 2016-06-15 14:33:50 +0900 | [diff] [blame] | 655 | return (ACTION_NO_CHANGE if old_val == new_val else ACTION_MOVE, |
| 656 | new_val) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 657 | |
Masahiro Yamada | 1d08556 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 658 | def update_dotconfig(self): |
Masahiro Yamada | 6ff36d2 | 2016-05-19 15:51:50 +0900 | [diff] [blame] | 659 | """Parse files for the config options and update the .config. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 660 | |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 661 | This function parses the generated .config and include/autoconf.mk |
| 662 | searching the target options. |
Masahiro Yamada | 6ff36d2 | 2016-05-19 15:51:50 +0900 | [diff] [blame] | 663 | Move the config option(s) to the .config as needed. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 664 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 665 | Args: |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 666 | defconfig: defconfig name. |
Masahiro Yamada | 522e8dc | 2016-05-19 15:52:01 +0900 | [diff] [blame] | 667 | |
| 668 | Returns: |
Masahiro Yamada | 7fb0bac | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 669 | Return a tuple of (updated flag, log string). |
| 670 | The "updated flag" is True if the .config was updated, False |
| 671 | otherwise. The "log string" shows what happend to the .config. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 672 | """ |
| 673 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 674 | results = [] |
Masahiro Yamada | 7fb0bac | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 675 | updated = False |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 676 | suspicious = False |
Masahiro Yamada | 07913d1 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 677 | rm_files = [self.config_autoconf, self.autoconf] |
| 678 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 679 | if self.args.spl: |
Masahiro Yamada | 07913d1 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 680 | if os.path.exists(self.spl_autoconf): |
| 681 | autoconf_path = self.spl_autoconf |
| 682 | rm_files.append(self.spl_autoconf) |
| 683 | else: |
| 684 | for f in rm_files: |
| 685 | os.remove(f) |
| 686 | return (updated, suspicious, |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 687 | color_text(self.args.color, COLOR_BROWN, |
Masahiro Yamada | 07913d1 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 688 | "SPL is not enabled. Skipped.") + '\n') |
| 689 | else: |
| 690 | autoconf_path = self.autoconf |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 691 | |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 692 | dotconfig_lines = read_file(self.dotconfig) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 693 | |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 694 | autoconf_lines = read_file(autoconf_path) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 695 | |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 696 | for config in self.configs: |
| 697 | result = self.parse_one_config(config, dotconfig_lines, |
Joe Hershberger | 96464ba | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 698 | autoconf_lines) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 699 | results.append(result) |
| 700 | |
| 701 | log = '' |
| 702 | |
| 703 | for (action, value) in results: |
| 704 | if action == ACTION_MOVE: |
| 705 | actlog = "Move '%s'" % value |
| 706 | log_color = COLOR_LIGHT_GREEN |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 707 | elif action == ACTION_NO_ENTRY: |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 708 | actlog = '%s is not defined in Kconfig. Do nothing.' % value |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 709 | log_color = COLOR_LIGHT_BLUE |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 710 | elif action == ACTION_NO_ENTRY_WARN: |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 711 | actlog = '%s is not defined in Kconfig (suspicious). Do nothing.' % value |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 712 | log_color = COLOR_YELLOW |
| 713 | suspicious = True |
Masahiro Yamada | cc00829 | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 714 | elif action == ACTION_NO_CHANGE: |
| 715 | actlog = "'%s' is the same as the define in Kconfig. Do nothing." \ |
| 716 | % value |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 717 | log_color = COLOR_LIGHT_PURPLE |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 718 | else: |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 719 | sys.exit('Internal Error. This should not happen.') |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 720 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 721 | log += color_text(self.args.color, log_color, actlog) + '\n' |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 722 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 723 | with open(self.dotconfig, 'a', encoding='utf-8') as out: |
Masahiro Yamada | e423d17 | 2016-05-19 15:51:49 +0900 | [diff] [blame] | 724 | for (action, value) in results: |
| 725 | if action == ACTION_MOVE: |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 726 | out.write(value + '\n') |
Masahiro Yamada | 7fb0bac | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 727 | updated = True |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 728 | |
Masahiro Yamada | 5da4f85 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 729 | self.results = results |
Masahiro Yamada | 07913d1 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 730 | for f in rm_files: |
| 731 | os.remove(f) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 732 | |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 733 | return (updated, suspicious, log) |
Masahiro Yamada | 522e8dc | 2016-05-19 15:52:01 +0900 | [diff] [blame] | 734 | |
Masahiro Yamada | 5da4f85 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 735 | def check_defconfig(self): |
| 736 | """Check the defconfig after savedefconfig |
| 737 | |
| 738 | Returns: |
| 739 | Return additional log if moved CONFIGs were removed again by |
| 740 | 'make savedefconfig'. |
| 741 | """ |
| 742 | |
| 743 | log = '' |
| 744 | |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 745 | defconfig_lines = read_file(self.defconfig) |
Masahiro Yamada | 5da4f85 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 746 | |
| 747 | for (action, value) in self.results: |
| 748 | if action != ACTION_MOVE: |
| 749 | continue |
Alper Nebi Yasak | 6c928c6 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 750 | if not value in defconfig_lines: |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 751 | log += color_text(self.args.color, COLOR_YELLOW, |
Masahiro Yamada | 5da4f85 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 752 | "'%s' was removed by savedefconfig.\n" % |
| 753 | value) |
| 754 | |
| 755 | return log |
| 756 | |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 757 | |
| 758 | class DatabaseThread(threading.Thread): |
| 759 | """This thread processes results from Slot threads. |
| 760 | |
| 761 | It collects the data in the master config directary. There is only one |
| 762 | result thread, and this helps to serialise the build output. |
| 763 | """ |
| 764 | def __init__(self, config_db, db_queue): |
| 765 | """Set up a new result thread |
| 766 | |
| 767 | Args: |
| 768 | builder: Builder which will be sent each result |
| 769 | """ |
| 770 | threading.Thread.__init__(self) |
| 771 | self.config_db = config_db |
| 772 | self.db_queue= db_queue |
| 773 | |
| 774 | def run(self): |
| 775 | """Called to start up the result thread. |
| 776 | |
| 777 | We collect the next result job and pass it on to the build. |
| 778 | """ |
| 779 | while True: |
| 780 | defconfig, configs = self.db_queue.get() |
| 781 | self.config_db[defconfig] = configs |
| 782 | self.db_queue.task_done() |
| 783 | |
| 784 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 785 | class Slot: |
| 786 | |
| 787 | """A slot to store a subprocess. |
| 788 | |
| 789 | Each instance of this class handles one subprocess. |
| 790 | This class is useful to control multiple threads |
| 791 | for faster processing. |
| 792 | """ |
| 793 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 794 | def __init__(self, toolchains, configs, args, progress, devnull, |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 795 | make_cmd, reference_src_dir, db_queue): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 796 | """Create a new process slot. |
| 797 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 798 | Args: |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 799 | toolchains: Toolchains object containing toolchains. |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 800 | configs: A list of CONFIGs to move. |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 801 | args: Program arguments |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 802 | progress: A progress indicator. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 803 | devnull: A file object of '/dev/null'. |
| 804 | make_cmd: command name of GNU Make. |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 805 | reference_src_dir: Determine the true starting config state from this |
| 806 | source tree. |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 807 | db_queue: output queue to write config info for the database |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 808 | """ |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 809 | self.toolchains = toolchains |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 810 | self.args = args |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 811 | self.progress = progress |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 812 | self.build_dir = tempfile.mkdtemp() |
| 813 | self.devnull = devnull |
| 814 | self.make_cmd = (make_cmd, 'O=' + self.build_dir) |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 815 | self.reference_src_dir = reference_src_dir |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 816 | self.db_queue = db_queue |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 817 | self.parser = KconfigParser(configs, args, self.build_dir) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 818 | self.state = STATE_IDLE |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 819 | self.failed_boards = set() |
| 820 | self.suspicious_boards = set() |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 821 | |
| 822 | def __del__(self): |
| 823 | """Delete the working directory |
| 824 | |
| 825 | This function makes sure the temporary directory is cleaned away |
| 826 | even if Python suddenly dies due to error. It should be done in here |
Joe Hershberger | f2dae75 | 2016-06-10 14:53:29 -0500 | [diff] [blame] | 827 | because it is guaranteed the destructor is always invoked when the |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 828 | instance of the class gets unreferenced. |
| 829 | |
| 830 | If the subprocess is still running, wait until it finishes. |
| 831 | """ |
| 832 | if self.state != STATE_IDLE: |
| 833 | while self.ps.poll() == None: |
| 834 | pass |
| 835 | shutil.rmtree(self.build_dir) |
| 836 | |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 837 | def add(self, defconfig): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 838 | """Assign a new subprocess for defconfig and add it to the slot. |
| 839 | |
| 840 | If the slot is vacant, create a new subprocess for processing the |
| 841 | given defconfig and add it to the slot. Just returns False if |
| 842 | the slot is occupied (i.e. the current subprocess is still running). |
| 843 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 844 | Args: |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 845 | defconfig: defconfig name. |
| 846 | |
| 847 | Returns: |
| 848 | Return True on success or False on failure |
| 849 | """ |
| 850 | if self.state != STATE_IDLE: |
| 851 | return False |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 852 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 853 | self.defconfig = defconfig |
Masahiro Yamada | 1d08556 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 854 | self.log = '' |
Masahiro Yamada | f432c33 | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 855 | self.current_src_dir = self.reference_src_dir |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 856 | self.do_defconfig() |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 857 | return True |
| 858 | |
| 859 | def poll(self): |
| 860 | """Check the status of the subprocess and handle it as needed. |
| 861 | |
| 862 | Returns True if the slot is vacant (i.e. in idle state). |
| 863 | If the configuration is successfully finished, assign a new |
| 864 | subprocess to build include/autoconf.mk. |
| 865 | If include/autoconf.mk is generated, invoke the parser to |
Masahiro Yamada | 7fb0bac | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 866 | parse the .config and the include/autoconf.mk, moving |
| 867 | config options to the .config as needed. |
| 868 | If the .config was updated, run "make savedefconfig" to sync |
| 869 | it, update the original defconfig, and then set the slot back |
| 870 | to the idle state. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 871 | |
| 872 | Returns: |
| 873 | Return True if the subprocess is terminated, False otherwise |
| 874 | """ |
| 875 | if self.state == STATE_IDLE: |
| 876 | return True |
| 877 | |
| 878 | if self.ps.poll() == None: |
| 879 | return False |
| 880 | |
| 881 | if self.ps.poll() != 0: |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 882 | self.handle_error() |
| 883 | elif self.state == STATE_DEFCONFIG: |
Masahiro Yamada | f432c33 | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 884 | if self.reference_src_dir and not self.current_src_dir: |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 885 | self.do_savedefconfig() |
| 886 | else: |
| 887 | self.do_autoconf() |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 888 | elif self.state == STATE_AUTOCONF: |
Masahiro Yamada | f432c33 | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 889 | if self.current_src_dir: |
| 890 | self.current_src_dir = None |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 891 | self.do_defconfig() |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 892 | elif self.args.build_db: |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 893 | self.do_build_db() |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 894 | else: |
| 895 | self.do_savedefconfig() |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 896 | elif self.state == STATE_SAVEDEFCONFIG: |
| 897 | self.update_defconfig() |
| 898 | else: |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 899 | sys.exit('Internal Error. This should not happen.') |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 900 | |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 901 | return True if self.state == STATE_IDLE else False |
Joe Hershberger | 96464ba | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 902 | |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 903 | def handle_error(self): |
| 904 | """Handle error cases.""" |
Masahiro Yamada | 8513dc0 | 2016-05-19 15:52:08 +0900 | [diff] [blame] | 905 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 906 | self.log += color_text(self.args.color, COLOR_LIGHT_RED, |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 907 | 'Failed to process.\n') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 908 | if self.args.verbose: |
| 909 | self.log += color_text(self.args.color, COLOR_LIGHT_CYAN, |
Markus Klotzbuecher | 4f5c5e9 | 2020-02-12 20:46:45 +0100 | [diff] [blame] | 910 | self.ps.stderr.read().decode()) |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 911 | self.finish(False) |
Joe Hershberger | 96464ba | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 912 | |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 913 | def do_defconfig(self): |
| 914 | """Run 'make <board>_defconfig' to create the .config file.""" |
Masahiro Yamada | c8e1b10 | 2016-05-19 15:52:07 +0900 | [diff] [blame] | 915 | |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 916 | cmd = list(self.make_cmd) |
| 917 | cmd.append(self.defconfig) |
| 918 | self.ps = subprocess.Popen(cmd, stdout=self.devnull, |
Masahiro Yamada | f432c33 | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 919 | stderr=subprocess.PIPE, |
| 920 | cwd=self.current_src_dir) |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 921 | self.state = STATE_DEFCONFIG |
Masahiro Yamada | c8e1b10 | 2016-05-19 15:52:07 +0900 | [diff] [blame] | 922 | |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 923 | def do_autoconf(self): |
Simon Glass | f3b8e64 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 924 | """Run 'make AUTO_CONF_PATH'.""" |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 925 | |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 926 | arch = self.parser.get_arch() |
| 927 | try: |
| 928 | toolchain = self.toolchains.Select(arch) |
| 929 | except ValueError: |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 930 | self.log += color_text(self.args.color, COLOR_YELLOW, |
Chris Packham | ce3ba45 | 2017-08-27 20:00:51 +1200 | [diff] [blame] | 931 | "Tool chain for '%s' is missing. Do nothing.\n" % arch) |
Masahiro Yamada | 4efef99 | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 932 | self.finish(False) |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 933 | return |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 934 | env = toolchain.MakeEnvironment(False) |
Masahiro Yamada | 90ed6cb | 2016-05-19 15:51:53 +0900 | [diff] [blame] | 935 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 936 | cmd = list(self.make_cmd) |
Joe Hershberger | 7740f65 | 2015-05-19 13:21:18 -0500 | [diff] [blame] | 937 | cmd.append('KCONFIG_IGNORE_DUPLICATES=1') |
Simon Glass | f3b8e64 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 938 | cmd.append(AUTO_CONF_PATH) |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 939 | self.ps = subprocess.Popen(cmd, stdout=self.devnull, env=env, |
Masahiro Yamada | f432c33 | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 940 | stderr=subprocess.PIPE, |
| 941 | cwd=self.current_src_dir) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 942 | self.state = STATE_AUTOCONF |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 943 | |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 944 | def do_build_db(self): |
| 945 | """Add the board to the database""" |
| 946 | configs = {} |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 947 | for line in read_file(os.path.join(self.build_dir, AUTO_CONF_PATH)): |
| 948 | if line.startswith('CONFIG'): |
| 949 | config, value = line.split('=', 1) |
| 950 | configs[config] = value.rstrip() |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 951 | self.db_queue.put([self.defconfig, configs]) |
| 952 | self.finish(True) |
| 953 | |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 954 | def do_savedefconfig(self): |
| 955 | """Update the .config and run 'make savedefconfig'.""" |
| 956 | |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 957 | (updated, suspicious, log) = self.parser.update_dotconfig() |
| 958 | if suspicious: |
| 959 | self.suspicious_boards.add(self.defconfig) |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 960 | self.log += log |
| 961 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 962 | if not self.args.force_sync and not updated: |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 963 | self.finish(True) |
| 964 | return |
| 965 | if updated: |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 966 | self.log += color_text(self.args.color, COLOR_LIGHT_GREEN, |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 967 | 'Syncing by savedefconfig...\n') |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 968 | else: |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 969 | self.log += 'Syncing by savedefconfig (forced by option)...\n' |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 970 | |
| 971 | cmd = list(self.make_cmd) |
| 972 | cmd.append('savedefconfig') |
| 973 | self.ps = subprocess.Popen(cmd, stdout=self.devnull, |
| 974 | stderr=subprocess.PIPE) |
| 975 | self.state = STATE_SAVEDEFCONFIG |
| 976 | |
| 977 | def update_defconfig(self): |
| 978 | """Update the input defconfig and go back to the idle state.""" |
| 979 | |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 980 | log = self.parser.check_defconfig() |
| 981 | if log: |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 982 | self.suspicious_boards.add(self.defconfig) |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 983 | self.log += log |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 984 | orig_defconfig = os.path.join('configs', self.defconfig) |
| 985 | new_defconfig = os.path.join(self.build_dir, 'defconfig') |
| 986 | updated = not filecmp.cmp(orig_defconfig, new_defconfig) |
| 987 | |
| 988 | if updated: |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 989 | self.log += color_text(self.args.color, COLOR_LIGHT_BLUE, |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 990 | 'defconfig was updated.\n') |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 991 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 992 | if not self.args.dry_run and updated: |
Masahiro Yamada | e307fa9 | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 993 | shutil.move(new_defconfig, orig_defconfig) |
| 994 | self.finish(True) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 995 | |
Masahiro Yamada | 4efef99 | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 996 | def finish(self, success): |
| 997 | """Display log along with progress and go to the idle state. |
Masahiro Yamada | 1d08556 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 998 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 999 | Args: |
Masahiro Yamada | 4efef99 | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 1000 | success: Should be True when the defconfig was processed |
| 1001 | successfully, or False when it fails. |
Masahiro Yamada | 1d08556 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 1002 | """ |
| 1003 | # output at least 30 characters to hide the "* defconfigs out of *". |
| 1004 | log = self.defconfig.ljust(30) + '\n' |
| 1005 | |
| 1006 | log += '\n'.join([ ' ' + s for s in self.log.split('\n') ]) |
| 1007 | # Some threads are running in parallel. |
| 1008 | # Print log atomically to not mix up logs from different threads. |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1009 | print(log, file=(sys.stdout if success else sys.stderr)) |
Masahiro Yamada | 4efef99 | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 1010 | |
| 1011 | if not success: |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1012 | if self.args.exit_on_error: |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1013 | sys.exit('Exit on error.') |
Masahiro Yamada | 4efef99 | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 1014 | # If --exit-on-error flag is not set, skip this board and continue. |
| 1015 | # Record the failed board. |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1016 | self.failed_boards.add(self.defconfig) |
Masahiro Yamada | 4efef99 | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 1017 | |
Masahiro Yamada | 1d08556 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 1018 | self.progress.inc() |
| 1019 | self.progress.show() |
Masahiro Yamada | 4efef99 | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 1020 | self.state = STATE_IDLE |
Masahiro Yamada | 1d08556 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 1021 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1022 | def get_failed_boards(self): |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1023 | """Returns a set of failed boards (defconfigs) in this slot. |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1024 | """ |
| 1025 | return self.failed_boards |
| 1026 | |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1027 | def get_suspicious_boards(self): |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1028 | """Returns a set of boards (defconfigs) with possible misconversion. |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1029 | """ |
Masahiro Yamada | 916224c | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 1030 | return self.suspicious_boards - self.failed_boards |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1031 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1032 | class Slots: |
| 1033 | |
| 1034 | """Controller of the array of subprocess slots.""" |
| 1035 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1036 | def __init__(self, toolchains, configs, args, progress, |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1037 | reference_src_dir, db_queue): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1038 | """Create a new slots controller. |
| 1039 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1040 | Args: |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1041 | toolchains: Toolchains object containing toolchains. |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 1042 | configs: A list of CONFIGs to move. |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1043 | args: Program arguments |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1044 | progress: A progress indicator. |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1045 | reference_src_dir: Determine the true starting config state from this |
| 1046 | source tree. |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1047 | db_queue: output queue to write config info for the database |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1048 | """ |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1049 | self.args = args |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1050 | self.slots = [] |
Simon Glass | 478920d | 2021-12-18 14:54:32 -0700 | [diff] [blame] | 1051 | devnull = subprocess.DEVNULL |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1052 | make_cmd = get_make_cmd() |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1053 | for i in range(args.jobs): |
| 1054 | self.slots.append(Slot(toolchains, configs, args, progress, |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1055 | devnull, make_cmd, reference_src_dir, |
| 1056 | db_queue)) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1057 | |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1058 | def add(self, defconfig): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1059 | """Add a new subprocess if a vacant slot is found. |
| 1060 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1061 | Args: |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1062 | defconfig: defconfig name to be put into. |
| 1063 | |
| 1064 | Returns: |
| 1065 | Return True on success or False on failure |
| 1066 | """ |
| 1067 | for slot in self.slots: |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1068 | if slot.add(defconfig): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1069 | return True |
| 1070 | return False |
| 1071 | |
| 1072 | def available(self): |
| 1073 | """Check if there is a vacant slot. |
| 1074 | |
| 1075 | Returns: |
| 1076 | Return True if at lease one vacant slot is found, False otherwise. |
| 1077 | """ |
| 1078 | for slot in self.slots: |
| 1079 | if slot.poll(): |
| 1080 | return True |
| 1081 | return False |
| 1082 | |
| 1083 | def empty(self): |
| 1084 | """Check if all slots are vacant. |
| 1085 | |
| 1086 | Returns: |
| 1087 | Return True if all the slots are vacant, False otherwise. |
| 1088 | """ |
| 1089 | ret = True |
| 1090 | for slot in self.slots: |
| 1091 | if not slot.poll(): |
| 1092 | ret = False |
| 1093 | return ret |
| 1094 | |
| 1095 | def show_failed_boards(self): |
| 1096 | """Display all of the failed boards (defconfigs).""" |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1097 | boards = set() |
Masahiro Yamada | 96dccd9 | 2016-06-15 14:33:53 +0900 | [diff] [blame] | 1098 | output_file = 'moveconfig.failed' |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1099 | |
| 1100 | for slot in self.slots: |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1101 | boards |= slot.get_failed_boards() |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1102 | |
Masahiro Yamada | 96dccd9 | 2016-06-15 14:33:53 +0900 | [diff] [blame] | 1103 | if boards: |
| 1104 | boards = '\n'.join(boards) + '\n' |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1105 | msg = 'The following boards were not processed due to error:\n' |
Masahiro Yamada | 96dccd9 | 2016-06-15 14:33:53 +0900 | [diff] [blame] | 1106 | msg += boards |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1107 | msg += '(the list has been saved in %s)\n' % output_file |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1108 | print(color_text(self.args.color, COLOR_LIGHT_RED, |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1109 | msg), file=sys.stderr) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1110 | |
Simon Glass | 2fd85bd | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 1111 | write_file(output_file, boards) |
Joe Hershberger | 2559cd8 | 2015-05-19 13:21:22 -0500 | [diff] [blame] | 1112 | |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1113 | def show_suspicious_boards(self): |
| 1114 | """Display all boards (defconfigs) with possible misconversion.""" |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1115 | boards = set() |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1116 | output_file = 'moveconfig.suspicious' |
| 1117 | |
| 1118 | for slot in self.slots: |
Masahiro Yamada | 09c6c06 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1119 | boards |= slot.get_suspicious_boards() |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1120 | |
| 1121 | if boards: |
| 1122 | boards = '\n'.join(boards) + '\n' |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1123 | msg = 'The following boards might have been converted incorrectly.\n' |
| 1124 | msg += 'It is highly recommended to check them manually:\n' |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1125 | msg += boards |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1126 | msg += '(the list has been saved in %s)\n' % output_file |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1127 | print(color_text(self.args.color, COLOR_YELLOW, |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1128 | msg), file=sys.stderr) |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1129 | |
Simon Glass | 2fd85bd | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 1130 | write_file(output_file, boards) |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1131 | |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1132 | class ReferenceSource: |
| 1133 | |
| 1134 | """Reference source against which original configs should be parsed.""" |
| 1135 | |
| 1136 | def __init__(self, commit): |
| 1137 | """Create a reference source directory based on a specified commit. |
| 1138 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1139 | Args: |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1140 | commit: commit to git-clone |
| 1141 | """ |
| 1142 | self.src_dir = tempfile.mkdtemp() |
Simon Glass | daa694d | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1143 | print('Cloning git repo to a separate work directory...') |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1144 | subprocess.check_output(['git', 'clone', os.getcwd(), '.'], |
| 1145 | cwd=self.src_dir) |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1146 | print("Checkout '%s' to build the original autoconf.mk." % \ |
| 1147 | subprocess.check_output(['git', 'rev-parse', '--short', commit]).strip()) |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1148 | subprocess.check_output(['git', 'checkout', commit], |
| 1149 | stderr=subprocess.STDOUT, cwd=self.src_dir) |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1150 | |
| 1151 | def __del__(self): |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1152 | """Delete the reference source directory |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1153 | |
| 1154 | This function makes sure the temporary directory is cleaned away |
| 1155 | even if Python suddenly dies due to error. It should be done in here |
| 1156 | because it is guaranteed the destructor is always invoked when the |
| 1157 | instance of the class gets unreferenced. |
| 1158 | """ |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1159 | shutil.rmtree(self.src_dir) |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1160 | |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1161 | def get_dir(self): |
| 1162 | """Return the absolute path to the reference source directory.""" |
| 1163 | |
| 1164 | return self.src_dir |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1165 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1166 | def move_config(toolchains, configs, args, db_queue): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1167 | """Move config options to defconfig files. |
| 1168 | |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1169 | Args: |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 1170 | configs: A list of CONFIGs to move. |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1171 | args: Program arguments |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1172 | """ |
Masahiro Yamada | b134bc1 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 1173 | if len(configs) == 0: |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1174 | if args.force_sync: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1175 | print('No CONFIG is specified. You are probably syncing defconfigs.', end=' ') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1176 | elif args.build_db: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1177 | print('Building %s database' % CONFIG_DATABASE) |
Masahiro Yamada | 6a9f79f | 2016-05-19 15:52:09 +0900 | [diff] [blame] | 1178 | else: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1179 | print('Neither CONFIG nor --force-sync is specified. Nothing will happen.', end=' ') |
Masahiro Yamada | 6a9f79f | 2016-05-19 15:52:09 +0900 | [diff] [blame] | 1180 | else: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1181 | print('Move ' + ', '.join(configs), end=' ') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1182 | print('(jobs: %d)\n' % args.jobs) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1183 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1184 | if args.git_ref: |
| 1185 | reference_src = ReferenceSource(args.git_ref) |
Masahiro Yamada | 5cc42a5 | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1186 | reference_src_dir = reference_src.get_dir() |
| 1187 | else: |
Masahiro Yamada | f432c33 | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 1188 | reference_src_dir = None |
Joe Hershberger | 6b96c1a | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1189 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1190 | if args.defconfigs: |
| 1191 | defconfigs = get_matched_defconfigs(args.defconfigs) |
Joe Hershberger | 91040e8 | 2015-05-19 13:21:19 -0500 | [diff] [blame] | 1192 | else: |
Masahiro Yamada | 684c306 | 2016-07-25 19:15:28 +0900 | [diff] [blame] | 1193 | defconfigs = get_all_defconfigs() |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1194 | |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1195 | progress = Progress(len(defconfigs)) |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1196 | slots = Slots(toolchains, configs, args, progress, reference_src_dir, |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1197 | db_queue) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1198 | |
| 1199 | # Main loop to process defconfig files: |
| 1200 | # Add a new subprocess into a vacant slot. |
| 1201 | # Sleep if there is no available slot. |
Masahiro Yamada | c5e60fd | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1202 | for defconfig in defconfigs: |
| 1203 | while not slots.add(defconfig): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1204 | while not slots.available(): |
| 1205 | # No available slot: sleep for a while |
| 1206 | time.sleep(SLEEP_TIME) |
| 1207 | |
| 1208 | # wait until all the subprocesses finish |
| 1209 | while not slots.empty(): |
| 1210 | time.sleep(SLEEP_TIME) |
| 1211 | |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1212 | print('') |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1213 | slots.show_failed_boards() |
Masahiro Yamada | fc2661e | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1214 | slots.show_suspicious_boards() |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1215 | |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1216 | def find_kconfig_rules(kconf, config, imply_config): |
| 1217 | """Check whether a config has a 'select' or 'imply' keyword |
| 1218 | |
| 1219 | Args: |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1220 | kconf: Kconfiglib.Kconfig object |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1221 | config: Name of config to check (without CONFIG_ prefix) |
| 1222 | imply_config: Implying config (without CONFIG_ prefix) which may or |
| 1223 | may not have an 'imply' for 'config') |
| 1224 | |
| 1225 | Returns: |
| 1226 | Symbol object for 'config' if found, else None |
| 1227 | """ |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1228 | sym = kconf.syms.get(imply_config) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1229 | if sym: |
Simon Glass | ea40b20 | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1230 | for sel, cond in (sym.selects + sym.implies): |
Simon Glass | a362708 | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1231 | if sel.name == config: |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1232 | return sym |
| 1233 | return None |
| 1234 | |
| 1235 | def check_imply_rule(kconf, config, imply_config): |
| 1236 | """Check if we can add an 'imply' option |
| 1237 | |
| 1238 | This finds imply_config in the Kconfig and looks to see if it is possible |
| 1239 | to add an 'imply' for 'config' to that part of the Kconfig. |
| 1240 | |
| 1241 | Args: |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1242 | kconf: Kconfiglib.Kconfig object |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1243 | config: Name of config to check (without CONFIG_ prefix) |
| 1244 | imply_config: Implying config (without CONFIG_ prefix) which may or |
| 1245 | may not have an 'imply' for 'config') |
| 1246 | |
| 1247 | Returns: |
| 1248 | tuple: |
| 1249 | filename of Kconfig file containing imply_config, or None if none |
| 1250 | line number within the Kconfig file, or 0 if none |
| 1251 | message indicating the result |
| 1252 | """ |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1253 | sym = kconf.syms.get(imply_config) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1254 | if not sym: |
| 1255 | return 'cannot find sym' |
Simon Glass | ea40b20 | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1256 | nodes = sym.nodes |
| 1257 | if len(nodes) != 1: |
| 1258 | return '%d locations' % len(nodes) |
Simon Glass | a362708 | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1259 | node = nodes[0] |
| 1260 | fname, linenum = node.filename, node.linenr |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1261 | cwd = os.getcwd() |
| 1262 | if cwd and fname.startswith(cwd): |
| 1263 | fname = fname[len(cwd) + 1:] |
| 1264 | file_line = ' at %s:%d' % (fname, linenum) |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 1265 | data = read_file(fname) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1266 | if data[linenum - 1] != 'config %s' % imply_config: |
| 1267 | return None, 0, 'bad sym format %s%s' % (data[linenum], file_line) |
| 1268 | return fname, linenum, 'adding%s' % file_line |
| 1269 | |
| 1270 | def add_imply_rule(config, fname, linenum): |
| 1271 | """Add a new 'imply' option to a Kconfig |
| 1272 | |
| 1273 | Args: |
| 1274 | config: config option to add an imply for (without CONFIG_ prefix) |
| 1275 | fname: Kconfig filename to update |
| 1276 | linenum: Line number to place the 'imply' before |
| 1277 | |
| 1278 | Returns: |
| 1279 | Message indicating the result |
| 1280 | """ |
| 1281 | file_line = ' at %s:%d' % (fname, linenum) |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 1282 | data = read_file(fname) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1283 | linenum -= 1 |
| 1284 | |
| 1285 | for offset, line in enumerate(data[linenum:]): |
| 1286 | if line.strip().startswith('help') or not line: |
| 1287 | data.insert(linenum + offset, '\timply %s' % config) |
Simon Glass | 2fd85bd | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 1288 | write_file(fname, data) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1289 | return 'added%s' % file_line |
| 1290 | |
| 1291 | return 'could not insert%s' |
| 1292 | |
| 1293 | (IMPLY_MIN_2, IMPLY_TARGET, IMPLY_CMD, IMPLY_NON_ARCH_BOARD) = ( |
| 1294 | 1, 2, 4, 8) |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1295 | |
| 1296 | IMPLY_FLAGS = { |
| 1297 | 'min2': [IMPLY_MIN_2, 'Show options which imply >2 boards (normally >5)'], |
| 1298 | 'target': [IMPLY_TARGET, 'Allow CONFIG_TARGET_... options to imply'], |
| 1299 | 'cmd': [IMPLY_CMD, 'Allow CONFIG_CMD_... to imply'], |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1300 | 'non-arch-board': [ |
| 1301 | IMPLY_NON_ARCH_BOARD, |
| 1302 | 'Allow Kconfig options outside arch/ and /board/ to imply'], |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1303 | } |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1304 | |
Simon Glass | 9d60339 | 2021-12-18 08:09:43 -0700 | [diff] [blame] | 1305 | |
| 1306 | def read_database(): |
| 1307 | """Read in the config database |
| 1308 | |
| 1309 | Returns: |
| 1310 | tuple: |
| 1311 | set of all config options seen (each a str) |
| 1312 | set of all defconfigs seen (each a str) |
| 1313 | dict of configs for each defconfig: |
| 1314 | key: defconfig name, e.g. "MPC8548CDS_legacy_defconfig" |
| 1315 | value: dict: |
| 1316 | key: CONFIG option |
| 1317 | value: Value of option |
| 1318 | dict of defconfigs for each config: |
| 1319 | key: CONFIG option |
| 1320 | value: set of boards using that option |
| 1321 | |
| 1322 | """ |
| 1323 | configs = {} |
| 1324 | |
| 1325 | # key is defconfig name, value is dict of (CONFIG_xxx, value) |
| 1326 | config_db = {} |
| 1327 | |
| 1328 | # Set of all config options we have seen |
| 1329 | all_configs = set() |
| 1330 | |
| 1331 | # Set of all defconfigs we have seen |
| 1332 | all_defconfigs = set() |
| 1333 | |
| 1334 | defconfig_db = collections.defaultdict(set) |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 1335 | for line in read_file(CONFIG_DATABASE): |
| 1336 | line = line.rstrip() |
| 1337 | if not line: # Separator between defconfigs |
| 1338 | config_db[defconfig] = configs |
| 1339 | all_defconfigs.add(defconfig) |
| 1340 | configs = {} |
| 1341 | elif line[0] == ' ': # CONFIG line |
| 1342 | config, value = line.strip().split('=', 1) |
| 1343 | configs[config] = value |
| 1344 | defconfig_db[config].add(defconfig) |
| 1345 | all_configs.add(config) |
| 1346 | else: # New defconfig |
| 1347 | defconfig = line |
Simon Glass | 9d60339 | 2021-12-18 08:09:43 -0700 | [diff] [blame] | 1348 | |
| 1349 | return all_configs, all_defconfigs, config_db, defconfig_db |
| 1350 | |
| 1351 | |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1352 | def do_imply_config(config_list, add_imply, imply_flags, skip_added, |
| 1353 | check_kconfig=True, find_superset=False): |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1354 | """Find CONFIG options which imply those in the list |
| 1355 | |
| 1356 | Some CONFIG options can be implied by others and this can help to reduce |
| 1357 | the size of the defconfig files. For example, CONFIG_X86 implies |
| 1358 | CONFIG_CMD_IRQ, so we can put 'imply CMD_IRQ' under 'config X86' and |
| 1359 | all x86 boards will have that option, avoiding adding CONFIG_CMD_IRQ to |
| 1360 | each of the x86 defconfig files. |
| 1361 | |
| 1362 | This function uses the moveconfig database to find such options. It |
| 1363 | displays a list of things that could possibly imply those in the list. |
| 1364 | The algorithm ignores any that start with CONFIG_TARGET since these |
| 1365 | typically refer to only a few defconfigs (often one). It also does not |
| 1366 | display a config with less than 5 defconfigs. |
| 1367 | |
| 1368 | The algorithm works using sets. For each target config in config_list: |
| 1369 | - Get the set 'defconfigs' which use that target config |
| 1370 | - For each config (from a list of all configs): |
| 1371 | - Get the set 'imply_defconfig' of defconfigs which use that config |
| 1372 | - |
| 1373 | - If imply_defconfigs contains anything not in defconfigs then |
| 1374 | this config does not imply the target config |
| 1375 | |
| 1376 | Params: |
| 1377 | config_list: List of CONFIG options to check (each a string) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1378 | add_imply: Automatically add an 'imply' for each config. |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1379 | imply_flags: Flags which control which implying configs are allowed |
| 1380 | (IMPLY_...) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1381 | skip_added: Don't show options which already have an imply added. |
| 1382 | check_kconfig: Check if implied symbols already have an 'imply' or |
| 1383 | 'select' for the target config, and show this information if so. |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1384 | find_superset: True to look for configs which are a superset of those |
| 1385 | already found. So for example if CONFIG_EXYNOS5 implies an option, |
| 1386 | but CONFIG_EXYNOS covers a larger set of defconfigs and also |
| 1387 | implies that option, this will drop the former in favour of the |
| 1388 | latter. In practice this option has not proved very used. |
| 1389 | |
| 1390 | Note the terminoloy: |
| 1391 | config - a CONFIG_XXX options (a string, e.g. 'CONFIG_CMD_EEPROM') |
| 1392 | defconfig - a defconfig file (a string, e.g. 'configs/snow_defconfig') |
| 1393 | """ |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1394 | kconf = KconfigScanner().conf if check_kconfig else None |
| 1395 | if add_imply and add_imply != 'all': |
Simon Glass | a362708 | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1396 | add_imply = add_imply.split(',') |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1397 | |
Simon Glass | 9d60339 | 2021-12-18 08:09:43 -0700 | [diff] [blame] | 1398 | all_configs, all_defconfigs, config_db, defconfig_db = read_database() |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1399 | |
Simon Glass | a362708 | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1400 | # Work through each target config option in turn, independently |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1401 | for config in config_list: |
| 1402 | defconfigs = defconfig_db.get(config) |
| 1403 | if not defconfigs: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1404 | print('%s not found in any defconfig' % config) |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1405 | continue |
| 1406 | |
| 1407 | # Get the set of defconfigs without this one (since a config cannot |
| 1408 | # imply itself) |
| 1409 | non_defconfigs = all_defconfigs - defconfigs |
| 1410 | num_defconfigs = len(defconfigs) |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1411 | print('%s found in %d/%d defconfigs' % (config, num_defconfigs, |
| 1412 | len(all_configs))) |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1413 | |
| 1414 | # This will hold the results: key=config, value=defconfigs containing it |
| 1415 | imply_configs = {} |
| 1416 | rest_configs = all_configs - set([config]) |
| 1417 | |
| 1418 | # Look at every possible config, except the target one |
| 1419 | for imply_config in rest_configs: |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1420 | if 'ERRATUM' in imply_config: |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1421 | continue |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1422 | if not imply_flags & IMPLY_CMD: |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1423 | if 'CONFIG_CMD' in imply_config: |
| 1424 | continue |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1425 | if not imply_flags & IMPLY_TARGET: |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1426 | if 'CONFIG_TARGET' in imply_config: |
| 1427 | continue |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1428 | |
| 1429 | # Find set of defconfigs that have this config |
| 1430 | imply_defconfig = defconfig_db[imply_config] |
| 1431 | |
| 1432 | # Get the intersection of this with defconfigs containing the |
| 1433 | # target config |
| 1434 | common_defconfigs = imply_defconfig & defconfigs |
| 1435 | |
| 1436 | # Get the set of defconfigs containing this config which DO NOT |
| 1437 | # also contain the taret config. If this set is non-empty it means |
| 1438 | # that this config affects other defconfigs as well as (possibly) |
| 1439 | # the ones affected by the target config. This means it implies |
| 1440 | # things we don't want to imply. |
| 1441 | not_common_defconfigs = imply_defconfig & non_defconfigs |
| 1442 | if not_common_defconfigs: |
| 1443 | continue |
| 1444 | |
| 1445 | # If there are common defconfigs, imply_config may be useful |
| 1446 | if common_defconfigs: |
| 1447 | skip = False |
| 1448 | if find_superset: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1449 | for prev in list(imply_configs.keys()): |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1450 | prev_count = len(imply_configs[prev]) |
| 1451 | count = len(common_defconfigs) |
| 1452 | if (prev_count > count and |
| 1453 | (imply_configs[prev] & common_defconfigs == |
| 1454 | common_defconfigs)): |
| 1455 | # skip imply_config because prev is a superset |
| 1456 | skip = True |
| 1457 | break |
| 1458 | elif count > prev_count: |
| 1459 | # delete prev because imply_config is a superset |
| 1460 | del imply_configs[prev] |
| 1461 | if not skip: |
| 1462 | imply_configs[imply_config] = common_defconfigs |
| 1463 | |
| 1464 | # Now we have a dict imply_configs of configs which imply each config |
| 1465 | # The value of each dict item is the set of defconfigs containing that |
| 1466 | # config. Rank them so that we print the configs that imply the largest |
| 1467 | # number of defconfigs first. |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1468 | ranked_iconfigs = sorted(imply_configs, |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1469 | key=lambda k: len(imply_configs[k]), reverse=True) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1470 | kconfig_info = '' |
| 1471 | cwd = os.getcwd() |
| 1472 | add_list = collections.defaultdict(list) |
| 1473 | for iconfig in ranked_iconfigs: |
| 1474 | num_common = len(imply_configs[iconfig]) |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1475 | |
| 1476 | # Don't bother if there are less than 5 defconfigs affected. |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1477 | if num_common < (2 if imply_flags & IMPLY_MIN_2 else 5): |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1478 | continue |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1479 | missing = defconfigs - imply_configs[iconfig] |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1480 | missing_str = ', '.join(missing) if missing else 'all' |
| 1481 | missing_str = '' |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1482 | show = True |
| 1483 | if kconf: |
| 1484 | sym = find_kconfig_rules(kconf, config[CONFIG_LEN:], |
| 1485 | iconfig[CONFIG_LEN:]) |
| 1486 | kconfig_info = '' |
| 1487 | if sym: |
Simon Glass | ea40b20 | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1488 | nodes = sym.nodes |
| 1489 | if len(nodes) == 1: |
| 1490 | fname, linenum = nodes[0].filename, nodes[0].linenr |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1491 | if cwd and fname.startswith(cwd): |
| 1492 | fname = fname[len(cwd) + 1:] |
| 1493 | kconfig_info = '%s:%d' % (fname, linenum) |
| 1494 | if skip_added: |
| 1495 | show = False |
| 1496 | else: |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1497 | sym = kconf.syms.get(iconfig[CONFIG_LEN:]) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1498 | fname = '' |
| 1499 | if sym: |
Simon Glass | ea40b20 | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1500 | nodes = sym.nodes |
| 1501 | if len(nodes) == 1: |
| 1502 | fname, linenum = nodes[0].filename, nodes[0].linenr |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1503 | if cwd and fname.startswith(cwd): |
| 1504 | fname = fname[len(cwd) + 1:] |
| 1505 | in_arch_board = not sym or (fname.startswith('arch') or |
| 1506 | fname.startswith('board')) |
| 1507 | if (not in_arch_board and |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1508 | not imply_flags & IMPLY_NON_ARCH_BOARD): |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1509 | continue |
| 1510 | |
| 1511 | if add_imply and (add_imply == 'all' or |
| 1512 | iconfig in add_imply): |
| 1513 | fname, linenum, kconfig_info = (check_imply_rule(kconf, |
| 1514 | config[CONFIG_LEN:], iconfig[CONFIG_LEN:])) |
| 1515 | if fname: |
| 1516 | add_list[fname].append(linenum) |
| 1517 | |
| 1518 | if show and kconfig_info != 'skip': |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1519 | print('%5d : %-30s%-25s %s' % (num_common, iconfig.ljust(30), |
| 1520 | kconfig_info, missing_str)) |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1521 | |
| 1522 | # Having collected a list of things to add, now we add them. We process |
| 1523 | # each file from the largest line number to the smallest so that |
| 1524 | # earlier additions do not affect our line numbers. E.g. if we added an |
| 1525 | # imply at line 20 it would change the position of each line after |
| 1526 | # that. |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1527 | for fname, linenums in add_list.items(): |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1528 | for linenum in sorted(linenums, reverse=True): |
| 1529 | add_imply_rule(config[CONFIG_LEN:], fname, linenum) |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1530 | |
Simon Glass | 941671a | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1531 | def defconfig_matches(configs, re_match): |
| 1532 | """Check if any CONFIG option matches a regex |
| 1533 | |
| 1534 | The match must be complete, i.e. from the start to end of the CONFIG option. |
| 1535 | |
| 1536 | Args: |
| 1537 | configs (dict): Dict of CONFIG options: |
| 1538 | key: CONFIG option |
| 1539 | value: Value of option |
| 1540 | re_match (re.Pattern): Match to check |
| 1541 | |
| 1542 | Returns: |
| 1543 | bool: True if any CONFIG matches the regex |
| 1544 | """ |
| 1545 | for cfg in configs: |
Simon Glass | d9c958f | 2022-03-05 20:18:54 -0700 | [diff] [blame] | 1546 | if re_match.fullmatch(cfg): |
Simon Glass | 941671a | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1547 | return True |
| 1548 | return False |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1549 | |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1550 | def do_find_config(config_list): |
| 1551 | """Find boards with a given combination of CONFIGs |
| 1552 | |
| 1553 | Params: |
Simon Glass | 941671a | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1554 | config_list: List of CONFIG options to check (each a regex consisting |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1555 | of a config option, with or without a CONFIG_ prefix. If an option |
| 1556 | is preceded by a tilde (~) then it must be false, otherwise it must |
| 1557 | be true) |
| 1558 | """ |
| 1559 | all_configs, all_defconfigs, config_db, defconfig_db = read_database() |
| 1560 | |
| 1561 | # Get the whitelist |
Simon Glass | 37f815c | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 1562 | adhoc_configs = set(read_file('scripts/config_whitelist.txt')) |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1563 | |
| 1564 | # Start with all defconfigs |
| 1565 | out = all_defconfigs |
| 1566 | |
| 1567 | # Work through each config in turn |
| 1568 | adhoc = [] |
| 1569 | for item in config_list: |
| 1570 | # Get the real config name and whether we want this config or not |
| 1571 | cfg = item |
| 1572 | want = True |
| 1573 | if cfg[0] == '~': |
| 1574 | want = False |
| 1575 | cfg = cfg[1:] |
| 1576 | |
| 1577 | if cfg in adhoc_configs: |
| 1578 | adhoc.append(cfg) |
| 1579 | continue |
| 1580 | |
| 1581 | # Search everything that is still in the running. If it has a config |
| 1582 | # that we want, or doesn't have one that we don't, add it into the |
| 1583 | # running for the next stage |
| 1584 | in_list = out |
| 1585 | out = set() |
Simon Glass | 941671a | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1586 | re_match = re.compile(cfg) |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1587 | for defc in in_list: |
Simon Glass | 941671a | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1588 | has_cfg = defconfig_matches(config_db[defc], re_match) |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1589 | if has_cfg == want: |
| 1590 | out.add(defc) |
| 1591 | if adhoc: |
| 1592 | print(f"Error: Not in Kconfig: %s" % ' '.join(adhoc)) |
| 1593 | else: |
| 1594 | print(f'{len(out)} matches') |
Simon Glass | 78f12e5 | 2022-03-05 20:18:53 -0700 | [diff] [blame] | 1595 | print(' '.join(item.split('_defconfig')[0] for item in out)) |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1596 | |
| 1597 | |
| 1598 | def prefix_config(cfg): |
| 1599 | """Prefix a config with CONFIG_ if needed |
| 1600 | |
| 1601 | This handles ~ operator, which indicates that the CONFIG should be disabled |
| 1602 | |
| 1603 | >>> prefix_config('FRED') |
| 1604 | 'CONFIG_FRED' |
| 1605 | >>> prefix_config('CONFIG_FRED') |
| 1606 | 'CONFIG_FRED' |
| 1607 | >>> prefix_config('~FRED') |
| 1608 | '~CONFIG_FRED' |
| 1609 | >>> prefix_config('~CONFIG_FRED') |
| 1610 | '~CONFIG_FRED' |
| 1611 | >>> prefix_config('A123') |
| 1612 | 'CONFIG_A123' |
| 1613 | """ |
| 1614 | op = '' |
| 1615 | if cfg[0] == '~': |
| 1616 | op = cfg[0] |
| 1617 | cfg = cfg[1:] |
| 1618 | if not cfg.startswith('CONFIG_'): |
| 1619 | cfg = 'CONFIG_' + cfg |
| 1620 | return op + cfg |
| 1621 | |
| 1622 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1623 | def main(): |
| 1624 | try: |
| 1625 | cpu_count = multiprocessing.cpu_count() |
| 1626 | except NotImplementedError: |
| 1627 | cpu_count = 1 |
| 1628 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1629 | epilog = '''Move config options from headers to defconfig files. See |
| 1630 | doc/develop/moveconfig.rst for documentation.''' |
| 1631 | |
| 1632 | parser = ArgumentParser(epilog=epilog) |
| 1633 | # Add arguments here |
| 1634 | parser.add_argument('-a', '--add-imply', type=str, default='', |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1635 | help='comma-separated list of CONFIG options to add ' |
| 1636 | "an 'imply' statement to for the CONFIG in -i") |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1637 | parser.add_argument('-A', '--skip-added', action='store_true', default=False, |
Simon Glass | cb00883 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1638 | help="don't show options which are already marked as " |
| 1639 | 'implying others') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1640 | parser.add_argument('-b', '--build-db', action='store_true', default=False, |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1641 | help='build a CONFIG database') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1642 | parser.add_argument('-c', '--color', action='store_true', default=False, |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1643 | help='display the log in color') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1644 | parser.add_argument('-C', '--commit', action='store_true', default=False, |
Simon Glass | 9ede212 | 2016-09-12 23:18:21 -0600 | [diff] [blame] | 1645 | help='Create a git commit for the operation') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1646 | parser.add_argument('-d', '--defconfigs', type=str, |
Simon Glass | ee4e61b | 2017-06-01 19:38:59 -0600 | [diff] [blame] | 1647 | help='a file containing a list of defconfigs to move, ' |
| 1648 | "one per line (for example 'snow_defconfig') " |
| 1649 | "or '-' to read from stdin") |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1650 | parser.add_argument('-e', '--exit-on-error', action='store_true', |
Simon Glass | e1ae563 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1651 | default=False, |
| 1652 | help='exit immediately on any error') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1653 | parser.add_argument('-f', '--find', action='store_true', default=False, |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1654 | help='Find boards with a given config combination') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1655 | parser.add_argument('-H', '--headers-only', dest='cleanup_headers_only', |
Simon Glass | e1ae563 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1656 | action='store_true', default=False, |
| 1657 | help='only cleanup the headers') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1658 | parser.add_argument('-i', '--imply', action='store_true', default=False, |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1659 | help='find options which imply others') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1660 | parser.add_argument('-I', '--imply-flags', type=str, default='', |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1661 | help="control the -i option ('help' for help") |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1662 | parser.add_argument('-j', '--jobs', type=int, default=cpu_count, |
Simon Glass | e1ae563 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1663 | help='the number of jobs to run simultaneously') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1664 | parser.add_argument('-n', '--dry-run', action='store_true', default=False, |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1665 | help='perform a trial run (show log with no changes)') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1666 | parser.add_argument('-r', '--git-ref', type=str, |
Simon Glass | e1ae563 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1667 | help='the git ref to clone for building the autoconf.mk') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1668 | parser.add_argument('-s', '--force-sync', action='store_true', default=False, |
Masahiro Yamada | 8513dc0 | 2016-05-19 15:52:08 +0900 | [diff] [blame] | 1669 | help='force sync by savedefconfig') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1670 | parser.add_argument('-S', '--spl', action='store_true', default=False, |
Masahiro Yamada | 07913d1 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 1671 | help='parse config options defined for SPL build') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1672 | parser.add_argument('-t', '--test', action='store_true', default=False, |
Simon Glass | e1ae563 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1673 | help='run unit tests') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1674 | parser.add_argument('-y', '--yes', action='store_true', default=False, |
Simon Glass | 6b403df | 2016-09-12 23:18:20 -0600 | [diff] [blame] | 1675 | help="respond 'yes' to any prompts") |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1676 | parser.add_argument('-v', '--verbose', action='store_true', default=False, |
Joe Hershberger | 95bf9c7 | 2015-05-19 13:21:24 -0500 | [diff] [blame] | 1677 | help='show any build errors as boards are built') |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1678 | parser.add_argument('configs', nargs='*') |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1679 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1680 | args = parser.parse_args() |
| 1681 | configs = args.configs |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1682 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1683 | if args.test: |
Simon Glass | 84067a5 | 2021-12-18 08:09:45 -0700 | [diff] [blame] | 1684 | sys.argv = [sys.argv[0]] |
| 1685 | fail, count = doctest.testmod() |
| 1686 | if fail: |
| 1687 | return 1 |
| 1688 | unittest.main() |
| 1689 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1690 | if not any((len(configs), args.force_sync, args.build_db, args.imply, |
| 1691 | args.find)): |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1692 | parser.print_usage() |
| 1693 | sys.exit(1) |
| 1694 | |
Masahiro Yamada | b6ef393 | 2016-05-19 15:51:58 +0900 | [diff] [blame] | 1695 | # prefix the option name with CONFIG_ if missing |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1696 | configs = [prefix_config(cfg) for cfg in configs] |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1697 | |
Joe Hershberger | 2144f88 | 2015-05-19 13:21:20 -0500 | [diff] [blame] | 1698 | check_top_directory() |
| 1699 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1700 | if args.imply: |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1701 | imply_flags = 0 |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1702 | if args.imply_flags == 'all': |
Simon Glass | dee36c7 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1703 | imply_flags = -1 |
| 1704 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1705 | elif args.imply_flags: |
| 1706 | for flag in args.imply_flags.split(','): |
Simon Glass | dee36c7 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1707 | bad = flag not in IMPLY_FLAGS |
| 1708 | if bad: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1709 | print("Invalid flag '%s'" % flag) |
Simon Glass | dee36c7 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1710 | if flag == 'help' or bad: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1711 | print("Imply flags: (separate with ',')") |
| 1712 | for name, info in IMPLY_FLAGS.items(): |
| 1713 | print(' %-15s: %s' % (name, info[1])) |
Simon Glass | dee36c7 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1714 | parser.print_usage() |
| 1715 | sys.exit(1) |
| 1716 | imply_flags |= IMPLY_FLAGS[flag][0] |
Simon Glass | 9b2a2e8 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1717 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1718 | do_imply_config(configs, args.add_imply, imply_flags, args.skip_added) |
Simon Glass | 99b6660 | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1719 | return |
| 1720 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1721 | if args.find: |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1722 | do_find_config(configs) |
| 1723 | return |
| 1724 | |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1725 | config_db = {} |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1726 | db_queue = queue.Queue() |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1727 | t = DatabaseThread(config_db, db_queue) |
| 1728 | t.setDaemon(True) |
| 1729 | t.start() |
| 1730 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1731 | if not args.cleanup_headers_only: |
Masahiro Yamada | f7536f7 | 2016-07-25 19:15:23 +0900 | [diff] [blame] | 1732 | check_clean_directory() |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1733 | bsettings.Setup('') |
Simon Glass | 6821a74 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1734 | toolchains = toolchain.Toolchains() |
| 1735 | toolchains.GetSettings() |
| 1736 | toolchains.Scan(verbose=False) |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1737 | move_config(toolchains, configs, args, db_queue) |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1738 | db_queue.join() |
Joe Hershberger | 2144f88 | 2015-05-19 13:21:20 -0500 | [diff] [blame] | 1739 | |
Masahiro Yamada | 6a9f79f | 2016-05-19 15:52:09 +0900 | [diff] [blame] | 1740 | if configs: |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1741 | cleanup_headers(configs, args) |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1742 | cleanup_whitelist(configs, args) |
| 1743 | cleanup_readme(configs, args) |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1744 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1745 | if args.commit: |
Simon Glass | 9ede212 | 2016-09-12 23:18:21 -0600 | [diff] [blame] | 1746 | subprocess.call(['git', 'add', '-u']) |
| 1747 | if configs: |
| 1748 | msg = 'Convert %s %sto Kconfig' % (configs[0], |
| 1749 | 'et al ' if len(configs) > 1 else '') |
| 1750 | msg += ('\n\nThis converts the following to Kconfig:\n %s\n' % |
| 1751 | '\n '.join(configs)) |
| 1752 | else: |
| 1753 | msg = 'configs: Resync with savedefconfig' |
| 1754 | msg += '\n\nRsync all defconfig files using moveconfig.py' |
| 1755 | subprocess.call(['git', 'commit', '-s', '-m', msg]) |
| 1756 | |
Simon Glass | b2e83c6 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1757 | if args.build_db: |
Simon Glass | 91197aa | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1758 | with open(CONFIG_DATABASE, 'w', encoding='utf-8') as fd: |
Simon Glass | 793dca3 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1759 | for defconfig, configs in config_db.items(): |
Simon Glass | c79d18c | 2017-08-13 16:02:54 -0600 | [diff] [blame] | 1760 | fd.write('%s\n' % defconfig) |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1761 | for config in sorted(configs.keys()): |
Simon Glass | c79d18c | 2017-08-13 16:02:54 -0600 | [diff] [blame] | 1762 | fd.write(' %s=%s\n' % (config, configs[config])) |
| 1763 | fd.write('\n') |
Simon Glass | d73fcb1 | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1764 | |
Masahiro Yamada | 5a27c73 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1765 | if __name__ == '__main__': |
Simon Glass | 65d7fce | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1766 | sys.exit(main()) |