Skip to content

Commit bc3f022

Browse files
committed
clang: Always pass POSIX paths to consumers
This commit ensures only POSIX style paths are passed to the compiler line, thus ensuring UNIX-style tools don't try to treat single backward slashes as Unicode escaped characters. Fixes #12191
1 parent 8758e13 commit bc3f022

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

mesonbuild/backend/backends.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ def get_target_filename(self, t: T.Union[build.Target, build.CustomTargetIndex],
309309
else:
310310
assert isinstance(t, build.BuildTarget), t
311311
filename = t.get_filename()
312-
return os.path.join(self.get_target_dir(t), filename)
312+
return (Path(self.get_target_dir(t)) / filename).as_posix()
313313

314314
def get_target_filename_abs(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str:
315-
return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target))
315+
return (Path(self.environment.get_build_dir()) / self.get_target_filename(target)).as_posix()
316316

317317
def get_source_dir_include_args(self, target: build.BuildTarget, compiler: 'Compiler', *, absolute_path: bool = False) -> T.List[str]:
318318
curdir = target.get_subdir()
@@ -339,16 +339,16 @@ def get_target_filename_for_linking(self, target: T.Union[build.Target, build.Cu
339339
# On all other platforms, we link to the library directly.
340340
if isinstance(target, build.SharedLibrary):
341341
link_lib = target.get_import_filename() or target.get_filename()
342-
return os.path.join(self.get_target_dir(target), link_lib)
342+
return (Path(self.get_target_dir(target)) / link_lib).as_posix()
343343
elif isinstance(target, build.StaticLibrary):
344-
return os.path.join(self.get_target_dir(target), target.get_filename())
344+
return (Path(self.get_target_dir(target)) / target.get_filename()).as_posix()
345345
elif isinstance(target, (build.CustomTarget, build.CustomTargetIndex)):
346346
if not target.is_linkable_target():
347347
raise MesonException(f'Tried to link against custom target "{target.name}", which is not linkable.')
348-
return os.path.join(self.get_target_dir(target), target.get_filename())
348+
return (Path(self.get_target_dir(target)) / target.get_filename()).as_posix()
349349
elif isinstance(target, build.Executable):
350350
if target.import_filename:
351-
return os.path.join(self.get_target_dir(target), target.get_import_filename())
351+
return (Path(self.get_target_dir(target)) / target.import_filename).as_posix()
352352
else:
353353
return None
354354
raise AssertionError(f'BUG: Tried to link to {target!r} which is not linkable')
@@ -1972,7 +1972,7 @@ def get_devenv(self) -> mesonlib.EnvironmentVariables:
19721972
in_default_dir = t.should_install() and not t.get_install_dir()[2]
19731973
if t.for_machine != MachineChoice.HOST or not in_default_dir:
19741974
continue
1975-
tdir = os.path.join(self.environment.get_build_dir(), self.get_target_dir(t))
1975+
tdir = (Path(self.environment.get_build_dir()) / self.get_target_dir(t)).as_posix()
19761976
if isinstance(t, build.Executable):
19771977
# Add binaries that are going to be installed in bindir into PATH
19781978
# so they get used by default instead of searching on system when

mesonbuild/backend/ninjabackend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ def generate_pch(self, target, header_deps=None):
32223222
def get_target_shsym_filename(self, target):
32233223
# Always name the .symbols file after the primary build output because it always exists
32243224
targetdir = self.get_target_private_dir(target)
3225-
return os.path.join(targetdir, target.get_filename() + '.symbols')
3225+
return (Path(targetdir) / (target.get_filename() + '.symbols')).as_posix()
32263226

32273227
def generate_shsym(self, target):
32283228
target_file = self.get_target_filename(target)
@@ -3235,7 +3235,7 @@ def generate_shsym(self, target):
32353235
self.add_build(elem)
32363236

32373237
def get_import_filename(self, target):
3238-
return os.path.join(self.get_target_dir(target), target.import_filename)
3238+
return (Path(self.get_target_dir(target)) / target.import_filename).as_posix()
32393239

32403240
def get_target_type_link_args(self, target, linker):
32413241
commands = []

unittests/allplatformstests.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4510,185 +4510,186 @@ def output_name(name, type_):
45104510
shared_lib_name = lambda name: output_name(name, SharedLibrary)
45114511
static_lib_name = lambda name: output_name(name, StaticLibrary)
45124512
exe_name = lambda name: output_name(name, Executable)
4513+
get_path = lambda f: Path(f).as_posix()
45134514

45144515
expected = {
45154516
'targets': {
4516-
f'{self.builddir}/out1-notag.txt': {
4517+
get_path(f'{self.builddir}/out1-notag.txt'): {
45174518
'destination': '{datadir}/out1-notag.txt',
45184519
'tag': None,
45194520
'subproject': None,
45204521
},
4521-
f'{self.builddir}/out2-notag.txt': {
4522+
get_path(f'{self.builddir}/out2-notag.txt'): {
45224523
'destination': '{datadir}/out2-notag.txt',
45234524
'tag': None,
45244525
'subproject': None,
45254526
},
4526-
f'{self.builddir}/libstatic.a': {
4527+
get_path(f'{self.builddir}/libstatic.a'): {
45274528
'destination': '{libdir_static}/libstatic.a',
45284529
'tag': 'devel',
45294530
'subproject': None,
45304531
},
4531-
f'{self.builddir}/' + exe_name('app'): {
4532+
get_path('{self.builddir}/' + exe_name('app')): {
45324533
'destination': '{bindir}/' + exe_name('app'),
45334534
'tag': 'runtime',
45344535
'subproject': None,
45354536
},
4536-
f'{self.builddir}/' + exe_name('app-otherdir'): {
4537+
get_path('{self.builddir}/' + exe_name('app-otherdir')): {
45374538
'destination': '{prefix}/otherbin/' + exe_name('app-otherdir'),
45384539
'tag': 'runtime',
45394540
'subproject': None,
45404541
},
4541-
f'{self.builddir}/subdir/' + exe_name('app2'): {
4542+
get_path('{self.builddir}/subdir/' + exe_name('app2')): {
45424543
'destination': '{bindir}/' + exe_name('app2'),
45434544
'tag': 'runtime',
45444545
'subproject': None,
45454546
},
4546-
f'{self.builddir}/' + shared_lib_name('shared'): {
4547+
get_path('{self.builddir}/' + shared_lib_name('shared')): {
45474548
'destination': '{libdir_shared}/' + shared_lib_name('shared'),
45484549
'tag': 'runtime',
45494550
'subproject': None,
45504551
},
4551-
f'{self.builddir}/' + shared_lib_name('both'): {
4552+
get_path('{self.builddir}/' + shared_lib_name('both')): {
45524553
'destination': '{libdir_shared}/' + shared_lib_name('both'),
45534554
'tag': 'runtime',
45544555
'subproject': None,
45554556
},
4556-
f'{self.builddir}/' + static_lib_name('both'): {
4557+
get_path('{self.builddir}/' + static_lib_name('both')): {
45574558
'destination': '{libdir_static}/' + static_lib_name('both'),
45584559
'tag': 'devel',
45594560
'subproject': None,
45604561
},
4561-
f'{self.builddir}/' + shared_lib_name('bothcustom'): {
4562+
get_path('{self.builddir}/' + shared_lib_name('bothcustom')): {
45624563
'destination': '{libdir_shared}/' + shared_lib_name('bothcustom'),
45634564
'tag': 'custom',
45644565
'subproject': None,
45654566
},
4566-
f'{self.builddir}/' + static_lib_name('bothcustom'): {
4567+
get_path('{self.builddir}/' + static_lib_name('bothcustom')): {
45674568
'destination': '{libdir_static}/' + static_lib_name('bothcustom'),
45684569
'tag': 'custom',
45694570
'subproject': None,
45704571
},
4571-
f'{self.builddir}/subdir/' + shared_lib_name('both2'): {
4572+
get_path('{self.builddir}/subdir/' + shared_lib_name('both2')): {
45724573
'destination': '{libdir_shared}/' + shared_lib_name('both2'),
45734574
'tag': 'runtime',
45744575
'subproject': None,
45754576
},
4576-
f'{self.builddir}/subdir/' + static_lib_name('both2'): {
4577+
get_path('{self.builddir}/subdir/' + static_lib_name('both2')): {
45774578
'destination': '{libdir_static}/' + static_lib_name('both2'),
45784579
'tag': 'devel',
45794580
'subproject': None,
45804581
},
4581-
f'{self.builddir}/out1-custom.txt': {
4582+
get_path('{self.builddir}/out1-custom.txt'): {
45824583
'destination': '{datadir}/out1-custom.txt',
45834584
'tag': 'custom',
45844585
'subproject': None,
45854586
},
4586-
f'{self.builddir}/out2-custom.txt': {
4587+
get_path('{self.builddir}/out2-custom.txt'): {
45874588
'destination': '{datadir}/out2-custom.txt',
45884589
'tag': 'custom',
45894590
'subproject': None,
45904591
},
4591-
f'{self.builddir}/out3-custom.txt': {
4592+
get_path('{self.builddir}/out3-custom.txt'): {
45924593
'destination': '{datadir}/out3-custom.txt',
45934594
'tag': 'custom',
45944595
'subproject': None,
45954596
},
4596-
f'{self.builddir}/subdir/out1.txt': {
4597+
get_path('{self.builddir}/subdir/out1.txt'): {
45974598
'destination': '{datadir}/out1.txt',
45984599
'tag': None,
45994600
'subproject': None,
46004601
},
4601-
f'{self.builddir}/subdir/out2.txt': {
4602+
get_path('{self.builddir}/subdir/out2.txt'): {
46024603
'destination': '{datadir}/out2.txt',
46034604
'tag': None,
46044605
'subproject': None,
46054606
},
4606-
f'{self.builddir}/out-devel.h': {
4607+
get_path('{self.builddir}/out-devel.h'): {
46074608
'destination': '{includedir}/out-devel.h',
46084609
'tag': 'devel',
46094610
'subproject': None,
46104611
},
4611-
f'{self.builddir}/out3-notag.txt': {
4612+
get_path('{self.builddir}/out3-notag.txt'): {
46124613
'destination': '{datadir}/out3-notag.txt',
46134614
'tag': None,
46144615
'subproject': None,
46154616
},
46164617
},
46174618
'configure': {
4618-
f'{self.builddir}/foo-notag.h': {
4619+
get_path('{self.builddir}/foo-notag.h'): {
46194620
'destination': '{datadir}/foo-notag.h',
46204621
'tag': None,
46214622
'subproject': None,
46224623
},
4623-
f'{self.builddir}/foo2-devel.h': {
4624+
get_path('{self.builddir}/foo2-devel.h'): {
46244625
'destination': '{includedir}/foo2-devel.h',
46254626
'tag': 'devel',
46264627
'subproject': None,
46274628
},
4628-
f'{self.builddir}/foo-custom.h': {
4629+
get_path('{self.builddir}/foo-custom.h'): {
46294630
'destination': '{datadir}/foo-custom.h',
46304631
'tag': 'custom',
46314632
'subproject': None,
46324633
},
4633-
f'{self.builddir}/subdir/foo2.h': {
4634+
get_path('{self.builddir}/subdir/foo2.h'): {
46344635
'destination': '{datadir}/foo2.h',
46354636
'tag': None,
46364637
'subproject': None,
46374638
},
46384639
},
46394640
'data': {
4640-
f'{testdir}/bar-notag.txt': {
4641+
get_path('{testdir}/bar-notag.txt'): {
46414642
'destination': '{datadir}/bar-notag.txt',
46424643
'tag': None,
46434644
'subproject': None,
46444645
},
4645-
f'{testdir}/bar-devel.h': {
4646+
get_path('{testdir}/bar-devel.h'): {
46464647
'destination': '{includedir}/bar-devel.h',
46474648
'tag': 'devel',
46484649
'subproject': None,
46494650
},
4650-
f'{testdir}/bar-custom.txt': {
4651+
get_path('{testdir}/bar-custom.txt'): {
46514652
'destination': '{datadir}/bar-custom.txt',
46524653
'tag': 'custom',
46534654
'subproject': None,
46544655
},
4655-
f'{testdir}/subdir/bar2-devel.h': {
4656+
get_path('{testdir}/subdir/bar2-devel.h'): {
46564657
'destination': '{includedir}/bar2-devel.h',
46574658
'tag': 'devel',
46584659
'subproject': None,
46594660
},
4660-
f'{testdir}/subprojects/subproject/aaa.txt': {
4661+
get_path('{testdir}/subprojects/subproject/aaa.txt'): {
46614662
'destination': '{datadir}/subproject/aaa.txt',
46624663
'tag': None,
46634664
'subproject': 'subproject',
46644665
},
4665-
f'{testdir}/subprojects/subproject/bbb.txt': {
4666+
get_path('{testdir}/subprojects/subproject/bbb.txt'): {
46664667
'destination': '{datadir}/subproject/bbb.txt',
46674668
'tag': 'data',
46684669
'subproject': 'subproject',
46694670
},
46704671
},
46714672
'headers': {
4672-
f'{testdir}/foo1-devel.h': {
4673+
get_path('{testdir}/foo1-devel.h'): {
46734674
'destination': '{includedir}/foo1-devel.h',
46744675
'tag': 'devel',
46754676
'subproject': None,
46764677
},
4677-
f'{testdir}/subdir/foo3-devel.h': {
4678+
get_path('{testdir}/subdir/foo3-devel.h'): {
46784679
'destination': '{includedir}/foo3-devel.h',
46794680
'tag': 'devel',
46804681
'subproject': None,
46814682
},
46824683
},
46834684
'install_subdirs': {
4684-
f'{testdir}/custom_files': {
4685+
get_path('{testdir}/custom_files'): {
46854686
'destination': '{datadir}/custom_files',
46864687
'tag': 'custom',
46874688
'subproject': None,
46884689
'exclude_dirs': [],
46894690
'exclude_files': [],
46904691
},
4691-
f'{testdir}/excludes': {
4692+
get_path('{testdir}/excludes'): {
46924693
'destination': '{datadir}/excludes',
46934694
'tag': 'custom',
46944695
'subproject': None,
@@ -4698,11 +4699,10 @@ def output_name(name, type_):
46984699
}
46994700
}
47004701

4701-
fix_path = lambda path: os.path.sep.join(path.split('/'))
47024702
expected_fixed = {
47034703
data_type: {
4704-
fix_path(source): {
4705-
key: fix_path(value) if key == 'destination' else value
4704+
get_path(source): {
4705+
key: get_path(value) if key == 'destination' else value
47064706
for key, value in attributes.items()
47074707
}
47084708
for source, attributes in files.items()

0 commit comments

Comments
 (0)