Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 3 | # |
| 4 | # Author: Masahiro Yamada <yamada.m@jp.panasonic.com> |
| 5 | # |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 6 | |
| 7 | """ |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 8 | Converter from Kconfig and MAINTAINERS to a board database. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 9 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 10 | Run 'tools/genboardscfg.py' to create a board database. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 11 | |
| 12 | Run 'tools/genboardscfg.py -h' for available options. |
Masahiro Yamada | 2134342 | 2014-08-27 14:05:51 +0900 | [diff] [blame] | 13 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 14 | Python 2.6 or later, but not Python 3.x is necessary to run this script. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 15 | """ |
| 16 | |
| 17 | import errno |
| 18 | import fnmatch |
| 19 | import glob |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 20 | import multiprocessing |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 21 | import optparse |
| 22 | import os |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 23 | import sys |
| 24 | import tempfile |
| 25 | import time |
| 26 | |
Peng Fan | 6080170 | 2018-07-24 14:27:18 +0800 | [diff] [blame] | 27 | sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'buildman')) |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 28 | import kconfiglib |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 29 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 30 | ### constant variables ### |
| 31 | OUTPUT_FILE = 'boards.cfg' |
| 32 | CONFIG_DIR = 'configs' |
| 33 | SLEEP_TIME = 0.03 |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 34 | COMMENT_BLOCK = '''# |
| 35 | # List of boards |
| 36 | # Automatically generated by %s: don't edit |
| 37 | # |
Masahiro Yamada | ca418dd | 2014-08-06 13:42:34 +0900 | [diff] [blame] | 38 | # Status, Arch, CPU, SoC, Vendor, Board, Target, Options, Maintainers |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 39 | |
| 40 | ''' % __file__ |
| 41 | |
| 42 | ### helper functions ### |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 43 | def try_remove(f): |
| 44 | """Remove a file ignoring 'No such file or directory' error.""" |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 45 | try: |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 46 | os.remove(f) |
| 47 | except OSError as exception: |
| 48 | # Ignore 'No such file or directory' error |
| 49 | if exception.errno != errno.ENOENT: |
| 50 | raise |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 51 | |
| 52 | def check_top_directory(): |
| 53 | """Exit if we are not at the top of source directory.""" |
| 54 | for f in ('README', 'Licenses'): |
| 55 | if not os.path.exists(f): |
Masahiro Yamada | 31e2141 | 2014-08-16 00:59:26 +0900 | [diff] [blame] | 56 | sys.exit('Please run at the top of source directory.') |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 57 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 58 | def output_is_new(output): |
| 59 | """Check if the output file is up to date. |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 60 | |
| 61 | Returns: |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 62 | True if the given output file exists and is newer than any of |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 63 | *_defconfig, MAINTAINERS and Kconfig*. False otherwise. |
| 64 | """ |
| 65 | try: |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 66 | ctime = os.path.getctime(output) |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 67 | except OSError as exception: |
| 68 | if exception.errno == errno.ENOENT: |
| 69 | # return False on 'No such file or directory' error |
| 70 | return False |
| 71 | else: |
| 72 | raise |
| 73 | |
| 74 | for (dirpath, dirnames, filenames) in os.walk(CONFIG_DIR): |
| 75 | for filename in fnmatch.filter(filenames, '*_defconfig'): |
| 76 | if fnmatch.fnmatch(filename, '.*'): |
| 77 | continue |
| 78 | filepath = os.path.join(dirpath, filename) |
| 79 | if ctime < os.path.getctime(filepath): |
| 80 | return False |
| 81 | |
| 82 | for (dirpath, dirnames, filenames) in os.walk('.'): |
| 83 | for filename in filenames: |
| 84 | if (fnmatch.fnmatch(filename, '*~') or |
| 85 | not fnmatch.fnmatch(filename, 'Kconfig*') and |
| 86 | not filename == 'MAINTAINERS'): |
| 87 | continue |
| 88 | filepath = os.path.join(dirpath, filename) |
| 89 | if ctime < os.path.getctime(filepath): |
| 90 | return False |
| 91 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 92 | # Detect a board that has been removed since the current board database |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 93 | # was generated |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 94 | with open(output, encoding="utf-8") as f: |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 95 | for line in f: |
| 96 | if line[0] == '#' or line == '\n': |
| 97 | continue |
| 98 | defconfig = line.split()[6] + '_defconfig' |
| 99 | if not os.path.exists(os.path.join(CONFIG_DIR, defconfig)): |
| 100 | return False |
| 101 | |
| 102 | return True |
| 103 | |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 104 | ### classes ### |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 105 | class KconfigScanner: |
| 106 | |
| 107 | """Kconfig scanner.""" |
| 108 | |
| 109 | ### constant variable only used in this class ### |
| 110 | _SYMBOL_TABLE = { |
| 111 | 'arch' : 'SYS_ARCH', |
| 112 | 'cpu' : 'SYS_CPU', |
| 113 | 'soc' : 'SYS_SOC', |
| 114 | 'vendor' : 'SYS_VENDOR', |
| 115 | 'board' : 'SYS_BOARD', |
| 116 | 'config' : 'SYS_CONFIG_NAME', |
| 117 | 'options' : 'SYS_EXTRA_OPTIONS' |
| 118 | } |
| 119 | |
| 120 | def __init__(self): |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 121 | """Scan all the Kconfig files and create a Kconfig object.""" |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 122 | # Define environment variables referenced from Kconfig |
| 123 | os.environ['srctree'] = os.getcwd() |
| 124 | os.environ['UBOOTVERSION'] = 'dummy' |
| 125 | os.environ['KCONFIG_OBJDIR'] = '' |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 126 | self._conf = kconfiglib.Kconfig(warn=False) |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 127 | |
| 128 | def __del__(self): |
| 129 | """Delete a leftover temporary file before exit. |
| 130 | |
| 131 | The scan() method of this class creates a temporay file and deletes |
| 132 | it on success. If scan() method throws an exception on the way, |
| 133 | the temporary file might be left over. In that case, it should be |
| 134 | deleted in this destructor. |
| 135 | """ |
| 136 | if hasattr(self, '_tmpfile') and self._tmpfile: |
| 137 | try_remove(self._tmpfile) |
| 138 | |
| 139 | def scan(self, defconfig): |
| 140 | """Load a defconfig file to obtain board parameters. |
| 141 | |
| 142 | Arguments: |
| 143 | defconfig: path to the defconfig file to be processed |
| 144 | |
| 145 | Returns: |
| 146 | A dictionary of board parameters. It has a form of: |
| 147 | { |
| 148 | 'arch': <arch_name>, |
| 149 | 'cpu': <cpu_name>, |
| 150 | 'soc': <soc_name>, |
| 151 | 'vendor': <vendor_name>, |
| 152 | 'board': <board_name>, |
| 153 | 'target': <target_name>, |
| 154 | 'config': <config_header_name>, |
| 155 | 'options': <extra_options> |
| 156 | } |
| 157 | """ |
| 158 | # strip special prefixes and save it in a temporary file |
| 159 | fd, self._tmpfile = tempfile.mkstemp() |
| 160 | with os.fdopen(fd, 'w') as f: |
| 161 | for line in open(defconfig): |
| 162 | colon = line.find(':CONFIG_') |
| 163 | if colon == -1: |
| 164 | f.write(line) |
| 165 | else: |
| 166 | f.write(line[colon + 1:]) |
| 167 | |
Tom Rini | 5e7c8a3 | 2019-09-20 17:42:08 -0400 | [diff] [blame] | 168 | self._conf.load_config(self._tmpfile) |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 169 | try_remove(self._tmpfile) |
| 170 | self._tmpfile = None |
| 171 | |
| 172 | params = {} |
| 173 | |
| 174 | # Get the value of CONFIG_SYS_ARCH, CONFIG_SYS_CPU, ... etc. |
| 175 | # Set '-' if the value is empty. |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 176 | for key, symbol in list(self._SYMBOL_TABLE.items()): |
Tom Rini | 65e05dd | 2019-09-20 17:42:09 -0400 | [diff] [blame] | 177 | value = self._conf.syms.get(symbol).str_value |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 178 | if value: |
| 179 | params[key] = value |
| 180 | else: |
| 181 | params[key] = '-' |
| 182 | |
| 183 | defconfig = os.path.basename(defconfig) |
| 184 | params['target'], match, rear = defconfig.partition('_defconfig') |
| 185 | assert match and not rear, '%s : invalid defconfig' % defconfig |
| 186 | |
| 187 | # fix-up for aarch64 |
| 188 | if params['arch'] == 'arm' and params['cpu'] == 'armv8': |
| 189 | params['arch'] = 'aarch64' |
| 190 | |
| 191 | # fix-up options field. It should have the form: |
| 192 | # <config name>[:comma separated config options] |
| 193 | if params['options'] != '-': |
| 194 | params['options'] = params['config'] + ':' + \ |
| 195 | params['options'].replace(r'\"', '"') |
| 196 | elif params['config'] != params['target']: |
| 197 | params['options'] = params['config'] |
| 198 | |
| 199 | return params |
| 200 | |
| 201 | def scan_defconfigs_for_multiprocess(queue, defconfigs): |
| 202 | """Scan defconfig files and queue their board parameters |
| 203 | |
| 204 | This function is intended to be passed to |
| 205 | multiprocessing.Process() constructor. |
| 206 | |
| 207 | Arguments: |
| 208 | queue: An instance of multiprocessing.Queue(). |
| 209 | The resulting board parameters are written into it. |
| 210 | defconfigs: A sequence of defconfig files to be scanned. |
| 211 | """ |
| 212 | kconf_scanner = KconfigScanner() |
| 213 | for defconfig in defconfigs: |
| 214 | queue.put(kconf_scanner.scan(defconfig)) |
| 215 | |
| 216 | def read_queues(queues, params_list): |
| 217 | """Read the queues and append the data to the paramers list""" |
| 218 | for q in queues: |
| 219 | while not q.empty(): |
| 220 | params_list.append(q.get()) |
| 221 | |
| 222 | def scan_defconfigs(jobs=1): |
| 223 | """Collect board parameters for all defconfig files. |
| 224 | |
| 225 | This function invokes multiple processes for faster processing. |
| 226 | |
| 227 | Arguments: |
| 228 | jobs: The number of jobs to run simultaneously |
| 229 | """ |
| 230 | all_defconfigs = [] |
| 231 | for (dirpath, dirnames, filenames) in os.walk(CONFIG_DIR): |
| 232 | for filename in fnmatch.filter(filenames, '*_defconfig'): |
| 233 | if fnmatch.fnmatch(filename, '.*'): |
| 234 | continue |
| 235 | all_defconfigs.append(os.path.join(dirpath, filename)) |
| 236 | |
| 237 | total_boards = len(all_defconfigs) |
| 238 | processes = [] |
| 239 | queues = [] |
| 240 | for i in range(jobs): |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 241 | defconfigs = all_defconfigs[total_boards * i // jobs : |
| 242 | total_boards * (i + 1) // jobs] |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 243 | q = multiprocessing.Queue(maxsize=-1) |
| 244 | p = multiprocessing.Process(target=scan_defconfigs_for_multiprocess, |
| 245 | args=(q, defconfigs)) |
| 246 | p.start() |
| 247 | processes.append(p) |
| 248 | queues.append(q) |
| 249 | |
| 250 | # The resulting data should be accumulated to this list |
| 251 | params_list = [] |
| 252 | |
| 253 | # Data in the queues should be retrieved preriodically. |
| 254 | # Otherwise, the queues would become full and subprocesses would get stuck. |
| 255 | while any([p.is_alive() for p in processes]): |
| 256 | read_queues(queues, params_list) |
| 257 | # sleep for a while until the queues are filled |
| 258 | time.sleep(SLEEP_TIME) |
| 259 | |
| 260 | # Joining subprocesses just in case |
| 261 | # (All subprocesses should already have been finished) |
| 262 | for p in processes: |
| 263 | p.join() |
| 264 | |
| 265 | # retrieve leftover data |
| 266 | read_queues(queues, params_list) |
| 267 | |
| 268 | return params_list |
| 269 | |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 270 | class MaintainersDatabase: |
| 271 | |
| 272 | """The database of board status and maintainers.""" |
| 273 | |
| 274 | def __init__(self): |
| 275 | """Create an empty database.""" |
| 276 | self.database = {} |
| 277 | |
| 278 | def get_status(self, target): |
| 279 | """Return the status of the given board. |
| 280 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 281 | The board status is generally either 'Active' or 'Orphan'. |
| 282 | Display a warning message and return '-' if status information |
| 283 | is not found. |
| 284 | |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 285 | Returns: |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 286 | 'Active', 'Orphan' or '-'. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 287 | """ |
Masahiro Yamada | b8828e8 | 2014-08-25 12:39:43 +0900 | [diff] [blame] | 288 | if not target in self.database: |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 289 | print("WARNING: no status info for '%s'" % target, file=sys.stderr) |
Masahiro Yamada | b8828e8 | 2014-08-25 12:39:43 +0900 | [diff] [blame] | 290 | return '-' |
| 291 | |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 292 | tmp = self.database[target][0] |
| 293 | if tmp.startswith('Maintained'): |
| 294 | return 'Active' |
Lokesh Vutla | dee7c68 | 2017-05-10 16:19:52 +0530 | [diff] [blame] | 295 | elif tmp.startswith('Supported'): |
| 296 | return 'Active' |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 297 | elif tmp.startswith('Orphan'): |
| 298 | return 'Orphan' |
| 299 | else: |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 300 | print(("WARNING: %s: unknown status for '%s'" % |
| 301 | (tmp, target)), file=sys.stderr) |
Masahiro Yamada | b8828e8 | 2014-08-25 12:39:43 +0900 | [diff] [blame] | 302 | return '-' |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 303 | |
| 304 | def get_maintainers(self, target): |
| 305 | """Return the maintainers of the given board. |
| 306 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 307 | Returns: |
| 308 | Maintainers of the board. If the board has two or more maintainers, |
| 309 | they are separated with colons. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 310 | """ |
Masahiro Yamada | b8828e8 | 2014-08-25 12:39:43 +0900 | [diff] [blame] | 311 | if not target in self.database: |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 312 | print("WARNING: no maintainers for '%s'" % target, file=sys.stderr) |
Masahiro Yamada | b8828e8 | 2014-08-25 12:39:43 +0900 | [diff] [blame] | 313 | return '' |
| 314 | |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 315 | return ':'.join(self.database[target][1]) |
| 316 | |
| 317 | def parse_file(self, file): |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 318 | """Parse a MAINTAINERS file. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 319 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 320 | Parse a MAINTAINERS file and accumulates board status and |
| 321 | maintainers information. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 322 | |
| 323 | Arguments: |
| 324 | file: MAINTAINERS file to be parsed |
| 325 | """ |
| 326 | targets = [] |
| 327 | maintainers = [] |
| 328 | status = '-' |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 329 | for line in open(file, encoding="utf-8"): |
Masahiro Yamada | 5dff844 | 2014-09-16 14:11:49 +0900 | [diff] [blame] | 330 | # Check also commented maintainers |
| 331 | if line[:3] == '#M:': |
| 332 | line = line[1:] |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 333 | tag, rest = line[:2], line[2:].strip() |
| 334 | if tag == 'M:': |
| 335 | maintainers.append(rest) |
| 336 | elif tag == 'F:': |
| 337 | # expand wildcard and filter by 'configs/*_defconfig' |
| 338 | for f in glob.glob(rest): |
| 339 | front, match, rear = f.partition('configs/') |
| 340 | if not front and match: |
| 341 | front, match, rear = rear.rpartition('_defconfig') |
| 342 | if match and not rear: |
| 343 | targets.append(front) |
| 344 | elif tag == 'S:': |
| 345 | status = rest |
Masahiro Yamada | 9c2d60c | 2014-08-22 14:10:43 +0900 | [diff] [blame] | 346 | elif line == '\n': |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 347 | for target in targets: |
| 348 | self.database[target] = (status, maintainers) |
| 349 | targets = [] |
| 350 | maintainers = [] |
| 351 | status = '-' |
| 352 | if targets: |
| 353 | for target in targets: |
| 354 | self.database[target] = (status, maintainers) |
| 355 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 356 | def insert_maintainers_info(params_list): |
| 357 | """Add Status and Maintainers information to the board parameters list. |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 358 | |
| 359 | Arguments: |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 360 | params_list: A list of the board parameters |
| 361 | """ |
| 362 | database = MaintainersDatabase() |
| 363 | for (dirpath, dirnames, filenames) in os.walk('.'): |
| 364 | if 'MAINTAINERS' in filenames: |
| 365 | database.parse_file(os.path.join(dirpath, 'MAINTAINERS')) |
| 366 | |
| 367 | for i, params in enumerate(params_list): |
| 368 | target = params['target'] |
| 369 | params['status'] = database.get_status(target) |
| 370 | params['maintainers'] = database.get_maintainers(target) |
| 371 | params_list[i] = params |
| 372 | |
| 373 | def format_and_output(params_list, output): |
| 374 | """Write board parameters into a file. |
| 375 | |
| 376 | Columnate the board parameters, sort lines alphabetically, |
| 377 | and then write them to a file. |
| 378 | |
| 379 | Arguments: |
| 380 | params_list: The list of board parameters |
| 381 | output: The path to the output file |
| 382 | """ |
| 383 | FIELDS = ('status', 'arch', 'cpu', 'soc', 'vendor', 'board', 'target', |
| 384 | 'options', 'maintainers') |
| 385 | |
| 386 | # First, decide the width of each column |
| 387 | max_length = dict([ (f, 0) for f in FIELDS]) |
| 388 | for params in params_list: |
| 389 | for f in FIELDS: |
| 390 | max_length[f] = max(max_length[f], len(params[f])) |
| 391 | |
| 392 | output_lines = [] |
| 393 | for params in params_list: |
| 394 | line = '' |
| 395 | for f in FIELDS: |
| 396 | # insert two spaces between fields like column -t would |
| 397 | line += ' ' + params[f].ljust(max_length[f]) |
| 398 | output_lines.append(line.strip()) |
| 399 | |
| 400 | # ignore case when sorting |
| 401 | output_lines.sort(key=str.lower) |
| 402 | |
Tom Rini | 3bc1409 | 2019-09-20 17:42:07 -0400 | [diff] [blame] | 403 | with open(output, 'w', encoding="utf-8") as f: |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 404 | f.write(COMMENT_BLOCK + '\n'.join(output_lines) + '\n') |
| 405 | |
Simon Glass | 69bbdd1 | 2019-12-05 15:59:11 -0700 | [diff] [blame] | 406 | def gen_boards_cfg(output, jobs=1, force=False, quiet=False): |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 407 | """Generate a board database file. |
| 408 | |
| 409 | Arguments: |
| 410 | output: The name of the output file |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 411 | jobs: The number of jobs to run simultaneously |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 412 | force: Force to generate the output even if it is new |
Simon Glass | 69bbdd1 | 2019-12-05 15:59:11 -0700 | [diff] [blame] | 413 | quiet: True to avoid printing a message if nothing needs doing |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 414 | """ |
Masahiro Yamada | 79d45d3 | 2014-08-25 12:39:46 +0900 | [diff] [blame] | 415 | check_top_directory() |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 416 | |
| 417 | if not force and output_is_new(output): |
Simon Glass | 69bbdd1 | 2019-12-05 15:59:11 -0700 | [diff] [blame] | 418 | if not quiet: |
| 419 | print("%s is up to date. Nothing to do." % output) |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 420 | sys.exit(0) |
| 421 | |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 422 | params_list = scan_defconfigs(jobs) |
| 423 | insert_maintainers_info(params_list) |
| 424 | format_and_output(params_list, output) |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 425 | |
| 426 | def main(): |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 427 | try: |
| 428 | cpu_count = multiprocessing.cpu_count() |
| 429 | except NotImplementedError: |
| 430 | cpu_count = 1 |
| 431 | |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 432 | parser = optparse.OptionParser() |
| 433 | # Add options here |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 434 | parser.add_option('-f', '--force', action="store_true", default=False, |
| 435 | help='regenerate the output even if it is new') |
Masahiro Yamada | f6c8f38 | 2014-09-01 19:57:38 +0900 | [diff] [blame] | 436 | parser.add_option('-j', '--jobs', type='int', default=cpu_count, |
| 437 | help='the number of jobs to run simultaneously') |
| 438 | parser.add_option('-o', '--output', default=OUTPUT_FILE, |
| 439 | help='output file [default=%s]' % OUTPUT_FILE) |
Simon Glass | 69bbdd1 | 2019-12-05 15:59:11 -0700 | [diff] [blame] | 440 | parser.add_option('-q', '--quiet', action="store_true", help='run silently') |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 441 | (options, args) = parser.parse_args() |
Masahiro Yamada | d1bf4af | 2014-08-25 12:39:47 +0900 | [diff] [blame] | 442 | |
Simon Glass | 69bbdd1 | 2019-12-05 15:59:11 -0700 | [diff] [blame] | 443 | gen_boards_cfg(options.output, jobs=options.jobs, force=options.force, |
| 444 | quiet=options.quiet) |
Masahiro Yamada | 3c08e8b | 2014-07-30 14:08:19 +0900 | [diff] [blame] | 445 | |
| 446 | if __name__ == '__main__': |
| 447 | main() |