Re: [PATCH] Makefile: ASCII-sort += lists
- From
Denton Liu <liu.denton@gmail.com>
- Date
- Oct 9, 2020, 01:45 UTC
- Message-ID
- <20201009014528.GA1314@generichostname>
- In-Reply-To
- <nycvar.QRO.7.76.6.2010081156350.50@tvgsbejvaqbjf.bet>
Hi Dscho,
On Thu, Oct 08, 2020 at 12:06:47PM +0200, Johannes Schindelin wrote:
> Also, this strikes me as yet another task that is so automatable that we > should really avoid bothering humans with it.
Yep, I found these changes via a similar-looking Python script. I like the Perl version, though, since it gives a path for inclusion so that we can automate this task.
Show 47 quoted lines
> I gave it a quick whirl, and
> this Perl script seems to do the job for me:
>
> $key = '';
> @to_sort = ();
>
> sub flush_sorted {
> if ($#to_sort >= 0) {
> print join('', sort @to_sort);
> @to_sort = ();
> }
> }
>
> while (<>) {
> if (/^(\S+) \+=/) {
> if ($key ne $1) {
> flush_sorted;
> $key = $1;
> }
> push @to_sort, $_;
> } else {
> flush_sorted;
> print $_;
> }
> }
> flush_sorted;
>
> It is not the most elegant Perl script I ever wrote, but it does the job
> for me. And we could probably adapt and use it for other instances where
> we want to keep things sorted (think `commands[]` in `git.c` and the
> `cmd_*()` declarations in `builtin.h`, for example) and hook it up in
> `ci/run-static-analysis.sh` for added benefit.
>
> My little script also finds this:
>
> -- snip --
> @@ -1231,8 +1231,8 @@ space := $(empty) $(empty)
>
> ifdef SANITIZE
> SANITIZERS := $(foreach flag,$(subst $(comma),$(space),$(SANITIZE)),$(flag))
> -BASIC_CFLAGS += -fsanitize=$(SANITIZE) -fno-sanitize-recover=$(SANITIZE)
> BASIC_CFLAGS += -fno-omit-frame-pointer
> +BASIC_CFLAGS += -fsanitize=$(SANITIZE) -fno-sanitize-recover=$(SANITIZE)
> ifneq ($(filter undefined,$(SANITIZERS)),)
> BASIC_CFLAGS += -DSHA1DC_FORCE_ALIGNED_ACCESS
> endif
> -- snap --I opted to exclude this hunk because it didn't seem like a list that should be sorted. Perhaps if we include this in the static-analysis script, we could define a whitelist of lists that we want to keep sorted?
Thanks, Denton