All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 02/11] Add a simple script to remove boards
Date: Sat, 11 May 2019 13:23:47 -0600	[thread overview]
Message-ID: <20190511192356.96651-3-sjg@chromium.org> (raw)
In-Reply-To: <20190511192356.96651-1-sjg@chromium.org>

This script attempts to create a git commit which removes a single board.
It is quite fallible and everything it does needs checking. But it can
help speed up the process.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/rmboard.py | 150 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 150 insertions(+)
 create mode 100755 tools/rmboard.py

diff --git a/tools/rmboard.py b/tools/rmboard.py
new file mode 100755
index 0000000000..17952f795d
--- /dev/null
+++ b/tools/rmboard.py
@@ -0,0 +1,150 @@
+#! /usr/bin/python
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2019 Google LLC
+#
+
+"""
+Script to remove boards
+
+Usage:
+   rmboard.py <board_name>...
+
+A single commit is created for each board removed.
+
+Some boards may depend on files provided by another and this will cause
+problems, generally the removal of files which should not be removed.
+
+This script works by:
+    - Looking through the MAINTAINERS files which mention a board to find out
+        what files the board uses
+    - Looking through the Kconfig files which mention a board to find one that
+        needs to have material removed
+
+Search for ## to update the commit message manually.
+"""
+
+from __future__ import print_function
+
+import glob
+import os
+import re
+import sys
+
+# Bring in the patman libraries
+our_path = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(our_path, '../tools/patman'))
+
+import command
+
+def rm_kconfig_include(path):
+    """Remove a path from Kconfig files
+
+    This function finds the given path in a 'source' statement in a Kconfig
+    file and removes that line from the file. This is needed because the path
+    is going to be removed, so any reference to it will cause a problem with
+    Kconfig parsing.
+
+    The changes are made locally and then added to the git staging area.
+
+    Args:
+        path: Path to search for and remove
+    """
+    cmd = ['git', 'grep', path]
+    stdout = command.RunPipe([cmd], capture=True, raise_on_error=False).stdout
+    if not stdout:
+        return
+    fname = stdout.split(':')[0]
+
+    print("Fixing up '%s' to remove reference to '%s'" % (fname, path))
+    cmd = ['sed', '-i', '\|%s|d' % path, fname]
+    stdout = command.RunPipe([cmd], capture=True).stdout
+
+    cmd = ['git', 'add', fname]
+    stdout = command.RunPipe([cmd], capture=True).stdout
+
+def rm_board(board):
+    """Create a commit which removes a single board
+
+    This looks up the MAINTAINERS file to file files that need to be removed,
+    then removes pieces from the Kconfig files that mention the board.
+
+
+    Args:
+        board: Board name to remove
+    """
+
+    # Find all MAINTAINERS and Kconfig files which mention the board
+    cmd = ['git', 'grep', '-l', board]
+    stdout = command.RunPipe([cmd], capture=True).stdout
+    maintain = []
+    kconfig = []
+    for line in stdout.splitlines():
+        line = line.strip()
+        if 'MAINTAINERS' in line:
+            if line not in maintain:
+                maintain.append(line)
+        elif 'Kconfig' in line:
+            kconfig.append(line)
+    paths = []
+    cc = []
+
+    # Look through the MAINTAINERS file to find things to remove
+    for fname in maintain:
+        with open(fname) as fd:
+            for line in fd:
+                line = line.strip()
+                fields = re.split('[ \t]', line, 1)
+                if len(fields) == 2:
+                    if fields[0] == 'M:':
+                        cc.append(fields[1])
+                    elif fields[0] == 'F:':
+                        paths.append(fields[1].strip())
+
+    # Expannd any wildcards in the MAINTAINRERS file
+    real = []
+    for path in paths:
+        if path[-1] == '/':
+            path = path[:-1]
+        if '*' in path:
+            globbed = glob.glob(path)
+            print("Expanded '%s' to '%s'" % (path, globbed))
+            real += globbed
+        else:
+            real.append(path)
+
+    # Search for Kconfig files in the resulting list. Remove any 'source' lines
+    # which reference Kconfig files we want to remove
+    for path in real:
+        cmd = ['find', path]
+        stdout = (command.RunPipe([cmd], capture=True, raise_on_error=False).
+                  stdout)
+        for fname in stdout.splitlines():
+            if fname.endswith('Kconfig'):
+                rm_kconfig_include(fname)
+
+    # Remove unwanted files
+    cmd = ['git', 'rm', '-r'] + real
+    stdout = command.RunPipe([cmd], capture=True).stdout
+
+    ## Change the messages as needed
+    msg = '''arm: Remove %s board
+
+This board has not been converted to CONFIG_DM_MMC by the deadline.
+Remove it.
+
+''' % board
+    for name in cc:
+        msg += 'Patch-cc: %s\n' % name
+
+    # Create the commit
+    cmd = ['git', 'commit', '-s', '-m', msg]
+    stdout = command.RunPipe([cmd], capture=True).stdout
+
+    # Check if the board is mentioned anywhere else. The user will need to deal
+    # with this
+    cmd = ['git', 'grep', '-il', board]
+    print(command.RunPipe([cmd], capture=True, raise_on_error=False).stdout)
+    print(' '.join(cmd))
+
+for board in sys.argv[1:]:
+    rm_board(board)
-- 
2.21.0.1020.gf2820cf01a-goog

  parent reply	other threads:[~2019-05-11 19:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-11 19:23 [U-Boot] [PATCH 00/11] dm: Removal of some boards due to DM_MMC deadline Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 01/11] patman: Update cros_subprocess to use bytearray Simon Glass
2019-05-11 19:23 ` Simon Glass [this message]
2019-05-11 19:44   ` [U-Boot] [PATCH 02/11] Add a simple script to remove boards Tom Rini
2019-05-12 19:03     ` Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 03/11] solidrun: Fix soldrun typo Simon Glass
2019-05-12 10:00   ` Stefan Roese
2019-05-11 19:23 ` [U-Boot] [PATCH 04/11] atmel: gurnard: Complete DM migration Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 05/11] bubblegum_96: " Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 06/11] arm: Remove s32v234evb board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 07/11] arm: Remove ls1088ardb_sdcard_qspi_SECURE_BOOT board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 08/11] arm: Remove ls1046ardb_sdcard_SECURE_BOOT board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 09/11] arm: Remove ls1043ardb_sdcard_SECURE_BOOT board Simon Glass
2019-05-11 19:23 ` [U-Boot] [PATCH 10/11] evb-ast2500: Enable CONFIG_DM_MMC Simon Glass
2019-05-13 16:39   ` Maxim Sloyko
2019-05-11 19:23 ` [U-Boot] [PATCH 11/11] vf610twr/_nand: " Simon Glass
2019-05-11 19:36 ` [U-Boot] [PATCH 00/11] dm: Removal of some boards due to DM_MMC deadline Tom Rini
2019-05-12 19:03   ` Simon Glass
2019-05-12 20:08     ` Simon Glass
2019-05-14 14:08       ` Tom Rini
2019-05-14 14:11     ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190511192356.96651-3-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.