Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the string '@LIBDIR@' somehow magic?

For some reason I looked at /usr/bin/hg and saw what seemed like a strange bit of code:

libdir = '@LIBDIR@'

if libdir != '@' 'LIBDIR' '@':
    ...

The if statement looks like a tautology/contradiction as '@LIBDIR@' should always equal '@' 'LIBDIR' '@' in Python, so the code will never run. Under what conditions does '@LIBDIR@' change into something else?

like image 276
Nick T Avatar asked Sep 05 '25 03:09

Nick T


1 Answers

I'm not familiar with Mercurial per se, but to me @LIBDIR@ is pretty clearly intended to be substituted with some other string by an automated search-and-replace, such as in a setup script. The if statement checks to see whether this in fact has been done: a search won't find @LIBDIR@ in '@' 'LIBDIR' '@' so this is a way of comparing the variable's value to its original placeholder value without triggering the substitution of the placeholder in the if statement.

In other words, the if statement is asking, "if a library path has been specified at installation time, then validate it and add it to the Python module search path."

I'd personally put this information in a configuration file, since that would be easier for the user to edit and would be less likely to be clobbered by an update, but it looks like Mercurial is using the source code munging approach to configuration.

like image 192
kindall Avatar answered Sep 07 '25 21:09

kindall