diff mbox series

[2/4] meson: fixes relpath may fail on win32.

Message ID 20200825165341.520-2-luoyonggang@gmail.com
State New
Headers show
Series [1/4] meson: Fixes the ninjatool issue that E$$: are generated in Makefile.ninja | expand

Commit Message

Yonggang Luo Aug. 25, 2020, 4:53 p.m. UTC
From: Yonggang Luo <luoyonggang@gmail.com>

On win32, os.path.relpath would raise exception when do the following relpath:
C:/msys64/mingw64/x.exe relative to E:/path/qemu-build would fail.
So we try catch it for stopping it from raise exception on msys2
---
 scripts/mtest2make.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Mark Cave-Ayland Aug. 25, 2020, 9:31 p.m. UTC | #1
On 25/08/2020 17:53, luoyonggang@gmail.com wrote:

> From: Yonggang Luo <luoyonggang@gmail.com>
> 
> On win32, os.path.relpath would raise exception when do the following relpath:
> C:/msys64/mingw64/x.exe relative to E:/path/qemu-build would fail.
> So we try catch it for stopping it from raise exception on msys2
> ---
>  scripts/mtest2make.py | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/mtest2make.py b/scripts/mtest2make.py
> index bdb257bbd9..d7a51bf97e 100644
> --- a/scripts/mtest2make.py
> +++ b/scripts/mtest2make.py
> @@ -53,9 +53,16 @@ i = 0
>  for test in json.load(sys.stdin):
>      env = ' '.join(('%s=%s' % (shlex.quote(k), shlex.quote(v))
>                      for k, v in test['env'].items()))
> -    executable = os.path.relpath(test['cmd'][0])
> +    executable = test['cmd'][0]
> +    try:
> +        executable = os.path.relpath(executable)
> +    except:
> +        pass
>      if test['workdir'] is not None:
> -        test['cmd'][0] = os.path.relpath(test['cmd'][0], test['workdir'])
> +        try:
> +            test['cmd'][0] = os.path.relpath(executable, test['workdir'])
> +        except:
> +            test['cmd'][0] = executable
>      else:
>          test['cmd'][0] = executable
>      cmd = '$(.test.env) %s %s' % (env, ' '.join((shlex.quote(x) for x in test['cmd'])))

I don't think this is relevant in my particular environment, however it didn't seem
to break the build. I'm curious as to why os.path.relpath throws an exception in this
particular case on Windows though - can you give us a bit more information about the
Exception that is being thrown?


ATB,

Mark.
Paolo Bonzini Aug. 26, 2020, 6:46 a.m. UTC | #2
On Tue, Aug 25, 2020 at 11:31 PM Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
> On 25/08/2020 17:53, luoyonggang@gmail.com wrote:
>
> > From: Yonggang Luo <luoyonggang@gmail.com>
> >
> > On win32, os.path.relpath would raise exception when do the following relpath:
> > C:/msys64/mingw64/x.exe relative to E:/path/qemu-build would fail.
> > So we try catch it for stopping it from raise exception on msys2
> I don't think this is relevant in my particular environment, however it didn't seem
> to break the build. I'm curious as to why os.path.relpath throws an exception in this
> particular case on Windows though - can you give us a bit more information about the
> Exception that is being thrown?

I think it's because it's impossible to make a relative path between
two different drives.

The patch is correct but is missing the Signed-off-by line.

Paolo
diff mbox series

Patch

diff --git a/scripts/mtest2make.py b/scripts/mtest2make.py
index bdb257bbd9..d7a51bf97e 100644
--- a/scripts/mtest2make.py
+++ b/scripts/mtest2make.py
@@ -53,9 +53,16 @@  i = 0
 for test in json.load(sys.stdin):
     env = ' '.join(('%s=%s' % (shlex.quote(k), shlex.quote(v))
                     for k, v in test['env'].items()))
-    executable = os.path.relpath(test['cmd'][0])
+    executable = test['cmd'][0]
+    try:
+        executable = os.path.relpath(executable)
+    except:
+        pass
     if test['workdir'] is not None:
-        test['cmd'][0] = os.path.relpath(test['cmd'][0], test['workdir'])
+        try:
+            test['cmd'][0] = os.path.relpath(executable, test['workdir'])
+        except:
+            test['cmd'][0] = executable
     else:
         test['cmd'][0] = executable
     cmd = '$(.test.env) %s %s' % (env, ' '.join((shlex.quote(x) for x in test['cmd'])))