Repository: mesonbuild/meson

Issue:
build/build.ninja contains expanded path to meson, not the used symbolic link
When creating the build directory and thus `build/build.ninja`, the full, resolved, path to the meson executable appears in it. This may make sense for stability, but it caused an issue when my system was upgraded from 1.0.0 to 1.0.1, since I was using the symlink; 1.0.0 had, in fact, been replaced, by a meson executable in a different path.

This is probably correct, to a point: keep the same version for the build. Then again, for all major versions 1.x.y, I would expect the meson executables to be backwards compatible, so 1.0.1 so should work fine with a 1.0.0 file.

On my system, the different versions get symlinked to an alias, `/opt/homebrew/bin/meson`. This causes the problem, since I run everything with this symlink, and I had expected this to continue to keep working. I would expect the `build/build.ninja` file to use the symlink, but it resolved the symlink, causing this version conflict after the upgrade to 1.0.1, and a resulting `/bin/sh .... 'meson': command not found` error.

As can be deduced from the alias, I'm on macOS, using Homebrew to install meson.
The full, unaliased path is
```
/opt/homebrew/Cellar/meson/1.0.1/bin/meson
```
or before that
```
/opt/homebrew/Cellar/meson/1.0.0/bin/meson
```

This is the path used in `build/build.ninja`; not `/opt/homebrew/bin/meson`, which is what I used.

I can't tell which option is better: use the full path, or the path as seen by the user (the symlink). 
I prefer the second option: If I explicitly want the 1.0.0 version, I would have used `/opt/homebrew/Cellar/meson/1.0.0/bin/meson --init ...` instead. But now I used `/opt/homebrew/bin/meson`, so I prefer that one to be used in the build.ninja file.

As mentioned earlier, if meson version 1.x.y is stable, the symlink should be safe enough to use after upgrades (until a meson v2, which could then perhaps be called meson2).


## Other details

macOS 13.2
meson 1.0.1
ninja 1.11.1
Python 3.11




Discussion:
A build directory generated with one version of meson is not allowed to be used with a different version. Meson guarantees introspection and the scripting language are backwards compat.

Resolving patch:
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -290,7 +290,7 @@ def main():
         assert os.path.isabs(sys.executable)
         launcher = sys.executable
     else:
-        launcher = os.path.realpath(sys.argv[0])
+        launcher = os.path.abspath(sys.argv[0])
     return run(sys.argv[1:], launcher)
 
 if __name__ == '__main__':


Test patch:
diff --git a/run_meson_command_tests.py b/run_meson_command_tests.py
--- a/run_meson_command_tests.py
+++ b/run_meson_command_tests.py
@@ -135,8 +135,7 @@ def test_meson_uninstalled(self):
         (bindir / 'python3').symlink_to(python_command[0])
         os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH']
         # use our overridden PATH-compatible python
-        path_resolved_meson_command = resolved_meson_command.copy()
-        path_resolved_meson_command[0] = str(bindir / 'python3')
+        path_resolved_meson_command = [str(bindir / 'meson')]
         # See if it works!
         meson_py = 'meson'
         meson_setup = [meson_py, 'setup']