meson_install.py: Start by checking if the shebang is directly runnable

If it's just runnable as-is, then we don't need to do fancy basename detection
and such to find the interpretor to use for running the script.
pull/455/head
Nirbheek Chauhan 9 years ago committed by Nirbheek Chauhan
parent a3004652ea
commit d5c9b98cab
  1. 8
      mesonbuild/scripts/meson_install.py

@ -118,9 +118,13 @@ def run_install_script(d):
if platform.system().lower() == 'windows' and suffix != '.bat': if platform.system().lower() == 'windows' and suffix != '.bat':
first_line = open(script).readline().strip() first_line = open(script).readline().strip()
if first_line.startswith('#!'): if first_line.startswith('#!'):
if shutil.which(first_line[2:]):
commands = [first_line[2:]]
else:
commands = first_line[2:].split('#')[0].strip().split() commands = first_line[2:].split('#')[0].strip().split()
commands[0] = shutil.which(commands[0].split('/')[-1]) commands[0] = shutil.which(commands[0].split('/')[-1])
if commands[0] is None: if commands[0] is None:
commands
raise RuntimeError("Don't know how to run script %s." % script) raise RuntimeError("Don't know how to run script %s." % script)
final_command = commands + [script] + i.cmd_arr[1:] final_command = commands + [script] + i.cmd_arr[1:]
else: else:
@ -129,8 +133,8 @@ def run_install_script(d):
rc = subprocess.call(final_command, env=child_env) rc = subprocess.call(final_command, env=child_env)
if rc != 0: if rc != 0:
sys.exit(rc) sys.exit(rc)
except Exception: except:
print('Failed to run install script:', i.cmd_arr[0]) print('Failed to run install script:', *i.cmd_arr)
sys.exit(1) sys.exit(1)
def is_elf_platform(): def is_elf_platform():

Loading…
Cancel
Save