Re: [PATCH v2 10/10] detect-compiler: detect clang even if it found CUDA
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 26, 2025, 18:07 UTC
- Message-ID
- <CAPig+cR+ESNg4tV1G6jbKKeRKABD053qZcG0BoFuQ7aC+1tGYw@mail.gmail.com>
- In-Reply-To
- <20250326174127.GA2508080@coredump.intra.peff.net>
On Wed, Mar 26, 2025 at 1:44 PM Jeff King <peff@peff.net> wrote:
Show 12 quoted lines
> On Tue, Mar 25, 2025 at 11:32:14PM +0000, Johannes Schindelin via GitGitGadget wrote:
> > Let's unconfuse the script by letting it parse the first matching line
> > and ignore the rest.
>
> Makes sense. I wondered if this:
>
> > get_version_line() {
> > - LANG=C LC_ALL=C $CC -v 2>&1 | grep ' version '
> > + LANG=C LC_ALL=C $CC -v 2>&1 | sed -n '/ version /{p;q}'
>
> might be more readable with "grep -m1", but it looks like "-m" is not in
> POSIX. So what you wrote is probably safer.It's probably an indication that I've done too much `sed` programming, but I find Dscho's version more obvious. That aside, your response made me take a closer look at what Dscho wrote and I noticed that it is syntactically flawed, at least for BSD-lineage `sed`. Testing on macOS reveals that this is indeed so:
% LANG=C LC_ALL=C cc -v 2>&1 | sed -n '/ version /{p;q}'
sed: 1: "/ version /{p;q}": extra characters at the end of q commandThe problem is that the `q` function takes no arguments, but BSD-lineage `sed` thinks that the closing `}` is an argument rather than a terminator. Fixing this requires inserting a terminator after `q`, which will be either a newline character or a semicolon. So, the correct form is:
sed -n '/ version /{p;q;}