public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Standardize the sorting of Makefile variables
@ 2023-04-28 11:48 Carlos O'Donell
  2023-04-28 11:48 ` [PATCH 1/2] nptl: Re-flow and sort variables in Makefile Carlos O'Donell
  2023-04-28 11:48 ` [PATCH 2/2] scripts: Add sort-makefile-lines.py to sort Makefile variables Carlos O'Donell
  0 siblings, 2 replies; 7+ messages in thread
From: Carlos O'Donell @ 2023-04-28 11:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Carlos O'Donell

The project has started to re-flow and sort Makefile variables to make
it easier to manage the lists of inputs and tests.  While splitting the
lines is easy to do, the sorting is more onerous because of the desire
to sort like tests with like tests.  The following is my attempt to
standardize teh sorting following the consensus discussion on the list
which suggested using LC_COLLATE=C and sorting similar tests in
numerical order of their prefix.

The series re-flows and then sorts sysdeps/pthread/Makefile using the
new helper python script.

Carlos O'Donell (2):
  nptl: Re-flow and sort variables in Makefile.
  scripts: Add sort-makefile-lines.py to sort Makefile variables.

 scripts/sort-makefile-lines.py                | 217 +++++++++
 sysdeps/pthread/Makefile                      | 433 +++++++++++++-----
 .../{tst-mutex7robust.c => tst-robust11.c}    |   0
 3 files changed, 537 insertions(+), 113 deletions(-)
 create mode 100755 scripts/sort-makefile-lines.py
 rename sysdeps/pthread/{tst-mutex7robust.c => tst-robust11.c} (100%)

-- 
2.39.2


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

* [PATCH 1/2] nptl: Re-flow and sort variables in Makefile.
  2023-04-28 11:48 [PATCH 0/2] Standardize the sorting of Makefile variables Carlos O'Donell
@ 2023-04-28 11:48 ` Carlos O'Donell
  2023-05-08 17:17   ` Siddhesh Poyarekar
  2023-04-28 11:48 ` [PATCH 2/2] scripts: Add sort-makefile-lines.py to sort Makefile variables Carlos O'Donell
  1 sibling, 1 reply; 7+ messages in thread
From: Carlos O'Donell @ 2023-04-28 11:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Carlos O'Donell

---
 sysdeps/pthread/Makefile                      | 433 +++++++++++++-----
 .../{tst-mutex7robust.c => tst-robust11.c}    |   0
 2 files changed, 320 insertions(+), 113 deletions(-)
 rename sysdeps/pthread/{tst-mutex7robust.c => tst-robust11.c} (100%)

diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
index c2f5588bd9..222f5b5142 100644
--- a/sysdeps/pthread/Makefile
+++ b/sysdeps/pthread/Makefile
@@ -21,9 +21,17 @@ $(objpfx)tst-timer: $(librt)
 endif
 
 ifneq (,$(filter $(subdir),htl nptl))
-headers += threads.h
-
-routines += thrd_current thrd_equal thrd_sleep thrd_yield pthread_atfork
+headers += \
+  threads.h \
+  # headers
+
+routines += \
+  pthread_atfork \
+  thrd_current \
+  thrd_equal \
+  thrd_sleep \
+  thrd_yield \
+  # routines
 
 $(libpthread-routines-var) += \
   call_once \
@@ -48,86 +56,231 @@ $(libpthread-routines-var) += \
   tss_delete \
   tss_get \
   tss_set \
+  # $(libpthread-routines-var)
 
-tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
-	 tst-cnd-timedwait tst-thrd-detach tst-mtx-basic tst-thrd-sleep \
-	 tst-mtx-recursive tst-tss-basic tst-call-once tst-mtx-timedlock \
-	 \
-	 tst-abstime \
-	 tst-pt-align tst-pt-align3 \
-	 tst-attr1 \
-	 tst-backtrace1 \
-	 tst-bad-schedattr \
-	 tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 \
-	 tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
-	 tst-basic7 \
-	 tst-cancel-self tst-cancel-self-cancelstate \
-	 tst-cancel-self-canceltype tst-cancel-self-testcancel \
-	 tst-cancel1 tst-cancel2 tst-cancel3 \
-	 tst-cancel4 tst-cancel5 \
-	 tst-cancel6 tst-cancel8 tst-cancel9 tst-cancel10 tst-cancel11 \
-	 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 tst-cancel16 \
-	 tst-cancel18 tst-cancel19 tst-cancel20 tst-cancel21 \
-	 tst-cancel22 tst-cancel23 tst-cancel26 tst-cancel27 tst-cancel28 \
-	 tst-cancel29 \
-	 tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 \
-	 tst-clock1 \
-	 tst-cond-except \
-	 tst-cond1 tst-cond2 tst-cond3 tst-cond4 tst-cond5 tst-cond6 tst-cond7 \
-	 tst-cond8 tst-cond9 tst-cond10 tst-cond11 tst-cond12 tst-cond13 \
-	 tst-cond14 tst-cond15 tst-cond16 tst-cond17 tst-cond18 tst-cond19 \
-	 tst-cond20 tst-cond21 tst-cond23 tst-cond24 tst-cond25 tst-cond27 \
-	 tst-create-detached \
-	 tst-detach1 \
-	 tst-eintr2 tst-eintr3 tst-eintr4 tst-eintr5 \
-	 tst-exec1 tst-exec2 tst-exec3 \
-	 tst-exit1 tst-exit2 tst-exit3 \
-	 tst-flock1 tst-flock2 \
-	 tst-fork1 tst-fork2 tst-fork3 tst-fork4 \
-	 tst-atfork1 \
-	 tst-getpid3 \
-	 tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 tst-join7 \
-	 tst-join8 tst-join9 tst-join10 tst-join11 tst-join12 tst-join13 \
-	 tst-join14 tst-join15 \
-	 tst-key1 tst-key2 tst-key3 tst-key4 \
-	 tst-kill1 tst-kill2 tst-kill3 tst-kill5 tst-kill6 \
-	 tst-locale1 tst-locale2 \
-	 tst-memstream \
-	 tst-mutex-errorcheck tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 \
-	 tst-mutex5 tst-mutex6 tst-mutex7 tst-mutex7robust tst-mutex9 \
-	 tst-mutex10 tst-mutex11 tst-pthread-mutexattr \
-	 tst-once1 tst-once2 tst-once3 tst-once4 \
-	 tst-pt-popen1 \
-	 tst-raise1 \
-	 tst-robust1 tst-robust2 tst-robust3 tst-robust4 tst-robust5 \
-	 tst-robust6 tst-robust7 tst-robust9 tst-robust10 \
-	 tst-rwlock1 tst-rwlock4 tst-rwlock5 tst-rwlock12 \
-	 tst-rwlock13 tst-rwlock14 tst-rwlock16 \
-	 tst-rwlock-tryrdlock-stall tst-rwlock-trywrlock-stall \
-	 tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 \
-	 tst-sem8 tst-sem9 tst-sem10 tst-sem14 tst-sem15 tst-sem16 \
-	 tst-setuid3 \
-	 tst-signal1 tst-signal2 \
-	 tst-signal4 tst-signal5 tst-signal6 tst-signal8 \
-	 tst-spin1 tst-spin2 tst-spin3 tst-spin4 \
-	 tst-stack1 \
-	 tst-stdio1 tst-stdio2 \
-	 tst-pt-sysconf \
-	 tst-pt-tls1 tst-pt-tls2 \
-	 tst-tsd1 tst-tsd2 tst-tsd5 tst-tsd6 \
-	 tst-umask1 \
-	 tst-unload \
-	 tst-unwind-thread \
-	 tst-pt-vfork1 tst-pt-vfork2 tst-vfork1x tst-vfork2x \
-	 tst-pthread-exit-signal \
-	 tst-pthread-setuid-loop \
-	 tst-pthread_cancel-exited \
-	 tst-pthread_cancel-select-loop \
-	 tst-pthread-raise-blocked-self \
-	 tst-pthread_kill-exited \
-	 tst-pthread_kill-exiting \
-	 tst-cancel30 \
-	 # tests
+tests += \
+  tst-abstime \
+  tst-atfork1 \
+  tst-attr1 \
+  tst-backtrace1 \
+  tst-bad-schedattr \
+  tst-barrier1 \
+  tst-barrier2 \
+  tst-barrier3 \
+  tst-barrier4 \
+  tst-basic1 \
+  tst-basic2 \
+  tst-basic3 \
+  tst-basic4 \
+  tst-basic5 \
+  tst-basic6 \
+  tst-basic7 \
+  tst-call-once \
+  tst-cancel-self \
+  tst-cancel-self-cancelstate \
+  tst-cancel-self-canceltype \
+  tst-cancel-self-testcancel \
+  tst-cancel1 \
+  tst-cancel2 \
+  tst-cancel3 \
+  tst-cancel4 \
+  tst-cancel5 \
+  tst-cancel6 \
+  tst-cancel8 \
+  tst-cancel9 \
+  tst-cancel10 \
+  tst-cancel11 \
+  tst-cancel12 \
+  tst-cancel13 \
+  tst-cancel14 \
+  tst-cancel15 \
+  tst-cancel16 \
+  tst-cancel18 \
+  tst-cancel19 \
+  tst-cancel20 \
+  tst-cancel21 \
+  tst-cancel22 \
+  tst-cancel23 \
+  tst-cancel26 \
+  tst-cancel27 \
+  tst-cancel28 \
+  tst-cancel29 \
+  tst-cancel30 \
+  tst-cleanup0 \
+  tst-cleanup1 \
+  tst-cleanup2 \
+  tst-cleanup3 \
+  tst-clock1 \
+  tst-cnd-basic \
+  tst-cnd-broadcast \
+  tst-cnd-timedwait \
+  tst-cond-except \
+  tst-cond1 \
+  tst-cond2 \
+  tst-cond3 \
+  tst-cond4 \
+  tst-cond5 \
+  tst-cond6 \
+  tst-cond7 \
+  tst-cond8 \
+  tst-cond9 \
+  tst-cond10 \
+  tst-cond11 \
+  tst-cond12 \
+  tst-cond13 \
+  tst-cond14 \
+  tst-cond15 \
+  tst-cond16 \
+  tst-cond17 \
+  tst-cond18 \
+  tst-cond19 \
+  tst-cond20 \
+  tst-cond21 \
+  tst-cond23 \
+  tst-cond24 \
+  tst-cond25 \
+  tst-cond27 \
+  tst-create-detached \
+  tst-detach1 \
+  tst-eintr2 \
+  tst-eintr3 \
+  tst-eintr4 \
+  tst-eintr5 \
+  tst-exec1 \
+  tst-exec2 \
+  tst-exec3 \
+  tst-exit1 \
+  tst-exit2 \
+  tst-exit3 \
+  tst-flock1 \
+  tst-flock2 \
+  tst-fork1 \
+  tst-fork2 \
+  tst-fork3 \
+  tst-fork4 \
+  tst-getpid3 \
+  tst-join1 \
+  tst-join2 \
+  tst-join3 \
+  tst-join4 \
+  tst-join5 \
+  tst-join6 \
+  tst-join7 \
+  tst-join8 \
+  tst-join9 \
+  tst-join10 \
+  tst-join11 \
+  tst-join12 \
+  tst-join13 \
+  tst-join14 \
+  tst-join15 \
+  tst-key1 \
+  tst-key2 \
+  tst-key3 \
+  tst-key4 \
+  tst-kill1 \
+  tst-kill2 \
+  tst-kill3 \
+  tst-kill5 \
+  tst-kill6 \
+  tst-locale1 \
+  tst-locale2 \
+  tst-memstream \
+  tst-mtx-basic \
+  tst-mtx-recursive \
+  tst-mtx-timedlock \
+  tst-mtx-trylock \
+  tst-mutex-errorcheck \
+  tst-mutex1 \
+  tst-mutex2 \
+  tst-mutex3 \
+  tst-mutex4 \
+  tst-mutex5 \
+  tst-mutex6 \
+  tst-mutex7 \
+  tst-mutex9 \
+  tst-mutex10 \
+  tst-mutex11 \
+  tst-once1 \
+  tst-once2 \
+  tst-once3 \
+  tst-once4 \
+  tst-pt-align \
+  tst-pt-align3 \
+  tst-pt-popen1 \
+  tst-pt-sysconf \
+  tst-pt-tls1 \
+  tst-pt-tls2 \
+  tst-pt-vfork1 \
+  tst-pt-vfork2 \
+  tst-pthread-exit-signal \
+  tst-pthread-mutexattr \
+  tst-pthread-raise-blocked-self \
+  tst-pthread-setuid-loop \
+  tst-pthread_cancel-exited \
+  tst-pthread_cancel-select-loop \
+  tst-pthread_kill-exited \
+  tst-pthread_kill-exiting \
+  tst-raise1 \
+  tst-robust1 \
+  tst-robust2 \
+  tst-robust3 \
+  tst-robust4 \
+  tst-robust5 \
+  tst-robust6 \
+  tst-robust7 \
+  tst-robust9 \
+  tst-robust10 \
+  tst-robust11 \
+  tst-rwlock-tryrdlock-stall \
+  tst-rwlock-trywrlock-stall \
+  tst-rwlock1 \
+  tst-rwlock4 \
+  tst-rwlock5 \
+  tst-rwlock12 \
+  tst-rwlock13 \
+  tst-rwlock14 \
+  tst-rwlock16 \
+  tst-sem1 \
+  tst-sem2 \
+  tst-sem3 \
+  tst-sem4 \
+  tst-sem5 \
+  tst-sem6 \
+  tst-sem7 \
+  tst-sem8 \
+  tst-sem9 \
+  tst-sem10 \
+  tst-sem14 \
+  tst-sem15 \
+  tst-sem16 \
+  tst-setuid3 \
+  tst-signal1 \
+  tst-signal2 \
+  tst-signal4 \
+  tst-signal5 \
+  tst-signal6 \
+  tst-signal8 \
+  tst-spin1 \
+  tst-spin2 \
+  tst-spin3 \
+  tst-spin4 \
+  tst-stack1 \
+  tst-stdio1 \
+  tst-stdio2 \
+  tst-thrd-detach \
+  tst-thrd-sleep \
+  tst-tsd1 \
+  tst-tsd2 \
+  tst-tsd5 \
+  tst-tsd6 \
+  tst-tss-basic \
+  tst-umask1 \
+  tst-unload \
+  tst-unwind-thread \
+  tst-vfork1x \
+  tst-vfork2x \
+  # tests
 
 tests-time64 += \
   tst-abstime-time64 \
@@ -138,47 +291,70 @@ tests-time64 += \
   tst-rwlock14-time64 \
   tst-sem5-time64 \
   tst-thrd-sleep-time64 \
+  # tests-time64
 
 static-only-routines = pthread_atfork
 
 # Files which must not be linked with libpthread.
-tests-nolibpthread += tst-unload
+tests-nolibpthread += \
+  tst-unload \
+  # tests-nolibpthread
 
 # GCC-4.9 compiles 'sprintf(NULL, ...)' into UD2 on x86_64 without -fno-builtin
 CFLAGS-tst-cleanup2.c += -fno-builtin
 CFLAGS-tst-cleanupx2.c += -fno-builtin
 
-tests += tst-cancelx2 tst-cancelx3 tst-cancelx6 tst-cancelx8 tst-cancelx9 \
-	 tst-cancelx4 tst-cancelx5 \
-	 tst-cancelx10 tst-cancelx11 tst-cancelx12 tst-cancelx13 tst-cancelx14 \
-	 tst-cancelx15 tst-cancelx16 tst-cancelx18 tst-cancelx20 tst-cancelx21 \
-	 tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3
+tests += \
+  tst-cancelx2 \
+  tst-cancelx3 \
+  tst-cancelx4 \
+  tst-cancelx5 \
+  tst-cancelx6 \
+  tst-cancelx8 \
+  tst-cancelx9 \
+  tst-cancelx10 \
+  tst-cancelx11 \
+  tst-cancelx12 \
+  tst-cancelx13 \
+  tst-cancelx14 \
+  tst-cancelx15 \
+  tst-cancelx16 \
+  tst-cancelx18 \
+  tst-cancelx20 \
+  tst-cancelx21 \
+  tst-cleanupx0 \
+  tst-cleanupx1 \
+  tst-cleanupx2 \
+  tst-cleanupx3 \
+  # tests
 
 ifeq ($(build-shared),yes)
 tests += \
-  tst-atfork2 \
-  tst-pt-tls4 \
   tst-_res1 \
-  tst-fini1 \
-  tst-create1 \
+  tst-atfork2 \
   tst-atfork3 \
   tst-atfork4 \
-# tests
+  tst-create1 \
+  tst-fini1 \
+  tst-pt-tls4 \
+  # tests
 
-tests-nolibpthread += tst-fini1
+tests-nolibpthread += \
+  tst-fini1 \
+  # tests-nolibpthread
 endif
 
 modules-names += \
-  tst-atfork2mod \
-  tst-tls4moda \
-  tst-tls4modb \
   tst-_res1mod1 \
   tst-_res1mod2 \
-  tst-fini1mod \
-  tst-create1mod \
+  tst-atfork2mod \
   tst-atfork3mod \
   tst-atfork4mod \
-# module-names
+  tst-create1mod \
+  tst-fini1mod \
+  tst-tls4moda \
+  tst-tls4modb \
+  # modules-names
 
 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
 
@@ -192,17 +368,30 @@ ifeq ($(build-shared),yes)
 tests: $(test-modules)
 endif
 
+tests-static += \
+  tst-cancel21-static \
+  tst-locale1 \
+  tst-locale2 \
+  # tests-static
 
-tests-static += tst-locale1 tst-locale2 tst-cancel21-static
-
-tests += tst-cancel21-static tst-cond11-static
+tests += \
+  tst-cancel21-static \
+  tst-cond11-static \
+  # tests
 
 # These tests are linked with libc before libpthread
-tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x
+tests-reverse += \
+  tst-cancel5 \
+  tst-cancel23 \
+  tst-vfork1x \
+  tst-vfork2x \
+  # tests-reverse
 
 ifeq ($(run-built-tests),yes)
 ifeq ($(build-shared),yes)
-tests-special += $(objpfx)tst-cleanup0-cmp.out
+tests-special += \
+  $(objpfx)tst-cleanup0-cmp.out \
+  # tests-special
 endif
 endif
 
@@ -286,20 +475,38 @@ $(objpfx)tst-_res1: $(objpfx)tst-_res1mod1.so $(objpfx)tst-_res1mod2.so \
 $(objpfx)tst-pt-tls4: $(shared-thread-library)
 $(objpfx)tst-pt-tls4.out: $(objpfx)tst-tls4moda.so $(objpfx)tst-tls4modb.so
 
-generated += tst-atfork2.mtrace
+generated += \
+  tst-atfork2.mtrace \
+  # generated
 
-generated += $(objpfx)tst-atfork2.mtrace \
-	     $(addsuffix .so,$(strip $(modules-names)))
+generated += \
+  $(objpfx)tst-atfork2.mtrace \
+  $(addsuffix .so,$(strip $(modules-names))) \
+  # generated
 
-tests-internal += tst-cancel25 tst-robust8
+tests-internal += \
+  tst-cancel25 \
+  tst-robust8 \
+  # tests-internal
 
-tests += tst-oncex3 tst-oncex4 tst-oncey3 tst-oncey4
+tests += \
+  tst-oncex3 \
+  tst-oncex4 \
+  tst-oncey3 \
+  tst-oncey4 \
+  # tests
 
-modules-names += tst-join7mod
+modules-names += \
+  tst-join7mod \
+  # modules-names
 
 ifeq ($(build-shared),yes)
-tests-static += tst-cond8-static
-tests += tst-cond8-static
+tests-static += \
+  tst-cond8-static \
+  # tests-static
+tests += \
+  tst-cond8-static \
+  # tests
 endif
 
 CFLAGS-tst-oncex3.c += -fexceptions
diff --git a/sysdeps/pthread/tst-mutex7robust.c b/sysdeps/pthread/tst-robust11.c
similarity index 100%
rename from sysdeps/pthread/tst-mutex7robust.c
rename to sysdeps/pthread/tst-robust11.c
-- 
2.39.2


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

* [PATCH 2/2] scripts: Add sort-makefile-lines.py to sort Makefile variables.
  2023-04-28 11:48 [PATCH 0/2] Standardize the sorting of Makefile variables Carlos O'Donell
  2023-04-28 11:48 ` [PATCH 1/2] nptl: Re-flow and sort variables in Makefile Carlos O'Donell
@ 2023-04-28 11:48 ` Carlos O'Donell
  2023-05-08 17:47   ` Siddhesh Poyarekar
  1 sibling, 1 reply; 7+ messages in thread
From: Carlos O'Donell @ 2023-04-28 11:48 UTC (permalink / raw)
  To: libc-alpha; +Cc: Carlos O'Donell

The scripts/sort-makefile-lines.py script sorts Makefile variables
according to project expected order.

The script is used like this:

$ scripts/sort-makefile-lines.py -i elf/Makefile -o elf/Makefile.tmp
$ mv elf/Makefile.tmp elf/Makefile
---
 scripts/sort-makefile-lines.py | 217 +++++++++++++++++++++++++++++++++
 1 file changed, 217 insertions(+)
 create mode 100755 scripts/sort-makefile-lines.py

diff --git a/scripts/sort-makefile-lines.py b/scripts/sort-makefile-lines.py
new file mode 100755
index 0000000000..06c0b3b3a2
--- /dev/null
+++ b/scripts/sort-makefile-lines.py
@@ -0,0 +1,217 @@
+#!/usr/bin/python3
+# Sort Makefile lines as expected by project policy.
+# Copyright (C) 2022-2023 Free Software Foundation, Inc.
+# Copyright The GNU Toolchain Authors.
+# 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/>.
+
+# The project consensus is to split Makefile variable assignment
+# across multiple lines with one value per line.  The values are
+# then sorted as described below, and terminated with a special
+# list termination marker.  This splitting makes it much easier
+# to add new tests to the list since they become just a single
+# line insertion.  It also makes backports and merges easier
+# since the new test may not conflict due to the ordering.
+#
+# Consensus discussion:
+# https://public-inbox.org/libc-alpha/f6406204-84f5-adb1-d00e-979ebeebbbde@redhat.com/
+#
+# To support cleaning up Makefiles we created this program to
+# help sort existing lists converted to the new format.
+#
+# The program takes as input the Makefile to sort correctly,
+# and the output file to write the correctly sorted output.
+#
+# Sorting is only carried out between two special markers:
+# (a) Marker start is '<variable> += \'
+# (b) Marker end is '  # <variable>'
+# With everthing between (a) and (b) being sorted.
+#
+# You can use it like this:
+# $ scripts/sort-makefile-lines.py -i elf/Makefile -o elf/Makefile.tmp
+# $ mv elf/Makefile.tmp elf/Makefile
+#
+# The Makefile lines in the project are sorted using the
+# following rules:
+# - First all lines are sorted as-if `LC_COLLATE=C sort`
+# - Then all entries by group are sorted against the last digits
+#   of the test.
+#
+# For example:
+# ~~~
+# tests += \
+#   test-a \
+#   test-b \
+#   test-b1 \
+#   test-b2 \
+#   test-b10 \
+#   test-b20 \
+#   test-b100 \
+#   # tests
+# ~~~
+# This example shows tests sorted alphabetically, followed
+# by a numeric suffix sort in increasing numeric order.
+#
+# Required cleanups:
+# - Tests that end in "a" or "b" variants must be renamed to
+#   end in just the numerical value. For example 'tst-mutex7robust'
+#   should be renamed to 'tst-mutex12' (the highest numbered test)
+#   or 'tst-robust11' (the highest numbered test).
+# - Modules that end in "mod" or "mod1" should be renamed. For
+#   example 'tst-atfork2mod' should be renamed to 'tst-mod-atfork2'
+#   (test module for atfork2). If there are more than one module
+#   then they should be named with a suffix that uses [0-9] first
+#   then [A-Z] next for a total of 36 possible modules per test.
+#   No manually listed test currently uses more than that (though
+#   automatically generated tests may; they don't need sorting).
+# - Avoid including another test and instead refactor into common
+#   code with all tests including hte common code, then give the
+#   tests unique names.
+#
+# If you have a Makefile that needs converting, then you can
+# quickly split the values into one-per-line, ensure the start
+# and end markers are in place, and then run the script to
+# sort the values.
+
+import argparse
+import sys
+import locale
+import re
+import functools
+
+def numeric_key(line):
+    # Turn a line into a numeric sort value by fetching
+    # the ending number and using that as a key.
+    var = re.search(r'([0-9]+) \\$', line)
+    if var == None:
+        print ("Error: Test line is currently: \"", end='')
+        print (line, end='')
+        print ("\"")
+        print (
+        '''
+Test name does not match expected pattern.
+Rename to match pattern e.g. tst-name[0-9]+.
+        '''
+        )
+        raise Exception ("Invalid test name.")
+    # Return the numeric value as the key or throws because
+    # var is None.
+    return int(var.group(1))
+
+def sort_lines(lines):
+
+    # Use the C locale for language independent collation.
+    locale.setlocale (locale.LC_ALL, "C")
+
+    # Sort with strcoll initially.  The tests ending in numeric
+    # names will not sort correctly, but we will adjust that next.
+    lines = sorted(lines, key=functools.cmp_to_key(locale.strcoll))
+
+    # We could use a trie here, but since the problem is restricted
+    # to just numeric suffix we sort by group with a unique key
+    # function.
+
+    # Build a list of all start markers (tuple includes prefix)
+    prefixes = []
+    groups = []
+    for i in range(len(lines)):
+        # Look for things like "  tst-foo1 \" to start the numbered list.
+        var = re.search(r'([0-9]+) \\$', lines[i])
+        if var:
+            prefix = lines[i][0:var.span()[0]]
+            if prefix in prefixes:
+                continue
+            prefixes.append(prefix)
+            groups.append((prefix, i))
+
+    # For each prefix find the range it covers that needs numeric sorting.
+    numgroups = []
+    for group in groups:
+        for j in range(group[1] + 1,len(lines)):
+            if not lines[j].startswith(group[0]):
+                # If it doesn't start with the prefix, then we're on to
+                # to the next group so mark the last entry as the end
+                # of the group.
+                numgroups.append((group[0], group[1], j - 1))
+                break
+
+    # We now have a list of groups to sort.
+    for ng in numgroups:
+        # Note slices exclude nth element, so we must add one to right side.
+        lines[ng[1]:ng[2]+1] = sorted(lines[ng[1]:ng[2]+1], key=numeric_key)
+
+    # Return a sorted list with numeric tests sorted by number.
+    return lines
+
+def sort_makefile_lines(infile, outfile):
+
+    # Read the whole Makefile.
+    mfile = open(infile)
+    lines = mfile.readlines()
+    mfile.close()
+
+    # We will output the Makefile here. Open it early to check
+    # for any errors.
+    ofile = open(outfile, "w")
+
+    # Build a list of all start markers (tuple includes name).
+    startmarks = []
+    for i in range(len(lines)):
+        # Look for things like "var += \" to start the sorted list.
+        var = re.search(r'^([a-zA-Z0-9]*) \+\= \\$', lines[i])
+        if var:
+            # Remember the index and the name.
+            startmarks.append((i, var.group(1)))
+
+    # For each start marker try to find a matching end mark
+    # and build a block that needs sorting.  The end marker
+    # must have the matching comment name for it to be valid.
+    rangemarks = []
+    for sm in startmarks:
+        # Look for things like "  # var" to end the sorted list.
+        reg = r'^  # ' + sm[1] + r'$'
+        for j in range(sm[0] + 1, len(lines)):
+            if re.search(reg, lines[j]):
+                # Rembember the block to sort (inclusive).
+                rangemarks.append((sm[0] + 1, j - 1))
+                break
+
+    # We now have a list of all ranges that need sorting.
+    # Sort those ranges.
+    for r in rangemarks:
+        lines[r[0]:r[1]] = sort_lines(lines[r[0]:r[1]])
+
+    # Output the whole list with sorted lines.
+    for line in lines:
+        ofile.write(line)
+
+    ofile.close()
+
+def get_parser():
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument('-i', dest='infile',
+                        help='Input Makefile to read lines from')
+    parser.add_argument('-o', dest='outfile',
+                        help='Output Makefile to write sorted lines to')
+    return parser
+
+def main(argv):
+    parser = get_parser()
+    opts = parser.parse_args(argv)
+    sort_makefile_lines (opts.infile, opts.outfile)
+
+if __name__ == '__main__':
+    main(sys.argv[1:])
-- 
2.39.2


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

* Re: [PATCH 1/2] nptl: Re-flow and sort variables in Makefile.
  2023-04-28 11:48 ` [PATCH 1/2] nptl: Re-flow and sort variables in Makefile Carlos O'Donell
@ 2023-05-08 17:17   ` Siddhesh Poyarekar
  2023-05-08 17:53     ` Siddhesh Poyarekar
  0 siblings, 1 reply; 7+ messages in thread
From: Siddhesh Poyarekar @ 2023-05-08 17:17 UTC (permalink / raw)
  To: Carlos O'Donell, libc-alpha

On 2023-04-28 07:48, Carlos O'Donell via Libc-alpha wrote:
> ---
>   sysdeps/pthread/Makefile                      | 433 +++++++++++++-----
>   .../{tst-mutex7robust.c => tst-robust11.c}    |   0
>   2 files changed, 320 insertions(+), 113 deletions(-)
>   rename sysdeps/pthread/{tst-mutex7robust.c => tst-robust11.c} (100%)

LGTM, since you also mentioned on the weekly patch review call that the 
patchset has no effect on generated code.

Thanks,
Sid

> 
> diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
> index c2f5588bd9..222f5b5142 100644
> --- a/sysdeps/pthread/Makefile
> +++ b/sysdeps/pthread/Makefile
> @@ -21,9 +21,17 @@ $(objpfx)tst-timer: $(librt)
>   endif
>   
>   ifneq (,$(filter $(subdir),htl nptl))
> -headers += threads.h
> -
> -routines += thrd_current thrd_equal thrd_sleep thrd_yield pthread_atfork
> +headers += \
> +  threads.h \
> +  # headers
> +
> +routines += \
> +  pthread_atfork \
> +  thrd_current \
> +  thrd_equal \
> +  thrd_sleep \
> +  thrd_yield \
> +  # routines
>   
>   $(libpthread-routines-var) += \
>     call_once \
> @@ -48,86 +56,231 @@ $(libpthread-routines-var) += \
>     tss_delete \
>     tss_get \
>     tss_set \
> +  # $(libpthread-routines-var)
>   
> -tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
> -	 tst-cnd-timedwait tst-thrd-detach tst-mtx-basic tst-thrd-sleep \
> -	 tst-mtx-recursive tst-tss-basic tst-call-once tst-mtx-timedlock \
> -	 \
> -	 tst-abstime \
> -	 tst-pt-align tst-pt-align3 \
> -	 tst-attr1 \
> -	 tst-backtrace1 \
> -	 tst-bad-schedattr \
> -	 tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 \
> -	 tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
> -	 tst-basic7 \
> -	 tst-cancel-self tst-cancel-self-cancelstate \
> -	 tst-cancel-self-canceltype tst-cancel-self-testcancel \
> -	 tst-cancel1 tst-cancel2 tst-cancel3 \
> -	 tst-cancel4 tst-cancel5 \
> -	 tst-cancel6 tst-cancel8 tst-cancel9 tst-cancel10 tst-cancel11 \
> -	 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 tst-cancel16 \
> -	 tst-cancel18 tst-cancel19 tst-cancel20 tst-cancel21 \
> -	 tst-cancel22 tst-cancel23 tst-cancel26 tst-cancel27 tst-cancel28 \
> -	 tst-cancel29 \
> -	 tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 \
> -	 tst-clock1 \
> -	 tst-cond-except \
> -	 tst-cond1 tst-cond2 tst-cond3 tst-cond4 tst-cond5 tst-cond6 tst-cond7 \
> -	 tst-cond8 tst-cond9 tst-cond10 tst-cond11 tst-cond12 tst-cond13 \
> -	 tst-cond14 tst-cond15 tst-cond16 tst-cond17 tst-cond18 tst-cond19 \
> -	 tst-cond20 tst-cond21 tst-cond23 tst-cond24 tst-cond25 tst-cond27 \
> -	 tst-create-detached \
> -	 tst-detach1 \
> -	 tst-eintr2 tst-eintr3 tst-eintr4 tst-eintr5 \
> -	 tst-exec1 tst-exec2 tst-exec3 \
> -	 tst-exit1 tst-exit2 tst-exit3 \
> -	 tst-flock1 tst-flock2 \
> -	 tst-fork1 tst-fork2 tst-fork3 tst-fork4 \
> -	 tst-atfork1 \
> -	 tst-getpid3 \
> -	 tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 tst-join7 \
> -	 tst-join8 tst-join9 tst-join10 tst-join11 tst-join12 tst-join13 \
> -	 tst-join14 tst-join15 \
> -	 tst-key1 tst-key2 tst-key3 tst-key4 \
> -	 tst-kill1 tst-kill2 tst-kill3 tst-kill5 tst-kill6 \
> -	 tst-locale1 tst-locale2 \
> -	 tst-memstream \
> -	 tst-mutex-errorcheck tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 \
> -	 tst-mutex5 tst-mutex6 tst-mutex7 tst-mutex7robust tst-mutex9 \
> -	 tst-mutex10 tst-mutex11 tst-pthread-mutexattr \
> -	 tst-once1 tst-once2 tst-once3 tst-once4 \
> -	 tst-pt-popen1 \
> -	 tst-raise1 \
> -	 tst-robust1 tst-robust2 tst-robust3 tst-robust4 tst-robust5 \
> -	 tst-robust6 tst-robust7 tst-robust9 tst-robust10 \
> -	 tst-rwlock1 tst-rwlock4 tst-rwlock5 tst-rwlock12 \
> -	 tst-rwlock13 tst-rwlock14 tst-rwlock16 \
> -	 tst-rwlock-tryrdlock-stall tst-rwlock-trywrlock-stall \
> -	 tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 \
> -	 tst-sem8 tst-sem9 tst-sem10 tst-sem14 tst-sem15 tst-sem16 \
> -	 tst-setuid3 \
> -	 tst-signal1 tst-signal2 \
> -	 tst-signal4 tst-signal5 tst-signal6 tst-signal8 \
> -	 tst-spin1 tst-spin2 tst-spin3 tst-spin4 \
> -	 tst-stack1 \
> -	 tst-stdio1 tst-stdio2 \
> -	 tst-pt-sysconf \
> -	 tst-pt-tls1 tst-pt-tls2 \
> -	 tst-tsd1 tst-tsd2 tst-tsd5 tst-tsd6 \
> -	 tst-umask1 \
> -	 tst-unload \
> -	 tst-unwind-thread \
> -	 tst-pt-vfork1 tst-pt-vfork2 tst-vfork1x tst-vfork2x \
> -	 tst-pthread-exit-signal \
> -	 tst-pthread-setuid-loop \
> -	 tst-pthread_cancel-exited \
> -	 tst-pthread_cancel-select-loop \
> -	 tst-pthread-raise-blocked-self \
> -	 tst-pthread_kill-exited \
> -	 tst-pthread_kill-exiting \
> -	 tst-cancel30 \
> -	 # tests
> +tests += \
> +  tst-abstime \
> +  tst-atfork1 \
> +  tst-attr1 \
> +  tst-backtrace1 \
> +  tst-bad-schedattr \
> +  tst-barrier1 \
> +  tst-barrier2 \
> +  tst-barrier3 \
> +  tst-barrier4 \
> +  tst-basic1 \
> +  tst-basic2 \
> +  tst-basic3 \
> +  tst-basic4 \
> +  tst-basic5 \
> +  tst-basic6 \
> +  tst-basic7 \
> +  tst-call-once \
> +  tst-cancel-self \
> +  tst-cancel-self-cancelstate \
> +  tst-cancel-self-canceltype \
> +  tst-cancel-self-testcancel \
> +  tst-cancel1 \
> +  tst-cancel2 \
> +  tst-cancel3 \
> +  tst-cancel4 \
> +  tst-cancel5 \
> +  tst-cancel6 \
> +  tst-cancel8 \
> +  tst-cancel9 \
> +  tst-cancel10 \
> +  tst-cancel11 \
> +  tst-cancel12 \
> +  tst-cancel13 \
> +  tst-cancel14 \
> +  tst-cancel15 \
> +  tst-cancel16 \
> +  tst-cancel18 \
> +  tst-cancel19 \
> +  tst-cancel20 \
> +  tst-cancel21 \
> +  tst-cancel22 \
> +  tst-cancel23 \
> +  tst-cancel26 \
> +  tst-cancel27 \
> +  tst-cancel28 \
> +  tst-cancel29 \
> +  tst-cancel30 \
> +  tst-cleanup0 \
> +  tst-cleanup1 \
> +  tst-cleanup2 \
> +  tst-cleanup3 \
> +  tst-clock1 \
> +  tst-cnd-basic \
> +  tst-cnd-broadcast \
> +  tst-cnd-timedwait \
> +  tst-cond-except \
> +  tst-cond1 \
> +  tst-cond2 \
> +  tst-cond3 \
> +  tst-cond4 \
> +  tst-cond5 \
> +  tst-cond6 \
> +  tst-cond7 \
> +  tst-cond8 \
> +  tst-cond9 \
> +  tst-cond10 \
> +  tst-cond11 \
> +  tst-cond12 \
> +  tst-cond13 \
> +  tst-cond14 \
> +  tst-cond15 \
> +  tst-cond16 \
> +  tst-cond17 \
> +  tst-cond18 \
> +  tst-cond19 \
> +  tst-cond20 \
> +  tst-cond21 \
> +  tst-cond23 \
> +  tst-cond24 \
> +  tst-cond25 \
> +  tst-cond27 \
> +  tst-create-detached \
> +  tst-detach1 \
> +  tst-eintr2 \
> +  tst-eintr3 \
> +  tst-eintr4 \
> +  tst-eintr5 \
> +  tst-exec1 \
> +  tst-exec2 \
> +  tst-exec3 \
> +  tst-exit1 \
> +  tst-exit2 \
> +  tst-exit3 \
> +  tst-flock1 \
> +  tst-flock2 \
> +  tst-fork1 \
> +  tst-fork2 \
> +  tst-fork3 \
> +  tst-fork4 \
> +  tst-getpid3 \
> +  tst-join1 \
> +  tst-join2 \
> +  tst-join3 \
> +  tst-join4 \
> +  tst-join5 \
> +  tst-join6 \
> +  tst-join7 \
> +  tst-join8 \
> +  tst-join9 \
> +  tst-join10 \
> +  tst-join11 \
> +  tst-join12 \
> +  tst-join13 \
> +  tst-join14 \
> +  tst-join15 \
> +  tst-key1 \
> +  tst-key2 \
> +  tst-key3 \
> +  tst-key4 \
> +  tst-kill1 \
> +  tst-kill2 \
> +  tst-kill3 \
> +  tst-kill5 \
> +  tst-kill6 \
> +  tst-locale1 \
> +  tst-locale2 \
> +  tst-memstream \
> +  tst-mtx-basic \
> +  tst-mtx-recursive \
> +  tst-mtx-timedlock \
> +  tst-mtx-trylock \
> +  tst-mutex-errorcheck \
> +  tst-mutex1 \
> +  tst-mutex2 \
> +  tst-mutex3 \
> +  tst-mutex4 \
> +  tst-mutex5 \
> +  tst-mutex6 \
> +  tst-mutex7 \
> +  tst-mutex9 \
> +  tst-mutex10 \
> +  tst-mutex11 \
> +  tst-once1 \
> +  tst-once2 \
> +  tst-once3 \
> +  tst-once4 \
> +  tst-pt-align \
> +  tst-pt-align3 \
> +  tst-pt-popen1 \
> +  tst-pt-sysconf \
> +  tst-pt-tls1 \
> +  tst-pt-tls2 \
> +  tst-pt-vfork1 \
> +  tst-pt-vfork2 \
> +  tst-pthread-exit-signal \
> +  tst-pthread-mutexattr \
> +  tst-pthread-raise-blocked-self \
> +  tst-pthread-setuid-loop \
> +  tst-pthread_cancel-exited \
> +  tst-pthread_cancel-select-loop \
> +  tst-pthread_kill-exited \
> +  tst-pthread_kill-exiting \
> +  tst-raise1 \
> +  tst-robust1 \
> +  tst-robust2 \
> +  tst-robust3 \
> +  tst-robust4 \
> +  tst-robust5 \
> +  tst-robust6 \
> +  tst-robust7 \
> +  tst-robust9 \
> +  tst-robust10 \
> +  tst-robust11 \
> +  tst-rwlock-tryrdlock-stall \
> +  tst-rwlock-trywrlock-stall \
> +  tst-rwlock1 \
> +  tst-rwlock4 \
> +  tst-rwlock5 \
> +  tst-rwlock12 \
> +  tst-rwlock13 \
> +  tst-rwlock14 \
> +  tst-rwlock16 \
> +  tst-sem1 \
> +  tst-sem2 \
> +  tst-sem3 \
> +  tst-sem4 \
> +  tst-sem5 \
> +  tst-sem6 \
> +  tst-sem7 \
> +  tst-sem8 \
> +  tst-sem9 \
> +  tst-sem10 \
> +  tst-sem14 \
> +  tst-sem15 \
> +  tst-sem16 \
> +  tst-setuid3 \
> +  tst-signal1 \
> +  tst-signal2 \
> +  tst-signal4 \
> +  tst-signal5 \
> +  tst-signal6 \
> +  tst-signal8 \
> +  tst-spin1 \
> +  tst-spin2 \
> +  tst-spin3 \
> +  tst-spin4 \
> +  tst-stack1 \
> +  tst-stdio1 \
> +  tst-stdio2 \
> +  tst-thrd-detach \
> +  tst-thrd-sleep \
> +  tst-tsd1 \
> +  tst-tsd2 \
> +  tst-tsd5 \
> +  tst-tsd6 \
> +  tst-tss-basic \
> +  tst-umask1 \
> +  tst-unload \
> +  tst-unwind-thread \
> +  tst-vfork1x \
> +  tst-vfork2x \
> +  # tests
>   
>   tests-time64 += \
>     tst-abstime-time64 \
> @@ -138,47 +291,70 @@ tests-time64 += \
>     tst-rwlock14-time64 \
>     tst-sem5-time64 \
>     tst-thrd-sleep-time64 \
> +  # tests-time64
>   
>   static-only-routines = pthread_atfork
>   
>   # Files which must not be linked with libpthread.
> -tests-nolibpthread += tst-unload
> +tests-nolibpthread += \
> +  tst-unload \
> +  # tests-nolibpthread
>   
>   # GCC-4.9 compiles 'sprintf(NULL, ...)' into UD2 on x86_64 without -fno-builtin
>   CFLAGS-tst-cleanup2.c += -fno-builtin
>   CFLAGS-tst-cleanupx2.c += -fno-builtin
>   
> -tests += tst-cancelx2 tst-cancelx3 tst-cancelx6 tst-cancelx8 tst-cancelx9 \
> -	 tst-cancelx4 tst-cancelx5 \
> -	 tst-cancelx10 tst-cancelx11 tst-cancelx12 tst-cancelx13 tst-cancelx14 \
> -	 tst-cancelx15 tst-cancelx16 tst-cancelx18 tst-cancelx20 tst-cancelx21 \
> -	 tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3
> +tests += \
> +  tst-cancelx2 \
> +  tst-cancelx3 \
> +  tst-cancelx4 \
> +  tst-cancelx5 \
> +  tst-cancelx6 \
> +  tst-cancelx8 \
> +  tst-cancelx9 \
> +  tst-cancelx10 \
> +  tst-cancelx11 \
> +  tst-cancelx12 \
> +  tst-cancelx13 \
> +  tst-cancelx14 \
> +  tst-cancelx15 \
> +  tst-cancelx16 \
> +  tst-cancelx18 \
> +  tst-cancelx20 \
> +  tst-cancelx21 \
> +  tst-cleanupx0 \
> +  tst-cleanupx1 \
> +  tst-cleanupx2 \
> +  tst-cleanupx3 \
> +  # tests
>   
>   ifeq ($(build-shared),yes)
>   tests += \
> -  tst-atfork2 \
> -  tst-pt-tls4 \
>     tst-_res1 \
> -  tst-fini1 \
> -  tst-create1 \
> +  tst-atfork2 \
>     tst-atfork3 \
>     tst-atfork4 \
> -# tests
> +  tst-create1 \
> +  tst-fini1 \
> +  tst-pt-tls4 \
> +  # tests
>   
> -tests-nolibpthread += tst-fini1
> +tests-nolibpthread += \
> +  tst-fini1 \
> +  # tests-nolibpthread
>   endif
>   
>   modules-names += \
> -  tst-atfork2mod \
> -  tst-tls4moda \
> -  tst-tls4modb \
>     tst-_res1mod1 \
>     tst-_res1mod2 \
> -  tst-fini1mod \
> -  tst-create1mod \
> +  tst-atfork2mod \
>     tst-atfork3mod \
>     tst-atfork4mod \
> -# module-names
> +  tst-create1mod \
> +  tst-fini1mod \
> +  tst-tls4moda \
> +  tst-tls4modb \
> +  # modules-names
>   
>   test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
>   
> @@ -192,17 +368,30 @@ ifeq ($(build-shared),yes)
>   tests: $(test-modules)
>   endif
>   
> +tests-static += \
> +  tst-cancel21-static \
> +  tst-locale1 \
> +  tst-locale2 \
> +  # tests-static
>   
> -tests-static += tst-locale1 tst-locale2 tst-cancel21-static
> -
> -tests += tst-cancel21-static tst-cond11-static
> +tests += \
> +  tst-cancel21-static \
> +  tst-cond11-static \
> +  # tests
>   
>   # These tests are linked with libc before libpthread
> -tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x
> +tests-reverse += \
> +  tst-cancel5 \
> +  tst-cancel23 \
> +  tst-vfork1x \
> +  tst-vfork2x \
> +  # tests-reverse
>   
>   ifeq ($(run-built-tests),yes)
>   ifeq ($(build-shared),yes)
> -tests-special += $(objpfx)tst-cleanup0-cmp.out
> +tests-special += \
> +  $(objpfx)tst-cleanup0-cmp.out \
> +  # tests-special
>   endif
>   endif
>   
> @@ -286,20 +475,38 @@ $(objpfx)tst-_res1: $(objpfx)tst-_res1mod1.so $(objpfx)tst-_res1mod2.so \
>   $(objpfx)tst-pt-tls4: $(shared-thread-library)
>   $(objpfx)tst-pt-tls4.out: $(objpfx)tst-tls4moda.so $(objpfx)tst-tls4modb.so
>   
> -generated += tst-atfork2.mtrace
> +generated += \
> +  tst-atfork2.mtrace \
> +  # generated
>   
> -generated += $(objpfx)tst-atfork2.mtrace \
> -	     $(addsuffix .so,$(strip $(modules-names)))
> +generated += \
> +  $(objpfx)tst-atfork2.mtrace \
> +  $(addsuffix .so,$(strip $(modules-names))) \
> +  # generated
>   
> -tests-internal += tst-cancel25 tst-robust8
> +tests-internal += \
> +  tst-cancel25 \
> +  tst-robust8 \
> +  # tests-internal
>   
> -tests += tst-oncex3 tst-oncex4 tst-oncey3 tst-oncey4
> +tests += \
> +  tst-oncex3 \
> +  tst-oncex4 \
> +  tst-oncey3 \
> +  tst-oncey4 \
> +  # tests
>   
> -modules-names += tst-join7mod
> +modules-names += \
> +  tst-join7mod \
> +  # modules-names
>   
>   ifeq ($(build-shared),yes)
> -tests-static += tst-cond8-static
> -tests += tst-cond8-static
> +tests-static += \
> +  tst-cond8-static \
> +  # tests-static
> +tests += \
> +  tst-cond8-static \
> +  # tests
>   endif
>   
>   CFLAGS-tst-oncex3.c += -fexceptions
> diff --git a/sysdeps/pthread/tst-mutex7robust.c b/sysdeps/pthread/tst-robust11.c
> similarity index 100%
> rename from sysdeps/pthread/tst-mutex7robust.c
> rename to sysdeps/pthread/tst-robust11.c

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

* Re: [PATCH 2/2] scripts: Add sort-makefile-lines.py to sort Makefile variables.
  2023-04-28 11:48 ` [PATCH 2/2] scripts: Add sort-makefile-lines.py to sort Makefile variables Carlos O'Donell
@ 2023-05-08 17:47   ` Siddhesh Poyarekar
  2023-05-09 17:58     ` Carlos O'Donell
  0 siblings, 1 reply; 7+ messages in thread
From: Siddhesh Poyarekar @ 2023-05-08 17:47 UTC (permalink / raw)
  To: Carlos O'Donell, libc-alpha

On 2023-04-28 07:48, Carlos O'Donell via Libc-alpha wrote:
> The scripts/sort-makefile-lines.py script sorts Makefile variables
> according to project expected order.
> 
> The script is used like this:
> 
> $ scripts/sort-makefile-lines.py -i elf/Makefile -o elf/Makefile.tmp
> $ mv elf/Makefile.tmp elf/Makefile

Should we have a convenience make target like `make sort-makefile-lines` 
to allow folks to reflow files?  I'm trying to think of how we could 
make it easy for users to consume this.

> ---
>   scripts/sort-makefile-lines.py | 217 +++++++++++++++++++++++++++++++++
>   1 file changed, 217 insertions(+)
>   create mode 100755 scripts/sort-makefile-lines.py
> 
> diff --git a/scripts/sort-makefile-lines.py b/scripts/sort-makefile-lines.py
> new file mode 100755
> index 0000000000..06c0b3b3a2
> --- /dev/null
> +++ b/scripts/sort-makefile-lines.py
> @@ -0,0 +1,217 @@
> +#!/usr/bin/python3
> +# Sort Makefile lines as expected by project policy.
> +# Copyright (C) 2022-2023 Free Software Foundation, Inc.
> +# Copyright The GNU Toolchain Authors.

Why both?  Does it include code that was written by someone who does not 
have copyright assignment on file with the FSF?

> +# 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/>.
> +
> +# The project consensus is to split Makefile variable assignment
> +# across multiple lines with one value per line.  The values are
> +# then sorted as described below, and terminated with a special
> +# list termination marker.  This splitting makes it much easier
> +# to add new tests to the list since they become just a single
> +# line insertion.  It also makes backports and merges easier
> +# since the new test may not conflict due to the ordering.
> +#
> +# Consensus discussion:
> +# https://public-inbox.org/libc-alpha/f6406204-84f5-adb1-d00e-979ebeebbbde@redhat.com/
> +#
> +# To support cleaning up Makefiles we created this program to
> +# help sort existing lists converted to the new format.
> +#
> +# The program takes as input the Makefile to sort correctly,
> +# and the output file to write the correctly sorted output.
> +#
> +# Sorting is only carried out between two special markers:
> +# (a) Marker start is '<variable> += \'
> +# (b) Marker end is '  # <variable>'
> +# With everthing between (a) and (b) being sorted.
> +#
> +# You can use it like this:
> +# $ scripts/sort-makefile-lines.py -i elf/Makefile -o elf/Makefile.tmp
> +# $ mv elf/Makefile.tmp elf/Makefile
> +#
> +# The Makefile lines in the project are sorted using the
> +# following rules:
> +# - First all lines are sorted as-if `LC_COLLATE=C sort`
> +# - Then all entries by group are sorted against the last digits
> +#   of the test.
> +#
> +# For example:
> +# ~~~
> +# tests += \
> +#   test-a \
> +#   test-b \
> +#   test-b1 \
> +#   test-b2 \
> +#   test-b10 \
> +#   test-b20 \
> +#   test-b100 \
> +#   # tests
> +# ~~~
> +# This example shows tests sorted alphabetically, followed
> +# by a numeric suffix sort in increasing numeric order.
> +#
> +# Required cleanups:
> +# - Tests that end in "a" or "b" variants must be renamed to
> +#   end in just the numerical value. For example 'tst-mutex7robust'
> +#   should be renamed to 'tst-mutex12' (the highest numbered test)
> +#   or 'tst-robust11' (the highest numbered test).
> +# - Modules that end in "mod" or "mod1" should be renamed. For
> +#   example 'tst-atfork2mod' should be renamed to 'tst-mod-atfork2'
> +#   (test module for atfork2). If there are more than one module
> +#   then they should be named with a suffix that uses [0-9] first
> +#   then [A-Z] next for a total of 36 possible modules per test.
> +#   No manually listed test currently uses more than that (though
> +#   automatically generated tests may; they don't need sorting).
> +# - Avoid including another test and instead refactor into common
> +#   code with all tests including hte common code, then give the
> +#   tests unique names.
> +#
> +# If you have a Makefile that needs converting, then you can
> +# quickly split the values into one-per-line, ensure the start
> +# and end markers are in place, and then run the script to
> +# sort the values.

I'm not going to block on this if you don't want to do it, but have you 
thought about making this even simpler by, e.g. only looking for the 
start and end marker, splitting everything in between and then sorting 
the values?  Basically don't require developers to break the lists into 
one value per line and do it through the script.

> +
> +import argparse
> +import sys
> +import locale
> +import re
> +import functools
> +
> +def numeric_key(line):
> +    # Turn a line into a numeric sort value by fetching
> +    # the ending number and using that as a key.
> +    var = re.search(r'([0-9]+) \\$', line)
> +    if var == None:
> +        print ("Error: Test line is currently: \"", end='')
> +        print (line, end='')
> +        print ("\"")
> +        print (
> +        '''
> +Test name does not match expected pattern.
> +Rename to match pattern e.g. tst-name[0-9]+.
> +        '''
> +        )
> +        raise Exception ("Invalid test name.")
> +    # Return the numeric value as the key or throws because
> +    # var is None.
> +    return int(var.group(1))
> +
> +def sort_lines(lines):
> +
> +    # Use the C locale for language independent collation.
> +    locale.setlocale (locale.LC_ALL, "C")

Will we ever have non-ASCII names for tests, routines, etc?

> +
> +    # Sort with strcoll initially.  The tests ending in numeric
> +    # names will not sort correctly, but we will adjust that next.
> +    lines = sorted(lines, key=functools.cmp_to_key(locale.strcoll))

I wonder if you could, instead of simply passing strcoll, use a custom 
function which calls strcoll (or a simple sort if we decide we'll never 
have non-ascii file names) and also accounts for the suffix, returning, 
e.g. -1 for cmp('tst-mutex9', 'tst-mutex10').

> +
> +    # We could use a trie here, but since the problem is restricted
> +    # to just numeric suffix we sort by group with a unique key
> +    # function.
> +
> +    # Build a list of all start markers (tuple includes prefix)
> +    prefixes = []
> +    groups = []
> +    for i in range(len(lines)):
> +        # Look for things like "  tst-foo1 \" to start the numbered list.
> +        var = re.search(r'([0-9]+) \\$', lines[i])
> +        if var:
> +            prefix = lines[i][0:var.span()[0]]
> +            if prefix in prefixes:
> +                continue
> +            prefixes.append(prefix)
> +            groups.append((prefix, i))
> +
> +    # For each prefix find the range it covers that needs numeric sorting.
> +    numgroups = []
> +    for group in groups:
> +        for j in range(group[1] + 1,len(lines)):
> +            if not lines[j].startswith(group[0]):
> +                # If it doesn't start with the prefix, then we're on to
> +                # to the next group so mark the last entry as the end
> +                # of the group.
> +                numgroups.append((group[0], group[1], j - 1))
> +                break
> +
> +    # We now have a list of groups to sort.
> +    for ng in numgroups:
> +        # Note slices exclude nth element, so we must add one to right side.
> +        lines[ng[1]:ng[2]+1] = sorted(lines[ng[1]:ng[2]+1], key=numeric_key)
> +
> +    # Return a sorted list with numeric tests sorted by number.
> +    return lines
> +
> +def sort_makefile_lines(infile, outfile):
> +

Maybe add a check here to ensure infile != outfile?  Or do we want to 
support that use case?  It should be doable since you're reading the 
entire file into a list at once.

> +    # Read the whole Makefile.
> +    mfile = open(infile)
> +    lines = mfile.readlines()
> +    mfile.close()
> +
> +    # We will output the Makefile here. Open it early to check
> +    # for any errors.
> +    ofile = open(outfile, "w")
> +
> +    # Build a list of all start markers (tuple includes name).
> +    startmarks = []
> +    for i in range(len(lines)):
> +        # Look for things like "var += \" to start the sorted list.
> +        var = re.search(r'^([a-zA-Z0-9]*) \+\= \\$', lines[i])
> +        if var:
> +            # Remember the index and the name.
> +            startmarks.append((i, var.group(1)))
> +
> +    # For each start marker try to find a matching end mark
> +    # and build a block that needs sorting.  The end marker
> +    # must have the matching comment name for it to be valid.
> +    rangemarks = []
> +    for sm in startmarks:
> +        # Look for things like "  # var" to end the sorted list.
> +        reg = r'^  # ' + sm[1] + r'$'
> +        for j in range(sm[0] + 1, len(lines)):
> +            if re.search(reg, lines[j]):
> +                # Rembember the block to sort (inclusive).
> +                rangemarks.append((sm[0] + 1, j - 1))
> +                break
> +
> +    # We now have a list of all ranges that need sorting.
> +    # Sort those ranges.
> +    for r in rangemarks:
> +        lines[r[0]:r[1]] = sort_lines(lines[r[0]:r[1]])
> +
> +    # Output the whole list with sorted lines.
> +    for line in lines:
> +        ofile.write(line)
> +
> +    ofile.close()
> +
> +def get_parser():
> +    parser = argparse.ArgumentParser(description=__doc__)
> +    parser.add_argument('-i', dest='infile',
> +                        help='Input Makefile to read lines from')
> +    parser.add_argument('-o', dest='outfile',
> +                        help='Output Makefile to write sorted lines to')
> +    return parser
> +
> +def main(argv):
> +    parser = get_parser()
> +    opts = parser.parse_args(argv)
> +    sort_makefile_lines (opts.infile, opts.outfile)
> +
> +if __name__ == '__main__':
> +    main(sys.argv[1:])

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

* Re: [PATCH 1/2] nptl: Re-flow and sort variables in Makefile.
  2023-05-08 17:17   ` Siddhesh Poyarekar
@ 2023-05-08 17:53     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 7+ messages in thread
From: Siddhesh Poyarekar @ 2023-05-08 17:53 UTC (permalink / raw)
  To: Carlos O'Donell, libc-alpha

On 2023-05-08 13:17, Siddhesh Poyarekar wrote:
> On 2023-04-28 07:48, Carlos O'Donell via Libc-alpha wrote:
>> ---
>>   sysdeps/pthread/Makefile                      | 433 +++++++++++++-----
>>   .../{tst-mutex7robust.c => tst-robust11.c}    |   0
>>   2 files changed, 320 insertions(+), 113 deletions(-)
>>   rename sysdeps/pthread/{tst-mutex7robust.c => tst-robust11.c} (100%)
> 
> LGTM, since you also mentioned on the weekly patch review call that the 
> patchset has no effect on generated code.
> 

Oh, and

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> Thanks,
> Sid
> 
>>
>> diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
>> index c2f5588bd9..222f5b5142 100644
>> --- a/sysdeps/pthread/Makefile
>> +++ b/sysdeps/pthread/Makefile
>> @@ -21,9 +21,17 @@ $(objpfx)tst-timer: $(librt)
>>   endif
>>   ifneq (,$(filter $(subdir),htl nptl))
>> -headers += threads.h
>> -
>> -routines += thrd_current thrd_equal thrd_sleep thrd_yield pthread_atfork
>> +headers += \
>> +  threads.h \
>> +  # headers
>> +
>> +routines += \
>> +  pthread_atfork \
>> +  thrd_current \
>> +  thrd_equal \
>> +  thrd_sleep \
>> +  thrd_yield \
>> +  # routines
>>   $(libpthread-routines-var) += \
>>     call_once \
>> @@ -48,86 +56,231 @@ $(libpthread-routines-var) += \
>>     tss_delete \
>>     tss_get \
>>     tss_set \
>> +  # $(libpthread-routines-var)
>> -tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
>> -     tst-cnd-timedwait tst-thrd-detach tst-mtx-basic tst-thrd-sleep \
>> -     tst-mtx-recursive tst-tss-basic tst-call-once tst-mtx-timedlock \
>> -     \
>> -     tst-abstime \
>> -     tst-pt-align tst-pt-align3 \
>> -     tst-attr1 \
>> -     tst-backtrace1 \
>> -     tst-bad-schedattr \
>> -     tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 \
>> -     tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
>> -     tst-basic7 \
>> -     tst-cancel-self tst-cancel-self-cancelstate \
>> -     tst-cancel-self-canceltype tst-cancel-self-testcancel \
>> -     tst-cancel1 tst-cancel2 tst-cancel3 \
>> -     tst-cancel4 tst-cancel5 \
>> -     tst-cancel6 tst-cancel8 tst-cancel9 tst-cancel10 tst-cancel11 \
>> -     tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 tst-cancel16 \
>> -     tst-cancel18 tst-cancel19 tst-cancel20 tst-cancel21 \
>> -     tst-cancel22 tst-cancel23 tst-cancel26 tst-cancel27 tst-cancel28 \
>> -     tst-cancel29 \
>> -     tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 \
>> -     tst-clock1 \
>> -     tst-cond-except \
>> -     tst-cond1 tst-cond2 tst-cond3 tst-cond4 tst-cond5 tst-cond6 
>> tst-cond7 \
>> -     tst-cond8 tst-cond9 tst-cond10 tst-cond11 tst-cond12 tst-cond13 \
>> -     tst-cond14 tst-cond15 tst-cond16 tst-cond17 tst-cond18 tst-cond19 \
>> -     tst-cond20 tst-cond21 tst-cond23 tst-cond24 tst-cond25 tst-cond27 \
>> -     tst-create-detached \
>> -     tst-detach1 \
>> -     tst-eintr2 tst-eintr3 tst-eintr4 tst-eintr5 \
>> -     tst-exec1 tst-exec2 tst-exec3 \
>> -     tst-exit1 tst-exit2 tst-exit3 \
>> -     tst-flock1 tst-flock2 \
>> -     tst-fork1 tst-fork2 tst-fork3 tst-fork4 \
>> -     tst-atfork1 \
>> -     tst-getpid3 \
>> -     tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 
>> tst-join7 \
>> -     tst-join8 tst-join9 tst-join10 tst-join11 tst-join12 tst-join13 \
>> -     tst-join14 tst-join15 \
>> -     tst-key1 tst-key2 tst-key3 tst-key4 \
>> -     tst-kill1 tst-kill2 tst-kill3 tst-kill5 tst-kill6 \
>> -     tst-locale1 tst-locale2 \
>> -     tst-memstream \
>> -     tst-mutex-errorcheck tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 \
>> -     tst-mutex5 tst-mutex6 tst-mutex7 tst-mutex7robust tst-mutex9 \
>> -     tst-mutex10 tst-mutex11 tst-pthread-mutexattr \
>> -     tst-once1 tst-once2 tst-once3 tst-once4 \
>> -     tst-pt-popen1 \
>> -     tst-raise1 \
>> -     tst-robust1 tst-robust2 tst-robust3 tst-robust4 tst-robust5 \
>> -     tst-robust6 tst-robust7 tst-robust9 tst-robust10 \
>> -     tst-rwlock1 tst-rwlock4 tst-rwlock5 tst-rwlock12 \
>> -     tst-rwlock13 tst-rwlock14 tst-rwlock16 \
>> -     tst-rwlock-tryrdlock-stall tst-rwlock-trywrlock-stall \
>> -     tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 \
>> -     tst-sem8 tst-sem9 tst-sem10 tst-sem14 tst-sem15 tst-sem16 \
>> -     tst-setuid3 \
>> -     tst-signal1 tst-signal2 \
>> -     tst-signal4 tst-signal5 tst-signal6 tst-signal8 \
>> -     tst-spin1 tst-spin2 tst-spin3 tst-spin4 \
>> -     tst-stack1 \
>> -     tst-stdio1 tst-stdio2 \
>> -     tst-pt-sysconf \
>> -     tst-pt-tls1 tst-pt-tls2 \
>> -     tst-tsd1 tst-tsd2 tst-tsd5 tst-tsd6 \
>> -     tst-umask1 \
>> -     tst-unload \
>> -     tst-unwind-thread \
>> -     tst-pt-vfork1 tst-pt-vfork2 tst-vfork1x tst-vfork2x \
>> -     tst-pthread-exit-signal \
>> -     tst-pthread-setuid-loop \
>> -     tst-pthread_cancel-exited \
>> -     tst-pthread_cancel-select-loop \
>> -     tst-pthread-raise-blocked-self \
>> -     tst-pthread_kill-exited \
>> -     tst-pthread_kill-exiting \
>> -     tst-cancel30 \
>> -     # tests
>> +tests += \
>> +  tst-abstime \
>> +  tst-atfork1 \
>> +  tst-attr1 \
>> +  tst-backtrace1 \
>> +  tst-bad-schedattr \
>> +  tst-barrier1 \
>> +  tst-barrier2 \
>> +  tst-barrier3 \
>> +  tst-barrier4 \
>> +  tst-basic1 \
>> +  tst-basic2 \
>> +  tst-basic3 \
>> +  tst-basic4 \
>> +  tst-basic5 \
>> +  tst-basic6 \
>> +  tst-basic7 \
>> +  tst-call-once \
>> +  tst-cancel-self \
>> +  tst-cancel-self-cancelstate \
>> +  tst-cancel-self-canceltype \
>> +  tst-cancel-self-testcancel \
>> +  tst-cancel1 \
>> +  tst-cancel2 \
>> +  tst-cancel3 \
>> +  tst-cancel4 \
>> +  tst-cancel5 \
>> +  tst-cancel6 \
>> +  tst-cancel8 \
>> +  tst-cancel9 \
>> +  tst-cancel10 \
>> +  tst-cancel11 \
>> +  tst-cancel12 \
>> +  tst-cancel13 \
>> +  tst-cancel14 \
>> +  tst-cancel15 \
>> +  tst-cancel16 \
>> +  tst-cancel18 \
>> +  tst-cancel19 \
>> +  tst-cancel20 \
>> +  tst-cancel21 \
>> +  tst-cancel22 \
>> +  tst-cancel23 \
>> +  tst-cancel26 \
>> +  tst-cancel27 \
>> +  tst-cancel28 \
>> +  tst-cancel29 \
>> +  tst-cancel30 \
>> +  tst-cleanup0 \
>> +  tst-cleanup1 \
>> +  tst-cleanup2 \
>> +  tst-cleanup3 \
>> +  tst-clock1 \
>> +  tst-cnd-basic \
>> +  tst-cnd-broadcast \
>> +  tst-cnd-timedwait \
>> +  tst-cond-except \
>> +  tst-cond1 \
>> +  tst-cond2 \
>> +  tst-cond3 \
>> +  tst-cond4 \
>> +  tst-cond5 \
>> +  tst-cond6 \
>> +  tst-cond7 \
>> +  tst-cond8 \
>> +  tst-cond9 \
>> +  tst-cond10 \
>> +  tst-cond11 \
>> +  tst-cond12 \
>> +  tst-cond13 \
>> +  tst-cond14 \
>> +  tst-cond15 \
>> +  tst-cond16 \
>> +  tst-cond17 \
>> +  tst-cond18 \
>> +  tst-cond19 \
>> +  tst-cond20 \
>> +  tst-cond21 \
>> +  tst-cond23 \
>> +  tst-cond24 \
>> +  tst-cond25 \
>> +  tst-cond27 \
>> +  tst-create-detached \
>> +  tst-detach1 \
>> +  tst-eintr2 \
>> +  tst-eintr3 \
>> +  tst-eintr4 \
>> +  tst-eintr5 \
>> +  tst-exec1 \
>> +  tst-exec2 \
>> +  tst-exec3 \
>> +  tst-exit1 \
>> +  tst-exit2 \
>> +  tst-exit3 \
>> +  tst-flock1 \
>> +  tst-flock2 \
>> +  tst-fork1 \
>> +  tst-fork2 \
>> +  tst-fork3 \
>> +  tst-fork4 \
>> +  tst-getpid3 \
>> +  tst-join1 \
>> +  tst-join2 \
>> +  tst-join3 \
>> +  tst-join4 \
>> +  tst-join5 \
>> +  tst-join6 \
>> +  tst-join7 \
>> +  tst-join8 \
>> +  tst-join9 \
>> +  tst-join10 \
>> +  tst-join11 \
>> +  tst-join12 \
>> +  tst-join13 \
>> +  tst-join14 \
>> +  tst-join15 \
>> +  tst-key1 \
>> +  tst-key2 \
>> +  tst-key3 \
>> +  tst-key4 \
>> +  tst-kill1 \
>> +  tst-kill2 \
>> +  tst-kill3 \
>> +  tst-kill5 \
>> +  tst-kill6 \
>> +  tst-locale1 \
>> +  tst-locale2 \
>> +  tst-memstream \
>> +  tst-mtx-basic \
>> +  tst-mtx-recursive \
>> +  tst-mtx-timedlock \
>> +  tst-mtx-trylock \
>> +  tst-mutex-errorcheck \
>> +  tst-mutex1 \
>> +  tst-mutex2 \
>> +  tst-mutex3 \
>> +  tst-mutex4 \
>> +  tst-mutex5 \
>> +  tst-mutex6 \
>> +  tst-mutex7 \
>> +  tst-mutex9 \
>> +  tst-mutex10 \
>> +  tst-mutex11 \
>> +  tst-once1 \
>> +  tst-once2 \
>> +  tst-once3 \
>> +  tst-once4 \
>> +  tst-pt-align \
>> +  tst-pt-align3 \
>> +  tst-pt-popen1 \
>> +  tst-pt-sysconf \
>> +  tst-pt-tls1 \
>> +  tst-pt-tls2 \
>> +  tst-pt-vfork1 \
>> +  tst-pt-vfork2 \
>> +  tst-pthread-exit-signal \
>> +  tst-pthread-mutexattr \
>> +  tst-pthread-raise-blocked-self \
>> +  tst-pthread-setuid-loop \
>> +  tst-pthread_cancel-exited \
>> +  tst-pthread_cancel-select-loop \
>> +  tst-pthread_kill-exited \
>> +  tst-pthread_kill-exiting \
>> +  tst-raise1 \
>> +  tst-robust1 \
>> +  tst-robust2 \
>> +  tst-robust3 \
>> +  tst-robust4 \
>> +  tst-robust5 \
>> +  tst-robust6 \
>> +  tst-robust7 \
>> +  tst-robust9 \
>> +  tst-robust10 \
>> +  tst-robust11 \
>> +  tst-rwlock-tryrdlock-stall \
>> +  tst-rwlock-trywrlock-stall \
>> +  tst-rwlock1 \
>> +  tst-rwlock4 \
>> +  tst-rwlock5 \
>> +  tst-rwlock12 \
>> +  tst-rwlock13 \
>> +  tst-rwlock14 \
>> +  tst-rwlock16 \
>> +  tst-sem1 \
>> +  tst-sem2 \
>> +  tst-sem3 \
>> +  tst-sem4 \
>> +  tst-sem5 \
>> +  tst-sem6 \
>> +  tst-sem7 \
>> +  tst-sem8 \
>> +  tst-sem9 \
>> +  tst-sem10 \
>> +  tst-sem14 \
>> +  tst-sem15 \
>> +  tst-sem16 \
>> +  tst-setuid3 \
>> +  tst-signal1 \
>> +  tst-signal2 \
>> +  tst-signal4 \
>> +  tst-signal5 \
>> +  tst-signal6 \
>> +  tst-signal8 \
>> +  tst-spin1 \
>> +  tst-spin2 \
>> +  tst-spin3 \
>> +  tst-spin4 \
>> +  tst-stack1 \
>> +  tst-stdio1 \
>> +  tst-stdio2 \
>> +  tst-thrd-detach \
>> +  tst-thrd-sleep \
>> +  tst-tsd1 \
>> +  tst-tsd2 \
>> +  tst-tsd5 \
>> +  tst-tsd6 \
>> +  tst-tss-basic \
>> +  tst-umask1 \
>> +  tst-unload \
>> +  tst-unwind-thread \
>> +  tst-vfork1x \
>> +  tst-vfork2x \
>> +  # tests
>>   tests-time64 += \
>>     tst-abstime-time64 \
>> @@ -138,47 +291,70 @@ tests-time64 += \
>>     tst-rwlock14-time64 \
>>     tst-sem5-time64 \
>>     tst-thrd-sleep-time64 \
>> +  # tests-time64
>>   static-only-routines = pthread_atfork
>>   # Files which must not be linked with libpthread.
>> -tests-nolibpthread += tst-unload
>> +tests-nolibpthread += \
>> +  tst-unload \
>> +  # tests-nolibpthread
>>   # GCC-4.9 compiles 'sprintf(NULL, ...)' into UD2 on x86_64 without 
>> -fno-builtin
>>   CFLAGS-tst-cleanup2.c += -fno-builtin
>>   CFLAGS-tst-cleanupx2.c += -fno-builtin
>> -tests += tst-cancelx2 tst-cancelx3 tst-cancelx6 tst-cancelx8 
>> tst-cancelx9 \
>> -     tst-cancelx4 tst-cancelx5 \
>> -     tst-cancelx10 tst-cancelx11 tst-cancelx12 tst-cancelx13 
>> tst-cancelx14 \
>> -     tst-cancelx15 tst-cancelx16 tst-cancelx18 tst-cancelx20 
>> tst-cancelx21 \
>> -     tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3
>> +tests += \
>> +  tst-cancelx2 \
>> +  tst-cancelx3 \
>> +  tst-cancelx4 \
>> +  tst-cancelx5 \
>> +  tst-cancelx6 \
>> +  tst-cancelx8 \
>> +  tst-cancelx9 \
>> +  tst-cancelx10 \
>> +  tst-cancelx11 \
>> +  tst-cancelx12 \
>> +  tst-cancelx13 \
>> +  tst-cancelx14 \
>> +  tst-cancelx15 \
>> +  tst-cancelx16 \
>> +  tst-cancelx18 \
>> +  tst-cancelx20 \
>> +  tst-cancelx21 \
>> +  tst-cleanupx0 \
>> +  tst-cleanupx1 \
>> +  tst-cleanupx2 \
>> +  tst-cleanupx3 \
>> +  # tests
>>   ifeq ($(build-shared),yes)
>>   tests += \
>> -  tst-atfork2 \
>> -  tst-pt-tls4 \
>>     tst-_res1 \
>> -  tst-fini1 \
>> -  tst-create1 \
>> +  tst-atfork2 \
>>     tst-atfork3 \
>>     tst-atfork4 \
>> -# tests
>> +  tst-create1 \
>> +  tst-fini1 \
>> +  tst-pt-tls4 \
>> +  # tests
>> -tests-nolibpthread += tst-fini1
>> +tests-nolibpthread += \
>> +  tst-fini1 \
>> +  # tests-nolibpthread
>>   endif
>>   modules-names += \
>> -  tst-atfork2mod \
>> -  tst-tls4moda \
>> -  tst-tls4modb \
>>     tst-_res1mod1 \
>>     tst-_res1mod2 \
>> -  tst-fini1mod \
>> -  tst-create1mod \
>> +  tst-atfork2mod \
>>     tst-atfork3mod \
>>     tst-atfork4mod \
>> -# module-names
>> +  tst-create1mod \
>> +  tst-fini1mod \
>> +  tst-tls4moda \
>> +  tst-tls4modb \
>> +  # modules-names
>>   test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
>> @@ -192,17 +368,30 @@ ifeq ($(build-shared),yes)
>>   tests: $(test-modules)
>>   endif
>> +tests-static += \
>> +  tst-cancel21-static \
>> +  tst-locale1 \
>> +  tst-locale2 \
>> +  # tests-static
>> -tests-static += tst-locale1 tst-locale2 tst-cancel21-static
>> -
>> -tests += tst-cancel21-static tst-cond11-static
>> +tests += \
>> +  tst-cancel21-static \
>> +  tst-cond11-static \
>> +  # tests
>>   # These tests are linked with libc before libpthread
>> -tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x
>> +tests-reverse += \
>> +  tst-cancel5 \
>> +  tst-cancel23 \
>> +  tst-vfork1x \
>> +  tst-vfork2x \
>> +  # tests-reverse
>>   ifeq ($(run-built-tests),yes)
>>   ifeq ($(build-shared),yes)
>> -tests-special += $(objpfx)tst-cleanup0-cmp.out
>> +tests-special += \
>> +  $(objpfx)tst-cleanup0-cmp.out \
>> +  # tests-special
>>   endif
>>   endif
>> @@ -286,20 +475,38 @@ $(objpfx)tst-_res1: $(objpfx)tst-_res1mod1.so 
>> $(objpfx)tst-_res1mod2.so \
>>   $(objpfx)tst-pt-tls4: $(shared-thread-library)
>>   $(objpfx)tst-pt-tls4.out: $(objpfx)tst-tls4moda.so 
>> $(objpfx)tst-tls4modb.so
>> -generated += tst-atfork2.mtrace
>> +generated += \
>> +  tst-atfork2.mtrace \
>> +  # generated
>> -generated += $(objpfx)tst-atfork2.mtrace \
>> -         $(addsuffix .so,$(strip $(modules-names)))
>> +generated += \
>> +  $(objpfx)tst-atfork2.mtrace \
>> +  $(addsuffix .so,$(strip $(modules-names))) \
>> +  # generated
>> -tests-internal += tst-cancel25 tst-robust8
>> +tests-internal += \
>> +  tst-cancel25 \
>> +  tst-robust8 \
>> +  # tests-internal
>> -tests += tst-oncex3 tst-oncex4 tst-oncey3 tst-oncey4
>> +tests += \
>> +  tst-oncex3 \
>> +  tst-oncex4 \
>> +  tst-oncey3 \
>> +  tst-oncey4 \
>> +  # tests
>> -modules-names += tst-join7mod
>> +modules-names += \
>> +  tst-join7mod \
>> +  # modules-names
>>   ifeq ($(build-shared),yes)
>> -tests-static += tst-cond8-static
>> -tests += tst-cond8-static
>> +tests-static += \
>> +  tst-cond8-static \
>> +  # tests-static
>> +tests += \
>> +  tst-cond8-static \
>> +  # tests
>>   endif
>>   CFLAGS-tst-oncex3.c += -fexceptions
>> diff --git a/sysdeps/pthread/tst-mutex7robust.c 
>> b/sysdeps/pthread/tst-robust11.c
>> similarity index 100%
>> rename from sysdeps/pthread/tst-mutex7robust.c
>> rename to sysdeps/pthread/tst-robust11.c
> 

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

* Re: [PATCH 2/2] scripts: Add sort-makefile-lines.py to sort Makefile variables.
  2023-05-08 17:47   ` Siddhesh Poyarekar
@ 2023-05-09 17:58     ` Carlos O'Donell
  0 siblings, 0 replies; 7+ messages in thread
From: Carlos O'Donell @ 2023-05-09 17:58 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha

On 5/8/23 13:47, Siddhesh Poyarekar wrote:
> On 2023-04-28 07:48, Carlos O'Donell via Libc-alpha wrote:
>> The scripts/sort-makefile-lines.py script sorts Makefile variables
>> according to project expected order.
>>
>> The script is used like this:
>>
>> $ scripts/sort-makefile-lines.py -i elf/Makefile -o elf/Makefile.tmp
>> $ mv elf/Makefile.tmp elf/Makefile
> 
> Should we have a convenience make target like `make
> sort-makefile-lines` to allow folks to reflow files?  I'm trying to
> think of how we could make it easy for users to consume this.

The reflow process is manual and NRE, so it doesn't deserve a target IMO.

We *do* need to either:
(a) Add a linter in make check.
(b) Add a pre-commit CI linter check.

Today we can't do this until we convert more of the Makefiles and it is my intent
to convert them all.

It *almost* passes today, we need to cleanup some half-dozen Makefiles.

>> ---
>>   scripts/sort-makefile-lines.py | 217 +++++++++++++++++++++++++++++++++
>>   1 file changed, 217 insertions(+)
>>   create mode 100755 scripts/sort-makefile-lines.py
>>
>> diff --git a/scripts/sort-makefile-lines.py b/scripts/sort-makefile-lines.py
>> new file mode 100755
>> index 0000000000..06c0b3b3a2
>> --- /dev/null
>> +++ b/scripts/sort-makefile-lines.py
>> @@ -0,0 +1,217 @@
>> +#!/usr/bin/python3
>> +# Sort Makefile lines as expected by project policy.
>> +# Copyright (C) 2022-2023 Free Software Foundation, Inc.
>> +# Copyright The GNU Toolchain Authors.
> 
> Why both?  Does it include code that was written by someone who does
> not have copyright assignment on file with the FSF?

That's a mistake I forgot to cleanup.

I'll post a v2.

In v2 I'm changing a number of things:

(a) Fold all the complex double-block sorting into a single sort routine.
(b) Stop issuing errors and just sort according to the rules.

> 
>> +# 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/>.
>> +
>> +# The project consensus is to split Makefile variable assignment
>> +# across multiple lines with one value per line.  The values are
>> +# then sorted as described below, and terminated with a special
>> +# list termination marker.  This splitting makes it much easier
>> +# to add new tests to the list since they become just a single
>> +# line insertion.  It also makes backports and merges easier
>> +# since the new test may not conflict due to the ordering.
>> +#
>> +# Consensus discussion:
>> +# https://public-inbox.org/libc-alpha/f6406204-84f5-adb1-d00e-979ebeebbbde@redhat.com/
>> +#
>> +# To support cleaning up Makefiles we created this program to
>> +# help sort existing lists converted to the new format.
>> +#
>> +# The program takes as input the Makefile to sort correctly,
>> +# and the output file to write the correctly sorted output.
>> +#
>> +# Sorting is only carried out between two special markers:
>> +# (a) Marker start is '<variable> += \'
>> +# (b) Marker end is '  # <variable>'
>> +# With everthing between (a) and (b) being sorted.
>> +#
>> +# You can use it like this:
>> +# $ scripts/sort-makefile-lines.py -i elf/Makefile -o elf/Makefile.tmp
>> +# $ mv elf/Makefile.tmp elf/Makefile
>> +#
>> +# The Makefile lines in the project are sorted using the
>> +# following rules:
>> +# - First all lines are sorted as-if `LC_COLLATE=C sort`
>> +# - Then all entries by group are sorted against the last digits
>> +#   of the test.
>> +#
>> +# For example:
>> +# ~~~
>> +# tests += \
>> +#   test-a \
>> +#   test-b \
>> +#   test-b1 \
>> +#   test-b2 \
>> +#   test-b10 \
>> +#   test-b20 \
>> +#   test-b100 \
>> +#   # tests
>> +# ~~~
>> +# This example shows tests sorted alphabetically, followed
>> +# by a numeric suffix sort in increasing numeric order.
>> +#
>> +# Required cleanups:
>> +# - Tests that end in "a" or "b" variants must be renamed to
>> +#   end in just the numerical value. For example 'tst-mutex7robust'
>> +#   should be renamed to 'tst-mutex12' (the highest numbered test)
>> +#   or 'tst-robust11' (the highest numbered test).
>> +# - Modules that end in "mod" or "mod1" should be renamed. For
>> +#   example 'tst-atfork2mod' should be renamed to 'tst-mod-atfork2'
>> +#   (test module for atfork2). If there are more than one module
>> +#   then they should be named with a suffix that uses [0-9] first
>> +#   then [A-Z] next for a total of 36 possible modules per test.
>> +#   No manually listed test currently uses more than that (though
>> +#   automatically generated tests may; they don't need sorting).
>> +# - Avoid including another test and instead refactor into common
>> +#   code with all tests including hte common code, then give the
>> +#   tests unique names.
>> +#
>> +# If you have a Makefile that needs converting, then you can
>> +# quickly split the values into one-per-line, ensure the start
>> +# and end markers are in place, and then run the script to
>> +# sort the values.
> 
> I'm not going to block on this if you don't want to do it, but have
> you thought about making this even simpler by, e.g. only looking for
> the start and end marker, splitting everything in between and then
> sorting the values?  Basically don't require developers to break the
> lists into one value per line and do it through the script.

I have, but that means writing code that only gets used once in the conversion
process and then we delete it because it's never needed again.

I want to keep this file as simple as possible with as little code as possible
for the future scenario where all the files are already converted and we're
just checking their sorting.

Notice I don't enforce any whitespace either here just the sorting.

The intent is to lint only the sorting of lines in a specific layout.

>> +
>> +import argparse
>> +import sys
>> +import locale
>> +import re
>> +import functools
>> +
>> +def numeric_key(line):
>> +    # Turn a line into a numeric sort value by fetching
>> +    # the ending number and using that as a key.
>> +    var = re.search(r'([0-9]+) \\$', line)
>> +    if var == None:
>> +        print ("Error: Test line is currently: \"", end='')
>> +        print (line, end='')
>> +        print ("\"")
>> +        print (
>> +        '''
>> +Test name does not match expected pattern.
>> +Rename to match pattern e.g. tst-name[0-9]+.
>> +        '''
>> +        )
>> +        raise Exception ("Invalid test name.")
>> +    # Return the numeric value as the key or throws because
>> +    # var is None.
>> +    return int(var.group(1))
>> +
>> +def sort_lines(lines):
>> +
>> +    # Use the C locale for language independent collation.
>> +    locale.setlocale (locale.LC_ALL, "C")
> 
> Will we ever have non-ASCII names for tests, routines, etc?

Yes.

With C we'll sort by code point order (byte-by-byte).

It won't match the sorting of any *language* but it will sort by UTF-8 code point order.

>> +
>> +    # Sort with strcoll initially.  The tests ending in numeric
>> +    # names will not sort correctly, but we will adjust that next.
>> +    lines = sorted(lines, key=functools.cmp_to_key(locale.strcoll))
> 
> I wonder if you could, instead of simply passing strcoll, use a
> custom function which calls strcoll (or a simple sort if we decide
> we'll never have non-ascii file names) and also accounts for the
> suffix, returning, e.g. -1 for cmp('tst-mutex9', 'tst-mutex10').

Fixed in v2.

> 
>> +
>> +    # We could use a trie here, but since the problem is restricted
>> +    # to just numeric suffix we sort by group with a unique key
>> +    # function.
>> +
>> +    # Build a list of all start markers (tuple includes prefix)
>> +    prefixes = []
>> +    groups = []
>> +    for i in range(len(lines)):
>> +        # Look for things like "  tst-foo1 \" to start the numbered list.
>> +        var = re.search(r'([0-9]+) \\$', lines[i])
>> +        if var:
>> +            prefix = lines[i][0:var.span()[0]]
>> +            if prefix in prefixes:
>> +                continue
>> +            prefixes.append(prefix)
>> +            groups.append((prefix, i))
>> +
>> +    # For each prefix find the range it covers that needs numeric sorting.
>> +    numgroups = []
>> +    for group in groups:
>> +        for j in range(group[1] + 1,len(lines)):
>> +            if not lines[j].startswith(group[0]):
>> +                # If it doesn't start with the prefix, then we're on to
>> +                # to the next group so mark the last entry as the end
>> +                # of the group.
>> +                numgroups.append((group[0], group[1], j - 1))
>> +                break
>> +
>> +    # We now have a list of groups to sort.
>> +    for ng in numgroups:
>> +        # Note slices exclude nth element, so we must add one to right side.
>> +        lines[ng[1]:ng[2]+1] = sorted(lines[ng[1]:ng[2]+1], key=numeric_key)
>> +
>> +    # Return a sorted list with numeric tests sorted by number.
>> +    return lines
>> +
>> +def sort_makefile_lines(infile, outfile):
>> +
> 
> Maybe add a check here to ensure infile != outfile?  Or do we want to
> support that use case?  It should be doable since you're reading the
> entire file into a list at once.

It should be allowed, we open, read, close, and then open, write close.

I've adjusted all the uses to avoid showing a temp file.
 
>> +    # Read the whole Makefile.
>> +    mfile = open(infile)
>> +    lines = mfile.readlines()
>> +    mfile.close()
>> +
>> +    # We will output the Makefile here. Open it early to check
>> +    # for any errors.
>> +    ofile = open(outfile, "w")
>> +
>> +    # Build a list of all start markers (tuple includes name).
>> +    startmarks = []
>> +    for i in range(len(lines)):
>> +        # Look for things like "var += \" to start the sorted list.
>> +        var = re.search(r'^([a-zA-Z0-9]*) \+\= \\$', lines[i])
>> +        if var:
>> +            # Remember the index and the name.
>> +            startmarks.append((i, var.group(1)))
>> +
>> +    # For each start marker try to find a matching end mark
>> +    # and build a block that needs sorting.  The end marker
>> +    # must have the matching comment name for it to be valid.
>> +    rangemarks = []
>> +    for sm in startmarks:
>> +        # Look for things like "  # var" to end the sorted list.
>> +        reg = r'^  # ' + sm[1] + r'$'
>> +        for j in range(sm[0] + 1, len(lines)):
>> +            if re.search(reg, lines[j]):
>> +                # Rembember the block to sort (inclusive).
>> +                rangemarks.append((sm[0] + 1, j - 1))
>> +                break
>> +
>> +    # We now have a list of all ranges that need sorting.
>> +    # Sort those ranges.
>> +    for r in rangemarks:
>> +        lines[r[0]:r[1]] = sort_lines(lines[r[0]:r[1]])
>> +
>> +    # Output the whole list with sorted lines.
>> +    for line in lines:
>> +        ofile.write(line)
>> +
>> +    ofile.close()
>> +
>> +def get_parser():
>> +    parser = argparse.ArgumentParser(description=__doc__)
>> +    parser.add_argument('-i', dest='infile',
>> +                        help='Input Makefile to read lines from')
>> +    parser.add_argument('-o', dest='outfile',
>> +                        help='Output Makefile to write sorted lines to')
>> +    return parser
>> +
>> +def main(argv):
>> +    parser = get_parser()
>> +    opts = parser.parse_args(argv)
>> +    sort_makefile_lines (opts.infile, opts.outfile)
>> +
>> +if __name__ == '__main__':
>> +    main(sys.argv[1:])
> 

-- 
Cheers,
Carlos.


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

end of thread, other threads:[~2023-05-09 17:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 11:48 [PATCH 0/2] Standardize the sorting of Makefile variables Carlos O'Donell
2023-04-28 11:48 ` [PATCH 1/2] nptl: Re-flow and sort variables in Makefile Carlos O'Donell
2023-05-08 17:17   ` Siddhesh Poyarekar
2023-05-08 17:53     ` Siddhesh Poyarekar
2023-04-28 11:48 ` [PATCH 2/2] scripts: Add sort-makefile-lines.py to sort Makefile variables Carlos O'Donell
2023-05-08 17:47   ` Siddhesh Poyarekar
2023-05-09 17:58     ` Carlos O'Donell

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).