(tmpFileName, f, args, fileName, cppStd)
| 59 | #------------------------------------------------------------------------------ |
| 60 | |
| 61 | def testCompile(tmpFileName, f, args, fileName, cppStd): |
| 62 | if os.name == 'nt': |
| 63 | cppStd = cppStd.replace('-std=', '/std:') |
| 64 | cppStd = cppStd.replace('2a', 'latest') |
| 65 | |
| 66 | cmd = [args['cxx'], cppStd, '-D__cxa_guard_acquire(x)=true', '-D__cxa_guard_release(x)', '-D__cxa_guard_abort(x)', '-I', os.getcwd()] |
| 67 | |
| 68 | if os.name != 'nt': |
| 69 | arch = platform.architecture()[0] |
| 70 | if (arch != '64bit') or ((arch == '64bit') and (sys.platform == 'darwin')): |
| 71 | cmd.append('-m64') |
| 72 | else: |
| 73 | cmd.extend(['/nologo', '/EHsc', '/IGNORE:C4335']) # C4335: mac file format detected. EHsc assume only C++ functions throw exceptions. |
| 74 | |
| 75 | # GCC seems to dislike empty '' |
| 76 | if '-std=c++98' == cppStd: |
| 77 | cmd += ['-Dalignas(x)='] |
| 78 | |
| 79 | cmd += ['-c', tmpFileName] |
| 80 | |
| 81 | stdout, stderr, returncode = runCmd(cmd) |
| 82 | |
| 83 | compileErrorFile = os.path.join(mypath, fileName + '.cerr') |
| 84 | if 0 != returncode: |
| 85 | if os.path.isfile(compileErrorFile): |
| 86 | ce = open(compileErrorFile, 'r', encoding='utf-8').read() |
| 87 | stderr = cleanStderr(stderr, tmpFileName) |
| 88 | |
| 89 | if ce == stderr: |
| 90 | print(f'[PASSED] Compile: {f}') |
| 91 | return True, None |
| 92 | |
| 93 | compileErrorFile = os.path.join(mypath, fileName + '.ccerr') |
| 94 | if os.path.isfile(compileErrorFile): |
| 95 | ce = open(compileErrorFile, 'r', encoding='utf-8').read() |
| 96 | stderr = stderr.replace(tmpFileName, '.tmp.cpp') |
| 97 | |
| 98 | if ce == stderr: |
| 99 | print('f[PASSED] Compile: {f}') |
| 100 | return True, None |
| 101 | |
| 102 | print(f'[ERROR] Compile failed: {f}') |
| 103 | print(stderr) |
| 104 | else: |
| 105 | if os.path.isfile(compileErrorFile): |
| 106 | print('unused file: %s' %(compileErrorFile)) |
| 107 | |
| 108 | ext = 'obj' if os.name == 'nt' else 'o' |
| 109 | |
| 110 | objFileName = '%s.%s' %(os.path.splitext(os.path.basename(tmpFileName))[0], ext) |
| 111 | os.remove(objFileName) |
| 112 | |
| 113 | print(f'[PASSED] Compile: {f}') |
| 114 | return True, None |
| 115 | |
| 116 | return False, stderr |
| 117 | #------------------------------------------------------------------------------ |
| 118 |
no test coverage detected