Fix destdir_join

The old implementation assumed a path is of Windows iff the second
character is a colon. However, that is not always true.
First, a colon can be included in a non-Windows path. For example, it is
totally fine to have a directory named ':' on Linux 5.17.0 tmpfs.
Second, a Windows path may start with \\ for UNC or extended length.

Use pathlib to handle all of these cases.
pull/10535/head
Akihiko Odaki 2 years ago committed by Eli Schwartz
parent 4c706e961b
commit c2c9359d46
  1. 6
      mesonbuild/scripts/__init__.py

@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import PurePath
def destdir_join(d1: str, d2: str) -> str:
if not d1:
return d2
# c:\destdir + c:\prefix must produce c:\destdir\prefix
if len(d2) > 1 and d2[1] == ':':
return d1 + d2[2:]
return d1 + d2
return str(PurePath(d1, *PurePath(d2).parts[1:]))

Loading…
Cancel
Save