aboutsummaryrefslogtreecommitdiff
path: root/meson.py
diff options
context:
space:
mode:
authorEmanuele Aina <emanuele.aina@collabora.com>2016-09-27 15:31:38 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2016-10-08 15:41:31 +0200
commit6c50253645dad81afbfd2e1bca2c5d9e08f42e05 (patch)
tree959112e58d4f988feef0c4b151dbe47546d4b2e2 /meson.py
parentcd6d5a642de41ccec5c934d5a6de074599f54436 (diff)
downloadmeson-6c50253645dad81afbfd2e1bca2c5d9e08f42e05.zip
meson-6c50253645dad81afbfd2e1bca2c5d9e08f42e05.tar.gz
meson-6c50253645dad81afbfd2e1bca2c5d9e08f42e05.tar.bz2
Use argv[0] to internally relaunch meson.py
When installing Meson, distutils may choose to put shim scripts in the `PATH` that only set up the egg requirements before launching the real `meson.py` contained in the egg. This means that `__file__` points to the real `meson.py` file, but launching it directly is doomed to fail as it's missing the metadata contained in the shim to set up the path egg, resulting in errors when trying to import the `mesonbuild` module. A similar issue affects Meson when installed as a zipapp, with the current code going great lengths to figure out how to relaunch itself. Using `argv[0]` avoids these issues as it gives us the way the current executable has been launched, so we are pretty much guaranteed that using it will create another instance of the same executable. We only need to resolve relative paths as the current working directory may get changed before re-launching the script, and using `realpath()` for that saves us the trouble of manually resolving links and getting caught in endless loops. This also mean that `meson_script_file` no longer necessarily point to a absolute file, so rename it to `_launcher` which hopefully would be less prone to inducing false assumptions.
Diffstat (limited to 'meson.py')
-rwxr-xr-xmeson.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/meson.py b/meson.py
index 7e21c78..492f70d 100755
--- a/meson.py
+++ b/meson.py
@@ -15,13 +15,11 @@
# limitations under the License.
from mesonbuild import mesonmain
-import sys, os
+import sys, os, os.path
-thisfile = __file__
-if not os.path.isabs(thisfile):
- thisfile = os.path.normpath(os.path.join(os.getcwd(), thisfile))
+launcher = sys.argv[0]
+# resolve the command path if not launched from $PATH
+if os.path.split(launcher)[0]:
+ launcher = os.path.realpath(launcher)
-# The first argument *must* be an absolute path because
-# the user may have launched the program from a dir
-# that is not in path.
-sys.exit(mesonmain.run(thisfile, sys.argv[1:]))
+sys.exit(mesonmain.run(launcher, sys.argv[1:]))