Home | History | Annotate | Download | only in Go
      1 import os
      2 import pipes
      3 import shlex
      4 import sys
      5 
      6 if not 'go' in config.root.llvm_bindings:
      7     config.unsupported = True
      8 
      9 if config.root.include_go_tests != 'ON':
     10     config.unsupported = True
     11 
     12 def find_executable(executable, path=None):
     13     if path is None:
     14         path = os.environ['PATH']
     15     paths = path.split(os.pathsep)
     16     base, ext = os.path.splitext(executable)
     17 
     18     if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
     19         executable = executable + '.exe'
     20 
     21     if not os.path.isfile(executable):
     22         for p in paths:
     23             f = os.path.join(p, executable)
     24             if os.path.isfile(f):
     25                 return f
     26         return None
     27     else:
     28         return executable
     29 
     30 # Resolve certain symlinks in the first word of compiler.
     31 #
     32 # This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the
     33 # substring 'clang' to determine if the compiler is Clang. This won't work if
     34 # $CC is cc and cc is a symlink pointing to clang, as it is on Darwin.
     35 #
     36 # Go tools also have problems with ccache, so we disable it.
     37 def fixup_compiler_path(compiler):
     38     args = shlex.split(compiler)
     39     if args[0].endswith('ccache'):
     40         args = args[1:]
     41 
     42     path = find_executable(args[0])
     43 
     44     try:
     45         if path.endswith('/cc') and os.readlink(path) == 'clang':
     46             args[0] = path[:len(path)-2] + 'clang'
     47     except (AttributeError, OSError):
     48         pass
     49 
     50     try:
     51         if path.endswith('/c++') and os.readlink(path) == 'clang++':
     52             args[0] = path[:len(path)-3] + 'clang++'
     53     except (AttributeError, OSError):
     54         pass
     55 
     56     return ' '.join([pipes.quote(arg) for arg in args])
     57 
     58 config.environment['CC'] = fixup_compiler_path(config.host_cc)
     59 config.environment['CXX'] = fixup_compiler_path(config.host_cxx)
     60 config.environment['CGO_LDFLAGS'] = config.host_ldflags
     61