Skip to content

Commit

Permalink
User argv[0] to internally relaunch meson.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
em- authored and jpakkane committed Sep 30, 2016
1 parent 0a49576 commit 338dbc9
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,4 @@
from mesonbuild import mesonmain
import sys, os

def main():
thisfile = __file__
if not os.path.isabs(thisfile):
thisfile = os.path.normpath(os.path.join(os.getcwd(), thisfile))
if __package__ == '':
thisfile = os.path.dirname(thisfile)

sys.exit(mesonmain.run(thisfile, sys.argv[1:]))

if __name__ == '__main__':
main()
sys.exit(mesonmain.run(sys.argv[0], sys.argv[1:]))

0 comments on commit 338dbc9

Please sign in to comment.