Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 3 | # |
| 4 | # Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
| 5 | # |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 6 | |
| 7 | """ |
| 8 | Move config options from headers to defconfig files. |
| 9 | |
Simon Glass | 83cc72e | 2021-07-21 21:35:51 -0600 | [diff] [blame] | 10 | See doc/develop/moveconfig.rst for documentation. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 11 | """ |
| 12 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 13 | from argparse import ArgumentParser |
Markus Klotzbuecher | bac0bb5 | 2020-02-12 20:46:44 +0100 | [diff] [blame] | 14 | import asteval |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 15 | import collections |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 16 | from contextlib import ExitStack |
Masahiro Yamada | ea8f534 | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 17 | import copy |
Masahiro Yamada | 573b390 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 18 | import difflib |
Simon Glass | bb57be7 | 2021-12-18 08:09:45 -0700 | [diff] [blame] | 19 | import doctest |
Masahiro Yamada | 0f6beda | 2016-05-19 15:52:07 +0900 | [diff] [blame] | 20 | import filecmp |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 21 | import fnmatch |
Masahiro Yamada | 3984d6e | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 22 | import glob |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 23 | import multiprocessing |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 24 | import os |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 25 | import queue |
Masahiro Yamada | b616081 | 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 | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 31 | import threading |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 32 | import time |
Simon Glass | bb57be7 | 2021-12-18 08:09:45 -0700 | [diff] [blame] | 33 | import unittest |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 34 | |
Simon Glass | f0d9c10 | 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 | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 38 | |
Masahiro Yamada | b616081 | 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 | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 42 | STATE_IDLE = 0 |
| 43 | STATE_DEFCONFIG = 1 |
| 44 | STATE_AUTOCONF = 2 |
Joe Hershberger | 166edec | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 45 | STATE_SAVEDEFCONFIG = 3 |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 46 | |
| 47 | ACTION_MOVE = 0 |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 48 | ACTION_NO_ENTRY = 1 |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 49 | ACTION_NO_ENTRY_WARN = 2 |
| 50 | ACTION_NO_CHANGE = 3 |
Masahiro Yamada | b616081 | 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 | 8fb5bd0 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 69 | AUTO_CONF_PATH = 'include/config/auto.conf' |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 70 | CONFIG_DATABASE = 'moveconfig.db' |
Simon Glass | 8fb5bd0 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 71 | |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 72 | CONFIG_LEN = len('CONFIG_') |
Simon Glass | 8fb5bd0 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 73 | |
Markus Klotzbuecher | 3d5d418 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 74 | SIZES = { |
Simon Glass | dc634d9 | 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 | 3d5d418 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Simon Glass | e803755 | 2022-02-08 11:49:45 -0700 | [diff] [blame] | 94 | RE_REMOVE_DEFCONFIG = re.compile(r'(.*)_defconfig') |
| 95 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 96 | ### helper functions ### |
Masahiro Yamada | b616081 | 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 | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 99 | for fname in 'README', 'Licenses': |
| 100 | if not os.path.exists(fname): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 101 | sys.exit('Please run at the top of source directory.') |
| 102 | |
Masahiro Yamada | 990e677 | 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 | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 105 | for fname in '.config', 'include/config': |
| 106 | if os.path.exists(fname): |
Masahiro Yamada | 990e677 | 2016-05-19 15:51:54 +0900 | [diff] [blame] | 107 | sys.exit("source tree is not clean, please run 'make mrproper'") |
| 108 | |
Masahiro Yamada | b616081 | 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 | b3464eb | 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 | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 120 | return ret[0].rstrip() |
| 121 | |
Simon Glass | 18774bc | 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 | b3464eb | 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 | 18774bc | 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 | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 131 | list of str: a list of matching defconfig files |
Simon Glass | 18774bc | 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 | 3984d6e | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 140 | def get_matched_defconfigs(defconfigs_file): |
Simon Glass | 8f3cf31 | 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 | b3464eb | 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 | 8f3cf31 | 2017-06-01 19:38:59 -0600 | [diff] [blame] | 146 | |
| 147 | Returns: |
Simon Glass | b3464eb | 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 | 8f3cf31 | 2017-06-01 19:38:59 -0600 | [diff] [blame] | 149 | """ |
Masahiro Yamada | 3984d6e | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 150 | defconfigs = [] |
Simon Glass | b3464eb | 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 | 3984d6e | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 167 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 168 | defconfigs += matched |
Masahiro Yamada | 3984d6e | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 169 | |
| 170 | # use set() to drop multiple matching |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 171 | return [defconfig[len('configs') + 1:] for defconfig in set(defconfigs)] |
Masahiro Yamada | 3984d6e | 2016-10-19 14:39:54 +0900 | [diff] [blame] | 172 | |
Masahiro Yamada | 58175e3 | 2016-07-25 19:15:28 +0900 | [diff] [blame] | 173 | def get_all_defconfigs(): |
Simon Glass | b3464eb | 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 | 58175e3 | 2016-07-25 19:15:28 +0900 | [diff] [blame] | 179 | defconfigs = [] |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 180 | for (dirpath, _, filenames) in os.walk('configs'): |
Masahiro Yamada | 58175e3 | 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 | b616081 | 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 | 465b7c0 | 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 | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 194 | return string |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 195 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 196 | def show_diff(alines, blines, file_path, color_enabled): |
Masahiro Yamada | 573b390 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 197 | """Show unidified diff. |
| 198 | |
Simon Glass | b3464eb | 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 | 573b390 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 204 | """ |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 205 | diff = difflib.unified_diff(alines, blines, |
Masahiro Yamada | 573b390 | 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 | cab8407 | 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 | a1a4b09 | 2016-07-25 19:15:26 +0900 | [diff] [blame] | 214 | else: |
Alper Nebi Yasak | cab8407 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 215 | print(line) |
Masahiro Yamada | 573b390 | 2016-07-25 19:15:25 +0900 | [diff] [blame] | 216 | |
Simon Glass | b3464eb | 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 | ea8f534 | 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 | b3464eb | 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 | ea8f534 | 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 | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 248 | for pat in pre_patterns: |
| 249 | if pat.search(lines[i - 1]): |
Masahiro Yamada | ea8f534 | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 250 | break |
| 251 | else: |
| 252 | # not matched |
| 253 | continue |
| 254 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 255 | for pat in post_patterns: |
| 256 | if pat.search(lines[j]): |
Masahiro Yamada | ea8f534 | 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 | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 270 | def confirm(args, prompt): |
Simon Glass | b3464eb | 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 | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 279 | if not args.yes: |
Chris Packham | 85e15c5 | 2017-05-02 21:30:46 +1200 | [diff] [blame] | 280 | while True: |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 281 | choice = input(f'{prompt} [y/n]: ') |
Chris Packham | 85e15c5 | 2017-05-02 21:30:46 +1200 | [diff] [blame] | 282 | choice = choice.lower() |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 283 | print(choice) |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 284 | if choice in ('y', 'n'): |
Chris Packham | 85e15c5 | 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 | b09ae45 | 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 | aba238f | 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 | afaddc7 | 2022-02-11 13:23:22 -0700 | [diff] [blame] | 331 | raise |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 332 | print("Failed on file %s': %s" % (fname, e)) |
| 333 | return None |
| 334 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 335 | def cleanup_empty_blocks(header_path, args): |
Chris Packham | 73f6c7c | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 336 | """Clean up empty conditional blocks |
| 337 | |
Simon Glass | b3464eb | 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 | 73f6c7c | 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 | aba238f | 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 | 73f6c7c | 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 | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 350 | args.color) |
Chris Packham | 73f6c7c | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 351 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 352 | if args.dry_run: |
Chris Packham | 73f6c7c | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 353 | return |
| 354 | |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 355 | if new_data != data: |
| 356 | write_file(header_path, new_data) |
Chris Packham | 73f6c7c | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 357 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 358 | def cleanup_one_header(header_path, patterns, args): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 359 | """Clean regex-matched lines away from a file. |
| 360 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 361 | Args: |
Masahiro Yamada | b616081 | 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 | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 365 | args (Namespace): program arguments |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 366 | """ |
Simon Glass | aba238f | 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 | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 370 | |
| 371 | matched = [] |
| 372 | for i, line in enumerate(lines): |
Alper Nebi Yasak | cab8407 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 373 | if i - 1 in matched and lines[i - 1].endswith('\\'): |
Masahiro Yamada | 6d798ba | 2016-07-25 19:15:27 +0900 | [diff] [blame] | 374 | matched.append(i) |
| 375 | continue |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 376 | for pattern in patterns: |
Masahiro Yamada | ea8f534 | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 377 | if pattern.search(line): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 378 | matched.append(i) |
| 379 | break |
| 380 | |
Masahiro Yamada | ea8f534 | 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 | cab8407 | 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 | ea8f534 | 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 | 573b390 | 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 | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 410 | show_diff(lines, tolines, header_path, args.color) |
Masahiro Yamada | ea8f534 | 2016-07-25 19:15:24 +0900 | [diff] [blame] | 411 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 412 | if args.dry_run: |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 413 | return |
| 414 | |
Simon Glass | b09ae45 | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 415 | write_file(header_path, tolines) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 416 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 417 | def cleanup_headers(configs, args): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 418 | """Delete config defines from board headers. |
| 419 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 420 | Args: |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 421 | configs: A list of CONFIGs to remove. |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 422 | args (Namespace): program arguments |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 423 | """ |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 424 | if not confirm(args, 'Clean up headers?'): |
Chris Packham | 85e15c5 | 2017-05-02 21:30:46 +1200 | [diff] [blame] | 425 | return |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 426 | |
| 427 | patterns = [] |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 428 | for config in configs: |
Alper Nebi Yasak | cab8407 | 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 | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 431 | |
Joe Hershberger | b78ad42 | 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 | 28a6d35 | 2016-07-25 19:15:22 +0900 | [diff] [blame] | 434 | if dirpath == os.path.join('include', 'generated'): |
| 435 | continue |
Joe Hershberger | b78ad42 | 2015-05-19 13:21:21 -0500 | [diff] [blame] | 436 | for filename in filenames: |
Simon Glass | ce44bf5 | 2020-08-11 11:23:34 -0600 | [diff] [blame] | 437 | if not filename.endswith(('~', '.dts', '.dtsi', '.bin', |
Trevor Woerner | aaad0c2 | 2021-03-15 12:01:33 -0400 | [diff] [blame] | 438 | '.elf','.aml','.dat')): |
Chris Packham | 73f6c7c | 2019-01-30 20:23:16 +1300 | [diff] [blame] | 439 | header_path = os.path.join(dirpath, filename) |
Tom Rini | e90c007 | 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 | d9c1da2 | 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 | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 445 | |
Chris Packham | 0e6deff | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 446 | def find_matching(patterns, line): |
| 447 | for pat in patterns: |
| 448 | if pat.search(line): |
| 449 | return True |
| 450 | return False |
| 451 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 452 | def cleanup_readme(configs, args): |
Chris Packham | 0e6deff | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 453 | """Delete config description in README |
| 454 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 455 | Args: |
Chris Packham | 0e6deff | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 456 | configs: A list of CONFIGs to remove. |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 457 | args (Namespace): program arguments |
Chris Packham | 0e6deff | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 458 | """ |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 459 | if not confirm(args, 'Clean up README?'): |
Chris Packham | 0e6deff | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 460 | return |
| 461 | |
| 462 | patterns = [] |
| 463 | for config in configs: |
| 464 | patterns.append(re.compile(r'^\s+%s' % config)) |
| 465 | |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 466 | lines = read_file('README') |
Chris Packham | 0e6deff | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 467 | |
| 468 | found = False |
| 469 | newlines = [] |
| 470 | for line in lines: |
| 471 | if not found: |
| 472 | found = find_matching(patterns, line) |
| 473 | if found: |
| 474 | continue |
| 475 | |
| 476 | if found and re.search(r'^\s+CONFIG', line): |
| 477 | found = False |
| 478 | |
| 479 | if not found: |
| 480 | newlines.append(line) |
| 481 | |
Simon Glass | b09ae45 | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 482 | write_file('README', newlines) |
Chris Packham | 0e6deff | 2017-05-02 21:30:48 +1200 | [diff] [blame] | 483 | |
Markus Klotzbuecher | 3d5d418 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 484 | def try_expand(line): |
| 485 | """If value looks like an expression, try expanding it |
| 486 | Otherwise just return the existing value |
| 487 | """ |
| 488 | if line.find('=') == -1: |
| 489 | return line |
| 490 | |
| 491 | try: |
Markus Klotzbuecher | bac0bb5 | 2020-02-12 20:46:44 +0100 | [diff] [blame] | 492 | aeval = asteval.Interpreter( usersyms=SIZES, minimal=True ) |
Markus Klotzbuecher | 3d5d418 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 493 | cfg, val = re.split("=", line) |
| 494 | val= val.strip('\"') |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 495 | if re.search(r'[*+-/]|<<|SZ_+|\(([^\)]+)\)', val): |
Markus Klotzbuecher | bac0bb5 | 2020-02-12 20:46:44 +0100 | [diff] [blame] | 496 | newval = hex(aeval(val)) |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 497 | print('\tExpanded expression %s to %s' % (val, newval)) |
Markus Klotzbuecher | 3d5d418 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 498 | return cfg+'='+newval |
| 499 | except: |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 500 | print('\tFailed to expand expression in %s' % line) |
Markus Klotzbuecher | 3d5d418 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 501 | |
| 502 | return line |
| 503 | |
Chris Packham | 9d5274f | 2017-05-02 21:30:47 +1200 | [diff] [blame] | 504 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 505 | ### classes ### |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 506 | class Progress: |
| 507 | |
| 508 | """Progress Indicator""" |
| 509 | |
| 510 | def __init__(self, total): |
| 511 | """Create a new progress indicator. |
| 512 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 513 | Args: |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 514 | total: A number of defconfig files to process. |
| 515 | """ |
| 516 | self.current = 0 |
| 517 | self.total = total |
| 518 | |
| 519 | def inc(self): |
| 520 | """Increment the number of processed defconfig files.""" |
| 521 | |
| 522 | self.current += 1 |
| 523 | |
| 524 | def show(self): |
| 525 | """Display the progress.""" |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 526 | print(' %d defconfigs out of %d\r' % (self.current, self.total), end=' ') |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 527 | sys.stdout.flush() |
| 528 | |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 529 | |
| 530 | class KconfigScanner: |
| 531 | """Kconfig scanner.""" |
| 532 | |
| 533 | def __init__(self): |
| 534 | """Scan all the Kconfig files and create a Config object.""" |
| 535 | # Define environment variables referenced from Kconfig |
| 536 | os.environ['srctree'] = os.getcwd() |
| 537 | os.environ['UBOOTVERSION'] = 'dummy' |
| 538 | os.environ['KCONFIG_OBJDIR'] = '' |
Tom Rini | 3c5f415 | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 539 | self.conf = kconfiglib.Kconfig() |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 540 | |
| 541 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 542 | class KconfigParser: |
| 543 | |
| 544 | """A parser of .config and include/autoconf.mk.""" |
| 545 | |
| 546 | re_arch = re.compile(r'CONFIG_SYS_ARCH="(.*)"') |
| 547 | re_cpu = re.compile(r'CONFIG_SYS_CPU="(.*)"') |
| 548 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 549 | def __init__(self, configs, args, build_dir): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 550 | """Create a new parser. |
| 551 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 552 | Args: |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 553 | configs: A list of CONFIGs to move. |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 554 | args (Namespace): program arguments |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 555 | build_dir: Build directory. |
| 556 | """ |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 557 | self.configs = configs |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 558 | self.args = args |
Masahiro Yamada | 5393b61 | 2016-05-19 15:52:00 +0900 | [diff] [blame] | 559 | self.dotconfig = os.path.join(build_dir, '.config') |
| 560 | self.autoconf = os.path.join(build_dir, 'include', 'autoconf.mk') |
Masahiro Yamada | 6d13917 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 561 | self.spl_autoconf = os.path.join(build_dir, 'spl', 'include', |
| 562 | 'autoconf.mk') |
Simon Glass | 8fb5bd0 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 563 | self.config_autoconf = os.path.join(build_dir, AUTO_CONF_PATH) |
Masahiro Yamada | 07f9852 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 564 | self.defconfig = os.path.join(build_dir, 'defconfig') |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 565 | |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 566 | def get_arch(self): |
| 567 | """Parse .config file and return the architecture. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 568 | |
| 569 | Returns: |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 570 | Architecture name (e.g. 'arm'). |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 571 | """ |
| 572 | arch = '' |
| 573 | cpu = '' |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 574 | for line in read_file(self.dotconfig): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 575 | m = self.re_arch.match(line) |
| 576 | if m: |
| 577 | arch = m.group(1) |
| 578 | continue |
| 579 | m = self.re_cpu.match(line) |
| 580 | if m: |
| 581 | cpu = m.group(1) |
| 582 | |
Masahiro Yamada | c4d76eb | 2016-05-19 15:51:53 +0900 | [diff] [blame] | 583 | if not arch: |
| 584 | return None |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 585 | |
| 586 | # fix-up for aarch64 |
| 587 | if arch == 'arm' and cpu == 'armv8': |
| 588 | arch = 'aarch64' |
| 589 | |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 590 | return arch |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 591 | |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 592 | def parse_one_config(self, config, dotconfig_lines, autoconf_lines): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 593 | """Parse .config, defconfig, include/autoconf.mk for one config. |
| 594 | |
| 595 | This function looks for the config options in the lines from |
| 596 | defconfig, .config, and include/autoconf.mk in order to decide |
| 597 | which action should be taken for this defconfig. |
| 598 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 599 | Args: |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 600 | config: CONFIG name to parse. |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 601 | dotconfig_lines: lines from the .config file. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 602 | autoconf_lines: lines from the include/autoconf.mk file. |
| 603 | |
| 604 | Returns: |
| 605 | A tupple of the action for this defconfig and the line |
| 606 | matched for the config. |
| 607 | """ |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 608 | not_set = '# %s is not set' % config |
| 609 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 610 | for line in autoconf_lines: |
| 611 | line = line.rstrip() |
| 612 | if line.startswith(config + '='): |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 613 | new_val = line |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 614 | break |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 615 | else: |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 616 | new_val = not_set |
| 617 | |
Markus Klotzbuecher | 3d5d418 | 2019-05-15 15:15:52 +0200 | [diff] [blame] | 618 | new_val = try_expand(new_val) |
| 619 | |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 620 | for line in dotconfig_lines: |
| 621 | line = line.rstrip() |
| 622 | if line.startswith(config + '=') or line == not_set: |
| 623 | old_val = line |
| 624 | break |
| 625 | else: |
| 626 | if new_val == not_set: |
| 627 | return (ACTION_NO_ENTRY, config) |
| 628 | else: |
| 629 | return (ACTION_NO_ENTRY_WARN, config) |
| 630 | |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 631 | # If this CONFIG is neither bool nor trisate |
| 632 | if old_val[-2:] != '=y' and old_val[-2:] != '=m' and old_val != not_set: |
| 633 | # tools/scripts/define2mk.sed changes '1' to 'y'. |
| 634 | # This is a problem if the CONFIG is int type. |
| 635 | # Check the type in Kconfig and handle it correctly. |
| 636 | if new_val[-2:] == '=y': |
| 637 | new_val = new_val[:-1] + '1' |
| 638 | |
Masahiro Yamada | b48387f | 2016-06-15 14:33:50 +0900 | [diff] [blame] | 639 | return (ACTION_NO_CHANGE if old_val == new_val else ACTION_MOVE, |
| 640 | new_val) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 641 | |
Masahiro Yamada | 465b7c0 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 642 | def update_dotconfig(self): |
Masahiro Yamada | 7c0d9d2 | 2016-05-19 15:51:50 +0900 | [diff] [blame] | 643 | """Parse files for the config options and update the .config. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 644 | |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 645 | This function parses the generated .config and include/autoconf.mk |
| 646 | searching the target options. |
Masahiro Yamada | 7c0d9d2 | 2016-05-19 15:51:50 +0900 | [diff] [blame] | 647 | Move the config option(s) to the .config as needed. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 648 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 649 | Args: |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 650 | defconfig: defconfig name. |
Masahiro Yamada | 69e2bbc | 2016-05-19 15:52:01 +0900 | [diff] [blame] | 651 | |
| 652 | Returns: |
Masahiro Yamada | 263d137 | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 653 | Return a tuple of (updated flag, log string). |
| 654 | The "updated flag" is True if the .config was updated, False |
| 655 | otherwise. The "log string" shows what happend to the .config. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 656 | """ |
| 657 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 658 | results = [] |
Masahiro Yamada | 263d137 | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 659 | updated = False |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 660 | suspicious = False |
Masahiro Yamada | 6d13917 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 661 | rm_files = [self.config_autoconf, self.autoconf] |
| 662 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 663 | if self.args.spl: |
Masahiro Yamada | 6d13917 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 664 | if os.path.exists(self.spl_autoconf): |
| 665 | autoconf_path = self.spl_autoconf |
| 666 | rm_files.append(self.spl_autoconf) |
| 667 | else: |
| 668 | for f in rm_files: |
| 669 | os.remove(f) |
| 670 | return (updated, suspicious, |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 671 | color_text(self.args.color, COLOR_BROWN, |
Masahiro Yamada | 6d13917 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 672 | "SPL is not enabled. Skipped.") + '\n') |
| 673 | else: |
| 674 | autoconf_path = self.autoconf |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 675 | |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 676 | dotconfig_lines = read_file(self.dotconfig) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 677 | |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 678 | autoconf_lines = read_file(autoconf_path) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 679 | |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 680 | for config in self.configs: |
| 681 | result = self.parse_one_config(config, dotconfig_lines, |
Joe Hershberger | 166edec | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 682 | autoconf_lines) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 683 | results.append(result) |
| 684 | |
| 685 | log = '' |
| 686 | |
| 687 | for (action, value) in results: |
| 688 | if action == ACTION_MOVE: |
| 689 | actlog = "Move '%s'" % value |
| 690 | log_color = COLOR_LIGHT_GREEN |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 691 | elif action == ACTION_NO_ENTRY: |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 692 | actlog = '%s is not defined in Kconfig. Do nothing.' % value |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 693 | log_color = COLOR_LIGHT_BLUE |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 694 | elif action == ACTION_NO_ENTRY_WARN: |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 695 | actlog = '%s is not defined in Kconfig (suspicious). Do nothing.' % value |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 696 | log_color = COLOR_YELLOW |
| 697 | suspicious = True |
Masahiro Yamada | 5643d6e | 2016-05-19 15:51:56 +0900 | [diff] [blame] | 698 | elif action == ACTION_NO_CHANGE: |
| 699 | actlog = "'%s' is the same as the define in Kconfig. Do nothing." \ |
| 700 | % value |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 701 | log_color = COLOR_LIGHT_PURPLE |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 702 | else: |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 703 | sys.exit('Internal Error. This should not happen.') |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 704 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 705 | log += color_text(self.args.color, log_color, actlog) + '\n' |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 706 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 707 | with open(self.dotconfig, 'a', encoding='utf-8') as out: |
Masahiro Yamada | 953d93b | 2016-05-19 15:51:49 +0900 | [diff] [blame] | 708 | for (action, value) in results: |
| 709 | if action == ACTION_MOVE: |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 710 | out.write(value + '\n') |
Masahiro Yamada | 263d137 | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 711 | updated = True |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 712 | |
Masahiro Yamada | 07f9852 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 713 | self.results = results |
Masahiro Yamada | 6d13917 | 2016-08-22 22:18:22 +0900 | [diff] [blame] | 714 | for f in rm_files: |
| 715 | os.remove(f) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 716 | |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 717 | return (updated, suspicious, log) |
Masahiro Yamada | 69e2bbc | 2016-05-19 15:52:01 +0900 | [diff] [blame] | 718 | |
Masahiro Yamada | 07f9852 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 719 | def check_defconfig(self): |
| 720 | """Check the defconfig after savedefconfig |
| 721 | |
| 722 | Returns: |
| 723 | Return additional log if moved CONFIGs were removed again by |
| 724 | 'make savedefconfig'. |
| 725 | """ |
| 726 | |
| 727 | log = '' |
| 728 | |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 729 | defconfig_lines = read_file(self.defconfig) |
Masahiro Yamada | 07f9852 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 730 | |
| 731 | for (action, value) in self.results: |
| 732 | if action != ACTION_MOVE: |
| 733 | continue |
Alper Nebi Yasak | cab8407 | 2022-01-29 18:22:08 +0300 | [diff] [blame] | 734 | if not value in defconfig_lines: |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 735 | log += color_text(self.args.color, COLOR_YELLOW, |
Masahiro Yamada | 07f9852 | 2016-05-19 15:52:06 +0900 | [diff] [blame] | 736 | "'%s' was removed by savedefconfig.\n" % |
| 737 | value) |
| 738 | |
| 739 | return log |
| 740 | |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 741 | |
| 742 | class DatabaseThread(threading.Thread): |
| 743 | """This thread processes results from Slot threads. |
| 744 | |
| 745 | It collects the data in the master config directary. There is only one |
| 746 | result thread, and this helps to serialise the build output. |
| 747 | """ |
| 748 | def __init__(self, config_db, db_queue): |
| 749 | """Set up a new result thread |
| 750 | |
| 751 | Args: |
| 752 | builder: Builder which will be sent each result |
| 753 | """ |
| 754 | threading.Thread.__init__(self) |
| 755 | self.config_db = config_db |
| 756 | self.db_queue= db_queue |
| 757 | |
| 758 | def run(self): |
| 759 | """Called to start up the result thread. |
| 760 | |
| 761 | We collect the next result job and pass it on to the build. |
| 762 | """ |
| 763 | while True: |
| 764 | defconfig, configs = self.db_queue.get() |
| 765 | self.config_db[defconfig] = configs |
| 766 | self.db_queue.task_done() |
| 767 | |
| 768 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 769 | class Slot: |
| 770 | |
| 771 | """A slot to store a subprocess. |
| 772 | |
| 773 | Each instance of this class handles one subprocess. |
| 774 | This class is useful to control multiple threads |
| 775 | for faster processing. |
| 776 | """ |
| 777 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 778 | def __init__(self, toolchains, configs, args, progress, devnull, |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 779 | make_cmd, reference_src_dir, db_queue): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 780 | """Create a new process slot. |
| 781 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 782 | Args: |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 783 | toolchains: Toolchains object containing toolchains. |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 784 | configs: A list of CONFIGs to move. |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 785 | args: Program arguments |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 786 | progress: A progress indicator. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 787 | devnull: A file object of '/dev/null'. |
| 788 | make_cmd: command name of GNU Make. |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 789 | reference_src_dir: Determine the true starting config state from this |
| 790 | source tree. |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 791 | db_queue: output queue to write config info for the database |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 792 | """ |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 793 | self.toolchains = toolchains |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 794 | self.args = args |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 795 | self.progress = progress |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 796 | self.build_dir = tempfile.mkdtemp() |
| 797 | self.devnull = devnull |
| 798 | self.make_cmd = (make_cmd, 'O=' + self.build_dir) |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 799 | self.reference_src_dir = reference_src_dir |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 800 | self.db_queue = db_queue |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 801 | self.parser = KconfigParser(configs, args, self.build_dir) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 802 | self.state = STATE_IDLE |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 803 | self.failed_boards = set() |
| 804 | self.suspicious_boards = set() |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 805 | |
| 806 | def __del__(self): |
| 807 | """Delete the working directory |
| 808 | |
| 809 | This function makes sure the temporary directory is cleaned away |
| 810 | even if Python suddenly dies due to error. It should be done in here |
Joe Hershberger | 640de87 | 2016-06-10 14:53:29 -0500 | [diff] [blame] | 811 | because it is guaranteed the destructor is always invoked when the |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 812 | instance of the class gets unreferenced. |
| 813 | |
| 814 | If the subprocess is still running, wait until it finishes. |
| 815 | """ |
| 816 | if self.state != STATE_IDLE: |
| 817 | while self.ps.poll() == None: |
| 818 | pass |
| 819 | shutil.rmtree(self.build_dir) |
| 820 | |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 821 | def add(self, defconfig): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 822 | """Assign a new subprocess for defconfig and add it to the slot. |
| 823 | |
| 824 | If the slot is vacant, create a new subprocess for processing the |
| 825 | given defconfig and add it to the slot. Just returns False if |
| 826 | the slot is occupied (i.e. the current subprocess is still running). |
| 827 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 828 | Args: |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 829 | defconfig: defconfig name. |
| 830 | |
| 831 | Returns: |
| 832 | Return True on success or False on failure |
| 833 | """ |
| 834 | if self.state != STATE_IDLE: |
| 835 | return False |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 836 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 837 | self.defconfig = defconfig |
Masahiro Yamada | 465b7c0 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 838 | self.log = '' |
Masahiro Yamada | 8f5256a | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 839 | self.current_src_dir = self.reference_src_dir |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 840 | self.do_defconfig() |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 841 | return True |
| 842 | |
| 843 | def poll(self): |
| 844 | """Check the status of the subprocess and handle it as needed. |
| 845 | |
| 846 | Returns True if the slot is vacant (i.e. in idle state). |
| 847 | If the configuration is successfully finished, assign a new |
| 848 | subprocess to build include/autoconf.mk. |
| 849 | If include/autoconf.mk is generated, invoke the parser to |
Masahiro Yamada | 263d137 | 2016-05-19 15:52:04 +0900 | [diff] [blame] | 850 | parse the .config and the include/autoconf.mk, moving |
| 851 | config options to the .config as needed. |
| 852 | If the .config was updated, run "make savedefconfig" to sync |
| 853 | it, update the original defconfig, and then set the slot back |
| 854 | to the idle state. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 855 | |
| 856 | Returns: |
| 857 | Return True if the subprocess is terminated, False otherwise |
| 858 | """ |
| 859 | if self.state == STATE_IDLE: |
| 860 | return True |
| 861 | |
| 862 | if self.ps.poll() == None: |
| 863 | return False |
| 864 | |
| 865 | if self.ps.poll() != 0: |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 866 | self.handle_error() |
| 867 | elif self.state == STATE_DEFCONFIG: |
Masahiro Yamada | 8f5256a | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 868 | if self.reference_src_dir and not self.current_src_dir: |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 869 | self.do_savedefconfig() |
| 870 | else: |
| 871 | self.do_autoconf() |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 872 | elif self.state == STATE_AUTOCONF: |
Masahiro Yamada | 8f5256a | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 873 | if self.current_src_dir: |
| 874 | self.current_src_dir = None |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 875 | self.do_defconfig() |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 876 | elif self.args.build_db: |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 877 | self.do_build_db() |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 878 | else: |
| 879 | self.do_savedefconfig() |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 880 | elif self.state == STATE_SAVEDEFCONFIG: |
| 881 | self.update_defconfig() |
| 882 | else: |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 883 | sys.exit('Internal Error. This should not happen.') |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 884 | |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 885 | return True if self.state == STATE_IDLE else False |
Joe Hershberger | 166edec | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 886 | |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 887 | def handle_error(self): |
| 888 | """Handle error cases.""" |
Masahiro Yamada | 83c1767 | 2016-05-19 15:52:08 +0900 | [diff] [blame] | 889 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 890 | self.log += color_text(self.args.color, COLOR_LIGHT_RED, |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 891 | 'Failed to process.\n') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 892 | if self.args.verbose: |
| 893 | self.log += color_text(self.args.color, COLOR_LIGHT_CYAN, |
Markus Klotzbuecher | 8773f35 | 2020-02-12 20:46:45 +0100 | [diff] [blame] | 894 | self.ps.stderr.read().decode()) |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 895 | self.finish(False) |
Joe Hershberger | 166edec | 2015-05-19 13:21:17 -0500 | [diff] [blame] | 896 | |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 897 | def do_defconfig(self): |
| 898 | """Run 'make <board>_defconfig' to create the .config file.""" |
Masahiro Yamada | 0f6beda | 2016-05-19 15:52:07 +0900 | [diff] [blame] | 899 | |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 900 | cmd = list(self.make_cmd) |
| 901 | cmd.append(self.defconfig) |
| 902 | self.ps = subprocess.Popen(cmd, stdout=self.devnull, |
Masahiro Yamada | 8f5256a | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 903 | stderr=subprocess.PIPE, |
| 904 | cwd=self.current_src_dir) |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 905 | self.state = STATE_DEFCONFIG |
Masahiro Yamada | 0f6beda | 2016-05-19 15:52:07 +0900 | [diff] [blame] | 906 | |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 907 | def do_autoconf(self): |
Simon Glass | 8fb5bd0 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 908 | """Run 'make AUTO_CONF_PATH'.""" |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 909 | |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 910 | arch = self.parser.get_arch() |
| 911 | try: |
| 912 | toolchain = self.toolchains.Select(arch) |
| 913 | except ValueError: |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 914 | self.log += color_text(self.args.color, COLOR_YELLOW, |
Chris Packham | 1ebcbd1 | 2017-08-27 20:00:51 +1200 | [diff] [blame] | 915 | "Tool chain for '%s' is missing. Do nothing.\n" % arch) |
Masahiro Yamada | 274a5ee | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 916 | self.finish(False) |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 917 | return |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 918 | env = toolchain.MakeEnvironment(False) |
Masahiro Yamada | c4d76eb | 2016-05-19 15:51:53 +0900 | [diff] [blame] | 919 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 920 | cmd = list(self.make_cmd) |
Joe Hershberger | 765442b | 2015-05-19 13:21:18 -0500 | [diff] [blame] | 921 | cmd.append('KCONFIG_IGNORE_DUPLICATES=1') |
Simon Glass | 8fb5bd0 | 2017-06-01 19:39:01 -0600 | [diff] [blame] | 922 | cmd.append(AUTO_CONF_PATH) |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 923 | self.ps = subprocess.Popen(cmd, stdout=self.devnull, env=env, |
Masahiro Yamada | 8f5256a | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 924 | stderr=subprocess.PIPE, |
| 925 | cwd=self.current_src_dir) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 926 | self.state = STATE_AUTOCONF |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 927 | |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 928 | def do_build_db(self): |
| 929 | """Add the board to the database""" |
| 930 | configs = {} |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 931 | for line in read_file(os.path.join(self.build_dir, AUTO_CONF_PATH)): |
| 932 | if line.startswith('CONFIG'): |
| 933 | config, value = line.split('=', 1) |
| 934 | configs[config] = value.rstrip() |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 935 | self.db_queue.put([self.defconfig, configs]) |
| 936 | self.finish(True) |
| 937 | |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 938 | def do_savedefconfig(self): |
| 939 | """Update the .config and run 'make savedefconfig'.""" |
| 940 | |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 941 | (updated, suspicious, log) = self.parser.update_dotconfig() |
| 942 | if suspicious: |
| 943 | self.suspicious_boards.add(self.defconfig) |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 944 | self.log += log |
| 945 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 946 | if not self.args.force_sync and not updated: |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 947 | self.finish(True) |
| 948 | return |
| 949 | if updated: |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 950 | self.log += color_text(self.args.color, COLOR_LIGHT_GREEN, |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 951 | 'Syncing by savedefconfig...\n') |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 952 | else: |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 953 | self.log += 'Syncing by savedefconfig (forced by option)...\n' |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 954 | |
| 955 | cmd = list(self.make_cmd) |
| 956 | cmd.append('savedefconfig') |
| 957 | self.ps = subprocess.Popen(cmd, stdout=self.devnull, |
| 958 | stderr=subprocess.PIPE) |
| 959 | self.state = STATE_SAVEDEFCONFIG |
| 960 | |
| 961 | def update_defconfig(self): |
| 962 | """Update the input defconfig and go back to the idle state.""" |
| 963 | |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 964 | log = self.parser.check_defconfig() |
| 965 | if log: |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 966 | self.suspicious_boards.add(self.defconfig) |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 967 | self.log += log |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 968 | orig_defconfig = os.path.join('configs', self.defconfig) |
| 969 | new_defconfig = os.path.join(self.build_dir, 'defconfig') |
| 970 | updated = not filecmp.cmp(orig_defconfig, new_defconfig) |
| 971 | |
| 972 | if updated: |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 973 | self.log += color_text(self.args.color, COLOR_LIGHT_BLUE, |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 974 | 'defconfig was updated.\n') |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 975 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 976 | if not self.args.dry_run and updated: |
Masahiro Yamada | cb256cb | 2016-06-08 11:47:37 +0900 | [diff] [blame] | 977 | shutil.move(new_defconfig, orig_defconfig) |
| 978 | self.finish(True) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 979 | |
Masahiro Yamada | 274a5ee | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 980 | def finish(self, success): |
| 981 | """Display log along with progress and go to the idle state. |
Masahiro Yamada | 465b7c0 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 982 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 983 | Args: |
Masahiro Yamada | 274a5ee | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 984 | success: Should be True when the defconfig was processed |
| 985 | successfully, or False when it fails. |
Masahiro Yamada | 465b7c0 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 986 | """ |
| 987 | # output at least 30 characters to hide the "* defconfigs out of *". |
| 988 | log = self.defconfig.ljust(30) + '\n' |
| 989 | |
| 990 | log += '\n'.join([ ' ' + s for s in self.log.split('\n') ]) |
| 991 | # Some threads are running in parallel. |
| 992 | # Print log atomically to not mix up logs from different threads. |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 993 | print(log, file=(sys.stdout if success else sys.stderr)) |
Masahiro Yamada | 274a5ee | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 994 | |
| 995 | if not success: |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 996 | if self.args.exit_on_error: |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 997 | sys.exit('Exit on error.') |
Masahiro Yamada | 274a5ee | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 998 | # If --exit-on-error flag is not set, skip this board and continue. |
| 999 | # Record the failed board. |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1000 | self.failed_boards.add(self.defconfig) |
Masahiro Yamada | 274a5ee | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 1001 | |
Masahiro Yamada | 465b7c0 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 1002 | self.progress.inc() |
| 1003 | self.progress.show() |
Masahiro Yamada | 274a5ee | 2016-05-19 15:52:03 +0900 | [diff] [blame] | 1004 | self.state = STATE_IDLE |
Masahiro Yamada | 465b7c0 | 2016-05-19 15:52:02 +0900 | [diff] [blame] | 1005 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1006 | def get_failed_boards(self): |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1007 | """Returns a set of failed boards (defconfigs) in this slot. |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1008 | """ |
| 1009 | return self.failed_boards |
| 1010 | |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1011 | def get_suspicious_boards(self): |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1012 | """Returns a set of boards (defconfigs) with possible misconversion. |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1013 | """ |
Masahiro Yamada | 35204d9 | 2016-08-22 22:18:21 +0900 | [diff] [blame] | 1014 | return self.suspicious_boards - self.failed_boards |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1015 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1016 | class Slots: |
| 1017 | |
| 1018 | """Controller of the array of subprocess slots.""" |
| 1019 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1020 | def __init__(self, toolchains, configs, args, progress, |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1021 | reference_src_dir, db_queue): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1022 | """Create a new slots controller. |
| 1023 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1024 | Args: |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1025 | toolchains: Toolchains object containing toolchains. |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 1026 | configs: A list of CONFIGs to move. |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1027 | args: Program arguments |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1028 | progress: A progress indicator. |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1029 | reference_src_dir: Determine the true starting config state from this |
| 1030 | source tree. |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1031 | db_queue: output queue to write config info for the database |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1032 | """ |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1033 | self.args = args |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1034 | self.slots = [] |
Simon Glass | 34c505f | 2021-12-18 14:54:32 -0700 | [diff] [blame] | 1035 | devnull = subprocess.DEVNULL |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1036 | make_cmd = get_make_cmd() |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1037 | for i in range(args.jobs): |
| 1038 | self.slots.append(Slot(toolchains, configs, args, progress, |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1039 | devnull, make_cmd, reference_src_dir, |
| 1040 | db_queue)) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1041 | |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1042 | def add(self, defconfig): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1043 | """Add a new subprocess if a vacant slot is found. |
| 1044 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1045 | Args: |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1046 | defconfig: defconfig name to be put into. |
| 1047 | |
| 1048 | Returns: |
| 1049 | Return True on success or False on failure |
| 1050 | """ |
| 1051 | for slot in self.slots: |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1052 | if slot.add(defconfig): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1053 | return True |
| 1054 | return False |
| 1055 | |
| 1056 | def available(self): |
| 1057 | """Check if there is a vacant slot. |
| 1058 | |
| 1059 | Returns: |
| 1060 | Return True if at lease one vacant slot is found, False otherwise. |
| 1061 | """ |
| 1062 | for slot in self.slots: |
| 1063 | if slot.poll(): |
| 1064 | return True |
| 1065 | return False |
| 1066 | |
| 1067 | def empty(self): |
| 1068 | """Check if all slots are vacant. |
| 1069 | |
| 1070 | Returns: |
| 1071 | Return True if all the slots are vacant, False otherwise. |
| 1072 | """ |
| 1073 | ret = True |
| 1074 | for slot in self.slots: |
| 1075 | if not slot.poll(): |
| 1076 | ret = False |
| 1077 | return ret |
| 1078 | |
| 1079 | def show_failed_boards(self): |
| 1080 | """Display all of the failed boards (defconfigs).""" |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1081 | boards = set() |
Masahiro Yamada | 0153f03 | 2016-06-15 14:33:53 +0900 | [diff] [blame] | 1082 | output_file = 'moveconfig.failed' |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1083 | |
| 1084 | for slot in self.slots: |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1085 | boards |= slot.get_failed_boards() |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1086 | |
Masahiro Yamada | 0153f03 | 2016-06-15 14:33:53 +0900 | [diff] [blame] | 1087 | if boards: |
| 1088 | boards = '\n'.join(boards) + '\n' |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1089 | msg = 'The following boards were not processed due to error:\n' |
Masahiro Yamada | 0153f03 | 2016-06-15 14:33:53 +0900 | [diff] [blame] | 1090 | msg += boards |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1091 | msg += '(the list has been saved in %s)\n' % output_file |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1092 | print(color_text(self.args.color, COLOR_LIGHT_RED, |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1093 | msg), file=sys.stderr) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1094 | |
Simon Glass | b09ae45 | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 1095 | write_file(output_file, boards) |
Joe Hershberger | dade12e | 2015-05-19 13:21:22 -0500 | [diff] [blame] | 1096 | |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1097 | def show_suspicious_boards(self): |
| 1098 | """Display all boards (defconfigs) with possible misconversion.""" |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1099 | boards = set() |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1100 | output_file = 'moveconfig.suspicious' |
| 1101 | |
| 1102 | for slot in self.slots: |
Masahiro Yamada | 1271b67 | 2016-08-22 22:18:20 +0900 | [diff] [blame] | 1103 | boards |= slot.get_suspicious_boards() |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1104 | |
| 1105 | if boards: |
| 1106 | boards = '\n'.join(boards) + '\n' |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1107 | msg = 'The following boards might have been converted incorrectly.\n' |
| 1108 | msg += 'It is highly recommended to check them manually:\n' |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1109 | msg += boards |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1110 | msg += '(the list has been saved in %s)\n' % output_file |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1111 | print(color_text(self.args.color, COLOR_YELLOW, |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1112 | msg), file=sys.stderr) |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1113 | |
Simon Glass | b09ae45 | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 1114 | write_file(output_file, boards) |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1115 | |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1116 | class ReferenceSource: |
| 1117 | |
| 1118 | """Reference source against which original configs should be parsed.""" |
| 1119 | |
| 1120 | def __init__(self, commit): |
| 1121 | """Create a reference source directory based on a specified commit. |
| 1122 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1123 | Args: |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1124 | commit: commit to git-clone |
| 1125 | """ |
| 1126 | self.src_dir = tempfile.mkdtemp() |
Simon Glass | dc634d9 | 2021-12-18 14:54:30 -0700 | [diff] [blame] | 1127 | print('Cloning git repo to a separate work directory...') |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1128 | subprocess.check_output(['git', 'clone', os.getcwd(), '.'], |
| 1129 | cwd=self.src_dir) |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1130 | print("Checkout '%s' to build the original autoconf.mk." % \ |
| 1131 | subprocess.check_output(['git', 'rev-parse', '--short', commit]).strip()) |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1132 | subprocess.check_output(['git', 'checkout', commit], |
| 1133 | stderr=subprocess.STDOUT, cwd=self.src_dir) |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1134 | |
| 1135 | def __del__(self): |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1136 | """Delete the reference source directory |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1137 | |
| 1138 | This function makes sure the temporary directory is cleaned away |
| 1139 | even if Python suddenly dies due to error. It should be done in here |
| 1140 | because it is guaranteed the destructor is always invoked when the |
| 1141 | instance of the class gets unreferenced. |
| 1142 | """ |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1143 | shutil.rmtree(self.src_dir) |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1144 | |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1145 | def get_dir(self): |
| 1146 | """Return the absolute path to the reference source directory.""" |
| 1147 | |
| 1148 | return self.src_dir |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1149 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1150 | def move_config(toolchains, configs, args, db_queue): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1151 | """Move config options to defconfig files. |
| 1152 | |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1153 | Args: |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 1154 | configs: A list of CONFIGs to move. |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1155 | args: Program arguments |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1156 | """ |
Masahiro Yamada | b80a667 | 2016-05-19 15:51:57 +0900 | [diff] [blame] | 1157 | if len(configs) == 0: |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1158 | if args.force_sync: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1159 | print('No CONFIG is specified. You are probably syncing defconfigs.', end=' ') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1160 | elif args.build_db: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1161 | print('Building %s database' % CONFIG_DATABASE) |
Masahiro Yamada | 9566abd | 2016-05-19 15:52:09 +0900 | [diff] [blame] | 1162 | else: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1163 | print('Neither CONFIG nor --force-sync is specified. Nothing will happen.', end=' ') |
Masahiro Yamada | 9566abd | 2016-05-19 15:52:09 +0900 | [diff] [blame] | 1164 | else: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1165 | print('Move ' + ', '.join(configs), end=' ') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1166 | print('(jobs: %d)\n' % args.jobs) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1167 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1168 | if args.git_ref: |
| 1169 | reference_src = ReferenceSource(args.git_ref) |
Masahiro Yamada | 2e74fee | 2016-06-15 14:33:51 +0900 | [diff] [blame] | 1170 | reference_src_dir = reference_src.get_dir() |
| 1171 | else: |
Masahiro Yamada | 8f5256a | 2016-06-15 14:33:52 +0900 | [diff] [blame] | 1172 | reference_src_dir = None |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1173 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1174 | if args.defconfigs: |
| 1175 | defconfigs = get_matched_defconfigs(args.defconfigs) |
Joe Hershberger | c6e043a | 2015-05-19 13:21:19 -0500 | [diff] [blame] | 1176 | else: |
Masahiro Yamada | 58175e3 | 2016-07-25 19:15:28 +0900 | [diff] [blame] | 1177 | defconfigs = get_all_defconfigs() |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1178 | |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1179 | progress = Progress(len(defconfigs)) |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1180 | slots = Slots(toolchains, configs, args, progress, reference_src_dir, |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1181 | db_queue) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1182 | |
| 1183 | # Main loop to process defconfig files: |
| 1184 | # Add a new subprocess into a vacant slot. |
| 1185 | # Sleep if there is no available slot. |
Masahiro Yamada | cefaa58 | 2016-05-19 15:51:55 +0900 | [diff] [blame] | 1186 | for defconfig in defconfigs: |
| 1187 | while not slots.add(defconfig): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1188 | while not slots.available(): |
| 1189 | # No available slot: sleep for a while |
| 1190 | time.sleep(SLEEP_TIME) |
| 1191 | |
| 1192 | # wait until all the subprocesses finish |
| 1193 | while not slots.empty(): |
| 1194 | time.sleep(SLEEP_TIME) |
| 1195 | |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1196 | print('') |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1197 | slots.show_failed_boards() |
Masahiro Yamada | 3c9bfea | 2016-06-15 14:33:54 +0900 | [diff] [blame] | 1198 | slots.show_suspicious_boards() |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1199 | |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1200 | def find_kconfig_rules(kconf, config, imply_config): |
| 1201 | """Check whether a config has a 'select' or 'imply' keyword |
| 1202 | |
| 1203 | Args: |
Tom Rini | 3c5f415 | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1204 | kconf: Kconfiglib.Kconfig object |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1205 | config: Name of config to check (without CONFIG_ prefix) |
| 1206 | imply_config: Implying config (without CONFIG_ prefix) which may or |
| 1207 | may not have an 'imply' for 'config') |
| 1208 | |
| 1209 | Returns: |
| 1210 | Symbol object for 'config' if found, else None |
| 1211 | """ |
Tom Rini | 3c5f415 | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1212 | sym = kconf.syms.get(imply_config) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1213 | if sym: |
Simon Glass | 520b47a | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1214 | for sel, cond in (sym.selects + sym.implies): |
Simon Glass | 93c0a9e | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1215 | if sel.name == config: |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1216 | return sym |
| 1217 | return None |
| 1218 | |
| 1219 | def check_imply_rule(kconf, config, imply_config): |
| 1220 | """Check if we can add an 'imply' option |
| 1221 | |
| 1222 | This finds imply_config in the Kconfig and looks to see if it is possible |
| 1223 | to add an 'imply' for 'config' to that part of the Kconfig. |
| 1224 | |
| 1225 | Args: |
Tom Rini | 3c5f415 | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1226 | kconf: Kconfiglib.Kconfig object |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1227 | config: Name of config to check (without CONFIG_ prefix) |
| 1228 | imply_config: Implying config (without CONFIG_ prefix) which may or |
| 1229 | may not have an 'imply' for 'config') |
| 1230 | |
| 1231 | Returns: |
| 1232 | tuple: |
| 1233 | filename of Kconfig file containing imply_config, or None if none |
| 1234 | line number within the Kconfig file, or 0 if none |
| 1235 | message indicating the result |
| 1236 | """ |
Tom Rini | 3c5f415 | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1237 | sym = kconf.syms.get(imply_config) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1238 | if not sym: |
| 1239 | return 'cannot find sym' |
Simon Glass | 520b47a | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1240 | nodes = sym.nodes |
| 1241 | if len(nodes) != 1: |
| 1242 | return '%d locations' % len(nodes) |
Simon Glass | 93c0a9e | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1243 | node = nodes[0] |
| 1244 | fname, linenum = node.filename, node.linenr |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1245 | cwd = os.getcwd() |
| 1246 | if cwd and fname.startswith(cwd): |
| 1247 | fname = fname[len(cwd) + 1:] |
| 1248 | file_line = ' at %s:%d' % (fname, linenum) |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 1249 | data = read_file(fname) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1250 | if data[linenum - 1] != 'config %s' % imply_config: |
| 1251 | return None, 0, 'bad sym format %s%s' % (data[linenum], file_line) |
| 1252 | return fname, linenum, 'adding%s' % file_line |
| 1253 | |
| 1254 | def add_imply_rule(config, fname, linenum): |
| 1255 | """Add a new 'imply' option to a Kconfig |
| 1256 | |
| 1257 | Args: |
| 1258 | config: config option to add an imply for (without CONFIG_ prefix) |
| 1259 | fname: Kconfig filename to update |
| 1260 | linenum: Line number to place the 'imply' before |
| 1261 | |
| 1262 | Returns: |
| 1263 | Message indicating the result |
| 1264 | """ |
| 1265 | file_line = ' at %s:%d' % (fname, linenum) |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 1266 | data = read_file(fname) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1267 | linenum -= 1 |
| 1268 | |
| 1269 | for offset, line in enumerate(data[linenum:]): |
| 1270 | if line.strip().startswith('help') or not line: |
| 1271 | data.insert(linenum + offset, '\timply %s' % config) |
Simon Glass | b09ae45 | 2021-12-18 14:54:33 -0700 | [diff] [blame] | 1272 | write_file(fname, data) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1273 | return 'added%s' % file_line |
| 1274 | |
| 1275 | return 'could not insert%s' |
| 1276 | |
| 1277 | (IMPLY_MIN_2, IMPLY_TARGET, IMPLY_CMD, IMPLY_NON_ARCH_BOARD) = ( |
| 1278 | 1, 2, 4, 8) |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1279 | |
| 1280 | IMPLY_FLAGS = { |
| 1281 | 'min2': [IMPLY_MIN_2, 'Show options which imply >2 boards (normally >5)'], |
| 1282 | 'target': [IMPLY_TARGET, 'Allow CONFIG_TARGET_... options to imply'], |
| 1283 | 'cmd': [IMPLY_CMD, 'Allow CONFIG_CMD_... to imply'], |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1284 | 'non-arch-board': [ |
| 1285 | IMPLY_NON_ARCH_BOARD, |
| 1286 | 'Allow Kconfig options outside arch/ and /board/ to imply'], |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1287 | } |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1288 | |
Simon Glass | f931c2f | 2021-12-18 08:09:43 -0700 | [diff] [blame] | 1289 | |
| 1290 | def read_database(): |
| 1291 | """Read in the config database |
| 1292 | |
| 1293 | Returns: |
| 1294 | tuple: |
| 1295 | set of all config options seen (each a str) |
| 1296 | set of all defconfigs seen (each a str) |
| 1297 | dict of configs for each defconfig: |
| 1298 | key: defconfig name, e.g. "MPC8548CDS_legacy_defconfig" |
| 1299 | value: dict: |
| 1300 | key: CONFIG option |
| 1301 | value: Value of option |
| 1302 | dict of defconfigs for each config: |
| 1303 | key: CONFIG option |
| 1304 | value: set of boards using that option |
| 1305 | |
| 1306 | """ |
| 1307 | configs = {} |
| 1308 | |
| 1309 | # key is defconfig name, value is dict of (CONFIG_xxx, value) |
| 1310 | config_db = {} |
| 1311 | |
| 1312 | # Set of all config options we have seen |
| 1313 | all_configs = set() |
| 1314 | |
| 1315 | # Set of all defconfigs we have seen |
| 1316 | all_defconfigs = set() |
| 1317 | |
| 1318 | defconfig_db = collections.defaultdict(set) |
Simon Glass | aba238f | 2021-12-18 14:54:34 -0700 | [diff] [blame] | 1319 | for line in read_file(CONFIG_DATABASE): |
| 1320 | line = line.rstrip() |
| 1321 | if not line: # Separator between defconfigs |
| 1322 | config_db[defconfig] = configs |
| 1323 | all_defconfigs.add(defconfig) |
| 1324 | configs = {} |
| 1325 | elif line[0] == ' ': # CONFIG line |
| 1326 | config, value = line.strip().split('=', 1) |
| 1327 | configs[config] = value |
| 1328 | defconfig_db[config].add(defconfig) |
| 1329 | all_configs.add(config) |
| 1330 | else: # New defconfig |
| 1331 | defconfig = line |
Simon Glass | f931c2f | 2021-12-18 08:09:43 -0700 | [diff] [blame] | 1332 | |
| 1333 | return all_configs, all_defconfigs, config_db, defconfig_db |
| 1334 | |
| 1335 | |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1336 | def do_imply_config(config_list, add_imply, imply_flags, skip_added, |
| 1337 | check_kconfig=True, find_superset=False): |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1338 | """Find CONFIG options which imply those in the list |
| 1339 | |
| 1340 | Some CONFIG options can be implied by others and this can help to reduce |
| 1341 | the size of the defconfig files. For example, CONFIG_X86 implies |
| 1342 | CONFIG_CMD_IRQ, so we can put 'imply CMD_IRQ' under 'config X86' and |
| 1343 | all x86 boards will have that option, avoiding adding CONFIG_CMD_IRQ to |
| 1344 | each of the x86 defconfig files. |
| 1345 | |
| 1346 | This function uses the moveconfig database to find such options. It |
| 1347 | displays a list of things that could possibly imply those in the list. |
| 1348 | The algorithm ignores any that start with CONFIG_TARGET since these |
| 1349 | typically refer to only a few defconfigs (often one). It also does not |
| 1350 | display a config with less than 5 defconfigs. |
| 1351 | |
| 1352 | The algorithm works using sets. For each target config in config_list: |
| 1353 | - Get the set 'defconfigs' which use that target config |
| 1354 | - For each config (from a list of all configs): |
| 1355 | - Get the set 'imply_defconfig' of defconfigs which use that config |
| 1356 | - |
| 1357 | - If imply_defconfigs contains anything not in defconfigs then |
| 1358 | this config does not imply the target config |
| 1359 | |
| 1360 | Params: |
| 1361 | config_list: List of CONFIG options to check (each a string) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1362 | add_imply: Automatically add an 'imply' for each config. |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1363 | imply_flags: Flags which control which implying configs are allowed |
| 1364 | (IMPLY_...) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1365 | skip_added: Don't show options which already have an imply added. |
| 1366 | check_kconfig: Check if implied symbols already have an 'imply' or |
| 1367 | 'select' for the target config, and show this information if so. |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1368 | find_superset: True to look for configs which are a superset of those |
| 1369 | already found. So for example if CONFIG_EXYNOS5 implies an option, |
| 1370 | but CONFIG_EXYNOS covers a larger set of defconfigs and also |
| 1371 | implies that option, this will drop the former in favour of the |
| 1372 | latter. In practice this option has not proved very used. |
| 1373 | |
| 1374 | Note the terminoloy: |
| 1375 | config - a CONFIG_XXX options (a string, e.g. 'CONFIG_CMD_EEPROM') |
| 1376 | defconfig - a defconfig file (a string, e.g. 'configs/snow_defconfig') |
| 1377 | """ |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1378 | kconf = KconfigScanner().conf if check_kconfig else None |
| 1379 | if add_imply and add_imply != 'all': |
Simon Glass | 93c0a9e | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1380 | add_imply = add_imply.split(',') |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1381 | |
Simon Glass | f931c2f | 2021-12-18 08:09:43 -0700 | [diff] [blame] | 1382 | all_configs, all_defconfigs, config_db, defconfig_db = read_database() |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1383 | |
Simon Glass | 93c0a9e | 2021-12-18 08:09:42 -0700 | [diff] [blame] | 1384 | # Work through each target config option in turn, independently |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1385 | for config in config_list: |
| 1386 | defconfigs = defconfig_db.get(config) |
| 1387 | if not defconfigs: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1388 | print('%s not found in any defconfig' % config) |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1389 | continue |
| 1390 | |
| 1391 | # Get the set of defconfigs without this one (since a config cannot |
| 1392 | # imply itself) |
| 1393 | non_defconfigs = all_defconfigs - defconfigs |
| 1394 | num_defconfigs = len(defconfigs) |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1395 | print('%s found in %d/%d defconfigs' % (config, num_defconfigs, |
| 1396 | len(all_configs))) |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1397 | |
| 1398 | # This will hold the results: key=config, value=defconfigs containing it |
| 1399 | imply_configs = {} |
| 1400 | rest_configs = all_configs - set([config]) |
| 1401 | |
| 1402 | # Look at every possible config, except the target one |
| 1403 | for imply_config in rest_configs: |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1404 | if 'ERRATUM' in imply_config: |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1405 | continue |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1406 | if not imply_flags & IMPLY_CMD: |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1407 | if 'CONFIG_CMD' in imply_config: |
| 1408 | continue |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1409 | if not imply_flags & IMPLY_TARGET: |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1410 | if 'CONFIG_TARGET' in imply_config: |
| 1411 | continue |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1412 | |
| 1413 | # Find set of defconfigs that have this config |
| 1414 | imply_defconfig = defconfig_db[imply_config] |
| 1415 | |
| 1416 | # Get the intersection of this with defconfigs containing the |
| 1417 | # target config |
| 1418 | common_defconfigs = imply_defconfig & defconfigs |
| 1419 | |
| 1420 | # Get the set of defconfigs containing this config which DO NOT |
| 1421 | # also contain the taret config. If this set is non-empty it means |
| 1422 | # that this config affects other defconfigs as well as (possibly) |
| 1423 | # the ones affected by the target config. This means it implies |
| 1424 | # things we don't want to imply. |
| 1425 | not_common_defconfigs = imply_defconfig & non_defconfigs |
| 1426 | if not_common_defconfigs: |
| 1427 | continue |
| 1428 | |
| 1429 | # If there are common defconfigs, imply_config may be useful |
| 1430 | if common_defconfigs: |
| 1431 | skip = False |
| 1432 | if find_superset: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1433 | for prev in list(imply_configs.keys()): |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1434 | prev_count = len(imply_configs[prev]) |
| 1435 | count = len(common_defconfigs) |
| 1436 | if (prev_count > count and |
| 1437 | (imply_configs[prev] & common_defconfigs == |
| 1438 | common_defconfigs)): |
| 1439 | # skip imply_config because prev is a superset |
| 1440 | skip = True |
| 1441 | break |
| 1442 | elif count > prev_count: |
| 1443 | # delete prev because imply_config is a superset |
| 1444 | del imply_configs[prev] |
| 1445 | if not skip: |
| 1446 | imply_configs[imply_config] = common_defconfigs |
| 1447 | |
| 1448 | # Now we have a dict imply_configs of configs which imply each config |
| 1449 | # The value of each dict item is the set of defconfigs containing that |
| 1450 | # config. Rank them so that we print the configs that imply the largest |
| 1451 | # number of defconfigs first. |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1452 | ranked_iconfigs = sorted(imply_configs, |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1453 | key=lambda k: len(imply_configs[k]), reverse=True) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1454 | kconfig_info = '' |
| 1455 | cwd = os.getcwd() |
| 1456 | add_list = collections.defaultdict(list) |
| 1457 | for iconfig in ranked_iconfigs: |
| 1458 | num_common = len(imply_configs[iconfig]) |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1459 | |
| 1460 | # Don't bother if there are less than 5 defconfigs affected. |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1461 | if num_common < (2 if imply_flags & IMPLY_MIN_2 else 5): |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1462 | continue |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1463 | missing = defconfigs - imply_configs[iconfig] |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1464 | missing_str = ', '.join(missing) if missing else 'all' |
| 1465 | missing_str = '' |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1466 | show = True |
| 1467 | if kconf: |
| 1468 | sym = find_kconfig_rules(kconf, config[CONFIG_LEN:], |
| 1469 | iconfig[CONFIG_LEN:]) |
| 1470 | kconfig_info = '' |
| 1471 | if sym: |
Simon Glass | 520b47a | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1472 | nodes = sym.nodes |
| 1473 | if len(nodes) == 1: |
| 1474 | fname, linenum = nodes[0].filename, nodes[0].linenr |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1475 | if cwd and fname.startswith(cwd): |
| 1476 | fname = fname[len(cwd) + 1:] |
| 1477 | kconfig_info = '%s:%d' % (fname, linenum) |
| 1478 | if skip_added: |
| 1479 | show = False |
| 1480 | else: |
Tom Rini | 3c5f415 | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 1481 | sym = kconf.syms.get(iconfig[CONFIG_LEN:]) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1482 | fname = '' |
| 1483 | if sym: |
Simon Glass | 520b47a | 2021-07-21 21:35:53 -0600 | [diff] [blame] | 1484 | nodes = sym.nodes |
| 1485 | if len(nodes) == 1: |
| 1486 | fname, linenum = nodes[0].filename, nodes[0].linenr |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1487 | if cwd and fname.startswith(cwd): |
| 1488 | fname = fname[len(cwd) + 1:] |
| 1489 | in_arch_board = not sym or (fname.startswith('arch') or |
| 1490 | fname.startswith('board')) |
| 1491 | if (not in_arch_board and |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1492 | not imply_flags & IMPLY_NON_ARCH_BOARD): |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1493 | continue |
| 1494 | |
| 1495 | if add_imply and (add_imply == 'all' or |
| 1496 | iconfig in add_imply): |
| 1497 | fname, linenum, kconfig_info = (check_imply_rule(kconf, |
| 1498 | config[CONFIG_LEN:], iconfig[CONFIG_LEN:])) |
| 1499 | if fname: |
| 1500 | add_list[fname].append(linenum) |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1501 | |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1502 | if show and kconfig_info != 'skip': |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1503 | print('%5d : %-30s%-25s %s' % (num_common, iconfig.ljust(30), |
| 1504 | kconfig_info, missing_str)) |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1505 | |
| 1506 | # Having collected a list of things to add, now we add them. We process |
| 1507 | # each file from the largest line number to the smallest so that |
| 1508 | # earlier additions do not affect our line numbers. E.g. if we added an |
| 1509 | # imply at line 20 it would change the position of each line after |
| 1510 | # that. |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1511 | for fname, linenums in add_list.items(): |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1512 | for linenum in sorted(linenums, reverse=True): |
| 1513 | add_imply_rule(config[CONFIG_LEN:], fname, linenum) |
| 1514 | |
Simon Glass | 99f7942 | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1515 | def defconfig_matches(configs, re_match): |
| 1516 | """Check if any CONFIG option matches a regex |
| 1517 | |
| 1518 | The match must be complete, i.e. from the start to end of the CONFIG option. |
| 1519 | |
| 1520 | Args: |
| 1521 | configs (dict): Dict of CONFIG options: |
| 1522 | key: CONFIG option |
| 1523 | value: Value of option |
| 1524 | re_match (re.Pattern): Match to check |
| 1525 | |
| 1526 | Returns: |
| 1527 | bool: True if any CONFIG matches the regex |
| 1528 | """ |
| 1529 | for cfg in configs: |
Simon Glass | fea71c9 | 2022-03-05 20:18:54 -0700 | [diff] [blame] | 1530 | if re_match.fullmatch(cfg): |
Simon Glass | 99f7942 | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1531 | return True |
| 1532 | return False |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1533 | |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1534 | def do_find_config(config_list): |
| 1535 | """Find boards with a given combination of CONFIGs |
| 1536 | |
| 1537 | Params: |
Simon Glass | 99f7942 | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1538 | config_list: List of CONFIG options to check (each a regex consisting |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1539 | of a config option, with or without a CONFIG_ prefix. If an option |
| 1540 | is preceded by a tilde (~) then it must be false, otherwise it must |
| 1541 | be true) |
| 1542 | """ |
| 1543 | all_configs, all_defconfigs, config_db, defconfig_db = read_database() |
| 1544 | |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1545 | # Start with all defconfigs |
| 1546 | out = all_defconfigs |
| 1547 | |
| 1548 | # Work through each config in turn |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1549 | for item in config_list: |
| 1550 | # Get the real config name and whether we want this config or not |
| 1551 | cfg = item |
| 1552 | want = True |
| 1553 | if cfg[0] == '~': |
| 1554 | want = False |
| 1555 | cfg = cfg[1:] |
| 1556 | |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1557 | # Search everything that is still in the running. If it has a config |
| 1558 | # that we want, or doesn't have one that we don't, add it into the |
| 1559 | # running for the next stage |
| 1560 | in_list = out |
| 1561 | out = set() |
Simon Glass | 99f7942 | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1562 | re_match = re.compile(cfg) |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1563 | for defc in in_list: |
Simon Glass | 99f7942 | 2022-02-08 11:49:46 -0700 | [diff] [blame] | 1564 | has_cfg = defconfig_matches(config_db[defc], re_match) |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1565 | if has_cfg == want: |
| 1566 | out.add(defc) |
Tom Rini | c1b64aa | 2022-12-04 10:14:16 -0500 | [diff] [blame] | 1567 | print(f'{len(out)} matches') |
| 1568 | print(' '.join(item.split('_defconfig')[0] for item in out)) |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1569 | |
| 1570 | |
| 1571 | def prefix_config(cfg): |
| 1572 | """Prefix a config with CONFIG_ if needed |
| 1573 | |
| 1574 | This handles ~ operator, which indicates that the CONFIG should be disabled |
| 1575 | |
| 1576 | >>> prefix_config('FRED') |
| 1577 | 'CONFIG_FRED' |
| 1578 | >>> prefix_config('CONFIG_FRED') |
| 1579 | 'CONFIG_FRED' |
| 1580 | >>> prefix_config('~FRED') |
| 1581 | '~CONFIG_FRED' |
| 1582 | >>> prefix_config('~CONFIG_FRED') |
| 1583 | '~CONFIG_FRED' |
| 1584 | >>> prefix_config('A123') |
| 1585 | 'CONFIG_A123' |
| 1586 | """ |
| 1587 | op = '' |
| 1588 | if cfg[0] == '~': |
| 1589 | op = cfg[0] |
| 1590 | cfg = cfg[1:] |
| 1591 | if not cfg.startswith('CONFIG_'): |
| 1592 | cfg = 'CONFIG_' + cfg |
| 1593 | return op + cfg |
| 1594 | |
| 1595 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1596 | def main(): |
| 1597 | try: |
| 1598 | cpu_count = multiprocessing.cpu_count() |
| 1599 | except NotImplementedError: |
| 1600 | cpu_count = 1 |
| 1601 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1602 | epilog = '''Move config options from headers to defconfig files. See |
| 1603 | doc/develop/moveconfig.rst for documentation.''' |
| 1604 | |
| 1605 | parser = ArgumentParser(epilog=epilog) |
| 1606 | # Add arguments here |
| 1607 | parser.add_argument('-a', '--add-imply', type=str, default='', |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1608 | help='comma-separated list of CONFIG options to add ' |
| 1609 | "an 'imply' statement to for the CONFIG in -i") |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1610 | parser.add_argument('-A', '--skip-added', action='store_true', default=False, |
Simon Glass | 4411633 | 2017-06-15 21:39:33 -0600 | [diff] [blame] | 1611 | help="don't show options which are already marked as " |
| 1612 | 'implying others') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1613 | parser.add_argument('-b', '--build-db', action='store_true', default=False, |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1614 | help='build a CONFIG database') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1615 | parser.add_argument('-c', '--color', action='store_true', default=False, |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1616 | help='display the log in color') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1617 | parser.add_argument('-C', '--commit', action='store_true', default=False, |
Simon Glass | 8bf41c2 | 2016-09-12 23:18:21 -0600 | [diff] [blame] | 1618 | help='Create a git commit for the operation') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1619 | parser.add_argument('-d', '--defconfigs', type=str, |
Simon Glass | 8f3cf31 | 2017-06-01 19:38:59 -0600 | [diff] [blame] | 1620 | help='a file containing a list of defconfigs to move, ' |
| 1621 | "one per line (for example 'snow_defconfig') " |
| 1622 | "or '-' to read from stdin") |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1623 | parser.add_argument('-e', '--exit-on-error', action='store_true', |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1624 | default=False, |
| 1625 | help='exit immediately on any error') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1626 | parser.add_argument('-f', '--find', action='store_true', default=False, |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1627 | help='Find boards with a given config combination') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1628 | parser.add_argument('-H', '--headers-only', dest='cleanup_headers_only', |
Joe Hershberger | 2347593 | 2015-05-19 13:21:20 -0500 | [diff] [blame] | 1629 | action='store_true', default=False, |
| 1630 | help='only cleanup the headers') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1631 | parser.add_argument('-i', '--imply', action='store_true', default=False, |
Simon Glass | 0559a74 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1632 | help='find options which imply others') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1633 | parser.add_argument('-I', '--imply-flags', type=str, default='', |
Simon Glass | 0559a74 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1634 | help="control the -i option ('help' for help") |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1635 | parser.add_argument('-j', '--jobs', type=int, default=cpu_count, |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1636 | help='the number of jobs to run simultaneously') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1637 | parser.add_argument('-n', '--dry-run', action='store_true', default=False, |
Simon Glass | 0559a74 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1638 | help='perform a trial run (show log with no changes)') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1639 | parser.add_argument('-r', '--git-ref', type=str, |
Joe Hershberger | b1a570f | 2016-06-10 14:53:32 -0500 | [diff] [blame] | 1640 | help='the git ref to clone for building the autoconf.mk') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1641 | parser.add_argument('-s', '--force-sync', action='store_true', default=False, |
Simon Glass | 0559a74 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1642 | help='force sync by savedefconfig') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1643 | parser.add_argument('-S', '--spl', action='store_true', default=False, |
Simon Glass | 0559a74 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1644 | help='parse config options defined for SPL build') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1645 | parser.add_argument('-t', '--test', action='store_true', default=False, |
Simon Glass | 0559a74 | 2021-12-18 08:09:44 -0700 | [diff] [blame] | 1646 | help='run unit tests') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1647 | parser.add_argument('-y', '--yes', action='store_true', default=False, |
Simon Glass | 13e05a0 | 2016-09-12 23:18:20 -0600 | [diff] [blame] | 1648 | help="respond 'yes' to any prompts") |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1649 | parser.add_argument('-v', '--verbose', action='store_true', default=False, |
Joe Hershberger | 808b63f | 2015-05-19 13:21:24 -0500 | [diff] [blame] | 1650 | help='show any build errors as boards are built') |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1651 | parser.add_argument('configs', nargs='*') |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1652 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1653 | args = parser.parse_args() |
| 1654 | configs = args.configs |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1655 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1656 | if args.test: |
Simon Glass | bb57be7 | 2021-12-18 08:09:45 -0700 | [diff] [blame] | 1657 | sys.argv = [sys.argv[0]] |
| 1658 | fail, count = doctest.testmod() |
| 1659 | if fail: |
| 1660 | return 1 |
| 1661 | unittest.main() |
| 1662 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1663 | if not any((len(configs), args.force_sync, args.build_db, args.imply, |
| 1664 | args.find)): |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1665 | parser.print_usage() |
| 1666 | sys.exit(1) |
| 1667 | |
Masahiro Yamada | b903c4e | 2016-05-19 15:51:58 +0900 | [diff] [blame] | 1668 | # prefix the option name with CONFIG_ if missing |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1669 | configs = [prefix_config(cfg) for cfg in configs] |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1670 | |
Joe Hershberger | 2347593 | 2015-05-19 13:21:20 -0500 | [diff] [blame] | 1671 | check_top_directory() |
| 1672 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1673 | if args.imply: |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1674 | imply_flags = 0 |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1675 | if args.imply_flags == 'all': |
Simon Glass | 5f09692 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1676 | imply_flags = -1 |
| 1677 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1678 | elif args.imply_flags: |
| 1679 | for flag in args.imply_flags.split(','): |
Simon Glass | 5f09692 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1680 | bad = flag not in IMPLY_FLAGS |
| 1681 | if bad: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1682 | print("Invalid flag '%s'" % flag) |
Simon Glass | 5f09692 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1683 | if flag == 'help' or bad: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1684 | print("Imply flags: (separate with ',')") |
| 1685 | for name, info in IMPLY_FLAGS.items(): |
| 1686 | print(' %-15s: %s' % (name, info[1])) |
Simon Glass | 5f09692 | 2017-07-10 14:47:46 -0600 | [diff] [blame] | 1687 | parser.print_usage() |
| 1688 | sys.exit(1) |
| 1689 | imply_flags |= IMPLY_FLAGS[flag][0] |
Simon Glass | 92e5558 | 2017-06-15 21:39:32 -0600 | [diff] [blame] | 1690 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1691 | do_imply_config(configs, args.add_imply, imply_flags, args.skip_added) |
Simon Glass | c6e73cf | 2017-06-01 19:39:03 -0600 | [diff] [blame] | 1692 | return |
| 1693 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1694 | if args.find: |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1695 | do_find_config(configs) |
| 1696 | return |
| 1697 | |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1698 | config_db = {} |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1699 | db_queue = queue.Queue() |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1700 | t = DatabaseThread(config_db, db_queue) |
| 1701 | t.setDaemon(True) |
| 1702 | t.start() |
| 1703 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1704 | if not args.cleanup_headers_only: |
Masahiro Yamada | d0a9d2a | 2016-07-25 19:15:23 +0900 | [diff] [blame] | 1705 | check_clean_directory() |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1706 | bsettings.Setup('') |
Simon Glass | 257f523 | 2017-07-10 14:47:47 -0600 | [diff] [blame] | 1707 | toolchains = toolchain.Toolchains() |
| 1708 | toolchains.GetSettings() |
| 1709 | toolchains.Scan(verbose=False) |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1710 | move_config(toolchains, configs, args, db_queue) |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1711 | db_queue.join() |
Joe Hershberger | 2347593 | 2015-05-19 13:21:20 -0500 | [diff] [blame] | 1712 | |
Masahiro Yamada | 9566abd | 2016-05-19 15:52:09 +0900 | [diff] [blame] | 1713 | if configs: |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1714 | cleanup_headers(configs, args) |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1715 | cleanup_readme(configs, args) |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1716 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1717 | if args.commit: |
Simon Glass | 8bf41c2 | 2016-09-12 23:18:21 -0600 | [diff] [blame] | 1718 | subprocess.call(['git', 'add', '-u']) |
| 1719 | if configs: |
| 1720 | msg = 'Convert %s %sto Kconfig' % (configs[0], |
| 1721 | 'et al ' if len(configs) > 1 else '') |
| 1722 | msg += ('\n\nThis converts the following to Kconfig:\n %s\n' % |
| 1723 | '\n '.join(configs)) |
| 1724 | else: |
| 1725 | msg = 'configs: Resync with savedefconfig' |
| 1726 | msg += '\n\nRsync all defconfig files using moveconfig.py' |
| 1727 | subprocess.call(['git', 'commit', '-s', '-m', msg]) |
| 1728 | |
Simon Glass | d9c1da2 | 2021-12-18 14:54:31 -0700 | [diff] [blame] | 1729 | if args.build_db: |
Simon Glass | b3464eb | 2021-12-18 14:54:35 -0700 | [diff] [blame] | 1730 | with open(CONFIG_DATABASE, 'w', encoding='utf-8') as fd: |
Simon Glass | 1f70186 | 2019-10-31 07:42:57 -0600 | [diff] [blame] | 1731 | for defconfig, configs in config_db.items(): |
Simon Glass | 1c87931 | 2017-08-13 16:02:54 -0600 | [diff] [blame] | 1732 | fd.write('%s\n' % defconfig) |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1733 | for config in sorted(configs.keys()): |
Simon Glass | 1c87931 | 2017-08-13 16:02:54 -0600 | [diff] [blame] | 1734 | fd.write(' %s=%s\n' % (config, configs[config])) |
| 1735 | fd.write('\n') |
Simon Glass | 43cf08f | 2017-06-01 19:39:02 -0600 | [diff] [blame] | 1736 | |
Masahiro Yamada | b616081 | 2015-05-20 11:36:07 +0900 | [diff] [blame] | 1737 | if __name__ == '__main__': |
Simon Glass | 0082b2e | 2021-12-18 08:09:46 -0700 | [diff] [blame] | 1738 | sys.exit(main()) |