Skip to content

Commit

Permalink
ISSUE-16731: "msvc" compatibility with "Visual Studio" is broken (#16732
Browse files Browse the repository at this point in the history
)

In case cppstd is set in the Conan profile for "Visual Studio", it is badly
migrated to "msvc". This change solves: #16731

The change also takes care of to handle the case when the 'default' cppstd is
set, in this case, it will be erased from the compatible package as well.
  • Loading branch information
harsszegi authored Jul 29, 2024
1 parent a9e6543 commit 4f11f9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
13 changes: 13 additions & 0 deletions conans/model/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,28 @@ def msvc_compatible(self):
version = compatible.settings.compiler.version
runtime = compatible.settings.compiler.runtime
runtime_type = compatible.settings.compiler.runtime_type
cppstd = compatible.settings.compiler.get_safe("cppstd")

compatible.settings.compiler = "Visual Studio"

if cppstd is not None:
# Restore cppstd, as switching to 'Visual Studio' clears it
compatible.settings.compiler.cppstd = cppstd

from conan.tools.microsoft.visual import msvc_version_to_vs_ide_version
visual_version = msvc_version_to_vs_ide_version(version)
compatible.settings.compiler.version = visual_version
runtime = "MT" if runtime == "static" else "MD"
if runtime_type == "Debug":
runtime = "{}d".format(runtime)
compatible.settings.compiler.runtime = runtime

# Some 'final adjustment'
# In case the cppstd is the 'default' for the compiler, it will actually be erased
default_cppstd = cppstd_default(compatible.settings)
if default_cppstd is not None and compatible.settings.compiler.get_safe("cppstd") == default_cppstd:
del compatible.settings.compiler.cppstd

return compatible

def apple_clang_compatible(self):
Expand Down
30 changes: 25 additions & 5 deletions conans/test/integration/package_id/compatible_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,25 +604,45 @@ def package_id(self):
def test_msvc_visual_incompatible():
conanfile = GenConanfile().with_settings("os", "compiler", "build_type", "arch")
client = TestClient()
profile = textwrap.dedent("""
# First we need to make sure to test that a 'non-default' cppstd is actually preserved
# and we can match that
profile1 = textwrap.dedent("""
[settings]
os=Windows
compiler=msvc
compiler.version=191
compiler.runtime=dynamic
compiler.cppstd=14
compiler.cppstd=17
build_type=Release
arch=x86_64
""")
client.save({"conanfile.py": conanfile,
"profile": profile})
"profile1": profile1})
client.run('create . pkg/0.1@ -s os=Windows -s compiler="Visual Studio" -s compiler.version=15 '
'-s compiler.cppstd=17 -s compiler.runtime=MD -s build_type=Release -s arch=x86_64')
client.run("install pkg/0.1@ -pr=profile1")
assert "Using compatible package" in client.out

# Now we need to test the 'default' cppstd case, in this case, this will be lost in the package id
profile2 = textwrap.dedent("""
[settings]
os=Windows
compiler=msvc
compiler.version=191
compiler.runtime=dynamic
compiler.cppstd=14
build_type=Release
arch=x86_64
""")
client.save({"profile2": profile2})
client.run('create . pkg/0.2@ -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@ -pr=profile")
client.run("install pkg/0.2@ -pr=profile2")
assert "Using compatible package" in client.out

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)
client.run("install pkg/0.1@ -pr=profile1", assert_error=True)
assert "ERROR: Missing prebuilt package for 'pkg/0.1'" in client.out


Expand Down

0 comments on commit 4f11f9f

Please sign in to comment.