From patchwork Thu Aug 10 16:31:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1819951 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=MYlgyR7N; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMCCb2HWpz1yfB for ; Fri, 11 Aug 2023 02:33:15 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A094B86878; Thu, 10 Aug 2023 18:32:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MYlgyR7N"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 64326868CE; Thu, 10 Aug 2023 18:32:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 269A3866B5 for ; Thu, 10 Aug 2023 18:32:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3493862cfb1so4027165ab.1 for ; Thu, 10 Aug 2023 09:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691685143; x=1692289943; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t79fUuIABjU6Jie7AhgmIUBL8DYS+7Od7VWJ+xTzMT4=; b=MYlgyR7NWog/WD8yFI4AArcMSJWDOzI5fgGzYegI1KSMNR2uBYPmZxUvrYXzrX02j8 2UivvGE3R0fYtLfIjPcvVogvElqik/N4BNR4H8T7wklJ9p7iPeNiZ1DXJB7tHq+e1gYb nX6MCEIHkXfDkTusJ6DtZy7Ubkp7KnhpoyZP4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691685143; x=1692289943; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t79fUuIABjU6Jie7AhgmIUBL8DYS+7Od7VWJ+xTzMT4=; b=FfykJwoE4LAars6p+EcBb3Up8rRe3jzvGqfZW0ViT6HdG2pEdP+6vQpZrNMd+FrB7g o7HrRKWKsHxvYzmMNadzIHR7szgUf3zFvSrc4T2b7CYU+71ZvbhlIlS08wCpJV5pw1x8 91iNBhRuMkqDmy+ub69zLWHsK36bJSrSbmJ+BYG8Loya41U/tjBO+rKwlJuHK5y3SODp YjsKaEpXhym+iVrgxo7czZxrB4l/OTJ4Gedwz7QW6HCMmhaoXKBI3S2LD7jEpf44Vfvp FGTHYpYfvL4TZzkwMnM42hB8qjMmG6alTE+Fc8cljClXAMBsl7Ru2QmKLpftzrOclilB VIhA== X-Gm-Message-State: AOJu0YzYxUeHGPPFT/rd+ich7gkv4Pco0emhJ6eIfJ+pUHlIlg7tlOgg draZ2WToBHHTlNO+OlryKIRef3EgK6kijFIg2xA= X-Google-Smtp-Source: AGHT+IFkFROUhaG1uzZCAXrvhHdD00c/EXoBs8iB46S5TJ58ovxQgPScepLllYmAsYq7+LxkkTtcbA== X-Received: by 2002:a05:6e02:d42:b0:349:76c3:e8af with SMTP id h2-20020a056e020d4200b0034976c3e8afmr2874072ilj.16.1691685143699; Thu, 10 Aug 2023 09:32:23 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:e0a2:950d:33f0:fddc]) by smtp.gmail.com with ESMTPSA id u21-20020a02aa95000000b0042b28813816sm487309jai.14.2023.08.10.09.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:32:23 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Masahiro Yamada , Simon Glass Subject: [PATCH 05/28] moveconfig: Drop unused cleanup options Date: Thu, 10 Aug 2023 10:31:37 -0600 Message-ID: <20230810163212.2368374-6-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230810163212.2368374-1-sjg@chromium.org> References: <20230810163212.2368374-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Cleaning up the README and config.h files are not needed now, since we don't have any CONFIG options to convert. Drop this code. Signed-off-by: Simon Glass --- tools/moveconfig.py | 254 +------------------------------------------- 1 file changed, 2 insertions(+), 252 deletions(-) diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 70dc6a4d144..767aee39a79 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -13,8 +13,6 @@ See doc/develop/moveconfig.rst for documentation. from argparse import ArgumentParser import collections from contextlib import ExitStack -import copy -import difflib import doctest import filecmp import fnmatch @@ -205,102 +203,6 @@ def color_text(color_enabled, color, string): for s in string.split('\n') ]) return string -def show_diff(alines, blines, file_path, color_enabled): - """Show unidified diff. - - Args: - alines (list of str): A list of lines (before) - blines (list of str): A list of lines (after) - file_path (str): Path to the file - color_enabled (bool): Display the diff in color - """ - diff = difflib.unified_diff(alines, blines, - fromfile=os.path.join('a', file_path), - tofile=os.path.join('b', file_path)) - - for line in diff: - if line.startswith('-') and not line.startswith('--'): - print(color_text(color_enabled, COLOR_RED, line)) - elif line.startswith('+') and not line.startswith('++'): - print(color_text(color_enabled, COLOR_GREEN, line)) - else: - print(line) - -def extend_matched_lines(lines, matched, pre_patterns, post_patterns, - extend_pre, extend_post): - """Extend matched lines if desired patterns are found before/after already - matched lines. - - Args: - lines (list of str): list of lines handled. - matched (list of int): list of line numbers that have been already - matched (will be updated by this function) - pre_patterns (list of re.Pattern): list of regular expression that should - be matched as preamble - post_patterns (list of re.Pattern): list of regular expression that should - be matched as postamble - extend_pre (bool): Add the line number of matched preamble to the matched - list - extend_post (bool): Add the line number of matched postamble to the - matched list - """ - extended_matched = [] - - j = matched[0] - - for i in matched: - if i == 0 or i < j: - continue - j = i - while j in matched: - j += 1 - if j >= len(lines): - break - - for pat in pre_patterns: - if pat.search(lines[i - 1]): - break - else: - # not matched - continue - - for pat in post_patterns: - if pat.search(lines[j]): - break - else: - # not matched - continue - - if extend_pre: - extended_matched.append(i - 1) - if extend_post: - extended_matched.append(j) - - matched += extended_matched - matched.sort() - -def confirm(args, prompt): - """Ask the user to confirm something - - Args: - args (Namespace ): program arguments - - Returns: - bool: True to confirm, False to cancel/stop - """ - if not args.yes: - while True: - choice = input(f'{prompt} [y/n]: ') - choice = choice.lower() - print(choice) - if choice in ('y', 'n'): - break - - if choice == 'n': - return False - - return True - def write_file(fname, data): """Write data to a file @@ -344,155 +246,6 @@ def read_file(fname, as_lines=True, skip_unicode=False): print("Failed on file %s': %s" % (fname, e)) return None -def cleanup_empty_blocks(header_path, args): - """Clean up empty conditional blocks - - Args: - header_path (str): path to the cleaned file. - args (Namespace): program arguments - """ - pattern = re.compile(r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*', flags=re.M) - data = read_file(header_path, as_lines=False, skip_unicode=True) - if data is None: - return - - new_data = pattern.sub('\n', data) - - show_diff(data.splitlines(True), new_data.splitlines(True), header_path, - args.color) - - if args.dry_run: - return - - if new_data != data: - write_file(header_path, new_data) - -def cleanup_one_header(header_path, patterns, args): - """Clean regex-matched lines away from a file. - - Args: - header_path: path to the cleaned file. - patterns: list of regex patterns. Any lines matching to these - patterns are deleted. - args (Namespace): program arguments - """ - lines = read_file(header_path, skip_unicode=True) - if lines is None: - return - - matched = [] - for i, line in enumerate(lines): - if i - 1 in matched and lines[i - 1].endswith('\\'): - matched.append(i) - continue - for pattern in patterns: - if pattern.search(line): - matched.append(i) - break - - if not matched: - return - - # remove empty #ifdef ... #endif, successive blank lines - pattern_if = re.compile(r'#\s*if(def|ndef)?\b') # #if, #ifdef, #ifndef - pattern_elif = re.compile(r'#\s*el(if|se)\b') # #elif, #else - pattern_endif = re.compile(r'#\s*endif\b') # #endif - pattern_blank = re.compile(r'^\s*$') # empty line - - while True: - old_matched = copy.copy(matched) - extend_matched_lines(lines, matched, [pattern_if], - [pattern_endif], True, True) - extend_matched_lines(lines, matched, [pattern_elif], - [pattern_elif, pattern_endif], True, False) - extend_matched_lines(lines, matched, [pattern_if, pattern_elif], - [pattern_blank], False, True) - extend_matched_lines(lines, matched, [pattern_blank], - [pattern_elif, pattern_endif], True, False) - extend_matched_lines(lines, matched, [pattern_blank], - [pattern_blank], True, False) - if matched == old_matched: - break - - tolines = copy.copy(lines) - - for i in reversed(matched): - tolines.pop(i) - - show_diff(lines, tolines, header_path, args.color) - - if args.dry_run: - return - - write_file(header_path, tolines) - -def cleanup_headers(configs, args): - """Delete config defines from board headers. - - Args: - configs: A list of CONFIGs to remove. - args (Namespace): program arguments - """ - if not confirm(args, 'Clean up headers?'): - return - - patterns = [] - for config in configs: - patterns.append(re.compile(r'#\s*define\s+%s\b' % config)) - patterns.append(re.compile(r'#\s*undef\s+%s\b' % config)) - - for dir in 'include', 'arch', 'board': - for (dirpath, dirnames, filenames) in os.walk(dir): - if dirpath == os.path.join('include', 'generated'): - continue - for filename in filenames: - if not filename.endswith(('~', '.dts', '.dtsi', '.bin', - '.elf','.aml','.dat')): - header_path = os.path.join(dirpath, filename) - # This file contains UTF-16 data and no CONFIG symbols - if header_path == 'include/video_font_data.h': - continue - cleanup_one_header(header_path, patterns, args) - cleanup_empty_blocks(header_path, args) - -def find_matching(patterns, line): - for pat in patterns: - if pat.search(line): - return True - return False - -def cleanup_readme(configs, args): - """Delete config description in README - - Args: - configs: A list of CONFIGs to remove. - args (Namespace): program arguments - """ - if not confirm(args, 'Clean up README?'): - return - - patterns = [] - for config in configs: - patterns.append(re.compile(r'^\s+%s' % config)) - - lines = read_file('README') - - found = False - newlines = [] - for line in lines: - if not found: - found = find_matching(patterns, line) - if found: - continue - - if found and re.search(r'^\s+CONFIG', line): - found = False - - if not found: - newlines.append(line) - - write_file('README', newlines) - def try_expand(line): """If value looks like an expression, try expanding it Otherwise just return the existing value @@ -2024,6 +1777,7 @@ doc/develop/moveconfig.rst for documentation.''' do_find_config(configs) return + # We are either building the database or forcing a sync of defconfigs config_db = {} db_queue = queue.Queue() t = DatabaseThread(config_db, db_queue) @@ -2035,13 +1789,9 @@ doc/develop/moveconfig.rst for documentation.''' toolchains = toolchain.Toolchains() toolchains.GetSettings() toolchains.Scan(verbose=False) - move_config(toolchains, configs, args, db_queue) + move_config(toolchains, [], args, db_queue) db_queue.join() - if configs: - cleanup_headers(configs, args) - cleanup_readme(configs, args) - if args.build_db: with open(CONFIG_DATABASE, 'w', encoding='utf-8') as fd: for defconfig, configs in config_db.items():