Skip to content

Commit

Permalink
build: better support for python3 systems
Browse files Browse the repository at this point in the history
Improve support for systems where `python` is actually `python3`.

Not all systems have a `python2` binary, so simply updating the shebang
won't work.

What we can do is apply some cleverness: start life as a shell script,
locate the python binary, then re-execute the script but this time as
python code.

Special care is taken to ensure that spaces in arguments are passed on
verbatim.

PR-URL: #14737
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information
bnoordhuis authored and MylesBorins committed Sep 12, 2017
1 parent d231ef6 commit 77dfa73
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion configure
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#!/usr/bin/env python
#!/bin/sh

# Locate python2 interpreter and re-execute the script. Note that the
# mix of single and double quotes is intentional, as is the fact that
# the ] goes on a new line.
_=[ 'exec' '/bin/sh' '-c' '''
which python2.7 >/dev/null && exec python2.7 "$0" "$@"
which python2 >/dev/null && exec python2 "$0" "$@"
exec python "$0" "$@"
''' "$0" "$@"
]
del _

import sys
if sys.version_info[0] != 2 or sys.version_info[1] not in (6, 7):
Expand Down

0 comments on commit 77dfa73

Please sign in to comment.