From patchwork Wed Jan 25 20:06:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 63686 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A2A7385B528 for ; Wed, 25 Jan 2023 20:06:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A2A7385B528 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674677211; bh=ApnLW56GpbBVlqCApDFwhdWUYGQDK7uwWMwxrFja7wI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=a72upkrcvdlaCABLI93olPKyXrmjvfl6R7XPDT6ALfxtr+Q7ekYIBe8edXS+O2ybn 1rNEvFPjusMCe3fH5LS6rL4Kzh3X66+3sX5kLZ/1M43vRwQfnO/iZs3xPbigT5nfS2 lj1lKu1RoTYheV1a0M4akygz26GLEvpvrdvyC1kQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id E52F23858D28 for ; Wed, 25 Jan 2023 20:06:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E52F23858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2AA4A21CE2; Wed, 25 Jan 2023 20:06:27 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1344913A06; Wed, 25 Jan 2023 20:06:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GGaDA8OL0WPmeAAAMHmgww (envelope-from ); Wed, 25 Jan 2023 20:06:27 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 1/3] [gdb/contrib] Add refactor.py Date: Wed, 25 Jan 2023 21:06:24 +0100 Message-Id: <20230125200626.29340-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230125200626.29340-1-tdevries@suse.de> References: <20230125200626.29340-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Add a refactoring script gdb/contrib/refactor.py that takes a transformation script as argument, for instance a script gdb/contrib/transform.py, like so: ... $ ./gdb/contrib/refactor.py transform ... --- gdb/contrib/refactor.py | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 gdb/contrib/refactor.py diff --git a/gdb/contrib/refactor.py b/gdb/contrib/refactor.py new file mode 100755 index 00000000000..fe2fa019051 --- /dev/null +++ b/gdb/contrib/refactor.py @@ -0,0 +1,73 @@ +#! /usr/bin/env python3 + +# Copyright (C) 2022 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +import sys +import re + +transform_file = sys.argv[1] +transform_file = re.sub(r"\.py$", r"", transform_file) + +transformation = __import__(transform_file) + +# Define scope of refactoring. + +# Sources. +#dirs = ["gdb", "gdbserver", "gdbsupport"] +#avoid_dir = "/testsuite/" +#exts = [".c", ".cc", ".h"] + +# Testsuite. +#dirs = ["gdb/testsuite"] +#avoid_dir = None +#exts = [".exp"] + +# In transformation file. +dirs=transformation.dirs +avoid_dir=transformation.avoid_dir +exts=transformation.exts + +def handle_file(filename): + file = open(filename, 'r+') + data = file.read() + file.close() + + transformation.have_match = False + data = transformation.transform(data) + if transformation.have_match: + file = open(filename, 'w') + file.write(data) + file.close() + +def main(): + for dir in dirs: + for walk_root, walk_dirs, walk_files in os.walk(dir): + for file in walk_files: + full = os.path.join(walk_root, file) + if avoid_dir != None and avoid_dir in full: + continue + found = False + for ext in exts: + if file.endswith(ext): + found = True + break + if found: + handle_file(full) + +main()