def verify_native(self): self.write_source(False) argv = self.build_link_argv() util.con_out( util.ConsoleHeader, 'Checking {0} compiler (vendor test {1})... '.format( self.mode_, self.family_), util.ConsoleBlue, '{0}'.format(argv), util.ConsoleNormal) p = util.CreateProcess(argv, env=self.env_, no_raise=False) if util.WaitForProcess(p) != 0: raise Exception('Compiler failed with return code {0}'.format( p.returncode)) inclusion_pattern = None if self.family_ == 'msvc': inclusion_pattern = msvc_utils.DetectInclusionPattern(p.stdoutText) lines = self.test_executable() return { 'vendor': lines[0], 'arch': lines[2], 'inclusion_pattern': inclusion_pattern, }
def verify_cross_compile(self): self.write_source(True) argv = self.build_pp_argv() util.con_out( util.ConsoleHeader, 'Checking {0} compiler (vendor test {1})... '.format( self.mode_, self.family_), util.ConsoleBlue, '{0}'.format(argv), util.ConsoleNormal) p = util.CreateProcess(argv, env=self.env_, no_raise=False) if util.WaitForProcess(p) != 0: raise Exception('compiler failed with return code {0}'.format( p.returncode)) lines = self.parse_pp(p.stdoutText) self.verify_lines(lines) # Execute one more time to test linkage. self.write_source(False) argv = self.build_link_argv() p = util.CreateProcess(argv, env=self.env_, no_raise=False) if util.WaitForProcess(p) != 0: raise Exception('compiler failed with return code {}: {}'.format( p.returncode, argv)) inclusion_pattern = None if self.family_ == 'msvc': inclusion_pattern = msvc_utils.DetectInclusionPattern(p.stdoutText) return { 'vendor': lines[0], 'arch': lines[2], 'inclusion_pattern': inclusion_pattern, }
def test_executable(self): executable_argv = [self.executable_] if self.family_ == 'emscripten': exe = 'node' executable_argv[0:0] = [exe] else: exe = util.MakePath('.', self.executable_) p = util.CreateProcess(executable_argv, executable=exe, env=self.env_) if p == None: raise Exception('failed to create executable with {0}'.format( self.argv_[0])) if util.WaitForProcess(p) != 0: raise Exception('executable failed with return code {0}'.format( p.returncode)) lines = p.stdoutText.splitlines() self.verify_lines(lines) return lines
def VerifyCompiler(env, mode, cmd, vendor): args = cmd.split() if 'CFLAGS' in env: args.extend(env['CFLAGS'].split()) if mode == 'CXX' and 'CXXFLAGS' in env: args.extend(env['CXXFLAGS'].split()) if mode == 'CXX': filename = 'test.cpp' else: filename = 'test.c' file = open(filename, 'w') file.write(""" #include <stdio.h> #include <stdlib.h> int main() { #if defined __ICC printf("icc %d\\n", __ICC); #elif defined __clang__ # if defined(__clang_major__) && defined(__clang_minor__) # if defined(__apple_build_version__) printf("apple-clang %d.%d\\n", __clang_major__, __clang_minor__); # else printf("clang %d.%d\\n", __clang_major__, __clang_minor__); # endif # else printf("clang 1.%d\\n", __GNUC_MINOR__); # endif #elif defined __GNUC__ printf("gcc %d.%d\\n", __GNUC__, __GNUC_MINOR__); #elif defined _MSC_VER printf("msvc %d\\n", _MSC_VER); #elif defined __TenDRA__ printf("tendra 0\\n"); #elif defined __SUNPRO_C printf("sun %x\\n", __SUNPRO_C); #elif defined __SUNPRO_CC printf("sun %x\\n", __SUNPRO_CC); #else #error "Unrecognized compiler!" #endif #if defined __cplusplus printf("CXX\\n"); #else printf("CC\\n"); #endif exit(0); } """) file.close() if mode == 'CC': executable = 'test' + util.ExecutableSuffix elif mode == 'CXX': executable = 'testp' + util.ExecutableSuffix # Make sure the exe is gone. if os.path.exists(executable): os.unlink(executable) # Until we can better detect vendors, don't do this. # if vendor == 'gcc' and mode == 'CXX': # args.extend(['-fno-exceptions', '-fno-rtti']) args.extend([filename, '-o', executable]) # For MSVC, we need to detect the inclusion pattern for foreign-language # systems. if vendor == 'msvc': args += ['-nologo', '-showIncludes'] util.con_out( util.ConsoleHeader, 'Checking {0} compiler (vendor test {1})... '.format(mode, vendor), util.ConsoleBlue, '{0}'.format(args), util.ConsoleNormal) p = util.CreateProcess(args) if p == None: print('not found') return False if util.WaitForProcess(p) != 0: print('failed with return code {0}'.format(p.returncode)) return False inclusion_pattern = None if vendor == 'msvc': inclusion_pattern = DetectMicrosoftInclusionPattern(p.stdoutText) exe = util.MakePath('.', executable) p = util.CreateProcess([executable], executable=exe) if p == None: print('failed to create executable with {0}'.format(cmd)) return False if util.WaitForProcess(p) != 0: print('executable failed with return code {0}'.format(p.returncode)) return False lines = p.stdoutText.splitlines() if len(lines) != 2: print('invalid executable output') return False if lines[1] != mode: print('requested {0} compiler, found {1}'.format(mode, lines[1])) return False vendor, version = lines[0].split(' ') if vendor == 'gcc': v = vendors.GCC(cmd, version) elif vendor == 'apple-clang': v = vendors.Clang('apple-clang', cmd, version) elif vendor == 'clang': v = vendors.Clang('clang', cmd, version) elif vendor == 'msvc': v = vendors.MSVC(cmd, version) elif vendor == 'sun': v = vendors.SunPro(cmd, version) else: print('Unknown vendor {0}'.format(vendor)) return False if inclusion_pattern is not None: v.extra_props['inclusion_pattern'] = inclusion_pattern util.con_out(util.ConsoleHeader, 'found {0} version {1}'.format(vendor, version), util.ConsoleNormal) return v
def VerifyCompiler(env, mode, cmd, assumed_family): base_argv = cmd.split() if 'CFLAGS' in env: base_argv.extend(env['CFLAGS'].split()) if mode == 'CXX' and 'CXXFLAGS' in env: base_argv.extend(env['CXXFLAGS'].split()) argv = base_argv[:] if mode == 'CXX': filename = 'test.cpp' else: filename = 'test.c' file = open(filename, 'w') file.write(""" #include <stdio.h> #include <stdlib.h> int main() { #if defined __ICC printf("icc %d\\n", __ICC); #elif defined(__EMSCRIPTEN__) printf("emscripten %d.%d\\n", __clang_major__, __clang_minor__); #elif defined __clang__ # if defined(__clang_major__) && defined(__clang_minor__) # if defined(__apple_build_version__) printf("apple-clang %d.%d\\n", __clang_major__, __clang_minor__); # else printf("clang %d.%d\\n", __clang_major__, __clang_minor__); # endif # else printf("clang 1.%d\\n", __GNUC_MINOR__); # endif #elif defined __GNUC__ printf("gcc %d.%d\\n", __GNUC__, __GNUC_MINOR__); #elif defined _MSC_VER printf("msvc %d\\n", _MSC_VER); #elif defined __TenDRA__ printf("tendra 0\\n"); #elif defined __SUNPRO_C printf("sun %x\\n", __SUNPRO_C); #elif defined __SUNPRO_CC printf("sun %x\\n", __SUNPRO_CC); #else #error "Unrecognized compiler!" #endif #if defined __cplusplus printf("CXX\\n"); #else printf("CC\\n"); #endif exit(0); } """) file.close() executable = 'test' if mode == 'CXX': executable += 'p' if assumed_family == 'emscripten': executable += '.js' else: executable += util.ExecutableSuffix # Make sure the exe is gone. if os.path.exists(executable): os.unlink(executable) argv.extend([filename, '-o', executable]) # For MSVC, we need to detect the inclusion pattern for foreign-language # systems. if assumed_family == 'msvc': argv += ['-nologo', '-showIncludes'] util.con_out( util.ConsoleHeader, 'Checking {0} compiler (vendor test {1})... '.format( mode, assumed_family), util.ConsoleBlue, '{0}'.format(argv), util.ConsoleNormal) p = util.CreateProcess(argv) if p == None: raise Exception('compiler not found') if util.WaitForProcess(p) != 0: raise Exception('compiler failed with return code {0}'.format( p.returncode)) inclusion_pattern = None if assumed_family == 'msvc': inclusion_pattern = MSVC.DetectInclusionPattern(p.stdoutText) executable_argv = [executable] if assumed_family == 'emscripten': exe = 'node' executable_argv[0:0] = [exe] else: exe = util.MakePath('.', executable) p = util.CreateProcess(executable_argv, executable=exe) if p == None: raise Exception('failed to create executable with {0}'.format(cmd)) if util.WaitForProcess(p) != 0: raise Exception('executable failed with return code {0}'.format( p.returncode)) lines = p.stdoutText.splitlines() if len(lines) != 2: raise Exception('invalid executable output') if lines[1] != mode: raise Exception('requested {0} compiler, found {1}'.format( mode, lines[1])) vendor, version = lines[0].split(' ') if vendor == 'gcc': v = GCC(version) elif vendor == 'emscripten': v = Emscripten(version) elif vendor == 'apple-clang': v = Clang(version, 'apple') elif vendor == 'clang': v = Clang(version) elif vendor == 'msvc': v = MSVC(version) elif vendor == 'sun': v = SunPro(version) else: raise Exception('Unknown vendor {0}'.format(vendor)) if inclusion_pattern is not None: v.extra_props['inclusion_pattern'] = inclusion_pattern util.con_out(util.ConsoleHeader, 'found {0} version {1}'.format(vendor, version), util.ConsoleNormal) return CommandAndVendor(base_argv, v)