-
Notifications
You must be signed in to change notification settings - Fork 1k
Add conan.tools.gnu.is_mingw()
in conan API
#12678
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
Changes from all commits
421d4bb
301e134
e45409b
1bc05f8
44aa15c
11b3f7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from conan.tools.gnu.autotools import Autotools | ||
from conan.tools.gnu.autotoolstoolchain import AutotoolsToolchain | ||
from conan.tools.gnu.autotoolsdeps import AutotoolsDeps | ||
from conan.tools.gnu.mingw import is_mingw | ||
from conan.tools.gnu.pkgconfig import PkgConfig | ||
from conan.tools.gnu.pkgconfigdeps import PkgConfigDeps |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
def is_mingw(conanfile): | ||
""" | ||
Validate if current compiler in host setttings is related to MinGW | ||
:param conanfile: ConanFile instance | ||
:return: True, if the host compiler is related to MinGW, otherwise False. | ||
""" | ||
host_os = conanfile.settings.get_safe("os") | ||
is_cygwin = host_os == "Windows" and conanfile.settings.get_safe("os.subsystem") == "cygwin" | ||
host_compiler = conanfile.settings.get_safe("compiler") | ||
is_mingw_gcc = host_os == "Windows" and not is_cygwin and host_compiler == "gcc" | ||
is_mingw_clang = host_os == "Windows" and not is_cygwin and host_compiler == "clang" and \ | ||
not conanfile.settings.get_safe("compiler.runtime") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's worth noting that I've prefered this condition over (but honestly if there was an extra attribute in conan settings of clang compiler in order to set windows flavor, it would be far easier) |
||
return is_mingw_gcc or is_mingw_clang |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
from mock import Mock | ||
|
||
from conan.tools.gnu import is_mingw | ||
from conans import ConanFile, Settings | ||
from conans.model.env_info import EnvValues | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"os,compiler_name,compiler_version,compiler_libcxx,compiler_runtime,compiler_runtime_type,expected", | ||
[ | ||
("Windows", "gcc", "9", "libstdc++11", None, None, True), | ||
("Windows", "clang", "16", "libstdc++11", None, None, True), | ||
("Windows", "Visual Studio", "17", "MD", None, None, False), | ||
("Windows", "msvc", "193", None, "dynamic", "Release", False), | ||
("Windows", "clang", "16", None, "MD", None, False), | ||
("Windows", "clang", "16", None, "dynamic", "Release", False), | ||
("Linux", "gcc", "9", "libstdc++11", None, None, False), | ||
("Linux", "clang", "16", "libc++", None, None, False), | ||
("Macos", "apple-clang", "14", "libc++", None, None, False), | ||
], | ||
) | ||
def test_is_mingw(os, compiler_name, compiler_version, compiler_libcxx, compiler_runtime, compiler_runtime_type, expected): | ||
compiler = {compiler_name: {"version": [compiler_version]}} | ||
if compiler_libcxx: | ||
compiler[compiler_name].update({"libcxx": [compiler_libcxx]}) | ||
if compiler_runtime: | ||
compiler[compiler_name].update({"runtime": [compiler_runtime]}) | ||
if compiler_runtime_type: | ||
compiler[compiler_name].update({"runtime_type": [compiler_runtime_type]}) | ||
settings = Settings({ | ||
"os": [os], | ||
"arch": ["x86_64"], | ||
"compiler": compiler, | ||
"build_type": ["Release"], | ||
}) | ||
conanfile = ConanFile(Mock(), None) | ||
conanfile.settings = "os", "arch", "compiler", "build_type" | ||
conanfile.initialize(settings, EnvValues()) | ||
conanfile.settings.os = os | ||
conanfile.settings.compiler = compiler_name | ||
conanfile.settings.compiler.version = compiler_version | ||
if compiler_libcxx: | ||
conanfile.settings.compiler.libcxx = compiler_libcxx | ||
if compiler_runtime: | ||
conanfile.settings.compiler.runtime = compiler_runtime | ||
if compiler_runtime_type: | ||
conanfile.settings.compiler.runtime_type = compiler_runtime_type | ||
assert is_mingw(conanfile) == expected |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also adding my comment here[1]:
I would propose something like early return:
PS: From trying to map the current code to my snippet I can only conclude that the current code is very hard to read and understand (if my mapping is not correct it proves that the proposed code is perhaps overly complex).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this, part this PR never got prioritized is because the logic reads too compact, and it also introduces new aspects that are not common practice in ConanCenter recipes, in which the majority just check
Windows && gcc => MinGW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a new aspect, but it's an important one. According to https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.html the compiler.runtime setting is the official way to distinguish between MinGW clang and VS clang-cl. Some recipes in Conan Center already take this into account, but most do not. This is one of the main reasons why we are struggling a lot with introducing Conan at our company (we use MinGW clang for compatibility and performance reasons).
This PR could help a lot with easier integration and broader adoption of this Windows clang distinction through Conan Center.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mhthies. There is an open ticket for this helper here: #15648, lets try to follow up there.