Skip to content

Commit

Permalink
- tests for toolchains and intel compiler
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
SSE4 committed Nov 19, 2020
1 parent 8ece0c0 commit c8d9e75
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 4 deletions.
18 changes: 14 additions & 4 deletions conans/client/toolchain/msbuild.py
Expand Up @@ -3,15 +3,17 @@
from xml.dom import minidom

from conans.client.toolchain.visual import vcvars_arch, vcvars_command
from conans.client.tools import msvs_toolset
from conans.client.tools import msvs_toolset, intel_compilervars_command
from conans.errors import ConanException
from conans.util.files import save, load


class MSBuildCmd(object):
def __init__(self, conanfile):
self._conanfile = conanfile
self.version = conanfile.settings.get_safe("compiler.version")
self.compiler = conanfile.settings.get_safe("compiler")
self.version = conanfile.settings.get_safe("compiler.base.version") or \
conanfile.settings.get_safe("compiler.version")
self.vcvars_arch = vcvars_arch(conanfile)
self.build_type = conanfile.settings.get_safe("build_type")
msvc_arch = {'x86': 'x86',
Expand All @@ -32,14 +34,20 @@ def command(self, sln):
vcvars_ver=None)
cmd = ('%s && msbuild "%s" /p:Configuration=%s /p:Platform=%s '
% (vcvars, sln, self.build_type, self.platform))

if self.compiler == 'intel':
cvars = intel_compilervars_command(self._conanfile)
cmd = '%s && %s' % (cvars, cmd)
cmd += '/p:PlatformToolset="%s"' % msvs_toolset(self._conanfile)

return cmd

def build(self, sln):
cmd = self.command(sln)
self._conanfile.run(cmd)

@staticmethod
def get_version(settings):
def get_version(_):
return NotImplementedError("get_version() method is not supported in MSBuild "
"toolchain helper")

Expand All @@ -50,6 +58,8 @@ def __init__(self, conanfile):
self._conanfile = conanfile
self.preprocessor_definitions = {}

filename = "conan_toolchain.props"

@staticmethod
def _name_condition(settings):
props = [("Configuration", settings.build_type),
Expand Down Expand Up @@ -108,7 +118,7 @@ def format_macro(k, value):
save(config_filepath, config_props)

def _write_main_toolchain(self, config_filename, condition):
main_toolchain_path = os.path.abspath("conan_toolchain.props")
main_toolchain_path = os.path.abspath(self.filename)
if os.path.isfile(main_toolchain_path):
content = load(main_toolchain_path)
else:
Expand Down
4 changes: 4 additions & 0 deletions conans/test/assets/sources.py
Expand Up @@ -34,6 +34,10 @@
std::cout << " {{ msg or name }} _MSVC_LANG" << _MSVC_LANG<< "\n";
#endif
#if __INTEL_COMPILER
std::cout << " {{ msg or name }} __INTEL_COMPILER" << __INTEL_COMPILER<< "\n";
#endif
{% for it in preprocessor -%}
std::cout << " {{msg}} {{it}}: " << {{it}} << "\n";
{%- endfor %}
Expand Down
Empty file.
56 changes: 56 additions & 0 deletions conans/test/integration/toolchains/intel/_base.py
@@ -0,0 +1,56 @@
import os
import platform
import textwrap
import unittest

from conans.client.tools.intel import intel_installation_path
from conans.errors import ConanException
from conans.test.utils.tools import TestClient


class BaseIntelTestCase(unittest.TestCase):
def setUp(self):
try:
installation_path = intel_installation_path(self.version, self.arch)
if not os.path.isdir(installation_path):
raise unittest.SkipTest("Intel C++ compiler is required")
except ConanException:
raise unittest.SkipTest("Intel C++ compiler is required")

self.t = TestClient()

@property
def version(self):
return '19.1'

@property
def arch(self):
return "x86_64"

@property
def settings(self):
the_os = {'Darwin': 'Macos'}.get(platform.system(), platform.system())
vars = [('compiler', 'intel'),
('compiler.version', self.version),
('build_type', 'Release'),
('arch', self.arch),
('os', the_os)]
if platform.system() == "Windows":
vars.append(('compiler.base', 'Visual Studio'))
vars.append(('compiler.base.version', '15'))
vars.append(('compiler.base.runtime', 'MD'))
else:
vars.append(('compiler.base', 'gcc'))
vars.append(('compiler.base.version', '10'))
vars.append(('compiler.base.libcxx', 'libstdc++'))
return vars

@property
def profile(self):
template = textwrap.dedent("""
include(default)
[settings]
{settings}
""")
settings = '\n'.join(["%s = %s" % (s[0], s[1]) for s in self.settings])
return template.format(settings=settings)
106 changes: 106 additions & 0 deletions conans/test/integration/toolchains/intel/test_using_cmake.py
@@ -0,0 +1,106 @@
import os
import pytest
import textwrap

from ._base import BaseIntelTestCase

from conans.client.toolchain.cmake.base import CMakeToolchainBase
from conans.client.toolchain.visual import vcvars_command
from conans.test.assets.sources import gen_function_cpp


cmakelists_txt = textwrap.dedent("""
cmake_minimum_required(VERSION 2.8.12)
project(MyApp CXX)
find_package(hello REQUIRED)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${CMAKE_PROJECT_NAME} main.cpp)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "d")
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE hello::hello)
install(TARGETS ${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
""")

conanfile_py = textwrap.dedent("""
from conans import ConanFile, CMake, CMakeToolchain
class App(ConanFile):
settings = 'os', 'arch', 'compiler', 'build_type'
exports_sources = "CMakeLists.txt", "main.cpp"
generators = "cmake_find_package_multi"
requires = "hello/0.1"
_cmake = None
def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
def toolchain(self):
tc = CMakeToolchain(self)
tc.write_toolchain_files()
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
cmake = self._configure_cmake()
cmake.install()
""")

@pytest.mark.toolchain
@pytest.mark.tool_cmake
@pytest.mark.tool_icc
class CMakeIntelTestCase(BaseIntelTestCase):

def test_use_cmake_toolchain(self):
self.t.save({'profile': self.profile})
self.t.run("new hello/0.1 -s")
self.t.run("create . hello/0.1@ -pr:h=profile")

app = gen_function_cpp(name="main", includes=["hello"], calls=["hello"])

# Prepare the actual consumer package
self.t.save({"conanfile.py": conanfile_py,
"main.cpp": app,
"CMakeLists.txt": cmakelists_txt,
'profile': self.profile},
clean_first=True)

# Build in the cache
self.t.run("install . -pr:h=profile")
self.assertIn("conanfile.py: Generator cmake_find_package_multi created helloTargets.cmake",
self.t.out)
self.t.run("build .")
self.assertIn("The CXX compiler identification is Intel 19.1", self.t.out)

exe = os.path.join("Release", "MyApp.exe")
self.t.run_command(exe)
self.assertIn("main __INTEL_COMPILER1910", self.t.out)

vcvars = vcvars_command(version="15", architecture="x64")
dumpbind_cmd = '%s && dumpbin /dependents "%s"' % (vcvars, exe)
self.t.run_command(dumpbind_cmd)
self.assertIn("KERNEL32.dll", self.t.out)

# Build locally
os.unlink(os.path.join(self.t.current_folder, exe))

self.t.run_command('cmake . -G "Visual Studio 15 2017" '
'-DCMAKE_TOOLCHAIN_FILE={}'.format(CMakeToolchainBase.filename))
self.t.run_command('cmake --build . --config Release')

self.t.run_command(exe)
self.assertIn("main __INTEL_COMPILER1910", self.t.out)

self.t.run_command(dumpbind_cmd)
self.assertIn("KERNEL32.dll", self.t.out)
87 changes: 87 additions & 0 deletions conans/test/integration/toolchains/intel/test_using_msbuild.py
@@ -0,0 +1,87 @@
import os
import platform
import pytest
import textwrap
import unittest

from ._base import BaseIntelTestCase
from ..test_msbuild import myapp_vcxproj, sln_file

from conans.client.toolchain.visual import vcvars_command
from conans.test.assets.sources import gen_function_cpp


conanfile_py = textwrap.dedent("""
from conans import ConanFile, MSBuild, MSBuildToolchain
class App(ConanFile):
settings = 'os', 'arch', 'compiler', 'build_type'
exports_sources = "MyProject.sln", "MyApp/MyApp.vcxproj", "MyApp/MyApp.cpp"
generators = "msbuild"
requires = "hello/0.1"
def toolchain(self):
tc = MSBuildToolchain(self)
tc.write_toolchain_files()
def build(self):
msbuild = MSBuild(self)
msbuild.build("MyProject.sln")
""")


@pytest.mark.toolchain
@pytest.mark.tool_cmake
@pytest.mark.tool_msbuild
@pytest.mark.tool_icc
@unittest.skipUnless(platform.system() == "Windows", "msbuild requires Windows")
class MSBuildIntelTestCase(BaseIntelTestCase):
def test_use_msbuild_toolchain(self):
self.t.save({'profile': self.profile})
self.t.run("new hello/0.1 -s")
self.t.run("create . hello/0.1@ -pr:h=profile")

app = gen_function_cpp(name="main", includes=["hello"], calls=["hello"])

# Prepare the actual consumer package
self.t.save({"conanfile.py": conanfile_py,
"MyProject.sln": sln_file,
"MyApp/MyApp.vcxproj": myapp_vcxproj,
"MyApp/MyApp.cpp": app,
'profile': self.profile},
clean_first=True)

# Build in the cache
self.t.run("install . -pr:h=profile -if=conan")

self.assertIn("conanfile.py: MSBuildToolchain created conan_toolchain_release_x64.props",
self.t.out)

self.t.run("build . -if=conan")
self.assertIn("Visual Studio 2017", self.t.out)
self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", self.t.out)

exe = "x64\\Release\\MyApp.exe"
self.t.run_command(exe)
self.assertIn("main __INTEL_COMPILER1910", self.t.out)

vcvars = vcvars_command(version="15", architecture="x64")
dumpbind_cmd = '%s && dumpbin /dependents "%s"' % (vcvars, exe)
self.t.run_command(dumpbind_cmd)
self.assertIn("KERNEL32.dll", self.t.out)

# Build locally
os.unlink(os.path.join(self.t.current_folder, exe))

cmd = vcvars + ' && msbuild "MyProject.sln" /p:Configuration=Release ' \
'/p:Platform=x64 /p:PlatformToolset="Intel C++ Compiler 19.1"'

self.t.run_command(cmd)
self.assertIn("Visual Studio 2017", self.t.out)
self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", self.t.out)

self.t.run_command(exe)
self.assertIn("main __INTEL_COMPILER1910", self.t.out)

self.t.run_command(dumpbind_cmd)
self.assertIn("KERNEL32.dll", self.t.out)

0 comments on commit c8d9e75

Please sign in to comment.