Re: [PATCH 3/5] meson: correct path to system config/attribute files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/8/25 5:48 PM, Junio C Hamano wrote:
> Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx> writes:
> 
>> -  '-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
>> -  '-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
>> ...
>> +system_attributes = get_option('gitattributes')
>> +if system_attributes != ''
>> +  libgit_c_args += '-DETC_GITATTRIBUTES="' + system_attributes + '"'
>> +else
>> +  libgit_c_args += '-DETC_GITATTRIBUTES="' + get_option('sysconfdir') + '/gitattributes"'
>> +endif
> 
> Just out of curiosity (because this cannot be a regression, since
> the original removed one used the same constructs).
> 
> I am guessing from the presence of double quote around the value
> that these strings are not directly used to invoke the compiler
> without involving any shell (in other words, you wouldn't want these
> quotes if you are shoving these strings in argv[] yourself to feed
> execv()).
> 
> How does the above, and get_option() in particular, cope with a
> pathname that has letters with special meanings to the shell when
> they appear inside double-quote pair (like backquote or backslash or
> even a dollar sign)?  On the Makefile side we give VAR_SQ for a raw
> variable VAR and use the latter to write something like
> 
>         -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'
> 
> to make sure we won't be broken by them.  Is Meson giving us an
> equivalent to us for free by simply using get_option() here?
> 
> Thanks.


Meson uses strong implicit typing. The object type of '"' is a string
with value of double-quote-char, and the type of libgit_c_args is
"array". It's not a result of get_option() here, except inasmuch as
get_option() returned a string type.

Meson guarantees that arrays of strings e.g.

libgit_c_args = [
    '-Dfoo=string containing the $ (mighty dollar)',
    '-Dbar=string containing the ` soft-deprecated',
    '-Doopsies=string containing the \' (you read that right)',
]


are passed to the shell in a manner suitable for reinterpretation as an
argv array, notwithstanding other concerns (e.g. I believe there's some
mingw hack regarding doubling backslash escapes so they don't get
eaten). And of course this is conditional on the idea that it is
possible to reliably pass arguments on the Windows command line, which
doesn't have the notion of an array.

So, given that meson takes care of this, the actual value of the -D
define will be

string containing the $ (mighty dollar)


etc.

e.g. here is the ninja output:


[1/3] ccache cc -Ifoo.p -I. -I.. -fdiagnostics-color=always
-D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g '-Dfoo=string
containing the $ (mighty dollar)' '-Dbar=string containing the `
soft-deprecated' '-Doopsies=string containing the '"'"' (you read that
right)' -MD -MQ foo.p/foo.c.o -MF foo.p/foo.c.o.d -o foo.p/foo.c.o -c
../foo.c
<command-line>: warning: missing terminating ' character

Notice that the array contained a single quote using a meson string type
backslash escape, but the generated command line chose to shell-escape
it as ' ... '"'"' .... '



In this case, the Makefile does:

-DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'


and if I understand correctly the _SQ is to handle single quotes in the
directory name:


-DETC_GITATTRIBUTES='"/etc/git'\''s attribute file"'


Or in meson,

libgit_c_args += [
    '-DETC_GITATTRIBUTES="/etc/git\'s attribute file"',
]


compiles as:

[1/3] ccache cc -Ifoo.p -I. -I.. -fdiagnostics-color=always
-D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g '-Dfoo=string
containing the $ (mighty dollar)' '-Dbar=string containing the `
soft-deprecated' '-Doopsies=string containing the '"'"' (you read that
right)' '-DETC_GITATTRIBUTES="/etc/git'"'"'s attribute file"' -MD -MQ
foo.p/foo.c.o -MF foo.p/foo.c.o.d -o foo.p/foo.c.o -c ../foo.c


Meson has refrained from backslashes again:

ccache cc '-DETC_GITATTRIBUTES="/etc/git'"'"'s attribute file"'

Double quotes are part of the define value, single quote gets de-escaped
via the sequence:

'"'"'

instead of the sequence

'\''


-- 
Eli Schwartz

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux