From cae54a30917a3fbffe0499792352be1c353b7e28 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 7 Jul 2023 13:01:01 -0700 Subject: [PATCH] build: Provide backward compatability for targets with path separators When a target name includes a path separator, extract the basename and assign that to the 'install_name' property. Then replace the path separators with '_' to 'flatten' the name, avoiding incidental creation of directories inside the build tree. Projects which depend on this behavior can be converted to use 'install_name' directly, once they depend on a version of meson with that feature. Signed-off-by: Keith Packard --- mesonbuild/build.py | 9 +++------ mesonbuild/utils/universal.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index c2bff171b8eb..152ae3208f05 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -37,6 +37,7 @@ get_filenames_templates_dict, substitute_values, has_path_sep, OptionKey, PerMachineDefaultable, OptionOverrideProxy, MesonBugException, EnvironmentVariables, pickle_load, + flatten_path, ) from .compilers import ( is_object, clink_langs, sort_clink, all_languages, @@ -538,13 +539,9 @@ def __post_init__(self, overrides: T.Optional[T.Dict[OptionKey, str]]) -> None: else: ovr = {} self.options = OptionOverrideProxy(ovr, self.environment.coredata.options, self.subproject) - # XXX: this should happen in the interpreter if has_path_sep(self.name): - # Fix failing test 53 when this becomes an error. - mlog.warning(textwrap.dedent(f'''\ - Target "{self.name}" has a path separator in its name. - This is not supported, it can cause unexpected failures and will become - a hard error in the future.''')) + self.install_name = os.path.basename(self.name) + self.name = flatten_path(self.name) # dataclass comparators? def __lt__(self, other: object) -> bool: diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index db59a601ee7c..ed6eb2193497 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -112,6 +112,7 @@ class _VerPickleLoadable(Protocol): 'expand_arguments', 'extract_as_list', 'first', + 'flatten_path', 'generate_list', 'get_compiler_for_source', 'get_filenames_templates_dict', @@ -1091,6 +1092,16 @@ def has_path_sep(name: str, sep: str = '/\\') -> bool: return False +def flatten_path(name: str, sep: str = '/\\', replace: str = '_') -> str: + 'Replaces any specified @sep path separators in @name with @replace' + result = '' + for char in name: + if char in sep: + char = replace + result = result + char + return result + + if is_windows(): # shlex.split is not suitable for splitting command line on Window (https://bugs.python.org/issue1724822); # shlex.quote is similarly problematic. Below are "proper" implementations of these functions according to