def test_mcst_lcc(self): runner = RunnerMock() runner.output = "#define __LCC__ 125\n" \ "#define __LCC_MINOR__ 6\n" \ "#define __e2k__ 1\n" compiler_id = detect_compiler_id("lcc", runner=runner) self.assertEqual(CompilerId(MCST_LCC, 1, 25, 6), compiler_id)
def test_gcc(self): runner = RunnerMock() runner.output = "#define __GNUC__ 7\n" \ "#define __GNUC_MINOR__ 3\n" \ "#define __GNUC_PATCHLEVEL__ 0\n" compiler_id = detect_compiler_id("gcc", runner=runner) self.assertEqual(CompilerId(GCC, 7, 3, 0), compiler_id)
def test_qcc(self): runner = RunnerMock() runner.output = "#define __QNX__ 1\n" \ "#define __GNUC__ 4\n" \ "#define __GNUC_MINOR__ 2\n" \ "#define __GNUC_PATCHLEVEL__ 4\n" compiler_id = detect_compiler_id("qcc", runner=runner) self.assertEqual(CompilerId(QCC, 4, 2, 4), compiler_id)
def test_intel(self): runner = RunnerMock() # Intel C++ may define __GNUC__ and _MSC_VER for compatibility runner.output = "#define _MSC_VER 1922\n" \ "#define __GNUC__ 4\n" \ "#define __GNUC_MINOR__ 1\n" \ "#define __GNUC_PATCHLEVEL__ 1\n" \ "#define __INTEL_COMPILER 1900\n" \ "#define __INTEL_COMPILER_UPDATE 3\n" compiler_id = detect_compiler_id("clang", runner=runner) self.assertEqual(CompilerId(INTEL, 19, 0, 3), compiler_id)
def test_apple_clang(self): runner = RunnerMock() runner.output = "#define __GNUC__ 4\n" \ "#define __GNUC_MINOR__ 1\n" \ "#define __GNUC_PATCHLEVEL__ 1\n" \ "#define __clang__ 1\n"\ "#define __clang_major__ 10\n" \ "#define __clang_minor__ 0\n" \ "#define __clang_patchlevel__ 1\n" \ "#define __apple_build_version__ 10010046\n" compiler_id = detect_compiler_id("clang", runner=runner) self.assertEqual(CompilerId(APPLE_CLANG, 10, 0, 1), compiler_id)
def test_clang(self): runner = RunnerMock() # clang defines __GNUC__ and may define _MSC_VER as well (on Windows) runner.output = "#define _MSC_VER 1922\n" \ "#define __GNUC__ 4\n" \ "#define __GNUC_MINOR__ 1\n" \ "#define __GNUC_PATCHLEVEL__ 1\n" \ "#define __clang__ 1\n"\ "#define __clang_major__ 9\n" \ "#define __clang_minor__ 0\n" \ "#define __clang_patchlevel__ 1\n" compiler_id = detect_compiler_id("clang", runner=runner) self.assertEqual(CompilerId(CLANG, 9, 0, 1), compiler_id)
def _get_cl_version(cl): import subprocess as sp from conans.client.conf.compiler_id import MSVC_TO_VS_VERSION, MSVC out = sp.check_output(cl, stderr=sp.STDOUT, universal_newlines=True) for line in out.splitlines(): m = re.search(r'version\D+(\d+)\.(\d+)\.(\d+)', line, re.IGNORECASE) if m: version = int(f'{m.group(1)}{int(m.group(2)):02}') if not version in MSVC_TO_VS_VERSION.keys(): extra_versions = { 1928: (16, 8), } vs_version = extra_versions[version] else: vs_version = MSVC_TO_VS_VERSION[version] return CompilerId(MSVC, vs_version[0], vs_version[1], None)
def find_msvc_toolchains(version=None, archs=None, **kwargs): archs = archs or ['x86_64', 'x86'] toolchains = set() cache_ = cache.build_root / 'cpppm-msvc-toolchains.cache' if not cache_.exists(): cache.build_root.mkdir(exist_ok=True, parents=True) data = _gen_msvc_cache(archs) json.dump(data, open(cache_, 'w')) else: data = json.load(open(cache_, 'r')) for arch in archs: vc_arch = _get_vc_arch(arch) if vc_arch not in data: data.update(_gen_msvc_cache([vc_arch])) json.dump(data, open(cache_, 'w')) if vc_arch not in data: continue vcvars = data[vc_arch] cl = Path(vcvars["cl"]) compiler_id = CompilerId(vcvars["compiler_id.name"], int(vcvars["compiler_id.major"]), int(vcvars["compiler_id.minor"]), int(vcvars["compiler_id.patch"])) if version and not SimpleSpec(version).match(Version(compiler_id.version)): continue link = cl.parent / 'link.exe' as_ = cl.parent / f'ml{"64" if vc_arch == "x64" else ""}.exe' ar = cl.parent / 'lib.exe' from cpppm.build.compiler import MsvcCompiler toolchains.add(Toolchain('msvc', compiler_id, arch, cl, cl, as_=as_, ar=ar, link=link, dbg=None, cxx_flags=['/EHsc'], compiler_class=MsvcCompiler, env=vcvars)) return toolchains
def test_suncc(self): runner = RunnerMock() runner.output = "#define __SUNPRO_CC 0x450\n" compiler_id = detect_compiler_id("suncc", runner=runner) self.assertEqual(CompilerId(SUNCC, 4, 5, 0), compiler_id)
def test_msvc(self, line, major, minor, patch): runner = RunnerMock() runner.output = line compiler_id = detect_compiler_id("cl", runner=runner) self.assertEqual(CompilerId(MSVC, major, minor, patch), compiler_id)
def test_msvc(self): runner = RunnerMock() runner.output = "MSC_CMD_FLAGS=-D_MSC_VER=1930" compiler_id = detect_compiler_id("cl", runner=runner) self.assertEqual(CompilerId(MSVC, 19, 30, 0), compiler_id)
def test_visual_studio(self, line, major, minor, patch): runner = RunnerMock() runner.output = line compiler_id = detect_compiler_id("cl", runner=runner) self.assertEqual(CompilerId(VISUAL_STUDIO, major, minor, patch), compiler_id)