From patchwork Tue Sep 1 20:27:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 142661 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C7A04BA799A for ; Tue, 1 Sep 2026 20:28:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C7A04BA799A Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=hfRLGK0Z; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Uo0fs5gG; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=mXs1SavB; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=24tCYa3E X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id D9E6A4BA2E35 for ; Tue, 1 Sep 2026 20:27:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9E6A4BA2E35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D9E6A4BA2E35 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788294473; cv=none; b=W7RvcdEqMAqkQo50bIm/gvDDDxp3OlwKAwBCLLcd9TpgU3wR1S5hZP39hkAc5Ilb+EqxfhyVTKNTySccov7tHapm7n6N922I4kkuR8QpmIms+R+4/FNIOZlficjNwYgUgD6PA4ye47ayBd8VqI5mn6rZG1xSTkwdP+xuw9KK9w8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788294473; c=relaxed/simple; bh=k6roZ6ykFgkE3SBq9u7dM9NcGT6GB91Xy/l+8r0IJTg=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=x+0jTMgpi8/EXHyf0go/1Vqc+7ydZ41C+0SoLmoqGN/HyIkkj1/B2wi/in5YYe3PhgzDcmfxnAueWwhAOnNWzLtFC5CEgc0t92XzUJ+Z6yhwZhDMfTOODoCSSuqLyqWKX2F03YmE1biNb2Hlvx2P9J71uoqyrds5vopW20r1/EQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=hfRLGK0Z; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Uo0fs5gG; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=mXs1SavB; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=24tCYa3E DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9E6A4BA2E35 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id 2FFF3221E3 for ; Tue, 1 Sep 2026 20:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788294467; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4ZhmdrIOHVV6zFuGqvTUXnbBOkvWS4mfo5CCWuEpqU0=; b=hfRLGK0ZL10CDySemaQ7bOEkv/t/jRexK1CA6jGoYYk8+5N4fhrhD8ag3dCn0xR7NwSiZQ hxwnHzi+/rTZOvElQusimT/H6iW0l5QdV3DABb1eeroWNUJWRiDnHqYfruMJGbxuAPemud cCoGL0Cd82qz0w+YfRgvRQ+F/D2x77A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788294467; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4ZhmdrIOHVV6zFuGqvTUXnbBOkvWS4mfo5CCWuEpqU0=; b=Uo0fs5gG2po51UZWrOFDFQU3BRg3JjYl3UX8EXz/G8yMJCleiIZho/Diyj0RPVCpdArk9o Vp0CYV2NEUDfnIAg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788294463; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4ZhmdrIOHVV6zFuGqvTUXnbBOkvWS4mfo5CCWuEpqU0=; b=mXs1SavB2eR4+cxUCTktZerEIQKvukq5YckdBXCNJ9ZJsCWG2e9eh7gIUyk4AxlYkNQc25 POHewxJIF/ERehTEwUw4X6LDnBFjbsYR9efRSmw640WX2YOwMouurz2vpvfTbAAOJhxirM mt+IrmCcg2T2OoxfoSa30ToG/B/EiZ4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788294463; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4ZhmdrIOHVV6zFuGqvTUXnbBOkvWS4mfo5CCWuEpqU0=; b=24tCYa3ENlKBUFkgzB/OJtsP+/2EjQfB3W3GzRy+Lm4lhmiOne3F91kVrcLHzvgr4NNyK2 vMGfeprJMr57wXDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id F1640136B2 for ; Tue, 1 Sep 2026 20:27:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id uC6zOD41l2qzUgAAD6G6ig (envelope-from ) for ; Tue, 01 Sep 2026 20:27:42 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 1/2] [pre-commit] Reject symlinks in check-file-mode Date: Tue, 1 Sep 2026 22:27:41 +0200 Message-ID: <20260901202742.320498-2-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260901202742.320498-1-tdevries@suse.de> References: <20260901202742.320498-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.993]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 In a recent commit I introduced two symlinks. After reading a bit more about it, I realized that this can be problematic on platforms without proper support for it [1]. Which is probably also the reason why there aren't any symlinks in the repo other than those two. Eliminate the symlinks, and extend check-file-mode to reject symlinks. While we're at it, move the existing check into a function, and improve comments and error message a bit. [1] https://gitforwindows.org/symbolic-links.html --- .pre-commit-config.yaml | 4 ++ gdb/contrib/check-file-mode.sh | 77 +++++++++++++++++++++++----------- gdbserver/.shellcheckrc | 4 +- gdbsupport/.shellcheckrc | 4 +- 4 files changed, 63 insertions(+), 26 deletions(-) mode change 120000 => 100644 gdbserver/.shellcheckrc mode change 120000 => 100644 gdbsupport/.shellcheckrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b4285e6c82..34d2cba40b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -151,6 +151,10 @@ repos: language: unsupported_script entry: gdb/contrib/check-file-mode.sh files: *gdb_files + # With the default types == [file], because types and types_or are + # and-ed, no symlinks will be selected, so we use types == [] instead. + types: [] + types_or: [file, symlink] - id: &id5 shellcheck name: *id5 files: '^(gdb|gdbsupport|gdbserver)/' diff --git a/gdb/contrib/check-file-mode.sh b/gdb/contrib/check-file-mode.sh index 5a9b0e89fbe..e9cfaf02ce4 100755 --- a/gdb/contrib/check-file-mode.sh +++ b/gdb/contrib/check-file-mode.sh @@ -17,30 +17,59 @@ set -e set -o pipefail -no_exec_files=() -for f in "$@"; do - case $f in - */*.py \ - | */*.sh \ - | */configure \ - | gdb/gstack-1.in \ - | gdb/gcore-1.in \ - | gdb/po/gdbtext \ - | gdb/make-init-c \ - | gdb/testsuite/lib/notty-wrap ) - continue - ;; - *) - no_exec_files=("${no_exec_files[@]}" "$f") - ;; - esac -done +# Flag files that are executable, but not meant to be executable. +check_exec () +{ + no_exec_files=() + for f in "$@"; do + case $f in + */*.py \ + | */*.sh ) + # Shell script or python. + continue + ;; + gdb/po/gdbtext \ + | gdb/make-init-c \ + | gdb/testsuite/lib/notty-wrap ) + # Shell script without .sh extension. + continue + ;; + */configure \ + | gdb/gstack-1.in \ + | gdb/gcore-1.in ) + # Used to generate shell script. + continue + ;; + *) + no_exec_files=("${no_exec_files[@]}" "$f") + ;; + esac + done -if [ ${#no_exec_files[@]} -eq 0 ]; then - exit 0 -fi + if [ ${#no_exec_files[@]} -eq 0 ]; then + return + fi -# Flag files that are executable, but not meant to be executable. + if ! git ls-files --stage -- "${no_exec_files[@]}" \ + | (! grep '^100755 '); then + echo "Found executable mode (100755) on file without .sh or .py" + echo "Please fix or add to exception list in $0" + exit 1 + fi +} + +# Flag symlinks. Symlinks are support by git, but can be problematic on +# platforms without proper support for it [1]. +# [1] https://gitforwindows.org/symbolic-links.html +check_symlinks () +{ + if ! git ls-files --stage -- "$@" \ + | (! grep '^120000 '); then + echo "Found symlink mode (120000)" + echo "Please replace by copy" + exit 1 + fi +} -git ls-files --stage -- "${no_exec_files[@]}" \ - | (! grep '^100755 ') +check_exec "$@" +check_symlinks "$@" diff --git a/gdbserver/.shellcheckrc b/gdbserver/.shellcheckrc deleted file mode 120000 index 2a49a004d21..00000000000 --- a/gdbserver/.shellcheckrc +++ /dev/null @@ -1 +0,0 @@ -../gdb/.shellcheckrc \ No newline at end of file diff --git a/gdbserver/.shellcheckrc b/gdbserver/.shellcheckrc new file mode 100644 index 00000000000..91b66edaf7a --- /dev/null +++ b/gdbserver/.shellcheckrc @@ -0,0 +1,3 @@ +# SC2002 was disabled by default in 0.11.0. Turn it on for +# compatibility with 0.10.0. +enable=useless-use-of-cat diff --git a/gdbsupport/.shellcheckrc b/gdbsupport/.shellcheckrc deleted file mode 120000 index 2a49a004d21..00000000000 --- a/gdbsupport/.shellcheckrc +++ /dev/null @@ -1 +0,0 @@ -../gdb/.shellcheckrc \ No newline at end of file diff --git a/gdbsupport/.shellcheckrc b/gdbsupport/.shellcheckrc new file mode 100644 index 00000000000..91b66edaf7a --- /dev/null +++ b/gdbsupport/.shellcheckrc @@ -0,0 +1,3 @@ +# SC2002 was disabled by default in 0.11.0. Turn it on for +# compatibility with 0.10.0. +enable=useless-use-of-cat From patchwork Tue Sep 1 20:27:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 142662 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13F4D4BA79A0 for ; Tue, 1 Sep 2026 20:29:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13F4D4BA79A0 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=WyAtciTK; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QuwuLG4B; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KCehBPxO; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=zavuQLyl X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id CEB454BA2E22 for ; Tue, 1 Sep 2026 20:27:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CEB454BA2E22 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CEB454BA2E22 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788294473; cv=none; b=P5pykPdC1fMjrrBwA8zAYKdp/7Vgf9CLSX/Em5l5aJApdQZrgZFuCBwU3Q6u8KhZX8CZNSA2nWn0ezy6duTrYowGaI6iO6ADJjwpqe1+vM+VGVV4ZzLGD9+6qhA2OzJeDgRmixdZ8Ne18cpNtU7GYC6E+mdE1TYv0VBwCipOFls= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788294473; c=relaxed/simple; bh=JNcqCAGAxKfu7iHLjIlvpvTfEQe7Df6zlCZhMZVAyyM=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=NDj1fyYyWrPKdTLanjd7NscBkwtcY0MKgSoSp/D59Kc5V4KDURfKngKD0pJFyte8D17OpiGxJWYzu4E6cIfz/UcQfIZ+2pBHlR/I0Grlm2nNXkQoW23xCwR6DZYU+a3peNKXmXbrs/O0/br3j6MkfyPBSHZn7mLpuB6LNa1fDHY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=WyAtciTK; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QuwuLG4B; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KCehBPxO; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=zavuQLyl DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEB454BA2E22 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id 54E61222F9 for ; Tue, 1 Sep 2026 20:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788294467; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L0EQ7+g3WrJ2PyWBJ4S1ZI5CnVQtk+bMcmM10o0s6Ek=; b=WyAtciTKOXjDJ3x9Lgtzr5+kHG0fU9Ifks4Wct+zVj/ufqQQzQM2ngRTLEDb0275LJeltI m/pEjV3Rq6WFR4ap9L4WQgiPkAOBhsK0PKPEPcRnisGBTvXqSkJWV50Hg1YKIHuaKq2jkZ kM1pwBeHiuOktdK1y3dWTd/HCR1yCtY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788294467; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L0EQ7+g3WrJ2PyWBJ4S1ZI5CnVQtk+bMcmM10o0s6Ek=; b=QuwuLG4BJ02cz0+gnfEmwqNTRF1FYyW1LdYfTJtO4I5UZP/v4x8z5wbkfyidArDsvZtWJo JTY651nPHCsZqACw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=KCehBPxO; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=zavuQLyl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788294463; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L0EQ7+g3WrJ2PyWBJ4S1ZI5CnVQtk+bMcmM10o0s6Ek=; b=KCehBPxOQ5MrsLADt9bIctq1c9DmyLZCLmh7CYAZ/rvGntk7AsVecNGaozgXA/KeT8GqUA wG6EAVHtqXYTpc7d5ovNW3VuVEvhaiCPqRjoa89H+bE3B7sLBBxZb07wbAg8Mo3UbqLsQ3 sSJWDIZMCXOSGnHVACCeOiNig99whUI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788294463; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L0EQ7+g3WrJ2PyWBJ4S1ZI5CnVQtk+bMcmM10o0s6Ek=; b=zavuQLyllPDGkXliQN6vcVcbOCJTSyT7bzW6Kt5K2WI+mB0VJYSeVmaN8dD3BDofSJYFn2 +MvYV/tTfrWeoLAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 23B1F136C7 for ; Tue, 1 Sep 2026 20:27:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id OJO1Bj81l2qzUgAAD6G6ig (envelope-from ) for ; Tue, 01 Sep 2026 20:27:43 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [pre-commit] Add check-copies Date: Tue, 1 Sep 2026 22:27:42 +0200 Message-ID: <20260901202742.320498-3-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260901202742.320498-1-tdevries@suse.de> References: <20260901202742.320498-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Level: X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 54E61222F9 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; URIBL_BLOCKED(0.00)[suse.de:dkim,suse.de:mid,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,sourceware.org:url]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns, imap1.dmz-prg2.suse.org:helo, suse.de:dkim, suse.de:mid] X-Spam-Score: -3.01 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 Instead of using symlinks we maintain identical files, which is error-prone [1]. Add pre-commit hook check-copies: ... $ pre-commit run check-copies --all-files -v check-copies............................................................Passed - hook id: check-copies - duration: 0.51s ... that checks that: - files that need to be copies are in fact copies, and - no other files are copies. I've excluded the testsuite from this check, to avoid having to handle: ... Accidental copies found: [ \ 'gdb/testsuite/config/arm-ice.exp', 'gdb/testsuite/config/bfin.exp', \ 'gdb/testsuite/config/cygmon.exp', 'gdb/testsuite/config/h8300.exp', \ 'gdb/testsuite/config/i386-bozo.exp'] Accidental copies found: [ \ 'gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.c', \ 'gdb/testsuite/gdb.base/run-after-attach.c'] Accidental copies found: [ \ 'gdb/testsuite/gdb.rocm/addr-bp-gpu-no-deb-info.cpp', \ 'gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.cpp'] ... [1] https://sourceware.org/pipermail/gdb-patches/2026-September/229897.html --- .pre-commit-config.yaml | 11 ++++++-- gdb/contrib/check-copies.py | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100755 gdb/contrib/check-copies.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34d2cba40b9..6d60f81c483 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -123,14 +123,14 @@ repos: entry: gdb/check-include-guards.py # All gdb header files, but not headers in the test suite. files: '^(gdb(support|server)?)/.*\.h$' - exclude: '.*/testsuite/.*' + exclude: &testsuite_files '.*/testsuite/.*' - id: &id1 check-gnu-style name: *id1 language: python additional_dependencies: ['termcolor', 'unidiff'] entry: gdb/contrib/check-gnu-style-pre-commit.sh files: '^(gdb(support|server)?)/.*\.(c|h|cc)$' - exclude: '.*/testsuite/.*' + exclude: *testsuite_files verbose: true - id: &id2 check-whitespace name: *id2 @@ -173,6 +173,13 @@ repos: args: [--config-check] additional_dependencies: ["pyyaml"] files: *pre_commit_config_file + - id: &id7 check-copies + name: *id7 + language: unsupported_script + entry: gdb/contrib/check-copies.py + files: *gdb_files + exclude: *testsuite_files + require_serial: true # Local Variables: # indent-tabs-mode: nil diff --git a/gdb/contrib/check-copies.py b/gdb/contrib/check-copies.py new file mode 100755 index 00000000000..11c226bb9d2 --- /dev/null +++ b/gdb/contrib/check-copies.py @@ -0,0 +1,54 @@ +#! /usr/bin/env python3 + +import subprocess +import sys +from itertools import chain + +# These files are required to be identical. +required_list = [ + ["gdb/.dir-locals.el", "gdbserver/.dir-locals.el", "gdbsupport/.dir-locals.el"], + ["gdb/.shellcheckrc", "gdbserver/.shellcheckrc", "gdbsupport/.shellcheckrc"], +] + + +def run_cmd(cmd, **kwargs): + res = subprocess.run(cmd, **kwargs) + if res.returncode != 0: + raise RuntimeError( + "command %s failed with exit status %s" % (cmd, res.returncode) + ) + return res + + +files = sys.argv[1:] +always_check_files = list(chain.from_iterable(required_list)) +cmd = ["git", "ls-files", "--stage"] + files + always_check_files +res = run_cmd(cmd, capture_output=True, text=True) + +hash_dict = {} +for line in res.stdout.splitlines(): + parts = line.split(maxsplit=3) + hash = parts[1] + file = parts[3] + hash_dict.setdefault(hash, []).append(file) + +copies = [] +for hash in hash_dict: + files = hash_dict[hash] + if len(files) == 1: + continue + copies.append(set(files)) + +required_set = [set(r) for r in required_list] + +for required in required_set: + if required in copies: + continue + print("No longer copies: %s" % required) + sys.exit(1) + +for copy in copies: + if copy in required_set: + continue + print("Accidental copies found: %s" % copy) + sys.exit(1)