(env: 'Environment', compiler: T.List[str], comp_class: T.Type['Compiler'],
                     for_machine: MachineChoice, *,
                     extra_args: T.Optional[T.List[str]] = None)
return linker
Helper for guessing what linker to use on Unix-Like OSes.

    :compiler: Invocation to use to get linker
    :comp_class: The Compiler Type (uninstantiated)
    :for_machine: which machine this linker targets
    :extra_args: Any additional arguments required (such as a source file)
Helper for guessing what linker to use on Unix-Like OSes.
Helper for guessing what linker to use on Unix - Like OSes .
def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Type['Compiler'],
                     for_machine: MachineChoice, *,
                     extra_args: T.Optional[T.List[str]] = None) -> 'DynamicLinker':
    """Helper for guessing what linker to use on Unix-Like OSes.

    :compiler: Invocation to use to get linker
    :comp_class: The Compiler Type (uninstantiated)
    :for_machine: which machine this linker targets
    :extra_args: Any additional arguments required (such as a source file)
    """
    env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
    extra_args = extra_args or []
    extra_args += env.coredata.options[OptionKey('args', lang=comp_class.language, machine=for_machine)].value

    if isinstance(comp_class.LINKER_PREFIX, str):
        check_args = [comp_class.LINKER_PREFIX + '--version'] + extra_args
    else:
        check_args = comp_class.LINKER_PREFIX + ['--version'] + extra_args

    override = []  # type: T.List[str]
    value = env.lookup_binary_entry(for_machine, comp_class.language + '_ld')
    if value is not None:
        override = comp_class.use_linker_args(value[0])
        check_args += override

    _, o, e = Popen_safe(compiler + check_args)
    v = search_version(o + e)
    linker: DynamicLinker
    if 'LLD' in o.split('\n')[0]:
        linker = LLVMDynamicLinker(
            compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
    elif 'Snapdragon' in e and 'LLVM' in e:
        linker = QualcommLLVMDynamicLinker(
            compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
    elif e.startswith('lld-link: '):
        # The LLD MinGW frontend didn't respond to --version before version 9.0.0,
        # and produced an error message about failing to link (when no object
        # files were specified), instead of printing the version number.
        # Let's try to extract the linker invocation command to grab the version.

        _, o, e = Popen_safe(compiler + check_args + ['-v'])

        try:
            linker_cmd = re.match(r'.*\n(.*?)\nlld-link: ', e, re.DOTALL).group(1)
            linker_cmd = shlex.split(linker_cmd)[0]
        except (AttributeError, IndexError, ValueError):
            pass
        else:
            _, o, e = Popen_safe([linker_cmd, '--version'])
            v = search_version(o)

        linker = LLVMDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
    # first is for apple clang, second is for real gcc, the third is icc
    elif e.endswith('(use -v to see invocation)\n') or 'macosx_version' in e or 'ld: unknown option:' in e:
        if isinstance(comp_class.LINKER_PREFIX, str):
            _, _, e = Popen_safe(compiler + [comp_class.LINKER_PREFIX + '-v'] + extra_args)
        else:
            _, _, e = Popen_safe(compiler + comp_class.LINKER_PREFIX + ['-v'] + extra_args)
        for line in e.split('\n'):
            if 'PROJECT:ld' in line:
                v = line.split('-')[1]
                break
        else:
            v = 'unknown version'
        linker = AppleDynamicLinker(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
    elif 'GNU' in o or 'GNU' in e:
        cls: T.Type[GnuDynamicLinker]
        if 'gold' in o or 'gold' in e:
            cls = GnuGoldDynamicLinker
        else:
            cls = GnuBFDDynamicLinker
        linker = cls(compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
    elif 'Solaris' in e or 'Solaris' in o:
        for line in (o+e).split('\n'):
            if 'ld: Software Generation Utilities' in line:
                v = line.split(':')[2].lstrip()
                break
        else:
            v = 'unknown version'
        linker = SolarisDynamicLinker(
            compiler, for_machine, comp_class.LINKER_PREFIX, override,
            version=v)
    elif 'ld: 0706-012 The -- flag is not recognized' in e:
        if isinstance(comp_class.LINKER_PREFIX, str):
            _, _, e = Popen_safe(compiler + [comp_class.LINKER_PREFIX + '-V'] + extra_args)
        else:
            _, _, e = Popen_safe(compiler + comp_class.LINKER_PREFIX + ['-V'] + extra_args)
        linker = AIXDynamicLinker(
            compiler, for_machine, comp_class.LINKER_PREFIX, override,
            version=search_version(e))
    else:
        __failed_to_detect_linker(compiler, check_args, o, e)
    return linker
def guess_nix_linker ( env : 'Environment' , compiler : T . List [ str ] , comp_class : T . Type [ 'Compiler' ] , for_machine : MachineChoice , * , extra_args : T . Optional [ T . List [ str ] ] = None ) -> 'DynamicLinker' : env . coredata . add_lang_args ( comp_class . language , comp_class , for_machine , env ) extra_args = extra_args or [ ] extra_args += env . coredata . options [ OptionKey ( 'args' , lang = comp_class . language , machine = for_machine ) ] . value if isinstance ( comp_class . LINKER_PREFIX , str ) : check_args = [ comp_class . LINKER_PREFIX + '--version' ] + extra_args else : check_args = comp_class . LINKER_PREFIX + [ '--version' ] + extra_args override = [ ] # type: T.List[str] value = env . lookup_binary_entry ( for_machine , comp_class . language + '_ld' ) if value is not None : override = comp_class . use_linker_args ( value [ 0 ] ) check_args += override _ , o , e = Popen_safe ( compiler + check_args ) v = search_version ( o + e ) linker : DynamicLinker if 'LLD' in o . split ( '\n' ) [ 0 ] : linker = LLVMDynamicLinker ( compiler , for_machine , comp_class . LINKER_PREFIX , override , version = v ) elif 'Snapdragon' in e and 'LLVM' in e : linker = QualcommLLVMDynamicLinker ( compiler , for_machine , comp_class . LINKER_PREFIX , override , version = v ) elif e . startswith ( 'lld-link: ' ) : # The LLD MinGW frontend didn't respond to --version before version 9.0.0, # and produced an error message about failing to link (when no object # files were specified), instead of printing the version number. # Let's try to extract the linker invocation command to grab the version. _ , o , e = Popen_safe ( compiler + check_args + [ '-v' ] ) try : linker_cmd = re . match ( r'.*\n(.*?)\nlld-link: ' , e , re . DOTALL ) . group ( 1 ) linker_cmd = shlex . split ( linker_cmd ) [ 0 ] except ( AttributeError , IndexError , ValueError ) : pass else : _ , o , e = Popen_safe ( [ linker_cmd , '--version' ] ) v = search_version ( o ) linker = LLVMDynamicLinker ( compiler , for_machine , comp_class . LINKER_PREFIX , override , version = v ) # first is for apple clang, second is for real gcc, the third is icc elif e . endswith ( '(use -v to see invocation)\n' ) or 'macosx_version' in e or 'ld: unknown option:' in e : if isinstance ( comp_class . LINKER_PREFIX , str ) : _ , _ , e = Popen_safe ( compiler + [ comp_class . LINKER_PREFIX + '-v' ] + extra_args ) else : _ , _ , e = Popen_safe ( compiler + comp_class . LINKER_PREFIX + [ '-v' ] + extra_args ) for line in e . split ( '\n' ) : if 'PROJECT:ld' in line : v = line . split ( '-' ) [ 1 ] break else : v = 'unknown version' linker = AppleDynamicLinker ( compiler , for_machine , comp_class . LINKER_PREFIX , override , version = v ) elif 'GNU' in o or 'GNU' in e : cls : T . Type [ GnuDynamicLinker ] if 'gold' in o or 'gold' in e : cls = GnuGoldDynamicLinker else : cls = GnuBFDDynamicLinker linker = cls ( compiler , for_machine , comp_class . LINKER_PREFIX , override , version = v ) elif 'Solaris' in e or 'Solaris' in o : for line in ( o + e ) . split ( '\n' ) : if 'ld: Software Generation Utilities' in line : v = line . split ( ':' ) [ 2 ] . lstrip ( ) break else : v = 'unknown version' linker = SolarisDynamicLinker ( compiler , for_machine , comp_class . LINKER_PREFIX , override , version = v ) elif 'ld: 0706-012 The -- flag is not recognized' in e : if isinstance ( comp_class . LINKER_PREFIX , str ) : _ , _ , e = Popen_safe ( compiler + [ comp_class . LINKER_PREFIX + '-V' ] + extra_args ) else : _ , _ , e = Popen_safe ( compiler + comp_class . LINKER_PREFIX + [ '-V' ] + extra_args ) linker = AIXDynamicLinker ( compiler , for_machine , comp_class . LINKER_PREFIX , override , version = search_version ( e ) ) else : __failed_to_detect_linker ( compiler , check_args , o , e ) return linker