1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 00:42:57 +00:00
mpv/waftools/inflector.py
Avi Halachmi (:avih) 7c5cd5ef10 build: lua version: sanitize id before storage (no-op)
The lua version names which are autodetected/chosen (such as "51deb")
are used for two things:
- as key for storing the pkg-config compile/link flags.
- as ID for config.h and elsewhere - they're sanitized to use "_".

Due to some inconsistensies, if the sanitized ID is different than
the original name, then the compile/link flags are stored with the
original name as key, while the retrieval happens with the sanitized
ID - and therefore fails to find the correct flags.

The solution is to use the original name only for display purpose at
the output of configure, while using the sanitized version for
everything else, so that storage and retrieval use the same key.

Currently there's no issue and the patch has no effect, because the
sanitizer considers all the current names as valid IDs.

However, the next commit will add names which the sanitizer modifies,
such as "lua-5.1", so this commit makes such names work too.
2021-10-03 19:48:29 +03:00

23 lines
618 B
Python

import re
def sanitize_id(word):
""" Converts a word "into_it_s_underscored_version"
Convert any "CamelCased" or "ordinary Word" into an
"underscored_word"."""
return re.sub('[^A-Z^a-z^0-9]+', '_', \
re.sub('([a-z\d])([A-Z])', '\\1_\\2', \
re.sub('([A-Z]+)([A-Z][a-z])', '\\1_\\2', re.sub('::', '/', word)))).lower()
def storage_key(dep):
return sanitize_id(dep)
def define_key(dep):
return ("have_" + storage_key(dep)).upper()
def define_dict(dep):
return {'define_name': define_key(dep)}
def storage_dict(dep):
return {'uselib_store': storage_key(dep)}