import distutils.spawn
import os
import pipes
import shlex

if not 'go' in config.root.llvm_bindings:
    config.unsupported = True

# Resolve certain symlinks in the first word of compiler.
#
# This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the
# substring 'clang' to determine if the compiler is Clang. This won't work if
# $CC is cc and cc is a symlink pointing to clang, as it is on Darwin.
def fixup_compiler_path(compiler):
    args = shlex.split(compiler)
    path = distutils.spawn.find_executable(args[0])

    try:
        if path.endswith('/cc') and os.readlink(path) == 'clang':
            args[0] = path[:len(path)-2] + 'clang'
    except OSError:
        skip

    try:
        if path.endswith('/c++') and os.readlink(path) == 'clang++':
            args[0] = path[:len(path)-3] + 'clang++'
    except OSError:
        skip

    return ' '.join([pipes.quote(arg) for arg in args])

config.environment['CC'] = fixup_compiler_path(config.host_cc)
config.environment['CXX'] = fixup_compiler_path(config.host_cxx)

import os
import pipes
import shlex
import sys

if not 'go' in config.root.llvm_bindings:
    config.unsupported = True

def find_executable(executable, path=None):
    if path is None:
        path = os.environ['PATH']
    paths = path.split(os.pathsep)
    base, ext = os.path.splitext(executable)

    if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
        executable = executable + '.exe'

    if not os.path.isfile(executable):
        for p in paths:
            f = os.path.join(p, executable)
            if os.path.isfile(f):
                return f
        return None
    else:
        return executable

# Resolve certain symlinks in the first word of compiler.
#
# This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the
# substring 'clang' to determine if the compiler is Clang. This won't work if
# $CC is cc and cc is a symlink pointing to clang, as it is on Darwin.
def fixup_compiler_path(compiler):
    args = shlex.split(compiler)
    path = find_executable(args[0])

    try:
        if path.endswith('/cc') and os.readlink(path) == 'clang':
            args[0] = path[:len(path)-2] + 'clang'
    except OSError:
        skip

    try:
        if path.endswith('/c++') and os.readlink(path) == 'clang++':
            args[0] = path[:len(path)-3] + 'clang++'
    except OSError:
        skip

    return ' '.join([pipes.quote(arg) for arg in args])

config.environment['CC'] = fixup_compiler_path(config.host_cc)
config.environment['CXX'] = fixup_compiler_path(config.host_cxx)

Add our own copy of the find_executable function to cope with installations that do not have the distutils.spawn package. Should hopefully fix the aarch64 buildbot.
Add our own copy of the find_executable function to cope with installations
that do not have the distutils.spawn package. Should hopefully fix the
aarch64 buildbot.

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@219991 91177308-0d34-0410-b5e6-96231b3b80d8
