From patchwork Tue May 30 12:07:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 1787455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=moJ4tTQO; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QVrlT2fWYz20Q4 for ; Tue, 30 May 2023 22:08:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 377C1385696A for ; Tue, 30 May 2023 12:08:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 377C1385696A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685448515; bh=96jPkBrPbPVprzzVyWP4BguDtzNLXD7JE5H0GPhrwVc=; 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=moJ4tTQOy3osY2wU9UCrcoEExBn6pMANUgVd2IeyFi8wBNvNoylAY7EhUBwdHu79u XHjXawKYGsIiSgbPEpu0gwPEWBvZ2g0MUMo3jjlhdBWzXOh/2mpOBnBxrxE3SKhpHQ NNZdlW/OhVN5rJWvS2X+RLPA96dxNM9Ulf9jRleI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D81533858D28 for ; Tue, 30 May 2023 12:08:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D81533858D28 Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-MUzafvjeOSCJplP3LVN5HQ-1; Tue, 30 May 2023 08:08:06 -0400 X-MC-Unique: MUzafvjeOSCJplP3LVN5HQ-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-565d6824f2dso53539657b3.0 for ; Tue, 30 May 2023 05:08:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685448485; x=1688040485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=96jPkBrPbPVprzzVyWP4BguDtzNLXD7JE5H0GPhrwVc=; b=JToq0NW0IFUNZjqTbR4LBMUQQM8/k7e4NW/wol/RDeXA12qFCgTeSu0k26s2RuPb6o jd7K1sUDfEwK4Z8TXkHF8Qonwis/Q3vCzgUbnLQPGvuyD5bbq/K3BQevVhoZLNpLDWWM BsxeuSm3QENRnZWdYldBlEiUmhIG7GyDcEyVjKHsKjWMmpVwyzydfZwscoeWHLYse9+7 k8Rlnjmcruo3fdqQddxXF/01zcyDlfW21id/NAzEGHd7WtQNYY5x7N0Fm3+9VJ8Zb8fn 9Xv7Asy887hDjRur97HXQ+hcAsLaugUsThlHXYMSFh7QTl5ny0oKGt7ZrzPCN4EBEtj6 D4bQ== X-Gm-Message-State: AC+VfDymOSgyONC62m9qFCcv9KH9sDe70kvEIpmiZg24b5s7Sv1mNwF1 Pebuxqe1/PvKFak0tqLs5RznG2PR/YxMgRBmZJI6EzFecqGQ89j7dyJe8YdEnaAoJ/5vTUAbWXs wEg4tz4+dLPXrbwK4U6kxdLtMWEo3EIwn+cvo/px0u4eajXHaYvqBQarbQy4zt3hnMT4YBdX9tu aSNw== X-Received: by 2002:a81:5a55:0:b0:55a:2ce1:2353 with SMTP id o82-20020a815a55000000b0055a2ce12353mr2118332ywb.2.1685448485502; Tue, 30 May 2023 05:08:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4q+xksoJrE2b+IqSltZnMRH/ANDKZGT1dMpT/izED3RiZD7dslnKUQnudSKpOhMrI2Iaz4Bw== X-Received: by 2002:a81:5a55:0:b0:55a:2ce1:2353 with SMTP id o82-20020a815a55000000b0055a2ce12353mr2118301ywb.2.1685448484934; Tue, 30 May 2023 05:08:04 -0700 (PDT) Received: from DESKTOP-1DH6NSL.localdomain ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id g127-20020a0dc485000000b00545a08184f8sm4357365ywd.136.2023.05.30.05.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 05:08:04 -0700 (PDT) To: libc-alpha@sourceware.org, alx.manpages@gmail.com, fweimer@redhat.com Cc: Carlos O'Donell Subject: [PATCH v2 2/2] Add lint-makefiles Makefile linting test. Date: Tue, 30 May 2023 08:07:59 -0400 Message-Id: <20230530120759.2150593-2-carlos@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530120759.2150593-1-carlos@redhat.com> References: <20230530120759.2150593-1-carlos@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Carlos O'Donell via Libc-alpha From: Carlos O'Donell Reply-To: Carlos O'Donell Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" We add a 'make check' test that lints all Makefiles in the source directory of the glibc build. This linting test ensures that the lines in all Makefiles will be sorted correctly as developers creates patches. It is added to 'make check' because it is light-weight and supports the existing developer workflow The test adds ~3s to a 'make check' execution. No regressions on x86_64 and i686. --- v2: Use `pwd` and add comments about 'light-weight' checking. Makefile | 10 +++++++ scripts/lint-makefiles.sh | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 scripts/lint-makefiles.sh diff --git a/Makefile b/Makefile index 224c792185..523efd42c1 100644 --- a/Makefile +++ b/Makefile @@ -564,6 +564,16 @@ $(objpfx)check-wrapper-headers.out: scripts/check-wrapper-headers.py $(headers) --generated $(common-generated) > $@; $(evaluate-test) endif # $(headers) +# Lint all Makefiles; including this one. Pass `pwd` as the source +# directory since the top-level Makefile is in the root of the source +# tree and these tests are run from there. We add light-weight linting +# to the 'check' target to support the existing developer workflow of: +# edit -> make -> make check; without needing an additional step. +tests-special += $(objpfx)lint-makefiles.out +$(objpfx)lint-makefiles.out: scripts/lint-makefiles.sh + $(SHELL) $< "$(PYTHON)" `pwd` > $@ ; \ + $(evaluate-test) + define summarize-tests @grep -E -v '^(PASS|XFAIL):' $(objpfx)$1 || true @echo "Summary of test results$2:" diff --git a/scripts/lint-makefiles.sh b/scripts/lint-makefiles.sh new file mode 100644 index 0000000000..c4558d9c82 --- /dev/null +++ b/scripts/lint-makefiles.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Copyright (C) 2023 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# The GNU C Library 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 +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . + +# This script checks to see that all Makefiles in the source tree +# conform to the sorted variable rules as defined by: +# scripts/sort-makefile-lines.py. +# Any difference is an error and should be corrected e.g. the lines +# reordered to sort correctly. +# The intent with this check is to ensure that changes made by +# developers match the expected format for the project. + +set -e +export LC_ALL=C + +tmpfile="$(mktemp)" + +cleanup () { + rm -f -- "$tmpfile" +} + +trap cleanup 0 + +PYTHON=$1 +# Absolute or relative path to the source directory. +srcdir=$2 + +# Must specify $PYTHON. +test -n "$PYTHON" +# Absolute or relative $srcdir must exist and be a directory. +test -d "$srcdir" + +echo "Linting Makefiles:" +echo "Check: Are all lines sorted correctly?" +linted=0 +for mfile in `find "$srcdir" -name Makefile`; do + echo "$mfile" + $PYTHON "${srcdir}/scripts/sort-makefile-lines.py" < "$mfile" > "$tmpfile" + diff -q "$mfile" "$tmpfile" + linted=$(( linted++ )) +done +# Must have linted at least the top-level Makefile +test $linted -ge 1