Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/msvc msbuild #8238

Merged
merged 40 commits into from Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0a6f828
working in msvc new settings
memsharded Dec 10, 2020
27c6fc4
merged develop
memsharded Dec 12, 2020
72f6bee
preliminary support for msvc compiler
memsharded Dec 12, 2020
369143b
fix migration
memsharded Dec 12, 2020
49dad85
adding msvc for msbuild toolchain
memsharded Dec 14, 2020
fb110ba
changing to version 19.1, 19.11, etc
memsharded Dec 15, 2020
ee99a73
merged develop
memsharded Dec 15, 2020
cfc28fe
working on static/dynamic runtime
memsharded Dec 16, 2020
c55072f
Merge branch 'develop' into feature/msvc
memsharded Dec 16, 2020
b245c43
extracting toolchain checkers to use in CMake
memsharded Dec 16, 2020
c363312
removed unused import
memsharded Dec 16, 2020
fb6b57b
adding checks
memsharded Dec 16, 2020
e98d911
adding check
memsharded Dec 16, 2020
ae91af5
Merge branch 'feature/toolchain_checkers' into feature/msvc
memsharded Dec 16, 2020
3c3a7b3
first proposal
memsharded Dec 16, 2020
3bb3e4d
msvc proposal for runtime
memsharded Dec 16, 2020
ef36fd2
fix migration test
memsharded Dec 16, 2020
2000c85
fixing tests
memsharded Dec 16, 2020
640b134
binary compatibility
memsharded Dec 16, 2020
fca3c79
merged develop
memsharded Dec 17, 2020
dc6ecbf
Merge branch 'feature/msvc' into feature/msvc_msbuild
memsharded Dec 19, 2020
1994d1f
command conan new generates files with new toolchains
memsharded Dec 19, 2020
3b71504
removed conanfile
memsharded Dec 19, 2020
e66dbe2
removed files
memsharded Dec 19, 2020
5e8fb4f
Merge branch 'feature/new_v2' into feature/msvc_msbuild
memsharded Dec 20, 2020
b0f86c6
msbuild working for msvc
memsharded Dec 20, 2020
1900ff8
merging develop
memsharded Jan 14, 2021
c0c445c
fixing tests
memsharded Jan 14, 2021
f6528c4
fixing tests
memsharded Jan 14, 2021
da8689f
refactors
memsharded Jan 15, 2021
a311923
Update conan/tools/microsoft/toolchain.py
memsharded Jan 18, 2021
59ed3b0
Update conan/tools/microsoft/toolchain.py
memsharded Jan 18, 2021
ef7053c
Fix #7715, in rpath_flags use host OS instead of build OS to determin…
Erlkoenig90 Jan 14, 2021
b4fd977
modernizing tests (#8340)
memsharded Jan 15, 2021
0f2a416
extracting some common code to base class (#8341)
memsharded Jan 16, 2021
52d5e42
modernizing tests (#8345)
memsharded Jan 18, 2021
07570f8
Fix help message in command remove --outdated (#8350)
danimtb Jan 18, 2021
c8b4897
[test] Add test creating a target without namespaces (CMake) (#8338)
jgsogo Jan 18, 2021
7d81f9d
update tests (#8354)
czoido Jan 18, 2021
7e2beca
added integration test for msbuild
memsharded Jan 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions conan/tools/microsoft/msbuild.py
Expand Up @@ -15,8 +15,15 @@ class MSBuild(object):
def __init__(self, conanfile):
self._conanfile = conanfile
self.compiler = conanfile.settings.get_safe("compiler")
# This is assuming this is the Visual Studio IDE version, used for the vcvars
self.version = (conanfile.settings.get_safe("compiler.base.version") or
conanfile.settings.get_safe("compiler.version"))
if self.compiler == "msvc":
version = self.version[:4] # Remove the latest version number 19.1X if existing
_visuals = {'19.0': '14', # TODO: This is common to CMake, refactor
'19.1': '15',
'19.2': '16'}
self.version = _visuals[version]
self.vcvars_arch = vcvars_arch(conanfile)
self.build_type = conanfile.settings.get_safe("build_type")
msvc_arch = {'x86': 'x86',
Expand Down
72 changes: 57 additions & 15 deletions conan/tools/microsoft/toolchain.py
Expand Up @@ -3,7 +3,6 @@
import warnings
from xml.dom import minidom

from conans.client.tools import msvs_toolset
from conans.errors import ConanException
from conans.util.files import save, load

Expand All @@ -17,6 +16,9 @@ def __init__(self, conanfile):
self.preprocessor_definitions = {}
self.compile_options = {}
self.configuration = conanfile.settings.build_type
self.runtime_library = self._runtime_library(conanfile.settings)
self.cppstd = conanfile.settings.get_safe("compiler.cppstd")
self.toolset = self._msvs_toolset(conanfile.settings)

def _name_condition(self, settings):
props = [("Configuration", self.configuration),
Expand Down Expand Up @@ -49,20 +51,59 @@ def generate(self):
self._write_config_toolchain(config_filename)
self._write_main_toolchain(config_filename, condition)

@staticmethod
def _msvs_toolset(settings):
compiler = settings.get_safe("compiler")
compiler_version = settings.get_safe("compiler.version")
if compiler == "msvc":
version = compiler_version[:4] # Remove the latest version number 19.1X if existing
toolsets = {'19.0': 'v140', # TODO: This is common to CMake, refactor
'19.1': 'v141',
'19.2': 'v142'}
return toolsets[version]
if compiler == "intel":
compiler_version = compiler_version if "." in compiler_version else \
"%s.0" % compiler_version
return "Intel C++ Compiler " + compiler_version
if compiler == "Visual Studio":
toolset = settings.get_safe("compiler.toolset")
if not toolset:
toolsets = {"16": "v142",
"15": "v141",
"14": "v140",
"12": "v120",
"11": "v110",
"10": "v100",
"9": "v90",
"8": "v80"}
toolset = toolsets.get(compiler_version)
return toolset or ""

@staticmethod
def _runtime_library(settings):
compiler = settings.compiler
runtime = settings.get_safe("compiler.runtime")
if compiler == "msvc":
build_type = settings.get_safe("build_type")
if build_type != "Debug":
runtime_library = {"static": "MultiThreaded",
"dynamic": "MultiThreadedDLL"}.get(runtime, "")
else:
runtime_library = {"static": "MultiThreadedDebug",
"dynamic": "MultiThreadedDebugDLL"}.get(runtime, "")
else:
runtime_library = {"MT": "MultiThreaded",
"MTd": "MultiThreadedDebug",
"MD": "MultiThreadedDLL",
"MDd": "MultiThreadedDebugDLL"}.get(runtime, "")
return runtime_library

def _write_config_toolchain(self, config_filename):

def format_macro(k, value):
return '%s="%s"' % (k, value) if value is not None else k

runtime = self._conanfile.settings.get_safe("compiler.runtime")
cppstd = self._conanfile.settings.get_safe("compiler.cppstd")
toolset = msvs_toolset(self._conanfile.settings)
runtime_library = {"MT": "MultiThreaded",
"MTd": "MultiThreadedDebug",
"MD": "MultiThreadedDLL",
"MDd": "MultiThreadedDebugDLL"}.get(runtime, "")

content = textwrap.dedent("""\
toolchain_file = textwrap.dedent("""\
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
Expand All @@ -81,17 +122,18 @@ def format_macro(k, value):
""")
preprocessor_definitions = ";".join([format_macro(k, v)
for k, v in self.preprocessor_definitions.items()])
# It is useless to set PlatformToolset in the config file, because the conditional checks it
cppstd = "stdcpp%s" % cppstd if cppstd else ""
toolset = toolset or ""

cppstd = "stdcpp%s" % self.cppstd if self.cppstd else ""
runtime_library = self.runtime_library
toolset = self.toolset
compile_options = self._conanfile.conf["tools.microsoft.msbuildtoolchain"].compile_options
if compile_options is not None:
compile_options = eval(compile_options)
self.compile_options.update(compile_options)
compile_options = "".join("\n <{k}>{v}</{k}>".format(k=k, v=v)
for k, v in self.compile_options.items())
config_props = content.format(preprocessor_definitions, runtime_library, cppstd,
compile_options, toolset)
config_props = toolchain_file.format(preprocessor_definitions, runtime_library, cppstd,
compile_options, toolset)
config_filepath = os.path.abspath(config_filename)
self._conanfile.output.info("MSBuildToolchain created %s" % config_filename)
save(config_filepath, config_props)
Expand Down
8 changes: 0 additions & 8 deletions conans/client/conf/__init__.py
Expand Up @@ -504,14 +504,6 @@ def full_transitive_package_id(self):
except ConanException:
return None

@property
def msvc_visual_incompatible(self):
try:
visual_comp = self.get_item("general.msvc_visual_incompatible")
return visual_comp.lower() in ("1", "true")
except ConanException:
return False

@property
def short_paths_home(self):
short_paths_home = get_env("CONAN_USER_HOME_SHORT")
Expand Down
3 changes: 2 additions & 1 deletion conans/client/graph/graph_binaries.py
Expand Up @@ -339,7 +339,8 @@ def _compute_package_id(self, node, default_package_id_mode, default_python_requ
python_requires=python_requires,
default_python_requires_id_mode=
default_python_requires_id_mode)
if not self._cache.config.msvc_visual_incompatible:

if not self._cache.new_config["core.package_id"].msvc_visual_incompatible:
msvc_compatible = conanfile.info.msvc_compatible()
if msvc_compatible:
conanfile.compatible_packages.append(msvc_compatible)
Expand Down
3 changes: 2 additions & 1 deletion conans/client/tools/win.py
Expand Up @@ -138,8 +138,9 @@ def msvs_toolset(conanfile):
settings = conanfile
toolset = settings.get_safe("compiler.toolset")
if not toolset:
compiler = settings.get_safe("compiler")
compiler_version = settings.get_safe("compiler.version")
if settings.get_safe("compiler") == "intel":
if compiler == "intel":
compiler_version = compiler_version if "." in compiler_version else \
"%s.0" % compiler_version
toolset = "Intel C++ Compiler " + compiler_version
Expand Down
1 change: 1 addition & 0 deletions conans/test/functional/toolchains/cmake/test_ninja.py
Expand Up @@ -10,6 +10,7 @@
from conans.test.utils.tools import TestClient
from conans.client.tools import which


@pytest.mark.tool_cmake
class CMakeNinjaTestCase(unittest.TestCase):
# This test assumes that 'CMake' and 'Ninja' are available in the system
Expand Down
15 changes: 10 additions & 5 deletions conans/test/functional/toolchains/test_msbuild.py
Expand Up @@ -6,6 +6,8 @@
import unittest

import pytest
from parameterized import parameterized


from conans.client.tools import chdir
from conans.util.files import mkdir
Expand Down Expand Up @@ -399,19 +401,22 @@ def _run_app(self, client, arch, build_type, shared=None):
self.assertIn("DEFINITIONS_CONFIG: %s" % build_type, client.out)

@pytest.mark.tool_cmake
def test_toolchain_win(self):
@parameterized.expand([("Visual Studio", "15", "MT"),
("msvc", "19.1", "static")]
)
def test_toolchain_win(self, compiler, version, runtime):
client = TestClient(path_with_spaces=False)
settings = {"compiler": "Visual Studio",
"compiler.version": "15",
settings = {"compiler": compiler,
"compiler.version": version,
"compiler.cppstd": "17",
"compiler.runtime": "MT",
"compiler.runtime": runtime,
"build_type": "Release",
"arch": "x86"}

# Build the profile according to the settings provided
settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v)

client.run("new hello/0.1 -s")
client.run("new hello/0.1 -m=v2_cmake")
client.run("create . hello/0.1@ %s" % (settings, ))

# Prepare the actual consumer package
Expand Down
25 changes: 17 additions & 8 deletions conans/test/integration/package_id/compatible_test.py
Expand Up @@ -4,6 +4,7 @@

from conans.model.ref import ConanFileReference
from conans.test.utils.tools import TestClient, GenConanfile
from conans.util.files import save


class CompatibleIDsTest(unittest.TestCase):
Expand Down Expand Up @@ -497,15 +498,23 @@ def package_id(self):
def test_msvc_visual_incompatible():
conanfile = GenConanfile().with_settings("os", "compiler", "build_type", "arch")
client = TestClient()
client.save({"conanfile.py": conanfile})
profile = textwrap.dedent("""
[settings]
os=Windows
compiler=msvc
compiler.version=19.1
compiler.runtime=dynamic
compiler.cppstd=14
build_type=Release
arch=x86_64
""")
client.save({"conanfile.py": conanfile,
"profile": profile})
client.run('create . pkg/0.1@ -s os=Windows -s compiler="Visual Studio" -s compiler.version=15 '
'-s compiler.runtime=MD -s build_type=Release -s arch=x86_64')
client.run("install pkg/0.1@ -s os=Windows -s compiler=msvc -s compiler.version=19.1 "
"-s compiler.runtime=dynamic -s build_type=Release -s arch=x86_64 "
"-s compiler.cppstd=14")
client.run("install pkg/0.1@ -pr=profile")
assert "Using compatible package" in client.out
client.run("config set general.msvc_visual_incompatible=1")
client.run("install pkg/0.1@ -s os=Windows -s compiler=msvc -s compiler.version=19.1 "
"-s compiler.runtime=dynamic -s build_type=Release -s arch=x86_64 "
"-s compiler.cppstd=14", assert_error=True)
new_config = "core.package_id:msvc_visual_incompatible=1"
save(client.cache.new_config_path, new_config)
client.run("install pkg/0.1@ -pr=profile", assert_error=True)
assert "ERROR: Missing prebuilt package for 'pkg/0.1'" in client.out
3 changes: 2 additions & 1 deletion conans/test/unittests/model/transitive_reqs_test.py
@@ -1,5 +1,5 @@
import unittest
from collections import namedtuple, Counter
from collections import namedtuple, Counter, defaultdict

import six
from mock import Mock
Expand Down Expand Up @@ -87,6 +87,7 @@ def setUp(self):
self.resolver, None)
cache = Mock()
cache.config.default_package_id_mode = "semver_direct_mode"
cache.new_config = defaultdict(Mock)
self.binaries_analyzer = GraphBinariesAnalyzer(cache, self.output, self.remote_manager)

def build_graph(self, content, options="", settings=""):
Expand Down