From patchwork Thu Apr 18 16:10:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88668 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 A15ED38708CC for ; Thu, 18 Apr 2024 16:11:15 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id D4B2138708A8 for ; Thu, 18 Apr 2024 16:10:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D4B2138708A8 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D4B2138708A8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713456646; cv=none; b=sLX5MemDf8T6IfEzvOgI1XmC4L/GZc14liUG3SeyeqozeGnKv0J2bUA4ZXS5OAtuf/EE1LNMLfoxg/z/9bLnTuIZONG8qYdvQD11sr0c2yYcRUB0gjDSAMlKC6QocLhLq4CgGB8L3AhbLpA1fzWcysFuJNUgs35TVCbxrLbZYG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713456646; c=relaxed/simple; bh=0BTz53ulBuq536RVTX9PhY3R4MyQFlP9qg9GW4rCXt0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=r10V23kjnS0sRPDp8fm4xwiq5AEeXkECYulT5Y4v/jwSe7NwKFTBH8UxxOvgMPx+kGygHnK/7n77A8BWMgZ5pwU6rPOpJlY+IbT/7HV98E4Gqop9J4DWkEJ5v1IY0dwS6MG7kRRPFSyP+sNnlG3s7Ql5nDujV5XTqqiE5+gE65Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-7c7f3f66d17so35217139f.0 for ; Thu, 18 Apr 2024 09:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1713456637; x=1714061437; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=X5ORZxDgsi6dv6Sz8YydaEoRRgD4i2cgYzuKj5wEzjQ=; b=S1MQDniccGm8Z/WkTwxJf6/hY4rMqNJlKnb+GpU73a5dz0Fl7EQK9AffnPq3f1SgkT AmHxzct/6yYSZd/lan28GvCiNS2czUa/TDnhrlyoAY3Lz92OPHXXE0qzZXyOxUE1M7gj z71vp7yK7ataycEO1L5xZvjvhpsiGV+DCiX439y11v1lCGy55YCItXEWshks4QtQYZ8q ncjQlOtTuriP9j2OHN9MhuOV8wqWeuXymi5AWNhhH9Jzw8tnd+goJE55q9/h4UAWmNFw hlcOgjOYfh6+88p78bUhAVKyEkj7zSAgMaj2ozPr61iR+/vCVWVKnSdlIxjDsdrEf8RE m5xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456637; x=1714061437; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X5ORZxDgsi6dv6Sz8YydaEoRRgD4i2cgYzuKj5wEzjQ=; b=PWnsDU5jOE5DbqT7yYf/mIrXkVVJjTjr8Z6AkhOk6iP5wqUhrEaL1ZlkxkKhg/sQ8y xbfpFRFFIdF/ANcAFTdWB87OG7BjsQQE4Jrg32UWUfDmOTK4XPEdySRsXA7dsO4vua4P EXs2ORifufH/uAKms87AWsxKTiRZbqQq7hW+2aqQYgm5NBPY7mZiwbKZ60G7nHAPDln2 g0a+qloR8/Ml9zAm14CJ+RdJqGXdzi29dDzo0jaTymcIShwwd1WVhfDL8V58aXFmxhsG c92YnDxJONDEbECIDBwuHIgm6H2EZ0U++t5Is64sV0VSTjb0dJ2A1FGXGcMJEUAZXFVP LUGg== X-Gm-Message-State: AOJu0YwkGg7UVjMTvpjykc/JXF5TAI9ciSZc3sGNkYRy2B7+PZQ9wGTz JmMWVx68TOEHLxeUbIxlQ6MVTG0U/vbmqHuuQLfh4sJoRqia2ZA8hjVgjm+QlXbF43hYm4EJxmk = X-Google-Smtp-Source: AGHT+IEnTb1e31QdMjJTo2vd+X/BUgYp4rC7qzSsAHdgA+r6g898Kie2A36T6Tmju4xPFXK/f/q2hw== X-Received: by 2002:a05:6602:256e:b0:7d5:be5b:c737 with SMTP id dj14-20020a056602256e00b007d5be5bc737mr4551489iob.4.1713456636937; Thu, 18 Apr 2024 09:10:36 -0700 (PDT) Received: from localhost.localdomain (97-122-82-115.hlrn.qwest.net. [97.122.82.115]) by smtp.gmail.com with ESMTPSA id he11-20020a0566386d0b00b00484b49ea932sm266393jab.147.2024.04.18.09.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:10:36 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add even more pre-commit hooks Date: Thu, 18 Apr 2024 10:10:30 -0600 Message-ID: <20240418161030.874533-1-tromey@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This adds pre-commit hooks to run gdbarch.py and make-target-delegates.py. They should be triggered when the appropriate input files are modified. This patch includes some minor hacks to the scripts so that they will continue to work if run from the root directory of the source tree. --- .pre-commit-config.yaml | 14 ++++++++++++++ gdb/gdbarch.py | 14 +++++++++----- gdb/make-target-delegates.py | 5 +++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8721dac678b..b35b53fecb1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,3 +22,17 @@ repos: - id: isort types_or: [file] files: 'gdb/.*\.py(\.in)?$' + - repo: local + hooks: + - id: make-target-delegates + name: make-target-delegates + language: python + entry: gdb/make-target-delegates.py + files: '^gdb/(make-target-delegates\.py|target\.h)$' + - repo: local + hooks: + - id: gdbarch + name: gdbarch + language: python + entry: gdb/gdbarch.py + files: '^gdb/gdbarch.*\.py$' diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py index 4b4db667ca4..df8dc442999 100755 --- a/gdb/gdbarch.py +++ b/gdb/gdbarch.py @@ -19,6 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os import textwrap # gdbarch_components is imported only for its side-effect of filling @@ -33,11 +34,6 @@ def indentation(n_columns: int): return "\t" * (n_columns // 8) + " " * (n_columns % 8) -copyright = gdbcopyright.copyright( - "gdbarch.py", "Dynamic architecture support for GDB, the GNU debugger." -) - - def info(c: Component): "Filter function to only allow Info components." return type(c) is Info @@ -48,6 +44,14 @@ def not_info(c: Component): return type(c) is not Info +# Maybe we're being run from the pre-commit hook. +if not os.path.exists("gdbarch.h") and os.path.exists("gdb/gdbarch.h"): + os.chdir("gdb") + +copyright = gdbcopyright.copyright( + "gdbarch.py", "Dynamic architecture support for GDB, the GNU debugger." +) + with open("gdbarch-gen.h", "w") as f: print(copyright, file=f) print(file=f) diff --git a/gdb/make-target-delegates.py b/gdb/make-target-delegates.py index 1893fc63ca8..f05d374861b 100755 --- a/gdb/make-target-delegates.py +++ b/gdb/make-target-delegates.py @@ -20,6 +20,7 @@ # Usage: # make-target-delegates.py +import os import re from typing import Dict, List, TextIO @@ -341,6 +342,10 @@ def print_class( delegators: List[str] = [] entries: Dict[str, Entry] = {} +# Maybe we're being run from the pre-commit hook. +if not os.path.exists("target.h") and os.path.exists("gdb/target.h"): + os.chdir("gdb") + for current_line in scan_target_h(): # See comments in scan_target_h. Here we strip away the leading # and trailing whitespace.