From patchwork Sat Jan 29 15:22:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 1586181 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=GPnLMEXj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JmJ3m56Z2z9sSs for ; Sun, 30 Jan 2022 02:22:42 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9D7D583563; Sat, 29 Jan 2022 16:22:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GPnLMEXj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6D3658366A; Sat, 29 Jan 2022 16:22:26 +0100 (CET) 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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (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 BADF6820FE for ; Sat, 29 Jan 2022 16:22:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ed1-x52f.google.com with SMTP id w14so16657997edd.10 for ; Sat, 29 Jan 2022 07:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=98wqY18OpStZyaKPCUbuMlrspch9FV6+vK/DrTo1aFU=; b=GPnLMEXjes59yNGE6kF+wzelkzEVlX+dNSM7bSAQKDvWw5Cx1ptnQomn1yFToz6DJN kpPpehdhHYOdfZwHSYf+QugnDRHnnHlua1dP6La37FNnQydrkGVBTR07s391yTmVqXIB 0PLemlOjlzoEn/snOhAIvHTbduvEd+sLAXFshjYIJViKJvaWgPDOgQeD61eGZRNgj49W WRimGhBlKh58Zp9idzmuy+CqriBAVrRh2qQT27clL2RZlxp1NGzOR7gaIppmrx2viR26 NTyJtp1bIdng8oQ++OzUZwB/G4HlB0SkWiSeMeCGJiVMsQaEwn0GQgkX9PzFgp8krjBn IgVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=98wqY18OpStZyaKPCUbuMlrspch9FV6+vK/DrTo1aFU=; b=RUGGChllgWO9DLs6KlpTTiGaJH+YnRTu9X+dMlsYcay7N+Ur26vn7WSfTZV0mmcnIv JlGHEULz1Pe496GES2v6boX7X9/o1RYISSppXU+NBThDHnRLMzgPxY9Eh9re/JSus4iW UrRuHSTG9d2ewJewz7suDDoB/848cizws2+fpuL9M8G6u1XQi0lhTXqXZ7slK8ZBO7XZ +En9fqCQEzs3oMKlHvcQapPRP7BXJx3DL4Ig4lzjX0NkorUcgUl3fJPqbmPwjzQTITVx v5ilnPsk7BSPRsrs9nTUhIuY7qddUXGMNKvIPFSBbM0LjSv+ePsTTHFk1+Y43q2dfSc2 Hrhw== X-Gm-Message-State: AOAM531FPLC0wmgwNcey/dDOUwGwXcfl6Hgvc+dsjvhI3InziAXQWsVk VNYdtvlBw8xWveatXCQmNE5mzxEsklg= X-Google-Smtp-Source: ABdhPJy9oRT/nsMeGa8RL+axFZo9F0bqhV/XC3NcE0iOQ3h778YZj1VNPH/LuwEroHkYD7bAebYZrQ== X-Received: by 2002:aa7:d412:: with SMTP id z18mr2428209edq.231.1643469742075; Sat, 29 Jan 2022 07:22:22 -0800 (PST) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id a27sm14663505edj.17.2022.01.29.07.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jan 2022 07:22:21 -0800 (PST) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Masahiro Yamada , Simon Glass , Trevor Woerner , Heinrich Schuchardt , Alper Nebi Yasak Subject: [PATCH] moveconfig: Fix code relying on now-stripped newline characters Date: Sat, 29 Jan 2022 18:22:08 +0300 Message-Id: <20220129152209.14850-1-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.34.1 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.5 at phobos.denx.de X-Virus-Status: Clean Commit 37f815cad07d ("moveconfig: Use a function to read files") adds a helper function that can read a file as lines, but strips the newline characters. This change broke parts of moveconfig code that relied on their existence, resulting in a few issues: Configs that are defined as empty aren't removed from header files (e.g. "#define CONFIG_REMAKE_ELF"). Make regex patterns use '\b' to match word boundaries instead of '\W' (which matched the newlines) so these lines still match and get removed. All changes in defconfig are considered removed by savedefconfig even if they weren't, and line continuations in the headers aren't recognized and removed properly, because their checks explicitly look for a newline character. Remove the character from both comparisons. The printed diff of header files is wrongly formatted and raises an IndexError if a blank line was removed. Let print() print the new lines, and use size-independent ways to check strings to fix the diff output. Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass Tested-by: Simon Glass --- tools/moveconfig.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 35fe6710d70a..1bcf58caf14c 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -205,12 +205,12 @@ def show_diff(alines, blines, file_path, color_enabled): tofile=os.path.join('b', file_path)) for line in diff: - if line[0] == '-' and line[1] != '-': - print(color_text(color_enabled, COLOR_RED, line), end=' ') - elif line[0] == '+' and line[1] != '+': - print(color_text(color_enabled, COLOR_GREEN, line), end=' ') + 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, end=' ') + print(line) def extend_matched_lines(lines, matched, pre_patterns, post_patterns, extend_pre, extend_post): @@ -368,7 +368,7 @@ def cleanup_one_header(header_path, patterns, args): matched = [] for i, line in enumerate(lines): - if i - 1 in matched and lines[i - 1][-2:] == '\\\n': + if i - 1 in matched and lines[i - 1].endswith('\\'): matched.append(i) continue for pattern in patterns: @@ -380,9 +380,9 @@ def cleanup_one_header(header_path, patterns, args): return # remove empty #ifdef ... #endif, successive blank lines - pattern_if = re.compile(r'#\s*if(def|ndef)?\W') # #if, #ifdef, #ifndef - pattern_elif = re.compile(r'#\s*el(if|se)\W') # #elif, #else - pattern_endif = re.compile(r'#\s*endif\W') # #endif + 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: @@ -424,8 +424,8 @@ def cleanup_headers(configs, args): patterns = [] for config in configs: - patterns.append(re.compile(r'#\s*define\s+%s\W' % config)) - patterns.append(re.compile(r'#\s*undef\s+%s\W' % config)) + 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): @@ -451,7 +451,7 @@ def cleanup_one_extra_option(defconfig_path, configs, args): """ start = 'CONFIG_SYS_EXTRA_OPTIONS="' - end = '"\n' + end = '"' lines = read_file(defconfig_path) @@ -812,7 +812,7 @@ def check_defconfig(self): for (action, value) in self.results: if action != ACTION_MOVE: continue - if not value + '\n' in defconfig_lines: + if not value in defconfig_lines: log += color_text(self.args.color, COLOR_YELLOW, "'%s' was removed by savedefconfig.\n" % value)