blob: eb4927f278ef95a05c88fa289611ff388310d8af [file] [log] [blame]
Masahiro Yamadab6160812015-05-20 11:36:07 +09001#!/usr/bin/env python2
2#
3# Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4#
5# SPDX-License-Identifier: GPL-2.0+
6#
7
8"""
9Move config options from headers to defconfig files.
10
11Since Kconfig was introduced to U-Boot, we have worked on moving
12config options from headers to Kconfig (defconfig).
13
14This tool intends to help this tremendous work.
15
16
17Usage
18-----
19
Masahiro Yamadab903c4e2016-05-19 15:51:58 +090020First, you must edit the Kconfig to add the menu entries for the configs
Joe Hershberger166edec2015-05-19 13:21:17 -050021you are moving.
22
Masahiro Yamadab903c4e2016-05-19 15:51:58 +090023And then run this tool giving CONFIG names you want to move.
24For example, if you want to move CONFIG_CMD_USB and CONFIG_SYS_TEXT_BASE,
25simply type as follows:
Masahiro Yamadab6160812015-05-20 11:36:07 +090026
Masahiro Yamadab903c4e2016-05-19 15:51:58 +090027 $ tools/moveconfig.py CONFIG_CMD_USB CONFIG_SYS_TEXT_BASE
Masahiro Yamadab6160812015-05-20 11:36:07 +090028
Masahiro Yamadab903c4e2016-05-19 15:51:58 +090029The tool walks through all the defconfig files and move the given CONFIGs.
Masahiro Yamadab6160812015-05-20 11:36:07 +090030
31The log is also displayed on the terminal.
32
Masahiro Yamada465b7c02016-05-19 15:52:02 +090033The log is printed for each defconfig as follows:
Masahiro Yamadab6160812015-05-20 11:36:07 +090034
Masahiro Yamada465b7c02016-05-19 15:52:02 +090035<defconfig_name>
36 <action1>
37 <action2>
38 <action3>
39 ...
Masahiro Yamadab6160812015-05-20 11:36:07 +090040
Masahiro Yamada465b7c02016-05-19 15:52:02 +090041<defconfig_name> is the name of the defconfig.
42
43<action*> shows what the tool did for that defconfig.
Masahiro Yamada7facf882016-08-21 16:12:36 +090044It looks like one of the following:
Masahiro Yamadab6160812015-05-20 11:36:07 +090045
46 - Move 'CONFIG_... '
47 This config option was moved to the defconfig
48
Masahiro Yamada5643d6e2016-05-19 15:51:56 +090049 - CONFIG_... is not defined in Kconfig. Do nothing.
Masahiro Yamada35204d92016-08-22 22:18:21 +090050 The entry for this CONFIG was not found in Kconfig. The option is not
51 defined in the config header, either. So, this case can be just skipped.
52
53 - CONFIG_... is not defined in Kconfig (suspicious). Do nothing.
54 This option is defined in the config header, but its entry was not found
55 in Kconfig.
Masahiro Yamada5643d6e2016-05-19 15:51:56 +090056 There are two common cases:
57 - You forgot to create an entry for the CONFIG before running
58 this tool, or made a typo in a CONFIG passed to this tool.
59 - The entry was hidden due to unmet 'depends on'.
Masahiro Yamada35204d92016-08-22 22:18:21 +090060 The tool does not know if the result is reasonable, so please check it
61 manually.
Masahiro Yamadab6160812015-05-20 11:36:07 +090062
Masahiro Yamada5643d6e2016-05-19 15:51:56 +090063 - 'CONFIG_...' is the same as the define in Kconfig. Do nothing.
64 The define in the config header matched the one in Kconfig.
65 We do not need to touch it.
Masahiro Yamadab6160812015-05-20 11:36:07 +090066
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +090067 - Compiler is missing. Do nothing.
68 The compiler specified for this architecture was not found
69 in your PATH environment.
70 (If -e option is passed, the tool exits immediately.)
71
72 - Failed to process.
Masahiro Yamadab6160812015-05-20 11:36:07 +090073 An error occurred during processing this defconfig. Skipped.
74 (If -e option is passed, the tool exits immediately on error.)
75
76Finally, you will be asked, Clean up headers? [y/n]:
77
78If you say 'y' here, the unnecessary config defines are removed
79from the config headers (include/configs/*.h).
80It just uses the regex method, so you should not rely on it.
81Just in case, please do 'git diff' to see what happened.
82
83
Masahiro Yamadab903c4e2016-05-19 15:51:58 +090084How does it work?
85-----------------
Masahiro Yamadab6160812015-05-20 11:36:07 +090086
87This tool runs configuration and builds include/autoconf.mk for every
88defconfig. The config options defined in Kconfig appear in the .config
89file (unless they are hidden because of unmet dependency.)
90On the other hand, the config options defined by board headers are seen
91in include/autoconf.mk. The tool looks for the specified options in both
Masahiro Yamadab903c4e2016-05-19 15:51:58 +090092of them to decide the appropriate action for the options. If the given
93config option is found in the .config, but its value does not match the
94one from the board header, the config option in the .config is replaced
95with the define in the board header. Then, the .config is synced by
96"make savedefconfig" and the defconfig is updated with it.
Masahiro Yamadab6160812015-05-20 11:36:07 +090097
98For faster processing, this tool handles multi-threading. It creates
99separate build directories where the out-of-tree build is run. The
100temporary build directories are automatically created and deleted as
101needed. The number of threads are chosen based on the number of the CPU
102cores of your system although you can change it via -j (--jobs) option.
103
104
105Toolchains
106----------
107
108Appropriate toolchain are necessary to generate include/autoconf.mk
109for all the architectures supported by U-Boot. Most of them are available
110at the kernel.org site, some are not provided by kernel.org.
111
112The default per-arch CROSS_COMPILE used by this tool is specified by
113the list below, CROSS_COMPILE. You may wish to update the list to
114use your own. Instead of modifying the list directly, you can give
115them via environments.
116
117
Simon Glass2d79f702017-06-01 19:39:00 -0600118Tips and trips
119--------------
120
121To sync only X86 defconfigs:
122
123 ./tools/moveconfig.py -s -d <(grep -l X86 configs/*)
124
125or:
126
127 grep -l X86 configs/* | ./tools/moveconfig.py -s -d -
128
129To process CONFIG_CMD_FPGAD only for a subset of configs based on path match:
130
131 ls configs/{hrcon*,iocon*,strider*} | \
132 ./tools/moveconfig.py -Cy CONFIG_CMD_FPGAD -d -
133
134
Simon Glassc6e73cf2017-06-01 19:39:03 -0600135Finding implied CONFIGs
136-----------------------
137
138Some CONFIG options can be implied by others and this can help to reduce
139the size of the defconfig files. For example, CONFIG_X86 implies
140CONFIG_CMD_IRQ, so we can put 'imply CMD_IRQ' under 'config X86' and
141all x86 boards will have that option, avoiding adding CONFIG_CMD_IRQ to
142each of the x86 defconfig files.
143
144This tool can help find such configs. To use it, first build a database:
145
146 ./tools/moveconfig.py -b
147
148Then try to query it:
149
150 ./tools/moveconfig.py -i CONFIG_CMD_IRQ
151 CONFIG_CMD_IRQ found in 311/2384 defconfigs
152 44 : CONFIG_SYS_FSL_ERRATUM_IFC_A002769
153 41 : CONFIG_SYS_FSL_ERRATUM_A007075
154 31 : CONFIG_SYS_FSL_DDR_VER_44
155 28 : CONFIG_ARCH_P1010
156 28 : CONFIG_SYS_FSL_ERRATUM_P1010_A003549
157 28 : CONFIG_SYS_FSL_ERRATUM_SEC_A003571
158 28 : CONFIG_SYS_FSL_ERRATUM_IFC_A003399
159 25 : CONFIG_SYS_FSL_ERRATUM_A008044
160 22 : CONFIG_ARCH_P1020
161 21 : CONFIG_SYS_FSL_DDR_VER_46
162 20 : CONFIG_MAX_PIRQ_LINKS
163 20 : CONFIG_HPET_ADDRESS
164 20 : CONFIG_X86
165 20 : CONFIG_PCIE_ECAM_SIZE
166 20 : CONFIG_IRQ_SLOT_COUNT
167 20 : CONFIG_I8259_PIC
168 20 : CONFIG_CPU_ADDR_BITS
169 20 : CONFIG_RAMBASE
170 20 : CONFIG_SYS_FSL_ERRATUM_A005871
171 20 : CONFIG_PCIE_ECAM_BASE
172 20 : CONFIG_X86_TSC_TIMER
173 20 : CONFIG_I8254_TIMER
174 20 : CONFIG_CMD_GETTIME
175 19 : CONFIG_SYS_FSL_ERRATUM_A005812
176 18 : CONFIG_X86_RUN_32BIT
177 17 : CONFIG_CMD_CHIP_CONFIG
178 ...
179
180This shows a list of config options which might imply CONFIG_CMD_EEPROM along
181with how many defconfigs they cover. From this you can see that CONFIG_X86
182implies CONFIG_CMD_EEPROM. Therefore, instead of adding CONFIG_CMD_EEPROM to
183the defconfig of every x86 board, you could add a single imply line to the
184Kconfig file:
185
186 config X86
187 bool "x86 architecture"
188 ...
189 imply CMD_EEPROM
190
191That will cover 20 defconfigs. Many of the options listed are not suitable as
192they are not related. E.g. it would be odd for CONFIG_CMD_GETTIME to imply
193CMD_EEPROM.
194
195Using this search you can reduce the size of moveconfig patches.
196
Simon Glass44116332017-06-15 21:39:33 -0600197You can automatically add 'imply' statements in the Kconfig with the -a
198option:
199
200 ./tools/moveconfig.py -s -i CONFIG_SCSI \
201 -a CONFIG_ARCH_LS1021A,CONFIG_ARCH_LS1043A
202
203This will add 'imply SCSI' to the two CONFIG options mentioned, assuming that
204the database indicates that they do actually imply CONFIG_SCSI and do not
205already have an 'imply SCSI'.
206
207The output shows where the imply is added:
208
209 18 : CONFIG_ARCH_LS1021A arch/arm/cpu/armv7/ls102xa/Kconfig:1
210 13 : CONFIG_ARCH_LS1043A arch/arm/cpu/armv8/fsl-layerscape/Kconfig:11
211 12 : CONFIG_ARCH_LS1046A arch/arm/cpu/armv8/fsl-layerscape/Kconfig:31
212
213The first number is the number of boards which can avoid having a special
214CONFIG_SCSI option in their defconfig file if this 'imply' is added.
215The location at the right is the Kconfig file and line number where the config
216appears. For example, adding 'imply CONFIG_SCSI' to the 'config ARCH_LS1021A'
217in arch/arm/cpu/armv7/ls102xa/Kconfig at line 1 will help 18 boards to reduce
218the size of their defconfig files.
219
220If you want to add an 'imply' to every imply config in the list, you can use
221
222 ./tools/moveconfig.py -s -i CONFIG_SCSI -a all
223
224To control which ones are displayed, use -I <list> where list is a list of
225options (use '-I help' to see possible options and their meaning).
226
227To skip showing you options that already have an 'imply' attached, use -A.
228
229When you have finished adding 'imply' options you can regenerate the
230defconfig files for affected boards with something like:
231
232 git show --stat | ./tools/moveconfig.py -s -d -
233
234This will regenerate only those defconfigs changed in the current commit.
235If you start with (say) 100 defconfigs being changed in the commit, and add
236a few 'imply' options as above, then regenerate, hopefully you can reduce the
237number of defconfigs changed in the commit.
238
Simon Glassc6e73cf2017-06-01 19:39:03 -0600239
Masahiro Yamadab6160812015-05-20 11:36:07 +0900240Available options
241-----------------
242
243 -c, --color
244 Surround each portion of the log with escape sequences to display it
245 in color on the terminal.
246
Simon Glass8bf41c22016-09-12 23:18:21 -0600247 -C, --commit
248 Create a git commit with the changes when the operation is complete. A
249 standard commit message is used which may need to be edited.
250
Joe Hershbergerc6e043a2015-05-19 13:21:19 -0500251 -d, --defconfigs
Masahiro Yamada3984d6e2016-10-19 14:39:54 +0900252 Specify a file containing a list of defconfigs to move. The defconfig
Simon Glass2d79f702017-06-01 19:39:00 -0600253 files can be given with shell-style wildcards. Use '-' to read from stdin.
Joe Hershbergerc6e043a2015-05-19 13:21:19 -0500254
Masahiro Yamadab6160812015-05-20 11:36:07 +0900255 -n, --dry-run
Masahiro Yamadab903c4e2016-05-19 15:51:58 +0900256 Perform a trial run that does not make any changes. It is useful to
Masahiro Yamadab6160812015-05-20 11:36:07 +0900257 see what is going to happen before one actually runs it.
258
259 -e, --exit-on-error
260 Exit immediately if Make exits with a non-zero status while processing
261 a defconfig file.
262
Masahiro Yamada83c17672016-05-19 15:52:08 +0900263 -s, --force-sync
264 Do "make savedefconfig" forcibly for all the defconfig files.
265 If not specified, "make savedefconfig" only occurs for cases
266 where at least one CONFIG was moved.
267
Masahiro Yamada6d139172016-08-22 22:18:22 +0900268 -S, --spl
269 Look for moved config options in spl/include/autoconf.mk instead of
270 include/autoconf.mk. This is useful for moving options for SPL build
271 because SPL related options (mostly prefixed with CONFIG_SPL_) are
272 sometimes blocked by CONFIG_SPL_BUILD ifdef conditionals.
273
Joe Hershberger23475932015-05-19 13:21:20 -0500274 -H, --headers-only
275 Only cleanup the headers; skip the defconfig processing
276
Masahiro Yamadab6160812015-05-20 11:36:07 +0900277 -j, --jobs
278 Specify the number of threads to run simultaneously. If not specified,
279 the number of threads is the same as the number of CPU cores.
280
Joe Hershbergerb1a570f2016-06-10 14:53:32 -0500281 -r, --git-ref
282 Specify the git ref to clone for building the autoconf.mk. If unspecified
283 use the CWD. This is useful for when changes to the Kconfig affect the
284 default values and you want to capture the state of the defconfig from
285 before that change was in effect. If in doubt, specify a ref pre-Kconfig
286 changes (use HEAD if Kconfig changes are not committed). Worst case it will
287 take a bit longer to run, but will always do the right thing.
288
Joe Hershberger808b63f2015-05-19 13:21:24 -0500289 -v, --verbose
290 Show any build errors as boards are built
291
Simon Glass13e05a02016-09-12 23:18:20 -0600292 -y, --yes
293 Instead of prompting, automatically go ahead with all operations. This
Simon Glass2d79f702017-06-01 19:39:00 -0600294 includes cleaning up headers, CONFIG_SYS_EXTRA_OPTIONS, the config whitelist
295 and the README.
Simon Glass13e05a02016-09-12 23:18:20 -0600296
Masahiro Yamadab6160812015-05-20 11:36:07 +0900297To see the complete list of supported options, run
298
299 $ tools/moveconfig.py -h
300
301"""
302
Simon Glassc6e73cf2017-06-01 19:39:03 -0600303import collections
Masahiro Yamadaea8f5342016-07-25 19:15:24 +0900304import copy
Masahiro Yamada573b3902016-07-25 19:15:25 +0900305import difflib
Masahiro Yamada0f6beda2016-05-19 15:52:07 +0900306import filecmp
Masahiro Yamadab6160812015-05-20 11:36:07 +0900307import fnmatch
Masahiro Yamada3984d6e2016-10-19 14:39:54 +0900308import glob
Masahiro Yamadab6160812015-05-20 11:36:07 +0900309import multiprocessing
310import optparse
311import os
Simon Glass43cf08f2017-06-01 19:39:02 -0600312import Queue
Masahiro Yamadab6160812015-05-20 11:36:07 +0900313import re
314import shutil
315import subprocess
316import sys
317import tempfile
Simon Glass43cf08f2017-06-01 19:39:02 -0600318import threading
Masahiro Yamadab6160812015-05-20 11:36:07 +0900319import time
320
Simon Glass44116332017-06-15 21:39:33 -0600321sys.path.append(os.path.join(os.path.dirname(__file__), 'buildman'))
322import kconfiglib
323
Masahiro Yamadab6160812015-05-20 11:36:07 +0900324SHOW_GNU_MAKE = 'scripts/show-gnu-make'
325SLEEP_TIME=0.03
326
327# Here is the list of cross-tools I use.
328# Most of them are available at kernel.org
Masahiro Yamada7facf882016-08-21 16:12:36 +0900329# (https://www.kernel.org/pub/tools/crosstool/files/bin/), except the following:
Masahiro Yamadab6160812015-05-20 11:36:07 +0900330# arc: https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases
Bin Meng3bb02f62015-09-25 01:22:39 -0700331# nds32: http://osdk.andestech.com/packages/nds32le-linux-glibc-v1.tgz
Masahiro Yamadab6160812015-05-20 11:36:07 +0900332# nios2: https://sourcery.mentor.com/GNUToolchain/subscription42545
333# sh: http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu
334CROSS_COMPILE = {
335 'arc': 'arc-linux-',
336 'aarch64': 'aarch64-linux-',
337 'arm': 'arm-unknown-linux-gnueabi-',
Masahiro Yamadab6160812015-05-20 11:36:07 +0900338 'm68k': 'm68k-linux-',
339 'microblaze': 'microblaze-linux-',
340 'mips': 'mips-linux-',
341 'nds32': 'nds32le-linux-',
342 'nios2': 'nios2-linux-gnu-',
Masahiro Yamadab6160812015-05-20 11:36:07 +0900343 'powerpc': 'powerpc-linux-',
344 'sh': 'sh-linux-gnu-',
Masahiro Yamadad1d9d602016-08-21 16:03:08 +0900345 'x86': 'i386-linux-',
346 'xtensa': 'xtensa-linux-'
Masahiro Yamadab6160812015-05-20 11:36:07 +0900347}
348
349STATE_IDLE = 0
350STATE_DEFCONFIG = 1
351STATE_AUTOCONF = 2
Joe Hershberger166edec2015-05-19 13:21:17 -0500352STATE_SAVEDEFCONFIG = 3
Masahiro Yamadab6160812015-05-20 11:36:07 +0900353
354ACTION_MOVE = 0
Masahiro Yamada5643d6e2016-05-19 15:51:56 +0900355ACTION_NO_ENTRY = 1
Masahiro Yamada35204d92016-08-22 22:18:21 +0900356ACTION_NO_ENTRY_WARN = 2
357ACTION_NO_CHANGE = 3
Masahiro Yamadab6160812015-05-20 11:36:07 +0900358
359COLOR_BLACK = '0;30'
360COLOR_RED = '0;31'
361COLOR_GREEN = '0;32'
362COLOR_BROWN = '0;33'
363COLOR_BLUE = '0;34'
364COLOR_PURPLE = '0;35'
365COLOR_CYAN = '0;36'
366COLOR_LIGHT_GRAY = '0;37'
367COLOR_DARK_GRAY = '1;30'
368COLOR_LIGHT_RED = '1;31'
369COLOR_LIGHT_GREEN = '1;32'
370COLOR_YELLOW = '1;33'
371COLOR_LIGHT_BLUE = '1;34'
372COLOR_LIGHT_PURPLE = '1;35'
373COLOR_LIGHT_CYAN = '1;36'
374COLOR_WHITE = '1;37'
375
Simon Glass8fb5bd02017-06-01 19:39:01 -0600376AUTO_CONF_PATH = 'include/config/auto.conf'
Simon Glass43cf08f2017-06-01 19:39:02 -0600377CONFIG_DATABASE = 'moveconfig.db'
Simon Glass8fb5bd02017-06-01 19:39:01 -0600378
Simon Glass44116332017-06-15 21:39:33 -0600379CONFIG_LEN = len('CONFIG_')
Simon Glass8fb5bd02017-06-01 19:39:01 -0600380
Masahiro Yamadab6160812015-05-20 11:36:07 +0900381### helper functions ###
382def get_devnull():
383 """Get the file object of '/dev/null' device."""
384 try:
385 devnull = subprocess.DEVNULL # py3k
386 except AttributeError:
387 devnull = open(os.devnull, 'wb')
388 return devnull
389
390def check_top_directory():
391 """Exit if we are not at the top of source directory."""
392 for f in ('README', 'Licenses'):
393 if not os.path.exists(f):
394 sys.exit('Please run at the top of source directory.')
395
Masahiro Yamada990e6772016-05-19 15:51:54 +0900396def check_clean_directory():
397 """Exit if the source tree is not clean."""
398 for f in ('.config', 'include/config'):
399 if os.path.exists(f):
400 sys.exit("source tree is not clean, please run 'make mrproper'")
401
Masahiro Yamadab6160812015-05-20 11:36:07 +0900402def get_make_cmd():
403 """Get the command name of GNU Make.
404
405 U-Boot needs GNU Make for building, but the command name is not
406 necessarily "make". (for example, "gmake" on FreeBSD).
407 Returns the most appropriate command name on your system.
408 """
409 process = subprocess.Popen([SHOW_GNU_MAKE], stdout=subprocess.PIPE)
410 ret = process.communicate()
411 if process.returncode:
412 sys.exit('GNU Make not found')
413 return ret[0].rstrip()
414
Simon Glass18774bc2017-06-01 19:38:58 -0600415def get_matched_defconfig(line):
416 """Get the defconfig files that match a pattern
417
418 Args:
419 line: Path or filename to match, e.g. 'configs/snow_defconfig' or
420 'k2*_defconfig'. If no directory is provided, 'configs/' is
421 prepended
422
423 Returns:
424 a list of matching defconfig files
425 """
426 dirname = os.path.dirname(line)
427 if dirname:
428 pattern = line
429 else:
430 pattern = os.path.join('configs', line)
431 return glob.glob(pattern) + glob.glob(pattern + '_defconfig')
432
Masahiro Yamada3984d6e2016-10-19 14:39:54 +0900433def get_matched_defconfigs(defconfigs_file):
Simon Glass8f3cf312017-06-01 19:38:59 -0600434 """Get all the defconfig files that match the patterns in a file.
435
436 Args:
437 defconfigs_file: File containing a list of defconfigs to process, or
438 '-' to read the list from stdin
439
440 Returns:
441 A list of paths to defconfig files, with no duplicates
442 """
Masahiro Yamada3984d6e2016-10-19 14:39:54 +0900443 defconfigs = []
Simon Glass8f3cf312017-06-01 19:38:59 -0600444 if defconfigs_file == '-':
445 fd = sys.stdin
446 defconfigs_file = 'stdin'
447 else:
448 fd = open(defconfigs_file)
449 for i, line in enumerate(fd):
Masahiro Yamada3984d6e2016-10-19 14:39:54 +0900450 line = line.strip()
451 if not line:
452 continue # skip blank lines silently
Simon Glass452fa8e2017-06-15 21:39:31 -0600453 if ' ' in line:
454 line = line.split(' ')[0] # handle 'git log' input
Simon Glass18774bc2017-06-01 19:38:58 -0600455 matched = get_matched_defconfig(line)
Masahiro Yamada3984d6e2016-10-19 14:39:54 +0900456 if not matched:
457 print >> sys.stderr, "warning: %s:%d: no defconfig matched '%s'" % \
458 (defconfigs_file, i + 1, line)
459
460 defconfigs += matched
461
462 # use set() to drop multiple matching
463 return [ defconfig[len('configs') + 1:] for defconfig in set(defconfigs) ]
464
Masahiro Yamada58175e32016-07-25 19:15:28 +0900465def get_all_defconfigs():
466 """Get all the defconfig files under the configs/ directory."""
467 defconfigs = []
468 for (dirpath, dirnames, filenames) in os.walk('configs'):
469 dirpath = dirpath[len('configs') + 1:]
470 for filename in fnmatch.filter(filenames, '*_defconfig'):
471 defconfigs.append(os.path.join(dirpath, filename))
472
473 return defconfigs
474
Masahiro Yamadab6160812015-05-20 11:36:07 +0900475def color_text(color_enabled, color, string):
476 """Return colored string."""
477 if color_enabled:
Masahiro Yamada465b7c02016-05-19 15:52:02 +0900478 # LF should not be surrounded by the escape sequence.
479 # Otherwise, additional whitespace or line-feed might be printed.
480 return '\n'.join([ '\033[' + color + 'm' + s + '\033[0m' if s else ''
481 for s in string.split('\n') ])
Masahiro Yamadab6160812015-05-20 11:36:07 +0900482 else:
483 return string
484
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900485def show_diff(a, b, file_path, color_enabled):
Masahiro Yamada573b3902016-07-25 19:15:25 +0900486 """Show unidified diff.
487
488 Arguments:
489 a: A list of lines (before)
490 b: A list of lines (after)
491 file_path: Path to the file
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900492 color_enabled: Display the diff in color
Masahiro Yamada573b3902016-07-25 19:15:25 +0900493 """
494
495 diff = difflib.unified_diff(a, b,
496 fromfile=os.path.join('a', file_path),
497 tofile=os.path.join('b', file_path))
498
499 for line in diff:
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900500 if line[0] == '-' and line[1] != '-':
501 print color_text(color_enabled, COLOR_RED, line),
502 elif line[0] == '+' and line[1] != '+':
503 print color_text(color_enabled, COLOR_GREEN, line),
504 else:
505 print line,
Masahiro Yamada573b3902016-07-25 19:15:25 +0900506
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +0900507def update_cross_compile(color_enabled):
Robert P. J. Day8c60f922016-05-04 04:47:31 -0400508 """Update per-arch CROSS_COMPILE via environment variables
Masahiro Yamadab6160812015-05-20 11:36:07 +0900509
510 The default CROSS_COMPILE values are available
511 in the CROSS_COMPILE list above.
512
Robert P. J. Day8c60f922016-05-04 04:47:31 -0400513 You can override them via environment variables
Masahiro Yamadab6160812015-05-20 11:36:07 +0900514 CROSS_COMPILE_{ARCH}.
515
516 For example, if you want to override toolchain prefixes
517 for ARM and PowerPC, you can do as follows in your shell:
518
519 export CROSS_COMPILE_ARM=...
520 export CROSS_COMPILE_POWERPC=...
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +0900521
522 Then, this function checks if specified compilers really exist in your
523 PATH environment.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900524 """
525 archs = []
526
527 for arch in os.listdir('arch'):
528 if os.path.exists(os.path.join('arch', arch, 'Makefile')):
529 archs.append(arch)
530
531 # arm64 is a special case
532 archs.append('aarch64')
533
534 for arch in archs:
535 env = 'CROSS_COMPILE_' + arch.upper()
536 cross_compile = os.environ.get(env)
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +0900537 if not cross_compile:
538 cross_compile = CROSS_COMPILE.get(arch, '')
539
540 for path in os.environ["PATH"].split(os.pathsep):
541 gcc_path = os.path.join(path, cross_compile + 'gcc')
542 if os.path.isfile(gcc_path) and os.access(gcc_path, os.X_OK):
543 break
544 else:
545 print >> sys.stderr, color_text(color_enabled, COLOR_YELLOW,
546 'warning: %sgcc: not found in PATH. %s architecture boards will be skipped'
547 % (cross_compile, arch))
548 cross_compile = None
549
550 CROSS_COMPILE[arch] = cross_compile
Masahiro Yamadab6160812015-05-20 11:36:07 +0900551
Masahiro Yamadaea8f5342016-07-25 19:15:24 +0900552def extend_matched_lines(lines, matched, pre_patterns, post_patterns, extend_pre,
553 extend_post):
554 """Extend matched lines if desired patterns are found before/after already
555 matched lines.
556
557 Arguments:
558 lines: A list of lines handled.
559 matched: A list of line numbers that have been already matched.
560 (will be updated by this function)
561 pre_patterns: A list of regular expression that should be matched as
562 preamble.
563 post_patterns: A list of regular expression that should be matched as
564 postamble.
565 extend_pre: Add the line number of matched preamble to the matched list.
566 extend_post: Add the line number of matched postamble to the matched list.
567 """
568 extended_matched = []
569
570 j = matched[0]
571
572 for i in matched:
573 if i == 0 or i < j:
574 continue
575 j = i
576 while j in matched:
577 j += 1
578 if j >= len(lines):
579 break
580
581 for p in pre_patterns:
582 if p.search(lines[i - 1]):
583 break
584 else:
585 # not matched
586 continue
587
588 for p in post_patterns:
589 if p.search(lines[j]):
590 break
591 else:
592 # not matched
593 continue
594
595 if extend_pre:
596 extended_matched.append(i - 1)
597 if extend_post:
598 extended_matched.append(j)
599
600 matched += extended_matched
601 matched.sort()
602
Chris Packham85e15c52017-05-02 21:30:46 +1200603def confirm(options, prompt):
604 if not options.yes:
605 while True:
606 choice = raw_input('{} [y/n]: '.format(prompt))
607 choice = choice.lower()
608 print choice
609 if choice == 'y' or choice == 'n':
610 break
611
612 if choice == 'n':
613 return False
614
615 return True
616
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900617def cleanup_one_header(header_path, patterns, options):
Masahiro Yamadab6160812015-05-20 11:36:07 +0900618 """Clean regex-matched lines away from a file.
619
620 Arguments:
621 header_path: path to the cleaned file.
622 patterns: list of regex patterns. Any lines matching to these
623 patterns are deleted.
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900624 options: option flags.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900625 """
626 with open(header_path) as f:
627 lines = f.readlines()
628
629 matched = []
630 for i, line in enumerate(lines):
Masahiro Yamada6d798ba2016-07-25 19:15:27 +0900631 if i - 1 in matched and lines[i - 1][-2:] == '\\\n':
632 matched.append(i)
633 continue
Masahiro Yamadab6160812015-05-20 11:36:07 +0900634 for pattern in patterns:
Masahiro Yamadaea8f5342016-07-25 19:15:24 +0900635 if pattern.search(line):
Masahiro Yamadab6160812015-05-20 11:36:07 +0900636 matched.append(i)
637 break
638
Masahiro Yamadaea8f5342016-07-25 19:15:24 +0900639 if not matched:
640 return
641
642 # remove empty #ifdef ... #endif, successive blank lines
643 pattern_if = re.compile(r'#\s*if(def|ndef)?\W') # #if, #ifdef, #ifndef
644 pattern_elif = re.compile(r'#\s*el(if|se)\W') # #elif, #else
645 pattern_endif = re.compile(r'#\s*endif\W') # #endif
646 pattern_blank = re.compile(r'^\s*$') # empty line
647
648 while True:
649 old_matched = copy.copy(matched)
650 extend_matched_lines(lines, matched, [pattern_if],
651 [pattern_endif], True, True)
652 extend_matched_lines(lines, matched, [pattern_elif],
653 [pattern_elif, pattern_endif], True, False)
654 extend_matched_lines(lines, matched, [pattern_if, pattern_elif],
655 [pattern_blank], False, True)
656 extend_matched_lines(lines, matched, [pattern_blank],
657 [pattern_elif, pattern_endif], True, False)
658 extend_matched_lines(lines, matched, [pattern_blank],
659 [pattern_blank], True, False)
660 if matched == old_matched:
661 break
662
Masahiro Yamada573b3902016-07-25 19:15:25 +0900663 tolines = copy.copy(lines)
664
665 for i in reversed(matched):
666 tolines.pop(i)
667
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900668 show_diff(lines, tolines, header_path, options.color)
Masahiro Yamadaea8f5342016-07-25 19:15:24 +0900669
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900670 if options.dry_run:
Masahiro Yamadab6160812015-05-20 11:36:07 +0900671 return
672
673 with open(header_path, 'w') as f:
Masahiro Yamada573b3902016-07-25 19:15:25 +0900674 for line in tolines:
675 f.write(line)
Masahiro Yamadab6160812015-05-20 11:36:07 +0900676
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900677def cleanup_headers(configs, options):
Masahiro Yamadab6160812015-05-20 11:36:07 +0900678 """Delete config defines from board headers.
679
680 Arguments:
Masahiro Yamadab80a6672016-05-19 15:51:57 +0900681 configs: A list of CONFIGs to remove.
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900682 options: option flags.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900683 """
Chris Packham85e15c52017-05-02 21:30:46 +1200684 if not confirm(options, 'Clean up headers?'):
685 return
Masahiro Yamadab6160812015-05-20 11:36:07 +0900686
687 patterns = []
Masahiro Yamadab80a6672016-05-19 15:51:57 +0900688 for config in configs:
Masahiro Yamadab6160812015-05-20 11:36:07 +0900689 patterns.append(re.compile(r'#\s*define\s+%s\W' % config))
690 patterns.append(re.compile(r'#\s*undef\s+%s\W' % config))
691
Joe Hershbergerb78ad422015-05-19 13:21:21 -0500692 for dir in 'include', 'arch', 'board':
693 for (dirpath, dirnames, filenames) in os.walk(dir):
Masahiro Yamada28a6d352016-07-25 19:15:22 +0900694 if dirpath == os.path.join('include', 'generated'):
695 continue
Joe Hershbergerb78ad422015-05-19 13:21:21 -0500696 for filename in filenames:
697 if not fnmatch.fnmatch(filename, '*~'):
698 cleanup_one_header(os.path.join(dirpath, filename),
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +0900699 patterns, options)
Masahiro Yamadab6160812015-05-20 11:36:07 +0900700
Masahiro Yamadadce28de2016-07-25 19:15:29 +0900701def cleanup_one_extra_option(defconfig_path, configs, options):
702 """Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in one defconfig file.
703
704 Arguments:
705 defconfig_path: path to the cleaned defconfig file.
706 configs: A list of CONFIGs to remove.
707 options: option flags.
708 """
709
710 start = 'CONFIG_SYS_EXTRA_OPTIONS="'
711 end = '"\n'
712
713 with open(defconfig_path) as f:
714 lines = f.readlines()
715
716 for i, line in enumerate(lines):
717 if line.startswith(start) and line.endswith(end):
718 break
719 else:
720 # CONFIG_SYS_EXTRA_OPTIONS was not found in this defconfig
721 return
722
723 old_tokens = line[len(start):-len(end)].split(',')
724 new_tokens = []
725
726 for token in old_tokens:
727 pos = token.find('=')
728 if not (token[:pos] if pos >= 0 else token) in configs:
729 new_tokens.append(token)
730
731 if new_tokens == old_tokens:
732 return
733
734 tolines = copy.copy(lines)
735
736 if new_tokens:
737 tolines[i] = start + ','.join(new_tokens) + end
738 else:
739 tolines.pop(i)
740
741 show_diff(lines, tolines, defconfig_path, options.color)
742
743 if options.dry_run:
744 return
745
746 with open(defconfig_path, 'w') as f:
747 for line in tolines:
748 f.write(line)
749
750def cleanup_extra_options(configs, options):
751 """Delete config defines in CONFIG_SYS_EXTRA_OPTIONS in defconfig files.
752
753 Arguments:
754 configs: A list of CONFIGs to remove.
755 options: option flags.
756 """
Chris Packham85e15c52017-05-02 21:30:46 +1200757 if not confirm(options, 'Clean up CONFIG_SYS_EXTRA_OPTIONS?'):
758 return
Masahiro Yamadadce28de2016-07-25 19:15:29 +0900759
760 configs = [ config[len('CONFIG_'):] for config in configs ]
761
762 defconfigs = get_all_defconfigs()
763
764 for defconfig in defconfigs:
765 cleanup_one_extra_option(os.path.join('configs', defconfig), configs,
766 options)
767
Chris Packham9d5274f2017-05-02 21:30:47 +1200768def cleanup_whitelist(configs, options):
769 """Delete config whitelist entries
770
771 Arguments:
772 configs: A list of CONFIGs to remove.
773 options: option flags.
774 """
775 if not confirm(options, 'Clean up whitelist entries?'):
776 return
777
778 with open(os.path.join('scripts', 'config_whitelist.txt')) as f:
779 lines = f.readlines()
780
781 lines = [x for x in lines if x.strip() not in configs]
782
783 with open(os.path.join('scripts', 'config_whitelist.txt'), 'w') as f:
784 f.write(''.join(lines))
785
Chris Packham0e6deff2017-05-02 21:30:48 +1200786def find_matching(patterns, line):
787 for pat in patterns:
788 if pat.search(line):
789 return True
790 return False
791
792def cleanup_readme(configs, options):
793 """Delete config description in README
794
795 Arguments:
796 configs: A list of CONFIGs to remove.
797 options: option flags.
798 """
799 if not confirm(options, 'Clean up README?'):
800 return
801
802 patterns = []
803 for config in configs:
804 patterns.append(re.compile(r'^\s+%s' % config))
805
806 with open('README') as f:
807 lines = f.readlines()
808
809 found = False
810 newlines = []
811 for line in lines:
812 if not found:
813 found = find_matching(patterns, line)
814 if found:
815 continue
816
817 if found and re.search(r'^\s+CONFIG', line):
818 found = False
819
820 if not found:
821 newlines.append(line)
822
823 with open('README', 'w') as f:
824 f.write(''.join(newlines))
825
Chris Packham9d5274f2017-05-02 21:30:47 +1200826
Masahiro Yamadab6160812015-05-20 11:36:07 +0900827### classes ###
Masahiro Yamadacefaa582016-05-19 15:51:55 +0900828class Progress:
829
830 """Progress Indicator"""
831
832 def __init__(self, total):
833 """Create a new progress indicator.
834
835 Arguments:
836 total: A number of defconfig files to process.
837 """
838 self.current = 0
839 self.total = total
840
841 def inc(self):
842 """Increment the number of processed defconfig files."""
843
844 self.current += 1
845
846 def show(self):
847 """Display the progress."""
848 print ' %d defconfigs out of %d\r' % (self.current, self.total),
849 sys.stdout.flush()
850
Simon Glass44116332017-06-15 21:39:33 -0600851
852class KconfigScanner:
853 """Kconfig scanner."""
854
855 def __init__(self):
856 """Scan all the Kconfig files and create a Config object."""
857 # Define environment variables referenced from Kconfig
858 os.environ['srctree'] = os.getcwd()
859 os.environ['UBOOTVERSION'] = 'dummy'
860 os.environ['KCONFIG_OBJDIR'] = ''
861 self.conf = kconfiglib.Config()
862
863
Masahiro Yamadab6160812015-05-20 11:36:07 +0900864class KconfigParser:
865
866 """A parser of .config and include/autoconf.mk."""
867
868 re_arch = re.compile(r'CONFIG_SYS_ARCH="(.*)"')
869 re_cpu = re.compile(r'CONFIG_SYS_CPU="(.*)"')
870
Masahiro Yamada69e2bbc2016-05-19 15:52:01 +0900871 def __init__(self, configs, options, build_dir):
Masahiro Yamadab6160812015-05-20 11:36:07 +0900872 """Create a new parser.
873
874 Arguments:
Masahiro Yamadab80a6672016-05-19 15:51:57 +0900875 configs: A list of CONFIGs to move.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900876 options: option flags.
877 build_dir: Build directory.
878 """
Masahiro Yamadab80a6672016-05-19 15:51:57 +0900879 self.configs = configs
Masahiro Yamadab6160812015-05-20 11:36:07 +0900880 self.options = options
Masahiro Yamada5393b612016-05-19 15:52:00 +0900881 self.dotconfig = os.path.join(build_dir, '.config')
882 self.autoconf = os.path.join(build_dir, 'include', 'autoconf.mk')
Masahiro Yamada6d139172016-08-22 22:18:22 +0900883 self.spl_autoconf = os.path.join(build_dir, 'spl', 'include',
884 'autoconf.mk')
Simon Glass8fb5bd02017-06-01 19:39:01 -0600885 self.config_autoconf = os.path.join(build_dir, AUTO_CONF_PATH)
Masahiro Yamada07f98522016-05-19 15:52:06 +0900886 self.defconfig = os.path.join(build_dir, 'defconfig')
Masahiro Yamadab6160812015-05-20 11:36:07 +0900887
888 def get_cross_compile(self):
889 """Parse .config file and return CROSS_COMPILE.
890
891 Returns:
892 A string storing the compiler prefix for the architecture.
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +0900893 Return a NULL string for architectures that do not require
894 compiler prefix (Sandbox and native build is the case).
895 Return None if the specified compiler is missing in your PATH.
896 Caller should distinguish '' and None.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900897 """
898 arch = ''
899 cpu = ''
Masahiro Yamada5393b612016-05-19 15:52:00 +0900900 for line in open(self.dotconfig):
Masahiro Yamadab6160812015-05-20 11:36:07 +0900901 m = self.re_arch.match(line)
902 if m:
903 arch = m.group(1)
904 continue
905 m = self.re_cpu.match(line)
906 if m:
907 cpu = m.group(1)
908
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +0900909 if not arch:
910 return None
Masahiro Yamadab6160812015-05-20 11:36:07 +0900911
912 # fix-up for aarch64
913 if arch == 'arm' and cpu == 'armv8':
914 arch = 'aarch64'
915
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +0900916 return CROSS_COMPILE.get(arch, None)
Masahiro Yamadab6160812015-05-20 11:36:07 +0900917
Masahiro Yamadab80a6672016-05-19 15:51:57 +0900918 def parse_one_config(self, config, dotconfig_lines, autoconf_lines):
Masahiro Yamadab6160812015-05-20 11:36:07 +0900919 """Parse .config, defconfig, include/autoconf.mk for one config.
920
921 This function looks for the config options in the lines from
922 defconfig, .config, and include/autoconf.mk in order to decide
923 which action should be taken for this defconfig.
924
925 Arguments:
Masahiro Yamadab80a6672016-05-19 15:51:57 +0900926 config: CONFIG name to parse.
Masahiro Yamada5643d6e2016-05-19 15:51:56 +0900927 dotconfig_lines: lines from the .config file.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900928 autoconf_lines: lines from the include/autoconf.mk file.
929
930 Returns:
931 A tupple of the action for this defconfig and the line
932 matched for the config.
933 """
Masahiro Yamadab6160812015-05-20 11:36:07 +0900934 not_set = '# %s is not set' % config
935
Masahiro Yamadab6160812015-05-20 11:36:07 +0900936 for line in autoconf_lines:
937 line = line.rstrip()
938 if line.startswith(config + '='):
Masahiro Yamada5643d6e2016-05-19 15:51:56 +0900939 new_val = line
Masahiro Yamadab6160812015-05-20 11:36:07 +0900940 break
Masahiro Yamadab6160812015-05-20 11:36:07 +0900941 else:
Masahiro Yamada5643d6e2016-05-19 15:51:56 +0900942 new_val = not_set
943
Masahiro Yamada35204d92016-08-22 22:18:21 +0900944 for line in dotconfig_lines:
945 line = line.rstrip()
946 if line.startswith(config + '=') or line == not_set:
947 old_val = line
948 break
949 else:
950 if new_val == not_set:
951 return (ACTION_NO_ENTRY, config)
952 else:
953 return (ACTION_NO_ENTRY_WARN, config)
954
Masahiro Yamada5643d6e2016-05-19 15:51:56 +0900955 # If this CONFIG is neither bool nor trisate
956 if old_val[-2:] != '=y' and old_val[-2:] != '=m' and old_val != not_set:
957 # tools/scripts/define2mk.sed changes '1' to 'y'.
958 # This is a problem if the CONFIG is int type.
959 # Check the type in Kconfig and handle it correctly.
960 if new_val[-2:] == '=y':
961 new_val = new_val[:-1] + '1'
962
Masahiro Yamadab48387f2016-06-15 14:33:50 +0900963 return (ACTION_NO_CHANGE if old_val == new_val else ACTION_MOVE,
964 new_val)
Masahiro Yamadab6160812015-05-20 11:36:07 +0900965
Masahiro Yamada465b7c02016-05-19 15:52:02 +0900966 def update_dotconfig(self):
Masahiro Yamada7c0d9d22016-05-19 15:51:50 +0900967 """Parse files for the config options and update the .config.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900968
Masahiro Yamada5643d6e2016-05-19 15:51:56 +0900969 This function parses the generated .config and include/autoconf.mk
970 searching the target options.
Masahiro Yamada7c0d9d22016-05-19 15:51:50 +0900971 Move the config option(s) to the .config as needed.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900972
973 Arguments:
974 defconfig: defconfig name.
Masahiro Yamada69e2bbc2016-05-19 15:52:01 +0900975
976 Returns:
Masahiro Yamada263d1372016-05-19 15:52:04 +0900977 Return a tuple of (updated flag, log string).
978 The "updated flag" is True if the .config was updated, False
979 otherwise. The "log string" shows what happend to the .config.
Masahiro Yamadab6160812015-05-20 11:36:07 +0900980 """
981
Masahiro Yamadab6160812015-05-20 11:36:07 +0900982 results = []
Masahiro Yamada263d1372016-05-19 15:52:04 +0900983 updated = False
Masahiro Yamada35204d92016-08-22 22:18:21 +0900984 suspicious = False
Masahiro Yamada6d139172016-08-22 22:18:22 +0900985 rm_files = [self.config_autoconf, self.autoconf]
986
987 if self.options.spl:
988 if os.path.exists(self.spl_autoconf):
989 autoconf_path = self.spl_autoconf
990 rm_files.append(self.spl_autoconf)
991 else:
992 for f in rm_files:
993 os.remove(f)
994 return (updated, suspicious,
995 color_text(self.options.color, COLOR_BROWN,
996 "SPL is not enabled. Skipped.") + '\n')
997 else:
998 autoconf_path = self.autoconf
Masahiro Yamadab6160812015-05-20 11:36:07 +0900999
Masahiro Yamada5393b612016-05-19 15:52:00 +09001000 with open(self.dotconfig) as f:
Masahiro Yamada5643d6e2016-05-19 15:51:56 +09001001 dotconfig_lines = f.readlines()
Masahiro Yamadab6160812015-05-20 11:36:07 +09001002
Masahiro Yamada6d139172016-08-22 22:18:22 +09001003 with open(autoconf_path) as f:
Masahiro Yamadab6160812015-05-20 11:36:07 +09001004 autoconf_lines = f.readlines()
1005
Masahiro Yamadab80a6672016-05-19 15:51:57 +09001006 for config in self.configs:
1007 result = self.parse_one_config(config, dotconfig_lines,
Joe Hershberger166edec2015-05-19 13:21:17 -05001008 autoconf_lines)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001009 results.append(result)
1010
1011 log = ''
1012
1013 for (action, value) in results:
1014 if action == ACTION_MOVE:
1015 actlog = "Move '%s'" % value
1016 log_color = COLOR_LIGHT_GREEN
Masahiro Yamada5643d6e2016-05-19 15:51:56 +09001017 elif action == ACTION_NO_ENTRY:
1018 actlog = "%s is not defined in Kconfig. Do nothing." % value
Masahiro Yamadab6160812015-05-20 11:36:07 +09001019 log_color = COLOR_LIGHT_BLUE
Masahiro Yamada35204d92016-08-22 22:18:21 +09001020 elif action == ACTION_NO_ENTRY_WARN:
1021 actlog = "%s is not defined in Kconfig (suspicious). Do nothing." % value
1022 log_color = COLOR_YELLOW
1023 suspicious = True
Masahiro Yamada5643d6e2016-05-19 15:51:56 +09001024 elif action == ACTION_NO_CHANGE:
1025 actlog = "'%s' is the same as the define in Kconfig. Do nothing." \
1026 % value
Masahiro Yamadab6160812015-05-20 11:36:07 +09001027 log_color = COLOR_LIGHT_PURPLE
Masahiro Yamada6d139172016-08-22 22:18:22 +09001028 elif action == ACTION_SPL_NOT_EXIST:
1029 actlog = "SPL is not enabled for this defconfig. Skip."
1030 log_color = COLOR_PURPLE
Masahiro Yamadab6160812015-05-20 11:36:07 +09001031 else:
1032 sys.exit("Internal Error. This should not happen.")
1033
Masahiro Yamada465b7c02016-05-19 15:52:02 +09001034 log += color_text(self.options.color, log_color, actlog) + '\n'
Masahiro Yamadab6160812015-05-20 11:36:07 +09001035
Masahiro Yamada5393b612016-05-19 15:52:00 +09001036 with open(self.dotconfig, 'a') as f:
Masahiro Yamada953d93b2016-05-19 15:51:49 +09001037 for (action, value) in results:
1038 if action == ACTION_MOVE:
1039 f.write(value + '\n')
Masahiro Yamada263d1372016-05-19 15:52:04 +09001040 updated = True
Masahiro Yamadab6160812015-05-20 11:36:07 +09001041
Masahiro Yamada07f98522016-05-19 15:52:06 +09001042 self.results = results
Masahiro Yamada6d139172016-08-22 22:18:22 +09001043 for f in rm_files:
1044 os.remove(f)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001045
Masahiro Yamada35204d92016-08-22 22:18:21 +09001046 return (updated, suspicious, log)
Masahiro Yamada69e2bbc2016-05-19 15:52:01 +09001047
Masahiro Yamada07f98522016-05-19 15:52:06 +09001048 def check_defconfig(self):
1049 """Check the defconfig after savedefconfig
1050
1051 Returns:
1052 Return additional log if moved CONFIGs were removed again by
1053 'make savedefconfig'.
1054 """
1055
1056 log = ''
1057
1058 with open(self.defconfig) as f:
1059 defconfig_lines = f.readlines()
1060
1061 for (action, value) in self.results:
1062 if action != ACTION_MOVE:
1063 continue
1064 if not value + '\n' in defconfig_lines:
1065 log += color_text(self.options.color, COLOR_YELLOW,
1066 "'%s' was removed by savedefconfig.\n" %
1067 value)
1068
1069 return log
1070
Simon Glass43cf08f2017-06-01 19:39:02 -06001071
1072class DatabaseThread(threading.Thread):
1073 """This thread processes results from Slot threads.
1074
1075 It collects the data in the master config directary. There is only one
1076 result thread, and this helps to serialise the build output.
1077 """
1078 def __init__(self, config_db, db_queue):
1079 """Set up a new result thread
1080
1081 Args:
1082 builder: Builder which will be sent each result
1083 """
1084 threading.Thread.__init__(self)
1085 self.config_db = config_db
1086 self.db_queue= db_queue
1087
1088 def run(self):
1089 """Called to start up the result thread.
1090
1091 We collect the next result job and pass it on to the build.
1092 """
1093 while True:
1094 defconfig, configs = self.db_queue.get()
1095 self.config_db[defconfig] = configs
1096 self.db_queue.task_done()
1097
1098
Masahiro Yamadab6160812015-05-20 11:36:07 +09001099class Slot:
1100
1101 """A slot to store a subprocess.
1102
1103 Each instance of this class handles one subprocess.
1104 This class is useful to control multiple threads
1105 for faster processing.
1106 """
1107
Simon Glass43cf08f2017-06-01 19:39:02 -06001108 def __init__(self, configs, options, progress, devnull, make_cmd,
1109 reference_src_dir, db_queue):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001110 """Create a new process slot.
1111
1112 Arguments:
Masahiro Yamadab80a6672016-05-19 15:51:57 +09001113 configs: A list of CONFIGs to move.
Masahiro Yamadab6160812015-05-20 11:36:07 +09001114 options: option flags.
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001115 progress: A progress indicator.
Masahiro Yamadab6160812015-05-20 11:36:07 +09001116 devnull: A file object of '/dev/null'.
1117 make_cmd: command name of GNU Make.
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001118 reference_src_dir: Determine the true starting config state from this
1119 source tree.
Simon Glass43cf08f2017-06-01 19:39:02 -06001120 db_queue: output queue to write config info for the database
Masahiro Yamadab6160812015-05-20 11:36:07 +09001121 """
1122 self.options = options
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001123 self.progress = progress
Masahiro Yamadab6160812015-05-20 11:36:07 +09001124 self.build_dir = tempfile.mkdtemp()
1125 self.devnull = devnull
1126 self.make_cmd = (make_cmd, 'O=' + self.build_dir)
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001127 self.reference_src_dir = reference_src_dir
Simon Glass43cf08f2017-06-01 19:39:02 -06001128 self.db_queue = db_queue
Masahiro Yamada69e2bbc2016-05-19 15:52:01 +09001129 self.parser = KconfigParser(configs, options, self.build_dir)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001130 self.state = STATE_IDLE
Masahiro Yamada1271b672016-08-22 22:18:20 +09001131 self.failed_boards = set()
1132 self.suspicious_boards = set()
Masahiro Yamadab6160812015-05-20 11:36:07 +09001133
1134 def __del__(self):
1135 """Delete the working directory
1136
1137 This function makes sure the temporary directory is cleaned away
1138 even if Python suddenly dies due to error. It should be done in here
Joe Hershberger640de872016-06-10 14:53:29 -05001139 because it is guaranteed the destructor is always invoked when the
Masahiro Yamadab6160812015-05-20 11:36:07 +09001140 instance of the class gets unreferenced.
1141
1142 If the subprocess is still running, wait until it finishes.
1143 """
1144 if self.state != STATE_IDLE:
1145 while self.ps.poll() == None:
1146 pass
1147 shutil.rmtree(self.build_dir)
1148
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001149 def add(self, defconfig):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001150 """Assign a new subprocess for defconfig and add it to the slot.
1151
1152 If the slot is vacant, create a new subprocess for processing the
1153 given defconfig and add it to the slot. Just returns False if
1154 the slot is occupied (i.e. the current subprocess is still running).
1155
1156 Arguments:
1157 defconfig: defconfig name.
1158
1159 Returns:
1160 Return True on success or False on failure
1161 """
1162 if self.state != STATE_IDLE:
1163 return False
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001164
Masahiro Yamadab6160812015-05-20 11:36:07 +09001165 self.defconfig = defconfig
Masahiro Yamada465b7c02016-05-19 15:52:02 +09001166 self.log = ''
Masahiro Yamada8f5256a2016-06-15 14:33:52 +09001167 self.current_src_dir = self.reference_src_dir
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001168 self.do_defconfig()
Masahiro Yamadab6160812015-05-20 11:36:07 +09001169 return True
1170
1171 def poll(self):
1172 """Check the status of the subprocess and handle it as needed.
1173
1174 Returns True if the slot is vacant (i.e. in idle state).
1175 If the configuration is successfully finished, assign a new
1176 subprocess to build include/autoconf.mk.
1177 If include/autoconf.mk is generated, invoke the parser to
Masahiro Yamada263d1372016-05-19 15:52:04 +09001178 parse the .config and the include/autoconf.mk, moving
1179 config options to the .config as needed.
1180 If the .config was updated, run "make savedefconfig" to sync
1181 it, update the original defconfig, and then set the slot back
1182 to the idle state.
Masahiro Yamadab6160812015-05-20 11:36:07 +09001183
1184 Returns:
1185 Return True if the subprocess is terminated, False otherwise
1186 """
1187 if self.state == STATE_IDLE:
1188 return True
1189
1190 if self.ps.poll() == None:
1191 return False
1192
1193 if self.ps.poll() != 0:
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001194 self.handle_error()
1195 elif self.state == STATE_DEFCONFIG:
Masahiro Yamada8f5256a2016-06-15 14:33:52 +09001196 if self.reference_src_dir and not self.current_src_dir:
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001197 self.do_savedefconfig()
1198 else:
1199 self.do_autoconf()
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001200 elif self.state == STATE_AUTOCONF:
Masahiro Yamada8f5256a2016-06-15 14:33:52 +09001201 if self.current_src_dir:
1202 self.current_src_dir = None
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001203 self.do_defconfig()
Simon Glass43cf08f2017-06-01 19:39:02 -06001204 elif self.options.build_db:
1205 self.do_build_db()
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001206 else:
1207 self.do_savedefconfig()
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001208 elif self.state == STATE_SAVEDEFCONFIG:
1209 self.update_defconfig()
1210 else:
1211 sys.exit("Internal Error. This should not happen.")
Masahiro Yamadab6160812015-05-20 11:36:07 +09001212
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001213 return True if self.state == STATE_IDLE else False
Joe Hershberger166edec2015-05-19 13:21:17 -05001214
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001215 def handle_error(self):
1216 """Handle error cases."""
Masahiro Yamada83c17672016-05-19 15:52:08 +09001217
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001218 self.log += color_text(self.options.color, COLOR_LIGHT_RED,
1219 "Failed to process.\n")
1220 if self.options.verbose:
1221 self.log += color_text(self.options.color, COLOR_LIGHT_CYAN,
1222 self.ps.stderr.read())
1223 self.finish(False)
Joe Hershberger166edec2015-05-19 13:21:17 -05001224
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001225 def do_defconfig(self):
1226 """Run 'make <board>_defconfig' to create the .config file."""
Masahiro Yamada0f6beda2016-05-19 15:52:07 +09001227
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001228 cmd = list(self.make_cmd)
1229 cmd.append(self.defconfig)
1230 self.ps = subprocess.Popen(cmd, stdout=self.devnull,
Masahiro Yamada8f5256a2016-06-15 14:33:52 +09001231 stderr=subprocess.PIPE,
1232 cwd=self.current_src_dir)
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001233 self.state = STATE_DEFCONFIG
Masahiro Yamada0f6beda2016-05-19 15:52:07 +09001234
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001235 def do_autoconf(self):
Simon Glass8fb5bd02017-06-01 19:39:01 -06001236 """Run 'make AUTO_CONF_PATH'."""
Masahiro Yamadab6160812015-05-20 11:36:07 +09001237
Joe Hershberger11b02702015-05-19 13:21:23 -05001238 self.cross_compile = self.parser.get_cross_compile()
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +09001239 if self.cross_compile is None:
Masahiro Yamada465b7c02016-05-19 15:52:02 +09001240 self.log += color_text(self.options.color, COLOR_YELLOW,
1241 "Compiler is missing. Do nothing.\n")
Masahiro Yamada274a5ee2016-05-19 15:52:03 +09001242 self.finish(False)
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001243 return
Masahiro Yamadac4d76eb2016-05-19 15:51:53 +09001244
Masahiro Yamadab6160812015-05-20 11:36:07 +09001245 cmd = list(self.make_cmd)
Joe Hershberger11b02702015-05-19 13:21:23 -05001246 if self.cross_compile:
1247 cmd.append('CROSS_COMPILE=%s' % self.cross_compile)
Joe Hershberger765442b2015-05-19 13:21:18 -05001248 cmd.append('KCONFIG_IGNORE_DUPLICATES=1')
Simon Glass8fb5bd02017-06-01 19:39:01 -06001249 cmd.append(AUTO_CONF_PATH)
Joe Hershberger11b02702015-05-19 13:21:23 -05001250 self.ps = subprocess.Popen(cmd, stdout=self.devnull,
Masahiro Yamada8f5256a2016-06-15 14:33:52 +09001251 stderr=subprocess.PIPE,
1252 cwd=self.current_src_dir)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001253 self.state = STATE_AUTOCONF
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001254
Simon Glass43cf08f2017-06-01 19:39:02 -06001255 def do_build_db(self):
1256 """Add the board to the database"""
1257 configs = {}
1258 with open(os.path.join(self.build_dir, AUTO_CONF_PATH)) as fd:
1259 for line in fd.readlines():
1260 if line.startswith('CONFIG'):
1261 config, value = line.split('=', 1)
1262 configs[config] = value.rstrip()
1263 self.db_queue.put([self.defconfig, configs])
1264 self.finish(True)
1265
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001266 def do_savedefconfig(self):
1267 """Update the .config and run 'make savedefconfig'."""
1268
Masahiro Yamada35204d92016-08-22 22:18:21 +09001269 (updated, suspicious, log) = self.parser.update_dotconfig()
1270 if suspicious:
1271 self.suspicious_boards.add(self.defconfig)
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001272 self.log += log
1273
1274 if not self.options.force_sync and not updated:
1275 self.finish(True)
1276 return
1277 if updated:
1278 self.log += color_text(self.options.color, COLOR_LIGHT_GREEN,
1279 "Syncing by savedefconfig...\n")
1280 else:
1281 self.log += "Syncing by savedefconfig (forced by option)...\n"
1282
1283 cmd = list(self.make_cmd)
1284 cmd.append('savedefconfig')
1285 self.ps = subprocess.Popen(cmd, stdout=self.devnull,
1286 stderr=subprocess.PIPE)
1287 self.state = STATE_SAVEDEFCONFIG
1288
1289 def update_defconfig(self):
1290 """Update the input defconfig and go back to the idle state."""
1291
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001292 log = self.parser.check_defconfig()
1293 if log:
Masahiro Yamada1271b672016-08-22 22:18:20 +09001294 self.suspicious_boards.add(self.defconfig)
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001295 self.log += log
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001296 orig_defconfig = os.path.join('configs', self.defconfig)
1297 new_defconfig = os.path.join(self.build_dir, 'defconfig')
1298 updated = not filecmp.cmp(orig_defconfig, new_defconfig)
1299
1300 if updated:
Joe Hershberger93f1c2d2016-06-10 14:53:30 -05001301 self.log += color_text(self.options.color, COLOR_LIGHT_BLUE,
Masahiro Yamadacb256cb2016-06-08 11:47:37 +09001302 "defconfig was updated.\n")
1303
1304 if not self.options.dry_run and updated:
1305 shutil.move(new_defconfig, orig_defconfig)
1306 self.finish(True)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001307
Masahiro Yamada274a5ee2016-05-19 15:52:03 +09001308 def finish(self, success):
1309 """Display log along with progress and go to the idle state.
Masahiro Yamada465b7c02016-05-19 15:52:02 +09001310
1311 Arguments:
Masahiro Yamada274a5ee2016-05-19 15:52:03 +09001312 success: Should be True when the defconfig was processed
1313 successfully, or False when it fails.
Masahiro Yamada465b7c02016-05-19 15:52:02 +09001314 """
1315 # output at least 30 characters to hide the "* defconfigs out of *".
1316 log = self.defconfig.ljust(30) + '\n'
1317
1318 log += '\n'.join([ ' ' + s for s in self.log.split('\n') ])
1319 # Some threads are running in parallel.
1320 # Print log atomically to not mix up logs from different threads.
Masahiro Yamada274a5ee2016-05-19 15:52:03 +09001321 print >> (sys.stdout if success else sys.stderr), log
1322
1323 if not success:
1324 if self.options.exit_on_error:
1325 sys.exit("Exit on error.")
1326 # If --exit-on-error flag is not set, skip this board and continue.
1327 # Record the failed board.
Masahiro Yamada1271b672016-08-22 22:18:20 +09001328 self.failed_boards.add(self.defconfig)
Masahiro Yamada274a5ee2016-05-19 15:52:03 +09001329
Masahiro Yamada465b7c02016-05-19 15:52:02 +09001330 self.progress.inc()
1331 self.progress.show()
Masahiro Yamada274a5ee2016-05-19 15:52:03 +09001332 self.state = STATE_IDLE
Masahiro Yamada465b7c02016-05-19 15:52:02 +09001333
Masahiro Yamadab6160812015-05-20 11:36:07 +09001334 def get_failed_boards(self):
Masahiro Yamada1271b672016-08-22 22:18:20 +09001335 """Returns a set of failed boards (defconfigs) in this slot.
Masahiro Yamadab6160812015-05-20 11:36:07 +09001336 """
1337 return self.failed_boards
1338
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001339 def get_suspicious_boards(self):
Masahiro Yamada1271b672016-08-22 22:18:20 +09001340 """Returns a set of boards (defconfigs) with possible misconversion.
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001341 """
Masahiro Yamada35204d92016-08-22 22:18:21 +09001342 return self.suspicious_boards - self.failed_boards
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001343
Masahiro Yamadab6160812015-05-20 11:36:07 +09001344class Slots:
1345
1346 """Controller of the array of subprocess slots."""
1347
Simon Glass43cf08f2017-06-01 19:39:02 -06001348 def __init__(self, configs, options, progress, reference_src_dir, db_queue):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001349 """Create a new slots controller.
1350
1351 Arguments:
Masahiro Yamadab80a6672016-05-19 15:51:57 +09001352 configs: A list of CONFIGs to move.
Masahiro Yamadab6160812015-05-20 11:36:07 +09001353 options: option flags.
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001354 progress: A progress indicator.
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001355 reference_src_dir: Determine the true starting config state from this
1356 source tree.
Simon Glass43cf08f2017-06-01 19:39:02 -06001357 db_queue: output queue to write config info for the database
Masahiro Yamadab6160812015-05-20 11:36:07 +09001358 """
1359 self.options = options
1360 self.slots = []
1361 devnull = get_devnull()
1362 make_cmd = get_make_cmd()
1363 for i in range(options.jobs):
Masahiro Yamadab80a6672016-05-19 15:51:57 +09001364 self.slots.append(Slot(configs, options, progress, devnull,
Simon Glass43cf08f2017-06-01 19:39:02 -06001365 make_cmd, reference_src_dir, db_queue))
Masahiro Yamadab6160812015-05-20 11:36:07 +09001366
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001367 def add(self, defconfig):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001368 """Add a new subprocess if a vacant slot is found.
1369
1370 Arguments:
1371 defconfig: defconfig name to be put into.
1372
1373 Returns:
1374 Return True on success or False on failure
1375 """
1376 for slot in self.slots:
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001377 if slot.add(defconfig):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001378 return True
1379 return False
1380
1381 def available(self):
1382 """Check if there is a vacant slot.
1383
1384 Returns:
1385 Return True if at lease one vacant slot is found, False otherwise.
1386 """
1387 for slot in self.slots:
1388 if slot.poll():
1389 return True
1390 return False
1391
1392 def empty(self):
1393 """Check if all slots are vacant.
1394
1395 Returns:
1396 Return True if all the slots are vacant, False otherwise.
1397 """
1398 ret = True
1399 for slot in self.slots:
1400 if not slot.poll():
1401 ret = False
1402 return ret
1403
1404 def show_failed_boards(self):
1405 """Display all of the failed boards (defconfigs)."""
Masahiro Yamada1271b672016-08-22 22:18:20 +09001406 boards = set()
Masahiro Yamada0153f032016-06-15 14:33:53 +09001407 output_file = 'moveconfig.failed'
Masahiro Yamadab6160812015-05-20 11:36:07 +09001408
1409 for slot in self.slots:
Masahiro Yamada1271b672016-08-22 22:18:20 +09001410 boards |= slot.get_failed_boards()
Masahiro Yamadab6160812015-05-20 11:36:07 +09001411
Masahiro Yamada0153f032016-06-15 14:33:53 +09001412 if boards:
1413 boards = '\n'.join(boards) + '\n'
1414 msg = "The following boards were not processed due to error:\n"
1415 msg += boards
1416 msg += "(the list has been saved in %s)\n" % output_file
1417 print >> sys.stderr, color_text(self.options.color, COLOR_LIGHT_RED,
1418 msg)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001419
Masahiro Yamada0153f032016-06-15 14:33:53 +09001420 with open(output_file, 'w') as f:
1421 f.write(boards)
Joe Hershbergerdade12e2015-05-19 13:21:22 -05001422
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001423 def show_suspicious_boards(self):
1424 """Display all boards (defconfigs) with possible misconversion."""
Masahiro Yamada1271b672016-08-22 22:18:20 +09001425 boards = set()
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001426 output_file = 'moveconfig.suspicious'
1427
1428 for slot in self.slots:
Masahiro Yamada1271b672016-08-22 22:18:20 +09001429 boards |= slot.get_suspicious_boards()
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001430
1431 if boards:
1432 boards = '\n'.join(boards) + '\n'
1433 msg = "The following boards might have been converted incorrectly.\n"
1434 msg += "It is highly recommended to check them manually:\n"
1435 msg += boards
1436 msg += "(the list has been saved in %s)\n" % output_file
1437 print >> sys.stderr, color_text(self.options.color, COLOR_YELLOW,
1438 msg)
1439
1440 with open(output_file, 'w') as f:
1441 f.write(boards)
1442
Masahiro Yamada2e74fee2016-06-15 14:33:51 +09001443class ReferenceSource:
1444
1445 """Reference source against which original configs should be parsed."""
1446
1447 def __init__(self, commit):
1448 """Create a reference source directory based on a specified commit.
1449
1450 Arguments:
1451 commit: commit to git-clone
1452 """
1453 self.src_dir = tempfile.mkdtemp()
1454 print "Cloning git repo to a separate work directory..."
1455 subprocess.check_output(['git', 'clone', os.getcwd(), '.'],
1456 cwd=self.src_dir)
1457 print "Checkout '%s' to build the original autoconf.mk." % \
1458 subprocess.check_output(['git', 'rev-parse', '--short', commit]).strip()
1459 subprocess.check_output(['git', 'checkout', commit],
1460 stderr=subprocess.STDOUT, cwd=self.src_dir)
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001461
1462 def __del__(self):
Masahiro Yamada2e74fee2016-06-15 14:33:51 +09001463 """Delete the reference source directory
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001464
1465 This function makes sure the temporary directory is cleaned away
1466 even if Python suddenly dies due to error. It should be done in here
1467 because it is guaranteed the destructor is always invoked when the
1468 instance of the class gets unreferenced.
1469 """
Masahiro Yamada2e74fee2016-06-15 14:33:51 +09001470 shutil.rmtree(self.src_dir)
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001471
Masahiro Yamada2e74fee2016-06-15 14:33:51 +09001472 def get_dir(self):
1473 """Return the absolute path to the reference source directory."""
1474
1475 return self.src_dir
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001476
Simon Glass43cf08f2017-06-01 19:39:02 -06001477def move_config(configs, options, db_queue):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001478 """Move config options to defconfig files.
1479
1480 Arguments:
Masahiro Yamadab80a6672016-05-19 15:51:57 +09001481 configs: A list of CONFIGs to move.
Masahiro Yamadab6160812015-05-20 11:36:07 +09001482 options: option flags
1483 """
Masahiro Yamadab80a6672016-05-19 15:51:57 +09001484 if len(configs) == 0:
Masahiro Yamada9566abd2016-05-19 15:52:09 +09001485 if options.force_sync:
1486 print 'No CONFIG is specified. You are probably syncing defconfigs.',
Simon Glass43cf08f2017-06-01 19:39:02 -06001487 elif options.build_db:
1488 print 'Building %s database' % CONFIG_DATABASE
Masahiro Yamada9566abd2016-05-19 15:52:09 +09001489 else:
1490 print 'Neither CONFIG nor --force-sync is specified. Nothing will happen.',
1491 else:
1492 print 'Move ' + ', '.join(configs),
1493 print '(jobs: %d)\n' % options.jobs
Masahiro Yamadab6160812015-05-20 11:36:07 +09001494
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001495 if options.git_ref:
Masahiro Yamada2e74fee2016-06-15 14:33:51 +09001496 reference_src = ReferenceSource(options.git_ref)
1497 reference_src_dir = reference_src.get_dir()
1498 else:
Masahiro Yamada8f5256a2016-06-15 14:33:52 +09001499 reference_src_dir = None
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001500
Joe Hershbergerc6e043a2015-05-19 13:21:19 -05001501 if options.defconfigs:
Masahiro Yamada3984d6e2016-10-19 14:39:54 +09001502 defconfigs = get_matched_defconfigs(options.defconfigs)
Joe Hershbergerc6e043a2015-05-19 13:21:19 -05001503 else:
Masahiro Yamada58175e32016-07-25 19:15:28 +09001504 defconfigs = get_all_defconfigs()
Masahiro Yamadab6160812015-05-20 11:36:07 +09001505
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001506 progress = Progress(len(defconfigs))
Simon Glass43cf08f2017-06-01 19:39:02 -06001507 slots = Slots(configs, options, progress, reference_src_dir, db_queue)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001508
1509 # Main loop to process defconfig files:
1510 # Add a new subprocess into a vacant slot.
1511 # Sleep if there is no available slot.
Masahiro Yamadacefaa582016-05-19 15:51:55 +09001512 for defconfig in defconfigs:
1513 while not slots.add(defconfig):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001514 while not slots.available():
1515 # No available slot: sleep for a while
1516 time.sleep(SLEEP_TIME)
1517
1518 # wait until all the subprocesses finish
1519 while not slots.empty():
1520 time.sleep(SLEEP_TIME)
1521
Joe Hershberger3fa1ab72015-05-19 13:21:25 -05001522 print ''
Masahiro Yamadab6160812015-05-20 11:36:07 +09001523 slots.show_failed_boards()
Masahiro Yamada3c9bfea2016-06-15 14:33:54 +09001524 slots.show_suspicious_boards()
Masahiro Yamadab6160812015-05-20 11:36:07 +09001525
Simon Glass44116332017-06-15 21:39:33 -06001526def find_kconfig_rules(kconf, config, imply_config):
1527 """Check whether a config has a 'select' or 'imply' keyword
1528
1529 Args:
1530 kconf: Kconfig.Config object
1531 config: Name of config to check (without CONFIG_ prefix)
1532 imply_config: Implying config (without CONFIG_ prefix) which may or
1533 may not have an 'imply' for 'config')
1534
1535 Returns:
1536 Symbol object for 'config' if found, else None
1537 """
1538 sym = kconf.get_symbol(imply_config)
1539 if sym:
1540 for sel in sym.get_selected_symbols():
1541 if sel.get_name() == config:
1542 return sym
1543 return None
1544
1545def check_imply_rule(kconf, config, imply_config):
1546 """Check if we can add an 'imply' option
1547
1548 This finds imply_config in the Kconfig and looks to see if it is possible
1549 to add an 'imply' for 'config' to that part of the Kconfig.
1550
1551 Args:
1552 kconf: Kconfig.Config object
1553 config: Name of config to check (without CONFIG_ prefix)
1554 imply_config: Implying config (without CONFIG_ prefix) which may or
1555 may not have an 'imply' for 'config')
1556
1557 Returns:
1558 tuple:
1559 filename of Kconfig file containing imply_config, or None if none
1560 line number within the Kconfig file, or 0 if none
1561 message indicating the result
1562 """
1563 sym = kconf.get_symbol(imply_config)
1564 if not sym:
1565 return 'cannot find sym'
1566 locs = sym.get_def_locations()
1567 if len(locs) != 1:
1568 return '%d locations' % len(locs)
1569 fname, linenum = locs[0]
1570 cwd = os.getcwd()
1571 if cwd and fname.startswith(cwd):
1572 fname = fname[len(cwd) + 1:]
1573 file_line = ' at %s:%d' % (fname, linenum)
1574 with open(fname) as fd:
1575 data = fd.read().splitlines()
1576 if data[linenum - 1] != 'config %s' % imply_config:
1577 return None, 0, 'bad sym format %s%s' % (data[linenum], file_line)
1578 return fname, linenum, 'adding%s' % file_line
1579
1580def add_imply_rule(config, fname, linenum):
1581 """Add a new 'imply' option to a Kconfig
1582
1583 Args:
1584 config: config option to add an imply for (without CONFIG_ prefix)
1585 fname: Kconfig filename to update
1586 linenum: Line number to place the 'imply' before
1587
1588 Returns:
1589 Message indicating the result
1590 """
1591 file_line = ' at %s:%d' % (fname, linenum)
1592 data = open(fname).read().splitlines()
1593 linenum -= 1
1594
1595 for offset, line in enumerate(data[linenum:]):
1596 if line.strip().startswith('help') or not line:
1597 data.insert(linenum + offset, '\timply %s' % config)
1598 with open(fname, 'w') as fd:
1599 fd.write('\n'.join(data) + '\n')
1600 return 'added%s' % file_line
1601
1602 return 'could not insert%s'
1603
1604(IMPLY_MIN_2, IMPLY_TARGET, IMPLY_CMD, IMPLY_NON_ARCH_BOARD) = (
1605 1, 2, 4, 8)
Simon Glass92e55582017-06-15 21:39:32 -06001606
1607IMPLY_FLAGS = {
1608 'min2': [IMPLY_MIN_2, 'Show options which imply >2 boards (normally >5)'],
1609 'target': [IMPLY_TARGET, 'Allow CONFIG_TARGET_... options to imply'],
1610 'cmd': [IMPLY_CMD, 'Allow CONFIG_CMD_... to imply'],
Simon Glass44116332017-06-15 21:39:33 -06001611 'non-arch-board': [
1612 IMPLY_NON_ARCH_BOARD,
1613 'Allow Kconfig options outside arch/ and /board/ to imply'],
Simon Glass92e55582017-06-15 21:39:32 -06001614};
1615
Simon Glass44116332017-06-15 21:39:33 -06001616def do_imply_config(config_list, add_imply, imply_flags, skip_added,
1617 check_kconfig=True, find_superset=False):
Simon Glassc6e73cf2017-06-01 19:39:03 -06001618 """Find CONFIG options which imply those in the list
1619
1620 Some CONFIG options can be implied by others and this can help to reduce
1621 the size of the defconfig files. For example, CONFIG_X86 implies
1622 CONFIG_CMD_IRQ, so we can put 'imply CMD_IRQ' under 'config X86' and
1623 all x86 boards will have that option, avoiding adding CONFIG_CMD_IRQ to
1624 each of the x86 defconfig files.
1625
1626 This function uses the moveconfig database to find such options. It
1627 displays a list of things that could possibly imply those in the list.
1628 The algorithm ignores any that start with CONFIG_TARGET since these
1629 typically refer to only a few defconfigs (often one). It also does not
1630 display a config with less than 5 defconfigs.
1631
1632 The algorithm works using sets. For each target config in config_list:
1633 - Get the set 'defconfigs' which use that target config
1634 - For each config (from a list of all configs):
1635 - Get the set 'imply_defconfig' of defconfigs which use that config
1636 -
1637 - If imply_defconfigs contains anything not in defconfigs then
1638 this config does not imply the target config
1639
1640 Params:
1641 config_list: List of CONFIG options to check (each a string)
Simon Glass44116332017-06-15 21:39:33 -06001642 add_imply: Automatically add an 'imply' for each config.
Simon Glass92e55582017-06-15 21:39:32 -06001643 imply_flags: Flags which control which implying configs are allowed
1644 (IMPLY_...)
Simon Glass44116332017-06-15 21:39:33 -06001645 skip_added: Don't show options which already have an imply added.
1646 check_kconfig: Check if implied symbols already have an 'imply' or
1647 'select' for the target config, and show this information if so.
Simon Glassc6e73cf2017-06-01 19:39:03 -06001648 find_superset: True to look for configs which are a superset of those
1649 already found. So for example if CONFIG_EXYNOS5 implies an option,
1650 but CONFIG_EXYNOS covers a larger set of defconfigs and also
1651 implies that option, this will drop the former in favour of the
1652 latter. In practice this option has not proved very used.
1653
1654 Note the terminoloy:
1655 config - a CONFIG_XXX options (a string, e.g. 'CONFIG_CMD_EEPROM')
1656 defconfig - a defconfig file (a string, e.g. 'configs/snow_defconfig')
1657 """
Simon Glass44116332017-06-15 21:39:33 -06001658 kconf = KconfigScanner().conf if check_kconfig else None
1659 if add_imply and add_imply != 'all':
1660 add_imply = add_imply.split()
1661
Simon Glassc6e73cf2017-06-01 19:39:03 -06001662 # key is defconfig name, value is dict of (CONFIG_xxx, value)
1663 config_db = {}
1664
1665 # Holds a dict containing the set of defconfigs that contain each config
1666 # key is config, value is set of defconfigs using that config
1667 defconfig_db = collections.defaultdict(set)
1668
1669 # Set of all config options we have seen
1670 all_configs = set()
1671
1672 # Set of all defconfigs we have seen
1673 all_defconfigs = set()
1674
1675 # Read in the database
1676 configs = {}
1677 with open(CONFIG_DATABASE) as fd:
1678 for line in fd.readlines():
1679 line = line.rstrip()
1680 if not line: # Separator between defconfigs
1681 config_db[defconfig] = configs
1682 all_defconfigs.add(defconfig)
1683 configs = {}
1684 elif line[0] == ' ': # CONFIG line
1685 config, value = line.strip().split('=', 1)
1686 configs[config] = value
1687 defconfig_db[config].add(defconfig)
1688 all_configs.add(config)
1689 else: # New defconfig
1690 defconfig = line
1691
1692 # Work through each target config option in tern, independently
1693 for config in config_list:
1694 defconfigs = defconfig_db.get(config)
1695 if not defconfigs:
1696 print '%s not found in any defconfig' % config
1697 continue
1698
1699 # Get the set of defconfigs without this one (since a config cannot
1700 # imply itself)
1701 non_defconfigs = all_defconfigs - defconfigs
1702 num_defconfigs = len(defconfigs)
1703 print '%s found in %d/%d defconfigs' % (config, num_defconfigs,
1704 len(all_configs))
1705
1706 # This will hold the results: key=config, value=defconfigs containing it
1707 imply_configs = {}
1708 rest_configs = all_configs - set([config])
1709
1710 # Look at every possible config, except the target one
1711 for imply_config in rest_configs:
Simon Glass92e55582017-06-15 21:39:32 -06001712 if 'ERRATUM' in imply_config:
Simon Glassc6e73cf2017-06-01 19:39:03 -06001713 continue
Simon Glass92e55582017-06-15 21:39:32 -06001714 if not (imply_flags & IMPLY_CMD):
1715 if 'CONFIG_CMD' in imply_config:
1716 continue
1717 if not (imply_flags & IMPLY_TARGET):
1718 if 'CONFIG_TARGET' in imply_config:
1719 continue
Simon Glassc6e73cf2017-06-01 19:39:03 -06001720
1721 # Find set of defconfigs that have this config
1722 imply_defconfig = defconfig_db[imply_config]
1723
1724 # Get the intersection of this with defconfigs containing the
1725 # target config
1726 common_defconfigs = imply_defconfig & defconfigs
1727
1728 # Get the set of defconfigs containing this config which DO NOT
1729 # also contain the taret config. If this set is non-empty it means
1730 # that this config affects other defconfigs as well as (possibly)
1731 # the ones affected by the target config. This means it implies
1732 # things we don't want to imply.
1733 not_common_defconfigs = imply_defconfig & non_defconfigs
1734 if not_common_defconfigs:
1735 continue
1736
1737 # If there are common defconfigs, imply_config may be useful
1738 if common_defconfigs:
1739 skip = False
1740 if find_superset:
1741 for prev in imply_configs.keys():
1742 prev_count = len(imply_configs[prev])
1743 count = len(common_defconfigs)
1744 if (prev_count > count and
1745 (imply_configs[prev] & common_defconfigs ==
1746 common_defconfigs)):
1747 # skip imply_config because prev is a superset
1748 skip = True
1749 break
1750 elif count > prev_count:
1751 # delete prev because imply_config is a superset
1752 del imply_configs[prev]
1753 if not skip:
1754 imply_configs[imply_config] = common_defconfigs
1755
1756 # Now we have a dict imply_configs of configs which imply each config
1757 # The value of each dict item is the set of defconfigs containing that
1758 # config. Rank them so that we print the configs that imply the largest
1759 # number of defconfigs first.
Simon Glass44116332017-06-15 21:39:33 -06001760 ranked_iconfigs = sorted(imply_configs,
Simon Glassc6e73cf2017-06-01 19:39:03 -06001761 key=lambda k: len(imply_configs[k]), reverse=True)
Simon Glass44116332017-06-15 21:39:33 -06001762 kconfig_info = ''
1763 cwd = os.getcwd()
1764 add_list = collections.defaultdict(list)
1765 for iconfig in ranked_iconfigs:
1766 num_common = len(imply_configs[iconfig])
Simon Glassc6e73cf2017-06-01 19:39:03 -06001767
1768 # Don't bother if there are less than 5 defconfigs affected.
Simon Glass92e55582017-06-15 21:39:32 -06001769 if num_common < (2 if imply_flags & IMPLY_MIN_2 else 5):
Simon Glassc6e73cf2017-06-01 19:39:03 -06001770 continue
Simon Glass44116332017-06-15 21:39:33 -06001771 missing = defconfigs - imply_configs[iconfig]
Simon Glassc6e73cf2017-06-01 19:39:03 -06001772 missing_str = ', '.join(missing) if missing else 'all'
1773 missing_str = ''
Simon Glass44116332017-06-15 21:39:33 -06001774 show = True
1775 if kconf:
1776 sym = find_kconfig_rules(kconf, config[CONFIG_LEN:],
1777 iconfig[CONFIG_LEN:])
1778 kconfig_info = ''
1779 if sym:
1780 locs = sym.get_def_locations()
1781 if len(locs) == 1:
1782 fname, linenum = locs[0]
1783 if cwd and fname.startswith(cwd):
1784 fname = fname[len(cwd) + 1:]
1785 kconfig_info = '%s:%d' % (fname, linenum)
1786 if skip_added:
1787 show = False
1788 else:
1789 sym = kconf.get_symbol(iconfig[CONFIG_LEN:])
1790 fname = ''
1791 if sym:
1792 locs = sym.get_def_locations()
1793 if len(locs) == 1:
1794 fname, linenum = locs[0]
1795 if cwd and fname.startswith(cwd):
1796 fname = fname[len(cwd) + 1:]
1797 in_arch_board = not sym or (fname.startswith('arch') or
1798 fname.startswith('board'))
1799 if (not in_arch_board and
1800 not (imply_flags & IMPLY_NON_ARCH_BOARD)):
1801 continue
1802
1803 if add_imply and (add_imply == 'all' or
1804 iconfig in add_imply):
1805 fname, linenum, kconfig_info = (check_imply_rule(kconf,
1806 config[CONFIG_LEN:], iconfig[CONFIG_LEN:]))
1807 if fname:
1808 add_list[fname].append(linenum)
Simon Glassc6e73cf2017-06-01 19:39:03 -06001809
Simon Glass44116332017-06-15 21:39:33 -06001810 if show and kconfig_info != 'skip':
1811 print '%5d : %-30s%-25s %s' % (num_common, iconfig.ljust(30),
1812 kconfig_info, missing_str)
1813
1814 # Having collected a list of things to add, now we add them. We process
1815 # each file from the largest line number to the smallest so that
1816 # earlier additions do not affect our line numbers. E.g. if we added an
1817 # imply at line 20 it would change the position of each line after
1818 # that.
1819 for fname, linenums in add_list.iteritems():
1820 for linenum in sorted(linenums, reverse=True):
1821 add_imply_rule(config[CONFIG_LEN:], fname, linenum)
1822
Simon Glassc6e73cf2017-06-01 19:39:03 -06001823
Masahiro Yamadab6160812015-05-20 11:36:07 +09001824def main():
1825 try:
1826 cpu_count = multiprocessing.cpu_count()
1827 except NotImplementedError:
1828 cpu_count = 1
1829
1830 parser = optparse.OptionParser()
1831 # Add options here
Simon Glass44116332017-06-15 21:39:33 -06001832 parser.add_option('-a', '--add-imply', type='string', default='',
1833 help='comma-separated list of CONFIG options to add '
1834 "an 'imply' statement to for the CONFIG in -i")
1835 parser.add_option('-A', '--skip-added', action='store_true', default=False,
1836 help="don't show options which are already marked as "
1837 'implying others')
Simon Glass43cf08f2017-06-01 19:39:02 -06001838 parser.add_option('-b', '--build-db', action='store_true', default=False,
1839 help='build a CONFIG database')
Masahiro Yamadab6160812015-05-20 11:36:07 +09001840 parser.add_option('-c', '--color', action='store_true', default=False,
1841 help='display the log in color')
Simon Glass8bf41c22016-09-12 23:18:21 -06001842 parser.add_option('-C', '--commit', action='store_true', default=False,
1843 help='Create a git commit for the operation')
Joe Hershbergerc6e043a2015-05-19 13:21:19 -05001844 parser.add_option('-d', '--defconfigs', type='string',
Simon Glass8f3cf312017-06-01 19:38:59 -06001845 help='a file containing a list of defconfigs to move, '
1846 "one per line (for example 'snow_defconfig') "
1847 "or '-' to read from stdin")
Simon Glassc6e73cf2017-06-01 19:39:03 -06001848 parser.add_option('-i', '--imply', action='store_true', default=False,
1849 help='find options which imply others')
Simon Glass92e55582017-06-15 21:39:32 -06001850 parser.add_option('-I', '--imply-flags', type='string', default='',
1851 help="control the -i option ('help' for help")
Masahiro Yamadab6160812015-05-20 11:36:07 +09001852 parser.add_option('-n', '--dry-run', action='store_true', default=False,
1853 help='perform a trial run (show log with no changes)')
1854 parser.add_option('-e', '--exit-on-error', action='store_true',
1855 default=False,
1856 help='exit immediately on any error')
Masahiro Yamada83c17672016-05-19 15:52:08 +09001857 parser.add_option('-s', '--force-sync', action='store_true', default=False,
1858 help='force sync by savedefconfig')
Masahiro Yamada6d139172016-08-22 22:18:22 +09001859 parser.add_option('-S', '--spl', action='store_true', default=False,
1860 help='parse config options defined for SPL build')
Joe Hershberger23475932015-05-19 13:21:20 -05001861 parser.add_option('-H', '--headers-only', dest='cleanup_headers_only',
1862 action='store_true', default=False,
1863 help='only cleanup the headers')
Masahiro Yamadab6160812015-05-20 11:36:07 +09001864 parser.add_option('-j', '--jobs', type='int', default=cpu_count,
1865 help='the number of jobs to run simultaneously')
Joe Hershbergerb1a570f2016-06-10 14:53:32 -05001866 parser.add_option('-r', '--git-ref', type='string',
1867 help='the git ref to clone for building the autoconf.mk')
Simon Glass13e05a02016-09-12 23:18:20 -06001868 parser.add_option('-y', '--yes', action='store_true', default=False,
1869 help="respond 'yes' to any prompts")
Joe Hershberger808b63f2015-05-19 13:21:24 -05001870 parser.add_option('-v', '--verbose', action='store_true', default=False,
1871 help='show any build errors as boards are built')
Masahiro Yamadab903c4e2016-05-19 15:51:58 +09001872 parser.usage += ' CONFIG ...'
Masahiro Yamadab6160812015-05-20 11:36:07 +09001873
Masahiro Yamadab903c4e2016-05-19 15:51:58 +09001874 (options, configs) = parser.parse_args()
Masahiro Yamadab6160812015-05-20 11:36:07 +09001875
Simon Glassc6e73cf2017-06-01 19:39:03 -06001876 if len(configs) == 0 and not any((options.force_sync, options.build_db,
1877 options.imply)):
Masahiro Yamadab6160812015-05-20 11:36:07 +09001878 parser.print_usage()
1879 sys.exit(1)
1880
Masahiro Yamadab903c4e2016-05-19 15:51:58 +09001881 # prefix the option name with CONFIG_ if missing
1882 configs = [ config if config.startswith('CONFIG_') else 'CONFIG_' + config
1883 for config in configs ]
Masahiro Yamadab6160812015-05-20 11:36:07 +09001884
Joe Hershberger23475932015-05-19 13:21:20 -05001885 check_top_directory()
1886
Simon Glassc6e73cf2017-06-01 19:39:03 -06001887 if options.imply:
Simon Glass92e55582017-06-15 21:39:32 -06001888 imply_flags = 0
1889 for flag in options.imply_flags.split():
1890 if flag == 'help' or flag not in IMPLY_FLAGS:
1891 print "Imply flags: (separate with ',')"
1892 for name, info in IMPLY_FLAGS.iteritems():
1893 print ' %-15s: %s' % (name, info[1])
1894 parser.print_usage()
1895 sys.exit(1)
1896 imply_flags |= IMPLY_FLAGS[flag][0]
1897
Simon Glass44116332017-06-15 21:39:33 -06001898 do_imply_config(configs, options.add_imply, imply_flags,
1899 options.skip_added)
Simon Glassc6e73cf2017-06-01 19:39:03 -06001900 return
1901
Simon Glass43cf08f2017-06-01 19:39:02 -06001902 config_db = {}
1903 db_queue = Queue.Queue()
1904 t = DatabaseThread(config_db, db_queue)
1905 t.setDaemon(True)
1906 t.start()
1907
Joe Hershberger23475932015-05-19 13:21:20 -05001908 if not options.cleanup_headers_only:
Masahiro Yamadad0a9d2a2016-07-25 19:15:23 +09001909 check_clean_directory()
1910 update_cross_compile(options.color)
Simon Glass43cf08f2017-06-01 19:39:02 -06001911 move_config(configs, options, db_queue)
1912 db_queue.join()
Joe Hershberger23475932015-05-19 13:21:20 -05001913
Masahiro Yamada9566abd2016-05-19 15:52:09 +09001914 if configs:
Masahiro Yamadaa1a4b092016-07-25 19:15:26 +09001915 cleanup_headers(configs, options)
Masahiro Yamadadce28de2016-07-25 19:15:29 +09001916 cleanup_extra_options(configs, options)
Chris Packham9d5274f2017-05-02 21:30:47 +12001917 cleanup_whitelist(configs, options)
Chris Packham0e6deff2017-05-02 21:30:48 +12001918 cleanup_readme(configs, options)
Masahiro Yamadab6160812015-05-20 11:36:07 +09001919
Simon Glass8bf41c22016-09-12 23:18:21 -06001920 if options.commit:
1921 subprocess.call(['git', 'add', '-u'])
1922 if configs:
1923 msg = 'Convert %s %sto Kconfig' % (configs[0],
1924 'et al ' if len(configs) > 1 else '')
1925 msg += ('\n\nThis converts the following to Kconfig:\n %s\n' %
1926 '\n '.join(configs))
1927 else:
1928 msg = 'configs: Resync with savedefconfig'
1929 msg += '\n\nRsync all defconfig files using moveconfig.py'
1930 subprocess.call(['git', 'commit', '-s', '-m', msg])
1931
Simon Glass43cf08f2017-06-01 19:39:02 -06001932 if options.build_db:
1933 with open(CONFIG_DATABASE, 'w') as fd:
1934 for defconfig, configs in config_db.iteritems():
1935 print >>fd, '%s' % defconfig
1936 for config in sorted(configs.keys()):
1937 print >>fd, ' %s=%s' % (config, configs[config])
1938 print >>fd
1939
Masahiro Yamadab6160812015-05-20 11:36:07 +09001940if __name__ == '__main__':
1941 main()