From nobody Tue Feb 10 21:59:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1653327544; cv=none; d=zohomail.com; s=zohoarc; b=lflO9uGa8PiPHABOlP2h8iGUv41qZqJza/BThmP2quMA8cKVK6zhjWI5V9tk7OoWav9jof0+bwX23kiVodtWn4Dn2BBXKxnhacG6+hOy3Wd3Fe6gVsZYteVd3IctiwWlGu6MPqvS1D8CHW+SSZb4fjkIQODktoSBE5AMJytevIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653327544; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AJ+akFBXYWpwIiM9E2H0LXDZXlC5+q/pMKI8X6FGvRM=; b=RWNphy9HYL1h4FbcSbQDMEDqp2UlTFa5E7Gka0aOtvbjNqd9BGz0r1ogsIgFa/wT+bqmaRbSRTdOE14uLXJgnh2G4rtoIGkNwlBXlx5Jcn6MqRgZ6sp8tz7I5g9OzrdRWZUecKCKrNsfpAIZphqsFY7A031yNIjkXX6R1r/caL4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1653327544099881.9712052347786; Mon, 23 May 2022 10:39:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-175-BkTksZjpNSihEXbJSO1P5Q-1; Mon, 23 May 2022 13:38:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4EFD1C05ED0; Mon, 23 May 2022 17:38:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EC301415103; Mon, 23 May 2022 17:38:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 61D9B194705D; Mon, 23 May 2022 17:38:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F05041947059 for ; Mon, 23 May 2022 17:38:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CB7E3112131B; Mon, 23 May 2022 17:38:04 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.40.192.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32C98112131E for ; Mon, 23 May 2022 17:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653327543; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=AJ+akFBXYWpwIiM9E2H0LXDZXlC5+q/pMKI8X6FGvRM=; b=Lodzi1almSxXDMKRUw87zeSuOj1G79Oh0qRBfgg7zAjIP+gmJ3YWTzpptysmmK7LV62mFG oKsBGRmIxyf+9lQO8sZ7NbM0WHEuhKKN4lDvdHDHbHhS7Eltc9Fmto8NnzXeWYAEzMGfb4 lefhML06FjHv8WEn5bq6ucR/NmlVz8w= X-MC-Unique: BkTksZjpNSihEXbJSO1P5Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 10/13] syntax-check: Reorganize file Date: Mon, 23 May 2022 19:37:51 +0200 Message-Id: <20220523173754.336735-11-abologna@redhat.com> In-Reply-To: <20220523173754.336735-1-abologna@redhat.com> References: <20220523173754.336735-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1653327546074100001 Content-Type: text/plain; charset="utf-8" Due to the way make works, we are not forced to follow a strict order in defining rules and variables. In fact _sc_search_regexp, which is used by all checks, is only defined halfway through the file. Shuffle things around so that the things that we need to look at the most frequently are closer to the top of the file. Signed-off-by: Andrea Bolognani --- build-aux/syntax-check.mk | 358 +++++++++++++++++++------------------- 1 file changed, 182 insertions(+), 176 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 13f565d1b8..a37e43b9f6 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -19,43 +19,10 @@ # along with this program. If not, see # . =20 -# Helper variables. -_empty =3D -_sp =3D $(_empty) $(_empty) - -VC_LIST =3D cd $(top_srcdir); git ls-tree -r 'HEAD:' | \ - sed -n "s|^100[^ ]*.||p" - -# This is to preprocess robustly the output of $(VC_LIST), so that even -# when $(top_srcdir) is a pathological name like "....", the leading sed c= ommand -# removes only the intended prefix. -_dot_escaped_srcdir =3D $(subst .,\.,$(top_srcdir)) -_dot_escaped_builddir =3D $(subst .,\.,$(top_builddir)) =20 -# Post-process $(VC_LIST) output, prepending $(top_srcdir)/, but only -# when $(top_srcdir) is not ".". -ifeq ($(top_srcdir),.) - _prepend_srcdir_prefix =3D -else - _prepend_srcdir_prefix =3D | $(SED) 's|^|$(top_srcdir)/|' -endif - -# In order to be able to consistently filter "."-relative names, -# (i.e., with no $(top_srcdir) prefix), this definition is careful to -# remove any $(top_srcdir) prefix, and to restore what it removes. -_sc_excl =3D \ - $(or $(exclude_file_name_regexp--$@),^$$) -VC_LIST_EXCEPT =3D \ - $(VC_LIST) | $(GREP) -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl= ))' \ - $(_prepend_srcdir_prefix) - -# Prevent programs like 'sort' from considering distinct strings to be equ= al. -# Doing it here saves us from having to set LC_ALL elsewhere in this file. -export LC_ALL =3D C - -## --------------- ## -## Sanity checks. ## -## --------------- ## +## ----- ## +## Rules ## +## ----- ## =20 # Files that should never cause syntax check failures. VC_LIST_ALWAYS_EXCLUDE_REGEX =3D \ @@ -927,143 +894,6 @@ sc_prohibit_dirent_d_type: halt=3D'do not use the d_type field in "struct dirent"' \ $(_sc_search_regexp) =20 - -# _sc_search_regexp -# -# This macro searches for a given construct in the selected files and -# then takes some action. -# -# Parameters (shell variables): -# -# prohibit | require -# -# Regular expression (ERE) denoting either a forbidden construct -# or a required construct. Those arguments are exclusive. -# -# exclude -# -# Regular expression (ERE) denoting lines to ignore that matched -# a prohibit construct. For example, this can be used to exclude -# comments that mention why the nearby code uses an alternative -# construct instead of the simpler prohibited construct. -# -# in_vc_files | in_files -# -# grep-E-style regexp selecting the files to check. For in_vc_files, -# the regexp is used to select matching files from the list of all -# version-controlled files; for in_files, it's from the names printed -# by "find $(top_srcdir)". When neither is specified, use all files t= hat -# are under version control. -# -# containing | non_containing -# -# Select the files (non) containing strings matching this regexp. -# If both arguments are specified then CONTAINING takes -# precedence. -# -# with_grep_options -# -# Extra options for grep. -# -# ignore_case -# -# Ignore case. -# -# halt -# -# Message to display before to halting execution. -# -# Finally, you may exempt files based on an ERE matching file names. -# For example, to exempt from the sc_space_tab check all files with the -# .diff suffix, set this Make variable: -# -# exclude_file_name_regexp--sc_space_tab =3D \.diff$ -# -# Note that while this functionality is mostly inherited via VC_LIST_EXCEP= T, -# when filtering by name via in_files, we explicitly filter out matching -# names here as well. - -# Initialize each, so that envvar settings cannot interfere. -export require =3D -export prohibit =3D -export exclude =3D -export in_vc_files =3D -export in_files =3D -export containing =3D -export non_containing =3D -export halt =3D -export with_grep_options =3D - -# By default, _sc_search_regexp does not ignore case. -export ignore_case =3D -_ignore_case =3D $$(test -n "$$ignore_case" && printf %s -i || :) - -define _sc_say_and_exit - dummy=3D; : so we do not need a semicolon before each use; \ - { printf '%s\n' "$$msg" 1>&2; exit 1; }; -endef - -define _sc_search_regexp - dummy=3D; : so we do not need a semicolon before each use; \ - \ - : Check arguments; \ - test -n "$$prohibit" && test -n "$$require" \ - && { msg=3D'Cannot specify both prohibit and require' \ - $(_sc_say_and_exit) } || :; \ - test -z "$$prohibit" && test -z "$$require" \ - && { msg=3D'Should specify either prohibit or require' \ - $(_sc_say_and_exit) } || :; \ - test -z "$$prohibit" && test -n "$$exclude" \ - && { msg=3D'Use of exclude requires a prohibit pattern' \ - $(_sc_say_and_exit) } || :; \ - test -n "$$in_vc_files" && test -n "$$in_files" \ - && { msg=3D'Cannot specify both in_vc_files and in_files' \ - $(_sc_say_and_exit) } || :; \ - test "x$$halt" !=3D x \ - || { msg=3D'halt not defined' $(_sc_say_and_exit) }; \ - \ - : Filter by file name; \ - if test -n "$$in_files"; then \ - files=3D$$(find $(top_srcdir) | $(GREP) -E "$$in_files" \ - | $(GREP) -Ev '$(_sc_excl)'); \ - else \ - files=3D$$($(VC_LIST_EXCEPT)); \ - if test -n "$$in_vc_files"; then \ - files=3D$$(echo "$$files" | $(GREP) -E "$$in_vc_files"); \ - fi; \ - fi; \ - \ - : Filter by content; \ - test -n "$$files" \ - && test -n "$$containing" \ - && { files=3D$$(echo "$$files" | xargs $(GREP) -l "$$containing"); } \ - || :; \ - test -n "$$files" \ - && test -n "$$non_containing" \ - && { files=3D$$(echo "$$files" | xargs $(GREP) -vl "$$non_containing"= ); } \ - || :; \ - \ - : Check for the construct; \ - if test -n "$$files"; then \ - if test -n "$$prohibit"; then \ - echo "$$files" \ - | xargs $(GREP) $$with_grep_options $(_ignore_case) -nE \ - "$$prohibit" /dev/null \ - | $(GREP) -vE "$${exclude:-^$$}" \ - && { msg=3D"$$halt" $(_sc_say_and_exit) } \ - || :; \ - else \ - echo "$$files" \ - | xargs \ - $(GREP) $$with_grep_options $(_ignore_case) -LE "$$require" \ - | $(GREP) . \ - && { msg=3D"$$halt" $(_sc_say_and_exit) } \ - || :; \ - fi \ - else :; \ - fi || :; -endef - sc_cast_of_argument_to_free: @prohibit=3D'\&2; exit 1; }; +endef + +define _sc_search_regexp + dummy=3D; : so we do not need a semicolon before each use; \ + \ + : Check arguments; \ + test -n "$$prohibit" && test -n "$$require" \ + && { msg=3D'Cannot specify both prohibit and require' \ + $(_sc_say_and_exit) } || :; \ + test -z "$$prohibit" && test -z "$$require" \ + && { msg=3D'Should specify either prohibit or require' \ + $(_sc_say_and_exit) } || :; \ + test -z "$$prohibit" && test -n "$$exclude" \ + && { msg=3D'Use of exclude requires a prohibit pattern' \ + $(_sc_say_and_exit) } || :; \ + test -n "$$in_vc_files" && test -n "$$in_files" \ + && { msg=3D'Cannot specify both in_vc_files and in_files' \ + $(_sc_say_and_exit) } || :; \ + test "x$$halt" !=3D x \ + || { msg=3D'halt not defined' $(_sc_say_and_exit) }; \ + \ + : Filter by file name; \ + if test -n "$$in_files"; then \ + files=3D$$(find $(top_srcdir) | $(GREP) -E "$$in_files" \ + | $(GREP) -Ev '$(_sc_excl)'); \ + else \ + files=3D$$($(VC_LIST_EXCEPT)); \ + if test -n "$$in_vc_files"; then \ + files=3D$$(echo "$$files" | $(GREP) -E "$$in_vc_files"); \ + fi; \ + fi; \ + \ + : Filter by content; \ + test -n "$$files" \ + && test -n "$$containing" \ + && { files=3D$$(echo "$$files" | xargs $(GREP) -l "$$containing"); } \ + || :; \ + test -n "$$files" \ + && test -n "$$non_containing" \ + && { files=3D$$(echo "$$files" | xargs $(GREP) -vl "$$non_containing"= ); } \ + || :; \ + \ + : Check for the construct; \ + if test -n "$$files"; then \ + if test -n "$$prohibit"; then \ + echo "$$files" \ + | xargs $(GREP) $$with_grep_options $(_ignore_case) -nE \ + "$$prohibit" /dev/null \ + | $(GREP) -vE "$${exclude:-^$$}" \ + && { msg=3D"$$halt" $(_sc_say_and_exit) } \ + || :; \ + else \ + echo "$$files" \ + | xargs \ + $(GREP) $$with_grep_options $(_ignore_case) -LE "$$require" \ + | $(GREP) . \ + && { msg=3D"$$halt" $(_sc_say_and_exit) } \ + || :; \ + fi \ + else :; \ + fi || :; +endef --=20 2.35.3