Skip to content

Commit

Permalink
build: Provide backward compatability for targets with path separators
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
keith-packard committed Jul 7, 2023
1 parent 0fc4a44 commit cae54a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 3 additions & 6 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cae54a3

Please sign in to comment.