mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.3k stars 1.52k forks source link

join_paths() works wrong when meet Windows style absolute path #13130

Open qaqland opened 3 weeks ago

qaqland commented 3 weeks ago

Describe the bug

join_paths() works wrong when meet Windows style absolute path

To Reproduce

meson.build

project('path test')

message('/usr/share' / 'projectname')
message('/usr/local' / '/etc/name')

message('C:\\foo\\bar' / 'builddir')
message('C:\\foo\\bar' / 'D:\\builddir')

run meson setup

The Meson build system
Version: 1.3.0
Source dir: /home/qaq/meson-path
Build dir: /home/qaq/meson-path/builddir
Build type: native build
Project name: path test
Project version: undefined
Host machine cpu family: x86_64
Host machine cpu: x86_64
Message: /usr/share/projectname
Message: /etc/name
Message: C:/foo/bar/builddir
Message: C:/foo/bar/D:/builddir    #### here
Build targets in project: 0

Found ninja-1.9 at /usr/bin/ninja

Expected behavior

If any one of the individual segments is an absolute path, all segments before it are dropped.

it should work as document: https://github.com/mesonbuild/meson/blob/master/docs/markdown/Syntax.md#string-path-building

Message: /usr/share/projectname
Message: /etc/name
Message: C:/foo/bar/builddir
Message: D:/builddir            #### here

system parameters

tristan957 commented 3 weeks ago

I'll take a look.

tristan957 commented 3 weeks ago

This seems like a rather hard problem to solve.

bruchar1 commented 3 weeks ago

I guess the difficulty comes from knowing whether the string is a posix path, or a Windows path, or a Windows paths using forward slashes as path separator...

bruchar1 commented 2 weeks ago

Rethinking about this, the real problem is that backslashes are valid characters in posix paths. Joining paths containing backslashes on a posix system should not convert the backslashes to slashes.

Having a different behavior on Windows and on posix systems is expected, since you are not manipulating the same kind of paths. Why would you want to join Windows paths on a posix system, and vice-versa?

tristan957 commented 2 weeks ago

Cross compiling would be one reason.