Hi Chris,

On Wed, 15 May 2019 at 01:54, Chris Packham <judge.pack...@gmail.com> wrote:
>
> On Wed, May 15, 2019 at 9:54 AM Simon Glass <s...@chromium.org> wrote:
> >
> > 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 <s...@chromium.org>
> > ---
>
> Did you mean to include this file in the series. It seems unrelated to
> the other patman/binman changes.

Well I originally had it as part of the series to drop/mangle boards
that have not been migrated. But I decided it might fit better here
since it was Python.

I'll send it again as a separate tool.

>
> >
> >  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
>
> Is there any specific advantage of using patman/command.py instead of
> python's subprocess module directly?

Just for consistency with the rest of the code.

The only difference really is that 'command' allows output to be
collected while the command is running rather than hanging the process
until the command exits. In this case the difference doesn't matter
though. since the command is pretty quick and we just wait for all the
output to come.

So, mostly just for consistency.

>
> > +    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
>
> Couple of typos s/Expannd/Expand/ and s/MAINTAINRERS/MAINTAINERS/
>

OK will fix, thanks.

Regards,
Simon
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to