(script: str)
return None
Check if the file has a shebang and manually parse it to figure out
        the interpreter to use. This is useful if the script is not executable
        or if we're on Windows (which does not understand shebangs).
Check if the file has a shebang and manually parse it to figure out
        the interpreter to use. This is useful if the script is not executable
        or if we're on Windows (which does not understand shebangs).
Check if the file has a shebang and manually parse it to figure out the interpreter to use . This is useful if the script is not executable or if we re on Windows ( which does not understand shebangs ) .
def _shebang_to_cmd(script: str) -> T.Optional[T.List[str]]:
        """
        Check if the file has a shebang and manually parse it to figure out
        the interpreter to use. This is useful if the script is not executable
        or if we're on Windows (which does not understand shebangs).
        """
        try:
            with open(script, encoding='utf-8') as f:
                first_line = f.readline().strip()
            if first_line.startswith('#!'):
                # In a shebang, everything before the first space is assumed to
                # be the command to run and everything after the first space is
                # the single argument to pass to that command. So we must split
                # exactly once.
                commands = first_line[2:].split('#')[0].strip().split(maxsplit=1)
                if mesonlib.is_windows():
                    # Windows does not have UNIX paths so remove them,
                    # but don't remove Windows paths
                    if commands[0].startswith('/'):
                        commands[0] = commands[0].split('/')[-1]
                    if len(commands) > 0 and commands[0] == 'env':
                        commands = commands[1:]
                    # Windows does not ship python3.exe, but we know the path to it
                    if len(commands) > 0 and commands[0] == 'python3':
                        commands = mesonlib.python_command + commands[1:]
                elif mesonlib.is_haiku():
                    # Haiku does not have /usr, but a lot of scripts assume that
                    # /usr/bin/env always exists. Detect that case and run the
                    # script with the interpreter after it.
                    if commands[0] == '/usr/bin/env':
                        commands = commands[1:]
                    # We know what python3 is, we're running on it
                    if len(commands) > 0 and commands[0] == 'python3':
                        commands = mesonlib.python_command + commands[1:]
                else:
                    # Replace python3 with the actual python3 that we are using
                    if commands[0] == '/usr/bin/env' and commands[1] == 'python3':
                        commands = mesonlib.python_command + commands[2:]
                    elif commands[0].split('/')[-1] == 'python3':
                        commands = mesonlib.python_command + commands[1:]
                return commands + [script]
        except Exception as e:
            mlog.debug(str(e))
        mlog.debug(f'Unusable script {script!r}')
        return None
def _shebang_to_cmd ( script : str ) -> T . Optional [ T . List [ str ] ] : try : with open ( script , encoding = 'utf-8' ) as f : first_line = f . readline ( ) . strip ( ) if first_line . startswith ( '#!' ) : # In a shebang, everything before the first space is assumed to # be the command to run and everything after the first space is # the single argument to pass to that command. So we must split # exactly once. commands = first_line [ 2 : ] . split ( '#' ) [ 0 ] . strip ( ) . split ( maxsplit = 1 ) if mesonlib . is_windows ( ) : # Windows does not have UNIX paths so remove them, # but don't remove Windows paths if commands [ 0 ] . startswith ( '/' ) : commands [ 0 ] = commands [ 0 ] . split ( '/' ) [ - 1 ] if len ( commands ) > 0 and commands [ 0 ] == 'env' : commands = commands [ 1 : ] # Windows does not ship python3.exe, but we know the path to it if len ( commands ) > 0 and commands [ 0 ] == 'python3' : commands = mesonlib . python_command + commands [ 1 : ] elif mesonlib . is_haiku ( ) : # Haiku does not have /usr, but a lot of scripts assume that # /usr/bin/env always exists. Detect that case and run the # script with the interpreter after it. if commands [ 0 ] == '/usr/bin/env' : commands = commands [ 1 : ] # We know what python3 is, we're running on it if len ( commands ) > 0 and commands [ 0 ] == 'python3' : commands = mesonlib . python_command + commands [ 1 : ] else : # Replace python3 with the actual python3 that we are using if commands [ 0 ] == '/usr/bin/env' and commands [ 1 ] == 'python3' : commands = mesonlib . python_command + commands [ 2 : ] elif commands [ 0 ] . split ( '/' ) [ - 1 ] == 'python3' : commands = mesonlib . python_command + commands [ 1 : ] return commands + [ script ] except Exception as e : mlog . debug ( str ( e ) ) mlog . debug ( f'Unusable script {script!r}' ) return None