Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
Ævar Arnfjörð Bjarmason writes: > Aside: I found it difficult to figure out how to submit patches to > this project. The Savannah page suggests the bug tracker, but as af > writing (and I'm logged in, as "avar") that link appears greyed out > in the web interface, and has a . I added a note to the README file on submitting patches and a note to the docs and README.git pointing there. As for the bug tracker I can't explain why it appears greyed out for you: it's never happened to me and when I visited just now without being logged in I was still able to see the bug tracker.
Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
On Fri, 2021-12-03 at 22:10 +0100, Ævar Arnfjörð Bjarmason wrote: > Would a patch that's updated to note that, and discusses the behavior > in older versions be acceptable for inclusion? I added a note about this to the docs. Thanks for pointing it out!
Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
It was documented but only in NEWS: martind@sirius:~/download/make$ sgrep wildcard | grep sort ./NEWS:179:* All wildcard expansion within GNU make, including $(wildcard ...), will sort ./NEWS:426: results from wildcard expansions, use the $(sort ...) function to request ./ChangeLog.3:1586: * NEWS: Accidentally forgot to back out the sorted wildcard martind@sirius:~/download/make$ That non-sorting of multiple arguments to wildcard, eg *.c *.h, is a nice gotcha, which wasn't in the NEWS item (presumably it didn't change). Not for me to say but the whole issue does feel worth a few lines to me. Then there's the wider topic of reproducible builds but perhaps I shouldn't pull on loose ends. From: Bug-make on behalf of Ævar Arnfjörð Bjarmason Sent: Friday, December 3, 2021 13:10 To: psm...@gnu.org Cc: bug-make@gnu.org Subject: Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3) * EXTERNAL EMAIL * On Fri, Dec 03 2021, Paul Smith wrote: > On Fri, 2021-12-03 at 11:08 +0100, Ævar Arnfjörð Bjarmason wrote: >> The motivation for this patch is that I've seen code like this in the >> wild: >> >> FILES = $(sort $(wildcard t*.sh)) >> >> I thought that it would be documented that that sort of thing was >> redundant, but I didn't find any mention of it in the manual. After >> some source spelunking I came up with this addition, which would have >> helped me when I consulted the manual. > > Originally it was not _guaranteed_ that wildcard yields sorted output. > > However, the output did happen to be sorted in older versions of GNU > make. In GNU make 3.82, that was changed to yield unsorted output. As > of GNU make 4.3, it was changed back and it is now guaranteed that > wildcard results are sorted: > > https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsavannah.gnu.org%2Fbugs%2Findex.php%3F52076&data=04%7C01%7CMartin.Dorey%40hitachivantara.com%7C18ef4b67200d42c876f808d9b6a1a956%7C18791e1761594f52a8d4de814ca8284a%7C0%7C0%7C637741627721341244%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=6av00xmXz7wmVpBSePOhJ3K3%2BNyytkQIOvXTas2qUmA%3D&reserved=0 > > I thought that I had updated the documentation to make this guarantee > clear but perhaps I forgot? As far as the proposed update goes what I should have noted that individual arguments to "wildcard" expand to sorted globs, but as noted in the thread: $(wildcard ? ?) Will return e.g. "1 2 3 1 2 3". Would a patch that's updated to note that, and discusses the behavior in older versions be acceptable for inclusion? Unless there's some place where this is documented that I didn't spot...
Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
On Fri, Dec 03 2021, Paul Smith wrote: > On Fri, 2021-12-03 at 11:08 +0100, Ævar Arnfjörð Bjarmason wrote: >> The motivation for this patch is that I've seen code like this in the >> wild: >> >> FILES = $(sort $(wildcard t*.sh)) >> >> I thought that it would be documented that that sort of thing was >> redundant, but I didn't find any mention of it in the manual. After >> some source spelunking I came up with this addition, which would have >> helped me when I consulted the manual. > > Originally it was not _guaranteed_ that wildcard yields sorted output. > > However, the output did happen to be sorted in older versions of GNU > make. In GNU make 3.82, that was changed to yield unsorted output. As > of GNU make 4.3, it was changed back and it is now guaranteed that > wildcard results are sorted: > > https://savannah.gnu.org/bugs/index.php?52076 > > I thought that I had updated the documentation to make this guarantee > clear but perhaps I forgot? As far as the proposed update goes what I should have noted that individual arguments to "wildcard" expand to sorted globs, but as noted in the thread: $(wildcard ? ?) Will return e.g. "1 2 3 1 2 3". Would a patch that's updated to note that, and discusses the behavior in older versions be acceptable for inclusion? Unless there's some place where this is documented that I didn't spot...
Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
On Fri, 2021-12-03 at 11:08 +0100, Ævar Arnfjörð Bjarmason wrote: > The motivation for this patch is that I've seen code like this in the > wild: > > FILES = $(sort $(wildcard t*.sh)) > > I thought that it would be documented that that sort of thing was > redundant, but I didn't find any mention of it in the manual. After > some source spelunking I came up with this addition, which would have > helped me when I consulted the manual. Originally it was not _guaranteed_ that wildcard yields sorted output. However, the output did happen to be sorted in older versions of GNU make. In GNU make 3.82, that was changed to yield unsorted output. As of GNU make 4.3, it was changed back and it is now guaranteed that wildcard results are sorted: https://savannah.gnu.org/bugs/index.php?52076 I thought that I had updated the documentation to make this guarantee clear but perhaps I forgot?
Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
On Fri, Dec 3, 2021 at 3:19 PM Ævar Arnfjörð Bjarmason wrote: > > The motivation for this patch is that I've seen code like this in the > wild: > > FILES = $(sort $(wildcard t*.sh)) > > I thought that it would be documented that that sort of thing was > redundant, but I didn't find any mention of it in the manual. Just for reference, the output of $(wildcard) wasn't sorted before make 4.3. As stated in the relevant bug report: https://savannah.gnu.org/bugs/index.php?52076 the code you spotted in the wild is in fact the most portable use of wildcard when the order matters. Regards, - Jouke
Re: [PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
On Fri, Dec 3, 2021 at 9:19 AM Ævar Arnfjörð Bjarmason wrote: > > The $subject isn't strictly true, as the it's implemented in terms of > MatchFirst() on Amiga, but that's obscure enough to not be noted in > the manual Then the manual will be lying to the users of amiga, right? > and in any case the tests added in 0d366b66 (* Added the > test suite to the main distribution., 1999-09-14) show that the output > is sorted on all platforms GNU make has been tested on. The tests don't verify that the output is sorted. It is just that this input in the test results in this output. Implementation may change (e.g. for performance reasons) to avoid sorting and the tests will be updated accordingly. Furthermore, a different input can result in not sorted output. $ ls 1 2 3 makefile $ cat makefile files:=$(wildcard 2 1 3) all:; $(info $(files)) $ make 2 1 3 make: 'all' is up to date. $ > Aside: I found it difficult to figure out how to submit patches to > this project. https://savannah.gnu.org/bugs/?group=make&func=additem regards, Dmitry
[PATCH] doc: note that $(wildcard) is implemented in terms of glob(3)
The $subject isn't strictly true, as the it's implemented in terms of MatchFirst() on Amiga, but that's obscure enough to not be noted in the manual, and in any case the tests added in 0d366b66 (* Added the test suite to the main distribution., 1999-09-14) show that the output is sorted on all platforms GNU make has been tested on. The motivation for this patch is that I've seen code like this in the wild: FILES = $(sort $(wildcard t*.sh)) I thought that it would be documented that that sort of thing was redundant, but I didn't find any mention of it in the manual. After some source spelunking I came up with this addition, which would have helped me when I consulted the manual. --- Aside: I found it difficult to figure out how to submit patches to this project. The Savannah page suggests the bug tracker, but as af writing (and I'm logged in, as "avar") that link appears greyed out in the web interface, and has a . doc/make.texi | 6 ++ 1 file changed, 6 insertions(+) diff --git a/doc/make.texi b/doc/make.texi index 4470386d..5cab7a9c 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -7664,6 +7664,12 @@ The argument @var{pattern} is a file name pattern, typically containing wildcard characters (as in shell file name patterns). The result of @code{wildcard} is a space-separated list of the names of existing files that match the pattern. + +The @code{wildcard} function is implemented in terms of the system's +@code{glob(3)} function (without a @code{GLOB_NOSORT} being +provided). So there's no reason to @code{$(sort)} its output if the +goal is to get output sorted in @code{glob(3)} order. + @xref{Wildcards, ,Using Wildcard Characters in File Names}. @item $(realpath @var{names}@dots{}) -- 2.34.GIT-dev