Repository: mesonbuild/meson

Issue:
ninjabackend: detect_vs_dep_prefix doesn't correctly handle clang-cl cross compilation.
```
Traceback (most recent call last):
  File "/d/code/meson/mesonbuild/mesonmain.py", line 127, in run
    return options.run_func(options)
  File "/d/code/meson/mesonbuild/msetup.py", line 240, in run
    app.generate()
  File "/d/code/meson/mesonbuild/msetup.py", line 158, in generate
    self._generate(env)
  File "/d/code/meson/mesonbuild/msetup.py", line 210, in _generate
    intr.backend.generate(intr)
  File "/d/code/meson/mesonbuild/backend/ninjabackend.py", line 292, in generate
    with self.detect_vs_dep_prefix(tempfilename) as outfile:
  File "/d/code/meson/mesonbuild/backend/ninjabackend.py", line 254, in detect_vs_dep_prefix
    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1258, in _execute_child
    executable = os.fsencode(executable)
  File "/usr/lib/python3.6/os.py", line 800, in fsencode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not list
```

Fixing this by changing:
`        pc = subprocess.Popen([compiler.get_exelist(),`
to:
`        pc = subprocess.Popen([compiler.get_exelist()[0],`

Resolves that issue, but then the regex used to figure out the prefix is wrong on Linux. I.e., it doesn't handle paths like:
`b'Note: including file: /d/code/chrome/src/third_party/depot_tools/win_toolchain/vs_files/418b3076791776573a815eb298c8aa590307af63/win_sdk/Include/10.0.18362.0/ucrt/stdio.h'`

> ERROR: Could not determine vs dep dependency prefix string.

This can be resolved by changing the regex from:
`        matchre = re.compile(rb"^(.*\s)[a-zA-Z]:\\.*stdio.h$")`
to:
`        matchre = re.compile(rb"^(.*\s)([a-zA-Z]:\\|\/).*stdio.h$")`


Discussion:
I'm new to meson, just started trying it, and immediately got stuck with the
> ERROR: Could not determine vs dep dependency prefix string.

issue, without doing any cross-compilation or anything nontrivial. Unfortunately, I can't tell if my case is related at all; Google sent me here, when looking for this error message, FWIW.

I got this with just MSVC, and not clang-cl.

This caused failure to compiler glib from source for me.
In meson v0.53.1 The "Could not determine vs dep dependency prefix string." portion of the problem still exists, and can be resolved using the updated matchre in OP, above (https://github.com/mesonbuild/meson/issues/5639#issue-467104366)

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -269,7 +269,9 @@ def detect_vs_dep_prefix(self, tempfilename):
         # 'Note: including file: d:\MyDir\include\stdio.h', however
         # different locales have different messages with a different
         # number of colons. Match up to the the drive name 'd:\'.
-        matchre = re.compile(rb"^(.*\s)[a-zA-Z]:\\.*stdio.h$")
+        # When used in cross compilation, the path separator is a
+        # backslash rather than a forward slash so handle both.
+        matchre = re.compile(rb"^(.*\s)([a-zA-Z]:\\|\/).*stdio.h$")
 
         def detect_prefix(out):
             for line in re.split(rb'\r?\n', out):


Test patch: