From patchwork Sun Jul 24 14:17:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 72660 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp720529qga; Sun, 24 Jul 2016 07:18:28 -0700 (PDT) X-Received: by 10.28.6.202 with SMTP id 193mr15704477wmg.53.1469369908247; Sun, 24 Jul 2016 07:18:28 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id d70si19908568wmd.1.2016.07.24.07.18.27; Sun, 24 Jul 2016 07:18:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0BF0CA75DC; Sun, 24 Jul 2016 16:18:27 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8FwSUKFnGtpc; Sun, 24 Jul 2016 16:18:26 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8192DA75B4; Sun, 24 Jul 2016 16:18:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E4785A7581 for ; Sun, 24 Jul 2016 16:18:21 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kVzyEHCuRe7J for ; Sun, 24 Jul 2016 16:18:21 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by theia.denx.de (Postfix) with ESMTPS id 3A8C7A75C2 for ; Sun, 24 Jul 2016 16:18:17 +0200 (CEST) Received: from grover.sesame (FL1-119-242-215-193.osk.mesh.ad.jp [119.242.215.193]) (authenticated) by conuserg-08.nifty.com with ESMTP id u6OEHflO008919; Sun, 24 Jul 2016 23:17:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com u6OEHflO008919 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1469369866; bh=sNSOFcW6hyfSBy2iOsXoQQVyFbMQZyG5t4AqrpH3Gd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=So4q4T3Kyh3WYjUtXXmB/h+/vh0DS/BVksmiqtp4Kuv/Ffhf9CyUt4OAZ04cKUhGj SOm0T5pR8+R2cMdkipILpbUFSzLfXOGo0lD8KfZ6RIf61hjseO5temotKLzA1tr8XK o846dYQrHMEmWYKD0f2fbVUBR9ogzxUgQrcEfA7I4CtL9fIWEYZGaYZwF+yg0HK6A8 SevRsIFHVM36tiPPJho7mf5ReF4D08qOQ/toGeDekyAfmf8q6/C/giof6u0KeculYr 2XTOqtCR/inVKcaV3/eNAHO5haS37YcbB/yxNPu2REGSiNSXtYMvtYFhlZBj6Xbfrq QvyIK16VVUS6A== X-Nifty-SrcIP: [119.242.215.193] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Sun, 24 Jul 2016 23:17:36 +0900 Message-Id: <1469369859-14277-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469369859-14277-1-git-send-email-yamada.masahiro@socionext.com> References: <1469369859-14277-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini , Joe Hershberger Subject: [U-Boot] [PATCH 1/4] tools: moveconfig: trim garbage lines after header cleanups X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The tools/moveconfig.py has a feature to cleanup #define/#undef's of moved config options, but I want this tool to do a better job. For example, when we are moving CONFIG_FOO and its define is surrounded by #ifdef ... #endif, like follows: #ifdef CONFIG_BAR # define CONFIG_FOO #endif The header cleanup will leave empty #ifdef ... #endif: #ifdef CONFIG_BAR #endif Likewise, if a define line between two blank lines #define CONFIG_FOO --- tools/moveconfig.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/tools/moveconfig.py b/tools/moveconfig.py index d362923..7d018e4 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -160,6 +160,7 @@ To see the complete list of supported options, run """ +import copy import filecmp import fnmatch import multiprocessing @@ -319,6 +320,41 @@ def update_cross_compile(color_enabled): CROSS_COMPILE[arch] = cross_compile +def extend_matched_lines(lines, matched, pre_pattern, post_pattern, extend_pre, + extend_post): + """Extend matched lines if desired patterns are found before/after already + matched lines. + + Arguments: + lines: A list of lines handled. + matched: A list of line numbers that have been already matched. + (will be updated by this function) + pre_pattern: Regular expression that should be matched as preamble. + post_pattern: Regular expression that should be matched as postamble. + extend_pre: Add the line number of matched preamble to the matched list. + extend_post: 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 + if pre_pattern.search(lines[i - 1]) and post_pattern.search(lines[j]): + if extend_pre: + extended_matched.append(i - 1) + if extend_post: + extended_matched.append(j) + + matched += extended_matched + matched.sort() + def cleanup_one_header(header_path, patterns, dry_run): """Clean regex-matched lines away from a file. @@ -334,13 +370,35 @@ def cleanup_one_header(header_path, patterns, dry_run): matched = [] for i, line in enumerate(lines): for pattern in patterns: - m = pattern.search(line) - if m: - print '%s: %s: %s' % (header_path, i + 1, line), + if pattern.search(line): matched.append(i) break - if dry_run or not matched: + if not matched: + return + + # remove empty #ifdef ... #endif, successive blank lines + pattern_ifdef = re.compile(r'#\s*if(def|ndef)?\s') + pattern_endif = re.compile(r'#\s*endif\s') + pattern_blank = re.compile(r'^\s*$') + + while True: + old_matched = copy.copy(matched) + extend_matched_lines(lines, matched, pattern_ifdef, pattern_endif, + True, True) + extend_matched_lines(lines, matched, pattern_ifdef, pattern_blank, + False, True) + extend_matched_lines(lines, matched, pattern_blank, pattern_endif, + True, False) + extend_matched_lines(lines, matched, pattern_blank, pattern_blank, + True, False) + if matched == old_matched: + break + + for i in matched: + print '%s: %s: %s' % (header_path, i + 1, lines[i]), + + if dry_run: return with open(header_path, 'w') as f: