From patchwork Tue May 30 13:32:12 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: 70318 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 39A7F3856605 for ; Tue, 30 May 2023 13:32:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39A7F3856605 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685453574; bh=n3yNgf9UzaTmD2Czbvlrubh/KlJNohWBp/BMAjfh6dw=; 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=QOBJPrYzoIPE22GvdQhaF6Zs/FiYqzDSevx0A9OOfqokaEsg0ZzWhLqzUwkr9bxud k+BtOnFWhimXaHYEIstpmDComHIOXgF24/EywcWmKLKo5xC8Uw6RA/ExXbZHoiM/30 YcryGtvLYkRitGtITGUesjy85csZe+BN6yWKwoNk= 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 C763B3858D28 for ; Tue, 30 May 2023 13:32:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C763B3858D28 Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-aC-bwoFuOSispwfI0dl9Dg-1; Tue, 30 May 2023 09:32:20 -0400 X-MC-Unique: aC-bwoFuOSispwfI0dl9Dg-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-565d1b86a64so35622447b3.3 for ; Tue, 30 May 2023 06:32:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685453539; x=1688045539; 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=n3yNgf9UzaTmD2Czbvlrubh/KlJNohWBp/BMAjfh6dw=; b=QE2yc0hqe42Uyocd99bqR43ndHfvWpXx/+mjn8Z7ujrYqDLE9WL7WmN9lbnuACSMM/ hFnLgy5dRgeesb46zHGyNkscsK3wWbpg/ApV9+BpoPi2G3Yi6ONTbWUweEDMFQw4jRDU K1n6zCEQcVobzxHeB0gCUSmKqWn9IrqXztQQO9oO65UsJD4z88a0jHEsvimvQrvkXrmT 5KRSk8KsTrSrCsyT/JVx+Rax/7wB2HbGIuM49umGnsMok5IYv9ma/NKY/HuKEF3bjTWw xvTsrb1+ifFkNVtDzX7eWbyRPbCKvay7ruZsa4I0F0vcMI2CohWvrDgplb99rIsP5D0b jGxA== X-Gm-Message-State: AC+VfDyDfa/AEjfnZcuO8Y0sm5QWSfCmwgDGLvIDXSXw9eZElgA+xZFF 3jGPRIuFKnYLK72Gr4MyKy5GucxBXYuS/FIwo9/d2LvSnNODw6huvbPGqhzm3J/EApbWmb8dyxX veAYpMcsnuA7sSVYLHg7dcZa81xFyWLLKRagRDZuHI7lezIExjz8I/HivQ/uujpfAdFp3ozucL8 CHRQ== X-Received: by 2002:a0d:e891:0:b0:559:f181:1a7d with SMTP id r139-20020a0de891000000b00559f1811a7dmr1686315ywe.27.1685453539120; Tue, 30 May 2023 06:32:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4CycHRjcbiQ7JPClv12ztMneiEonNxd9fF3IfDm9l+4oWRl+qIInsGhoXMmNcbKlxK2S3EBQ== X-Received: by 2002:a0d:e891:0:b0:559:f181:1a7d with SMTP id r139-20020a0de891000000b00559f1811a7dmr1686293ywe.27.1685453538736; Tue, 30 May 2023 06:32:18 -0700 (PDT) Received: from DESKTOP-1DH6NSL.localdomain ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id w19-20020a814913000000b0056872195267sm1780559ywa.129.2023.05.30.06.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 06:32:18 -0700 (PDT) To: libc-alpha@sourceware.org, fweimer@redhat.com, alx.manpages@gmail.com Cc: Carlos O'Donell Subject: [PATCH v3 2/2] Add lint-makefiles Makefile linting test. Date: Tue, 30 May 2023 09:32:12 -0400 Message-Id: <20230530133212.3935551-2-carlos@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530133212.3935551-1-carlos@redhat.com> References: <20230530133212.3935551-1-carlos@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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+patchwork=sourceware.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. Reviewed-by: Florian Weimer --- v3: Print nothing on success. Use diff -u. Use output as fixit patch. Makefile | 10 ++++++ scripts/lint-makefiles.sh | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 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..0d202346bd --- /dev/null +++ b/scripts/lint-makefiles.sh @@ -0,0 +1,74 @@ +#!/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. + +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. +if [ -z "$PYTHON" ]; then + echo 'Please specify $PYTHON interpreter' + exit 1 +fi +# Absolute or relative $srcdir must exist and be a directory. +if [ ! -d "$srcdir" ]; then + echo 'Please specify $srcdir in which to look for Makefiles' + exit 1 +fi + +linted=0 +failed=0 +for mfile in `find "$srcdir" -name Makefile`; do + $PYTHON "${srcdir}/scripts/sort-makefile-lines.py" < "$mfile" > "$tmpfile" + # Printed the expected -> actual difference on error. + if ! diff -u --label "$mfile.expected" "$tmpfile" "$mfile"; then + failed=$((failed+1)) + fi + linted=$((linted+1)) +done +# Must have linted at least the top-level Makefile. +if [ $linted -lt 1 ]; then + echo "Did not lint any Makefiles!" + exit 1 +fi +if [ $failed -gt 0 ]; then + echo "---" + echo "Tested $linted Makefiles and $failed were incorrectly sorted" + echo 'Please use `patch -R -pN` and the output above to correct the sorting' + exit 1 +fi +# All Makefiles linted clean. +exit 0