-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * wip * Test for BazelDeps in the build context (#16025) * feat add test to bazeldeps * Fixed several bugs. Improved tests coverage * Reverted * Better name --------- Co-authored-by: Francisco Ramirez de Anton <franchuti688@gmail.com> * copy only if different (#16031) * allow conf in exports-sources and export (#16034) * refactor apple_min_version_flag() (#16017) * refactor apple_min_version_flag() * Refactored all the apple module and where it was being used (AutotoolsToolchain and MesonToolchain for now) * Fixed bad return * Fixing tests * Keeping legacy behavior in apple_min_version_flag function * Preventing possible breaking change --------- Co-authored-by: Francisco Ramirez de Anton <franchuti688@gmail.com> * Allow to unhide git url (#16038) * Add hide_url tests for git scm tool * Add hide_url flag to clone and fetch_commit. Resolves #15684 * Update conans/test/functional/tools/scm/test_git.py * Update conans/test/functional/tools/scm/test_git.py --------- Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es> * wip * wip * wip * fix * Update conan/tools/build/cstd.py Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es> * Update conan/tools/build/cstd.py Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es> * Update conan/tools/build/cstd.py Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es> --------- Co-authored-by: Ernesto de Gracia Herranz <vivalaburocracia@hotmail.com> Co-authored-by: Francisco Ramirez de Anton <franchuti688@gmail.com> Co-authored-by: Sebastian Höffner <info@sebastian-hoeffner.de> Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
- Loading branch information
1 parent
2dcaf42
commit b88c8bb
Showing
20 changed files
with
447 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import operator | ||
|
||
from conan.errors import ConanInvalidConfiguration, ConanException | ||
from conans.model.version import Version | ||
|
||
|
||
def check_min_cstd(conanfile, cstd, gnu_extensions=False): | ||
""" Check if current cstd fits the minimal version required. | ||
In case the current cstd doesn't fit the minimal version required | ||
by cstd, a ConanInvalidConfiguration exception will be raised. | ||
1. If settings.compiler.cstd, the tool will use settings.compiler.cstd to compare | ||
2. It not settings.compiler.cstd, the tool will use compiler to compare (reading the | ||
default from cstd_default) | ||
3. If not settings.compiler is present (not declared in settings) will raise because it | ||
cannot compare. | ||
4. If can not detect the default cstd for settings.compiler, a exception will be raised. | ||
:param conanfile: The current recipe object. Always use ``self``. | ||
:param cstd: Minimal cstd version required | ||
:param gnu_extensions: GNU extension is required (e.g gnu17) | ||
""" | ||
_check_cstd(conanfile, cstd, operator.lt, gnu_extensions) | ||
|
||
|
||
def check_max_cstd(conanfile, cstd, gnu_extensions=False): | ||
""" Check if current cstd fits the maximum version required. | ||
In case the current cstd doesn't fit the maximum version required | ||
by cstd, a ConanInvalidConfiguration exception will be raised. | ||
1. If settings.compiler.cstd, the tool will use settings.compiler.cstd to compare | ||
2. It not settings.compiler.cstd, the tool will use compiler to compare (reading the | ||
default from cstd_default) | ||
3. If not settings.compiler is present (not declared in settings) will raise because it | ||
cannot compare. | ||
4. If can not detect the default cstd for settings.compiler, a exception will be raised. | ||
:param conanfile: The current recipe object. Always use ``self``. | ||
:param cstd: Maximum cstd version required | ||
:param gnu_extensions: GNU extension is required (e.g gnu17) | ||
""" | ||
_check_cstd(conanfile, cstd, operator.gt, gnu_extensions) | ||
|
||
|
||
def valid_min_cstd(conanfile, cstd, gnu_extensions=False): | ||
""" Validate if current cstd fits the minimal version required. | ||
:param conanfile: The current recipe object. Always use ``self``. | ||
:param cstd: Minimal cstd version required | ||
:param gnu_extensions: GNU extension is required (e.g gnu17). This option ONLY works on Linux. | ||
:return: True, if current cstd matches the required cstd version. Otherwise, False. | ||
""" | ||
try: | ||
check_min_cstd(conanfile, cstd, gnu_extensions) | ||
except ConanInvalidConfiguration: | ||
return False | ||
return True | ||
|
||
|
||
def valid_max_cstd(conanfile, cstd, gnu_extensions=False): | ||
""" Validate if current cstd fits the maximum version required. | ||
:param conanfile: The current recipe object. Always use ``self``. | ||
:param cstd: Maximum cstd version required | ||
:param gnu_extensions: GNU extension is required (e.g gnu17). This option ONLY works on Linux. | ||
:return: True, if current cstd matches the required cstd version. Otherwise, False. | ||
""" | ||
try: | ||
check_max_cstd(conanfile, cstd, gnu_extensions) | ||
except ConanInvalidConfiguration: | ||
return False | ||
return True | ||
|
||
|
||
def supported_cstd(conanfile, compiler=None, compiler_version=None): | ||
""" | ||
Get a list of supported ``compiler.cstd`` for the "conanfile.settings.compiler" and | ||
"conanfile.settings.compiler_version" or for the parameters "compiler" and "compiler_version" | ||
if specified. | ||
:param conanfile: The current recipe object. Always use ``self``. | ||
:param compiler: Name of the compiler e.g: gcc | ||
:param compiler_version: Version of the compiler e.g: 12 | ||
:return: a list of supported ``cstd`` values. | ||
""" | ||
compiler = compiler or conanfile.settings.get_safe("compiler") | ||
compiler_version = compiler_version or conanfile.settings.get_safe("compiler.version") | ||
if not compiler or not compiler_version: | ||
raise ConanException("Called supported_cstd with no compiler or no compiler.version") | ||
|
||
func = {"apple-clang": _apple_clang_supported_cstd, | ||
"gcc": _gcc_supported_cstd, | ||
"msvc": _msvc_supported_cstd, | ||
"clang": _clang_supported_cstd, | ||
}.get(compiler) | ||
if func: | ||
return func(Version(compiler_version)) | ||
return None | ||
|
||
|
||
def _check_cstd(conanfile, cstd, comparator, gnu_extensions): | ||
""" Check if current cstd fits the version required according to a given comparator. | ||
In case the current cstd doesn't fit the maximum version required | ||
by cstd, a ConanInvalidConfiguration exception will be raised. | ||
1. If settings.compiler.cstd, the tool will use settings.compiler.cstd to compare | ||
2. It not settings.compiler.cstd, the tool will use compiler to compare (reading the | ||
default from cstd_default) | ||
3. If not settings.compiler is present (not declared in settings) will raise because it | ||
cannot compare. | ||
4. If can not detect the default cstd for settings.compiler, a exception will be raised. | ||
:param conanfile: The current recipe object. Always use ``self``. | ||
:param cstd: Required cstd version. | ||
:param comparator: Operator to use to compare the detected and the required cstd versions. | ||
:param gnu_extensions: GNU extension is required (e.g gnu17) | ||
""" | ||
if not str(cstd).isdigit(): | ||
raise ConanException("cstd parameter must be a number") | ||
|
||
def compare(lhs, rhs, comp): | ||
def extract_cpp_version(_cstd): | ||
return str(_cstd).replace("gnu", "") | ||
|
||
def add_millennium(_cstd): | ||
return "19%s" % _cstd if _cstd == "99" else "20%s" % _cstd | ||
|
||
lhs = add_millennium(extract_cpp_version(lhs)) | ||
rhs = add_millennium(extract_cpp_version(rhs)) | ||
return not comp(lhs, rhs) | ||
|
||
current_cstd = conanfile.settings.get_safe("compiler.cstd") | ||
if current_cstd is None: | ||
raise ConanInvalidConfiguration("The compiler.cstd is not defined for this configuration") | ||
|
||
if gnu_extensions and "gnu" not in current_cstd: | ||
raise ConanInvalidConfiguration("The cstd GNU extension is required") | ||
|
||
if not compare(current_cstd, cstd, comparator): | ||
raise ConanInvalidConfiguration( | ||
"Current cstd ({}) is {} than the required C standard ({}).".format( | ||
current_cstd, "higher" if comparator == operator.gt else "lower", cstd)) | ||
|
||
|
||
def _apple_clang_supported_cstd(version): | ||
# TODO: Per-version support | ||
return ["99", "gnu99", "11", "gnu11", "17", "gnu17", "23", "gnu23"] | ||
|
||
|
||
def _gcc_supported_cstd(version): | ||
if version < "4.7": | ||
return ["99", "gnu99"] | ||
if version < "8": | ||
return ["99", "gnu99", "11", "gnu11"] | ||
if version < "14": | ||
return ["99", "gnu99", "11", "gnu11", "17", "gnu17"] | ||
return ["99", "gnu99", "11", "gnu11", "17", "gnu17", "23", "gnu23"] | ||
|
||
|
||
def _msvc_supported_cstd(version): | ||
if version < "192": | ||
return [] | ||
return ["11", "17"] | ||
|
||
|
||
def _clang_supported_cstd(version): | ||
if version < "3": | ||
return ["99", "gnu99"] | ||
if version < "6": | ||
return ["99", "gnu99", "11", "gnu11"] | ||
if version < "18": | ||
return ["99", "gnu99", "11", "gnu11", "17", "gnu17"] | ||
return ["99", "gnu99", "11", "gnu11", "17", "gnu17", "23", "gnu23"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.