Repository: mesonbuild/meson

Issue:
Invalid 'runpython' dependency added to custom_target
Attempting to build glib on Windows with the meson executable (meson.exe) installed via Meson's MSI installer produces the following:

```
C:\Users\XXXX\src\glib>ninja -C meson-build
ninja: Entering directory `meson-build'
ninja: error: '../runpython', needed by 'gobject/tests/marshalers.c', missing and no known rule to make it
```

The generated build.ninja file shows an erroneous '../runpython' dependency:

```
build gobject/tests/marshalers.c: CUSTOM_COMMAND ../gobject/tests/marshalers.list | ../runpython gobject/glib-genmarshal
 COMMAND = "C:/Program$ Files/Meson/meson.exe" "runpython" "gobject/glib-genmarshal" "--prefix=test" "--valist-marshallers" "--include-header=marshalers.h" "--output=gobject/tests/marshalers.c" "--quiet" "--body" "../gobject/tests/marshalers.list"
```

'runpython' seems to be the way that Meson wants to invoke Python 3 when running from within 'meson.exe'.

I found this in Meson's mesonbuild/mesonlib.py:

```
if os.path.basename(sys.executable) == 'meson.exe':
    # In Windows and using the MSI installed executable.
    python_command = [sys.executable, 'runpython']
else:
    python_command = [sys.executable]
meson_command = None
```

Within the glib build, the python module is resolved in the top-level meson.build:

```
python = import('python3').find_python()
```

It's later referenced inside gobject/tests/meson.build:

```
marshalers_c = custom_target('marshalers_c',
  output : 'marshalers.c',
  input : 'marshalers.list',
  command : [
    python, glib_genmarshal,
    '--prefix=test',
    '--valist-marshallers',
    '--include-header=marshalers.h',
    '--output=@OUTPUT@',
    '--quiet',
    '--body',
    '@INPUT@',
  ],
)
```

On the surface this appears to be a Meson issue, but perhaps the glib build should be structured differently?


Discussion:
I think this bug should block the release. Seems like the MSI installer is a bit broken.

Resolving patch:
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -349,7 +349,11 @@ def run(original_args, mainfile):
 
 def main():
     # Always resolve the command path so Ninja can find it for regen, tests, etc.
-    launcher = os.path.realpath(sys.argv[0])
+    if 'meson.exe' in sys.executable:
+        assert(os.path.isabs(sys.executable))
+        launcher = sys.executable
+    else:
+        launcher = os.path.realpath(sys.argv[0])
     return run(sys.argv[1:], launcher)
 
 if __name__ == '__main__':
diff --git a/msi/createmsi.py b/msi/createmsi.py
--- a/msi/createmsi.py
+++ b/msi/createmsi.py
@@ -85,6 +85,7 @@ def build_dist(self):
         main_stage, ninja_stage = self.staging_dirs
         modules = [os.path.splitext(os.path.split(x)[1])[0] for x in glob(os.path.join('mesonbuild/modules/*'))]
         modules = ['mesonbuild.modules.' + x for x in modules if not x.startswith('_')]
+        modules += ['distutils.version']
         modulestr = ','.join(modules)
         python = shutil.which('python')
         cxfreeze = os.path.join(os.path.dirname(python), "Scripts", "cxfreeze")


Test patch: