diff options
author | Emanuele Aina <emanuele.aina@collabora.com> | 2016-09-27 15:31:38 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-10-08 15:41:31 +0200 |
commit | 6c50253645dad81afbfd2e1bca2c5d9e08f42e05 (patch) | |
tree | 959112e58d4f988feef0c4b151dbe47546d4b2e2 /mesonbuild/environment.py | |
parent | cd6d5a642de41ccec5c934d5a6de074599f54436 (diff) | |
download | meson-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 'mesonbuild/environment.py')
-rw-r--r-- | mesonbuild/environment.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index e411687..86c23ae 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -179,12 +179,10 @@ class Environment(): coredata_file = os.path.join(private_dir, 'coredata.dat') version_regex = '\d+(\.\d+)+(-[a-zA-Z0-9]+)?' - def __init__(self, source_dir, build_dir, main_script_file, options, original_cmd_line_args): - assert(os.path.isabs(main_script_file)) - assert(not os.path.islink(main_script_file)) + def __init__(self, source_dir, build_dir, main_script_launcher, options, original_cmd_line_args): self.source_dir = source_dir self.build_dir = build_dir - self.meson_script_file = main_script_file + self.meson_script_launcher = main_script_launcher self.scratch_dir = os.path.join(build_dir, Environment.private_dir) self.log_dir = os.path.join(build_dir, Environment.log_dir) os.makedirs(self.scratch_dir, exist_ok=True) @@ -198,7 +196,7 @@ class Environment(): # re-initialized with project options by the interpreter during # build file parsing. self.coredata = coredata.CoreData(options) - self.coredata.meson_script_file = self.meson_script_file + self.coredata.meson_script_launcher = self.meson_script_launcher self.first_invocation = True if self.coredata.cross_file: self.cross_info = CrossBuildInfo(self.coredata.cross_file) @@ -253,7 +251,7 @@ class Environment(): return self.coredata def get_build_command(self): - return self.meson_script_file + return self.meson_script_launcher def is_header(self, fname): return is_header(fname) |