public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] elf: Sort Makefile variables.
@ 2023-05-30 12:07 Carlos O'Donell
  2023-05-30 12:07 ` [PATCH v2 2/2] Add lint-makefiles Makefile linting test Carlos O'Donell
  2023-05-30 12:20 ` [PATCH v2 1/2] elf: Sort Makefile variables Florian Weimer
  0 siblings, 2 replies; 5+ messages in thread
From: Carlos O'Donell @ 2023-05-30 12:07 UTC (permalink / raw)
  To: libc-alpha, alx.manpages, fweimer; +Cc: Carlos O'Donell

Sort Makefile variables using scrips/sort-makefile-lines.py.

No code generation changes observed in non-test binary artifacts.
No regressions on x86_64 and i686.
---
 elf/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/elf/Makefile b/elf/Makefile
index 3bfc305d98..c00e2ccfc5 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -274,8 +274,8 @@ tests-static-normal := \
   # tests-static-normal
 
 tests-static-internal := \
-  tst-dl_find_object-static \
   tst-dl-printf-static \
+  tst-dl_find_object-static \
   tst-ptrguard1-static \
   tst-stackguard1-static \
   tst-tls1-static \
-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] Add lint-makefiles Makefile linting test.
  2023-05-30 12:07 [PATCH v2 1/2] elf: Sort Makefile variables Carlos O'Donell
@ 2023-05-30 12:07 ` Carlos O'Donell
  2023-05-30 12:25   ` Florian Weimer
  2023-05-30 12:20 ` [PATCH v2 1/2] elf: Sort Makefile variables Florian Weimer
  1 sibling, 1 reply; 5+ messages in thread
From: Carlos O'Donell @ 2023-05-30 12:07 UTC (permalink / raw)
  To: libc-alpha, alx.manpages, fweimer; +Cc: Carlos O'Donell

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
+# <https://www.gnu.org/licenses/>.
+
+# 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
-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] elf: Sort Makefile variables.
  2023-05-30 12:07 [PATCH v2 1/2] elf: Sort Makefile variables Carlos O'Donell
  2023-05-30 12:07 ` [PATCH v2 2/2] Add lint-makefiles Makefile linting test Carlos O'Donell
@ 2023-05-30 12:20 ` Florian Weimer
  1 sibling, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2023-05-30 12:20 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha, alx.manpages

* Carlos O'Donell:

> Sort Makefile variables using scrips/sort-makefile-lines.py.
>
> No code generation changes observed in non-test binary artifacts.
> No regressions on x86_64 and i686.
> ---
>  elf/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/elf/Makefile b/elf/Makefile
> index 3bfc305d98..c00e2ccfc5 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -274,8 +274,8 @@ tests-static-normal := \
>    # tests-static-normal
>  
>  tests-static-internal := \
> -  tst-dl_find_object-static \
>    tst-dl-printf-static \
> +  tst-dl_find_object-static \
>    tst-ptrguard1-static \
>    tst-stackguard1-static \
>    tst-tls1-static \

Okay,

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] Add lint-makefiles Makefile linting test.
  2023-05-30 12:07 ` [PATCH v2 2/2] Add lint-makefiles Makefile linting test Carlos O'Donell
@ 2023-05-30 12:25   ` Florian Weimer
  2023-05-30 13:02     ` Carlos O'Donell
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2023-05-30 12:25 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha, alx.manpages

* Carlos O'Donell:

> +echo "Linting Makefiles:"
> +echo "Check: Are all lines sorted correctly?"

Maybe don't print anything if there isn't an error?

> +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"

Please use diff -u, make the diff go from expected to actual (other
direction), use --label to label $tmpfile, and keep going after the
first failure.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] Add lint-makefiles Makefile linting test.
  2023-05-30 12:25   ` Florian Weimer
@ 2023-05-30 13:02     ` Carlos O'Donell
  0 siblings, 0 replies; 5+ messages in thread
From: Carlos O'Donell @ 2023-05-30 13:02 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, alx.manpages

On 5/30/23 08:25, Florian Weimer wrote:
> * Carlos O'Donell:
> 
>> +echo "Linting Makefiles:"
>> +echo "Check: Are all lines sorted correctly?"
> 
> Maybe don't print anything if there isn't an error?
> 
>> +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"
> 
> Please use diff -u, make the diff go from expected to actual (other
> direction), use --label to label $tmpfile, and keep going after the
> first failure.

Ah! I like where you're going with this. I'll post a v3 shortly that will let you use
patch -R -pN to apply the *.out file as a fix-it for the sorting.

-- 
Cheers,
Carlos.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-30 13:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 12:07 [PATCH v2 1/2] elf: Sort Makefile variables Carlos O'Donell
2023-05-30 12:07 ` [PATCH v2 2/2] Add lint-makefiles Makefile linting test Carlos O'Donell
2023-05-30 12:25   ` Florian Weimer
2023-05-30 13:02     ` Carlos O'Donell
2023-05-30 12:20 ` [PATCH v2 1/2] elf: Sort Makefile variables Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).