diff mbox

[U-Boot,v2] tools: moveconfig: support wildcards in --defconfigs file

Message ID 1476855594-23654-1-git-send-email-yamada.masahiro@socionext.com
State Accepted
Commit 0dbc9b591a56bc5a93455632de5e4d62c73e6ca5
Delegated to: Tom Rini
Headers show

Commit Message

Masahiro Yamada Oct. 19, 2016, 5:39 a.m. UTC
Supporting shell-style wildcards for the --defconfigs option will be
useful to run the moveconfig tool against a specific platform.  For
example, "uniphier*" in the file passed by --defconfigs option will
be expanded to defconfig files that start with "uniphier".  This is
easier than listing out all defconfig files you are interested in.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v2:
  - Warn when a pattern does not match any defconfig.
    (suggested by Joe)

 tools/moveconfig.py | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

Comments

Joe Hershberger Oct. 19, 2016, 6:11 p.m. UTC | #1
On Wed, Oct 19, 2016 at 12:39 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Supporting shell-style wildcards for the --defconfigs option will be
> useful to run the moveconfig tool against a specific platform.  For
> example, "uniphier*" in the file passed by --defconfigs option will
> be expanded to defconfig files that start with "uniphier".  This is
> easier than listing out all defconfig files you are interested in.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Tom Rini Oct. 24, 2016, 3:24 p.m. UTC | #2
On Wed, Oct 19, 2016 at 02:39:54PM +0900, Masahiro Yamada wrote:

> Supporting shell-style wildcards for the --defconfigs option will be
> useful to run the moveconfig tool against a specific platform.  For
> example, "uniphier*" in the file passed by --defconfigs option will
> be expanded to defconfig files that start with "uniphier".  This is
> easier than listing out all defconfig files you are interested in.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/tools/moveconfig.py b/tools/moveconfig.py
index 87e2bb2..228d098 100755
--- a/tools/moveconfig.py
+++ b/tools/moveconfig.py
@@ -127,7 +127,8 @@  Available options
    standard commit message is used which may need to be edited.
 
  -d, --defconfigs
-  Specify a file containing a list of defconfigs to move
+  Specify a file containing a list of defconfigs to move.  The defconfig
+  files can be given with shell-style wildcards.
 
  -n, --dry-run
    Perform a trial run that does not make any changes.  It is useful to
@@ -180,6 +181,7 @@  import copy
 import difflib
 import filecmp
 import fnmatch
+import glob
 import multiprocessing
 import optparse
 import os
@@ -284,6 +286,24 @@  def get_make_cmd():
         sys.exit('GNU Make not found')
     return ret[0].rstrip()
 
+def get_matched_defconfigs(defconfigs_file):
+    """Get all the defconfig files that match the patterns in a file."""
+    defconfigs = []
+    for i, line in enumerate(open(defconfigs_file)):
+        line = line.strip()
+        if not line:
+            continue # skip blank lines silently
+        pattern = os.path.join('configs', line)
+        matched = glob.glob(pattern) + glob.glob(pattern + '_defconfig')
+        if not matched:
+            print >> sys.stderr, "warning: %s:%d: no defconfig matched '%s'" % \
+                                                 (defconfigs_file, i + 1, line)
+
+        defconfigs += matched
+
+    # use set() to drop multiple matching
+    return [ defconfig[len('configs') + 1:]  for defconfig in set(defconfigs) ]
+
 def get_all_defconfigs():
     """Get all the defconfig files under the configs/ directory."""
     defconfigs = []
@@ -1204,13 +1224,7 @@  def move_config(configs, options):
         reference_src_dir = None
 
     if options.defconfigs:
-        defconfigs = [line.strip() for line in open(options.defconfigs)]
-        for i, defconfig in enumerate(defconfigs):
-            if not defconfig.endswith('_defconfig'):
-                defconfigs[i] = defconfig + '_defconfig'
-            if not os.path.exists(os.path.join('configs', defconfigs[i])):
-                sys.exit('%s - defconfig does not exist. Stopping.' %
-                         defconfigs[i])
+        defconfigs = get_matched_defconfigs(options.defconfigs)
     else:
         defconfigs = get_all_defconfigs()