diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 28a92d28e148..c9f47f6acda6 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -150,7 +150,7 @@ class TargetInstallData: def __post_init__(self, outdir_name: T.Optional[str]) -> None: if outdir_name is None: outdir_name = os.path.join('{prefix}', self.outdir) - self.out_name = os.path.join(outdir_name, os.path.basename(self.fname)) + self.out_name = Path(outdir_name, os.path.basename(self.fname)).as_posix() @dataclass(eq=False) class InstallEmptyDir: @@ -307,16 +307,16 @@ def get_target_filename(self, t: T.Union[build.Target, build.CustomTargetIndex], else: assert isinstance(t, build.BuildTarget), t filename = t.get_filename() - return os.path.join(self.get_target_dir(t), filename) + return Path(self.get_target_dir(t), filename).as_posix() def get_target_filename_abs(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str: - return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target)) + return Path(self.environment.get_build_dir(), self.get_target_filename(target)).as_posix() def get_target_debug_filename(self, target: build.BuildTarget) -> T.Optional[str]: assert isinstance(target, build.BuildTarget), target if target.get_debug_filename(): debug_filename = target.get_debug_filename() - return os.path.join(self.get_target_dir(target), debug_filename) + return Path(self.get_target_dir(target), debug_filename).as_posix() else: return None @@ -324,7 +324,7 @@ def get_target_debug_filename_abs(self, target: build.BuildTarget) -> T.Optional assert isinstance(target, build.BuildTarget), target if not target.get_debug_filename(): return None - return os.path.join(self.environment.get_build_dir(), self.get_target_debug_filename(target)) + return Path(self.environment.get_build_dir(), self.get_target_debug_filename(target)).as_posix() def get_source_dir_include_args(self, target: build.BuildTarget, compiler: 'Compiler', *, absolute_path: bool = False) -> T.List[str]: curdir = target.get_subdir() diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index b783417cad2d..f9f95ddfaba2 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -3349,7 +3349,7 @@ def generate_pch(self, target, header_deps=None): def get_target_shsym_filename(self, target): # Always name the .symbols file after the primary build output because it always exists targetdir = self.get_target_private_dir(target) - return os.path.join(targetdir, target.get_filename() + '.symbols') + return Path(targetdir, target.get_filename() + '.symbols').as_posix() def generate_shsym(self, target) -> None: target_file = self.get_target_filename(target) @@ -3368,7 +3368,7 @@ def generate_shsym(self, target) -> None: self.add_build(elem) def get_import_filename(self, target) -> str: - return os.path.join(self.get_target_dir(target), target.import_filename) + return Path(self.get_target_dir(target), target.import_filename).as_posix() def get_target_type_link_args(self, target, linker): commands = [] diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 6986186bdad5..57fa286b7e7b 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -128,7 +128,7 @@ def list_installed(installdata: backends.InstallData) -> T.Dict[str, str]: def list_install_plan(installdata: backends.InstallData) -> T.Dict[str, T.Dict[str, T.Dict[str, T.Optional[str]]]]: plan: T.Dict[str, T.Dict[str, T.Dict[str, T.Optional[str]]]] = { 'targets': { - os.path.join(installdata.build_dir, target.fname): { + Path(installdata.build_dir, target.fname).as_posix(): { 'destination': target.out_name, 'tag': target.tag or None, 'subproject': target.subproject or None, @@ -145,13 +145,14 @@ def list_install_plan(installdata: backends.InstallData) -> T.Dict[str, T.Dict[s }.items(): # Mypy doesn't recognize SubdirInstallData as a subclass of InstallDataBase for data in data_list: # type: ignore[attr-defined] + data_path = Path(data.path).as_posix() data_type = data.data_type or key - install_path_name = data.install_path_name + install_path_name = Path(data.install_path_name) if key == 'headers': # in the headers, install_path_name is the directory - install_path_name = os.path.join(install_path_name, os.path.basename(data.path)) + install_path_name = install_path_name / os.path.basename(data.path) entry = { - 'destination': install_path_name, + 'destination': install_path_name.as_posix(), 'tag': data.tag or None, 'subproject': data.subproject or None, } @@ -162,7 +163,7 @@ def list_install_plan(installdata: backends.InstallData) -> T.Dict[str, T.Dict[s entry['exclude_files'] = list(exclude_files) plan[data_type] = plan.get(data_type, {}) - plan[data_type][data.path] = entry + plan[data_type][data_path] = entry return plan diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 8f56611d1fe0..02001a471c71 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -4802,124 +4802,125 @@ def output_name(name, type_): shared_lib_name = lambda name: output_name(name, SharedLibrary) static_lib_name = lambda name: output_name(name, StaticLibrary) exe_name = lambda name: output_name(name, Executable) + get_path = lambda f: Path(f).as_posix() expected = { 'targets': { - f'{self.builddir}/out1-notag.txt': { + get_path(f'{self.builddir}/out1-notag.txt'): { 'destination': '{datadir}/out1-notag.txt', 'install_rpath': None, 'tag': None, 'subproject': None, }, - f'{self.builddir}/out2-notag.txt': { + get_path(f'{self.builddir}/out2-notag.txt'): { 'destination': '{datadir}/out2-notag.txt', 'install_rpath': None, 'tag': None, 'subproject': None, }, - f'{self.builddir}/libstatic.a': { + get_path(f'{self.builddir}/libstatic.a'): { 'destination': '{libdir_static}/libstatic.a', 'install_rpath': None, 'tag': 'devel', 'subproject': None, }, - f'{self.builddir}/' + exe_name('app'): { + get_path(f'{self.builddir}/' + exe_name('app')): { 'destination': '{bindir}/' + exe_name('app'), 'install_rpath': None, 'tag': 'runtime', 'subproject': None, }, - f'{self.builddir}/' + exe_name('app-otherdir'): { + get_path(f'{self.builddir}/' + exe_name('app-otherdir')): { 'destination': '{prefix}/otherbin/' + exe_name('app-otherdir'), 'install_rpath': None, 'tag': 'runtime', 'subproject': None, }, - f'{self.builddir}/subdir/' + exe_name('app2'): { + get_path(f'{self.builddir}/subdir/' + exe_name('app2')): { 'destination': '{bindir}/' + exe_name('app2'), 'install_rpath': None, 'tag': 'runtime', 'subproject': None, }, - f'{self.builddir}/' + shared_lib_name('shared'): { + get_path(f'{self.builddir}/' + shared_lib_name('shared')): { 'destination': '{libdir_shared}/' + shared_lib_name('shared'), 'install_rpath': None, 'tag': 'runtime', 'subproject': None, }, - f'{self.builddir}/' + shared_lib_name('both'): { + get_path(f'{self.builddir}/' + shared_lib_name('both')): { 'destination': '{libdir_shared}/' + shared_lib_name('both'), 'install_rpath': None, 'tag': 'runtime', 'subproject': None, }, - f'{self.builddir}/' + static_lib_name('both'): { + get_path(f'{self.builddir}/' + static_lib_name('both')): { 'destination': '{libdir_static}/' + static_lib_name('both'), 'install_rpath': None, 'tag': 'devel', 'subproject': None, }, - f'{self.builddir}/' + shared_lib_name('bothcustom'): { + get_path(f'{self.builddir}/' + shared_lib_name('bothcustom')): { 'destination': '{libdir_shared}/' + shared_lib_name('bothcustom'), 'install_rpath': None, 'tag': 'custom', 'subproject': None, }, - f'{self.builddir}/' + static_lib_name('bothcustom'): { + get_path(f'{self.builddir}/' + static_lib_name('bothcustom')): { 'destination': '{libdir_static}/' + static_lib_name('bothcustom'), 'install_rpath': None, 'tag': 'custom', 'subproject': None, }, - f'{self.builddir}/subdir/' + shared_lib_name('both2'): { + get_path(f'{self.builddir}/subdir/' + shared_lib_name('both2')): { 'destination': '{libdir_shared}/' + shared_lib_name('both2'), 'install_rpath': None, 'tag': 'runtime', 'subproject': None, }, - f'{self.builddir}/subdir/' + static_lib_name('both2'): { + get_path(f'{self.builddir}/subdir/' + static_lib_name('both2')): { 'destination': '{libdir_static}/' + static_lib_name('both2'), 'install_rpath': None, 'tag': 'devel', 'subproject': None, }, - f'{self.builddir}/out1-custom.txt': { + get_path(f'{self.builddir}/out1-custom.txt'): { 'destination': '{datadir}/out1-custom.txt', 'install_rpath': None, 'tag': 'custom', 'subproject': None, }, - f'{self.builddir}/out2-custom.txt': { + get_path(f'{self.builddir}/out2-custom.txt'): { 'destination': '{datadir}/out2-custom.txt', 'install_rpath': None, 'tag': 'custom', 'subproject': None, }, - f'{self.builddir}/out3-custom.txt': { + get_path(f'{self.builddir}/out3-custom.txt'): { 'destination': '{datadir}/out3-custom.txt', 'install_rpath': None, 'tag': 'custom', 'subproject': None, }, - f'{self.builddir}/subdir/out1.txt': { + get_path(f'{self.builddir}/subdir/out1.txt'): { 'destination': '{datadir}/out1.txt', 'install_rpath': None, 'tag': None, 'subproject': None, }, - f'{self.builddir}/subdir/out2.txt': { + get_path(f'{self.builddir}/subdir/out2.txt'): { 'destination': '{datadir}/out2.txt', 'install_rpath': None, 'tag': None, 'subproject': None, }, - f'{self.builddir}/out-devel.h': { + get_path(f'{self.builddir}/out-devel.h'): { 'destination': '{includedir}/out-devel.h', 'install_rpath': None, 'tag': 'devel', 'subproject': None, }, - f'{self.builddir}/out3-notag.txt': { + get_path(f'{self.builddir}/out3-notag.txt'): { 'destination': '{datadir}/out3-notag.txt', 'install_rpath': None, 'tag': None, @@ -4927,80 +4928,80 @@ def output_name(name, type_): }, }, 'configure': { - f'{self.builddir}/foo-notag.h': { + get_path(f'{self.builddir}/foo-notag.h'): { 'destination': '{datadir}/foo-notag.h', 'tag': None, 'subproject': None, }, - f'{self.builddir}/foo2-devel.h': { + get_path(f'{self.builddir}/foo2-devel.h'): { 'destination': '{includedir}/foo2-devel.h', 'tag': 'devel', 'subproject': None, }, - f'{self.builddir}/foo-custom.h': { + get_path(f'{self.builddir}/foo-custom.h'): { 'destination': '{datadir}/foo-custom.h', 'tag': 'custom', 'subproject': None, }, - f'{self.builddir}/subdir/foo2.h': { + get_path(f'{self.builddir}/subdir/foo2.h'): { 'destination': '{datadir}/foo2.h', 'tag': None, 'subproject': None, }, }, 'data': { - f'{testdir}/bar-notag.txt': { + get_path(f'{testdir}/bar-notag.txt'): { 'destination': '{datadir}/bar-notag.txt', 'tag': None, 'subproject': None, }, - f'{testdir}/bar-devel.h': { + get_path(f'{testdir}/bar-devel.h'): { 'destination': '{includedir}/bar-devel.h', 'tag': 'devel', 'subproject': None, }, - f'{testdir}/bar-custom.txt': { + get_path(f'{testdir}/bar-custom.txt'): { 'destination': '{datadir}/bar-custom.txt', 'tag': 'custom', 'subproject': None, }, - f'{testdir}/subdir/bar2-devel.h': { + get_path(f'{testdir}/subdir/bar2-devel.h'): { 'destination': '{includedir}/bar2-devel.h', 'tag': 'devel', 'subproject': None, }, - f'{testdir}/subprojects/subproject/aaa.txt': { + get_path(f'{testdir}/subprojects/subproject/aaa.txt'): { 'destination': '{datadir}/subproject/aaa.txt', 'tag': None, 'subproject': 'subproject', }, - f'{testdir}/subprojects/subproject/bbb.txt': { + get_path(f'{testdir}/subprojects/subproject/bbb.txt'): { 'destination': '{datadir}/subproject/bbb.txt', 'tag': 'data', 'subproject': 'subproject', }, }, 'headers': { - f'{testdir}/foo1-devel.h': { + get_path(f'{testdir}/foo1-devel.h'): { 'destination': '{includedir}/foo1-devel.h', 'tag': 'devel', 'subproject': None, }, - f'{testdir}/subdir/foo3-devel.h': { + get_path(f'{testdir}/subdir/foo3-devel.h'): { 'destination': '{includedir}/foo3-devel.h', 'tag': 'devel', 'subproject': None, }, }, 'install_subdirs': { - f'{testdir}/custom_files': { + get_path(f'{testdir}/custom_files'): { 'destination': '{datadir}/custom_files', 'tag': 'custom', 'subproject': None, 'exclude_dirs': [], 'exclude_files': [], }, - f'{testdir}/excludes': { + get_path(f'{testdir}/excludes'): { 'destination': '{datadir}/excludes', 'tag': 'custom', 'subproject': None, @@ -5010,11 +5011,10 @@ def output_name(name, type_): } } - fix_path = lambda path: os.path.sep.join(path.split('/')) expected_fixed = { data_type: { - fix_path(source): { - key: fix_path(value) if key == 'destination' else value + get_path(source): { + key: get_path(value) if key == 'destination' else value for key, value in attributes.items() } for source, attributes in files.items() @@ -5025,6 +5025,7 @@ def output_name(name, type_): for data_type, files in expected_fixed.items(): for file, details in files.items(): with self.subTest(key='{}.{}'.format(data_type, file)): + if data_type == 'data': print(res[data_type]) self.assertEqual(res[data_type][file], details) @skip_if_not_language('rust')