git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 0/3] detect-compiler: clang updates

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 7, 2021, 14:26 UTC
Message-ID
<8735rlz5r2.fsf@evledraar.gmail.com>
In-Reply-To
<YQ6VJW0AwkouDnDe@coredump.intra.peff.net>
On Sat, Aug 07 2021, Jeff King wrote:
Show 38 quoted lines
> On Sat, Aug 07, 2021 at 04:56:04AM +0200, Ævar Arnfjörð Bjarmason wrote:
>
>> > On Sat, Aug 07, 2021 at 04:02:45AM +0200, Ævar Arnfjörð Bjarmason wrote:
>> >
>> >> Perhaps I've missed some obvious reason not to do this, but why are we
>> >> parsing the --version output of two modern compilers, as opposed to just
>> >> asking them what type/version they are via their usual macro facilities?
>> >> I.e. something like the below:
>> >
>> > That would probably work OK in practice, but it actually seems more
>> > complex to me (how do other random compilers react to "-E -"?
>> 
>> We only care about gcc and clang in that script, which I think have
>> supported that form of "-E" on stdin input for any version we're likely
>> to care about for the purposes of config.mak.dev. It seems unlikely that
>> we'll care about non-modern compilers in config.mak.dev, so using more
>> modern features there seems fine (it's all for opting us into even more
>> modern warning flags and the like...).
>
> Yeah, but we don't find out what we have until we run the script in
> question. I guess it is OK as long as we redirect stderr, ignore the
> exit code, and only look for a positive outcome in the output (your
> patch does the latter two already).
>
> I also wondered how this might interact with CC="ccache gcc" (where
> caching might fail to notice version changes). But from some quick
> testing, it looks like it doesn't cache in this case (neither stdin, nor
> with -E).
>
>> > Is it possible for us to get other output from the preprocessor that
>> > would confuse an eval?).
>> 
>> Probably, I just meant that as a POC. We could pipe it into some
>> awk/grep/cut/perl or whatever that would be more strict.
>
> That would probably be better. I would be curious to hear from somebody
> with a mac if this technique gives more sensible version numbers for the
> Apple-clang compiler.
It does, on the gcc304 box on the gccfarm (recent apple M1 Mac Mini):
    avar@minimac ~ % uname -a
    Darwin minimac.moose.housegordon.com 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:41 PDT 2021; root:xnu-7195.101.2~1/RELEASE_ARM64_T8101 arm64    
    avar@minimac ~ % clang --version
    Apple clang version 12.0.5 (clang-1205.0.22.9)
    Target: arm64-apple-darwin20.4.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    avar@minimac ~ % cat >f  
    GNUC=__GNUC__
    GNUC_MINOR=__GNUC_MINOR__
    GNUC_PATCHLEVEL=__GNUC_PATCHLEVEL__
    clang=__clang__
    clang_major=__clang_major__
    clang_minor=__clang_minor__
    clang_patchlevel=__clang_patchlevel__
    
    ^C
    avar@minimac ~ % clang -E - <f
    # 1 "<stdin>"
    # 1 "<built-in>" 1
    # 1 "<built-in>" 3
    # 384 "<built-in>" 3
    # 1 "<command line>" 1
    # 1 "<built-in>" 2
    # 1 "<stdin>" 2
    GNUC=4
    GNUC_MINOR=2
    GNUC_PATCHLEVEL=1
    clang=1
    clang_major=12
    clang_minor=0
    clang_patchlevel=5

I think nobody who's using clang derivatives is screwing with these macro variables, they're just changing whatever the "product name" or whatever is in the --version output.

Previous: Jeff KingNext: Jeff King
Message 17 of 22 in “makefile: update detect-compiler for newer Xcode version”
  1. makefile: update detect-compiler for newer Xcode versionCarlo Marcelo Arenas Belón, Aug 6, 2021
  2. Bagas SanjayaAug 6, 2021
  3. Carlo ArenasAug 6, 2021
  4. Eric SunshineAug 6, 2021
  5. Atharva RaykarAug 6, 2021
  6. Junio C HamanoAug 6, 2021
  7. Jeff KingAug 6, 2021
  8. 0/3 detect-compiler: clang updatesJunio C Hamano, Aug 6, 2021
  9. 1/3 build: update detect-compiler for newer Xcode versionJunio C Hamano, Aug 6, 2021
  10. 2/3 build: clang version may not be followed by extra wordsJunio C Hamano, Aug 6, 2021
  11. 3/3 build: catch clang that identifies itself as "$VENDOR clang"Junio C Hamano, Aug 6, 2021
  12. Jeff KingAug 7, 2021
  13. Ævar Arnfjörð BjarmasonAug 7, 2021
  14. Jeff KingAug 7, 2021
  15. Ævar Arnfjörð BjarmasonAug 7, 2021
  16. Jeff KingAug 7, 2021
  17. Ævar Arnfjörð BjarmasonAug 7, 2021
  18. Jeff KingAug 7, 2021
  19. Ævar Arnfjörð BjarmasonAug 7, 2021
  20. Jeff KingAug 9, 2021
  21. Carlo ArenasAug 8, 2021
  22. Jeff KingAug 9, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.