-
Notifications
You must be signed in to change notification settings - Fork 1k
Feature/language #16028
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
Merged
Merged
Feature/language #16028
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4ce9f6c
wip
memsharded aaeaebe
Merge branch 'develop2' into feature/language
memsharded a4e18e2
wip
memsharded 01d151c
Merge branch 'develop2' into feature/language
memsharded 4ba8049
wip
memsharded 69ee385
Test for BazelDeps in the build context (#16025)
ErniGH c8545d8
copy only if different (#16031)
memsharded 7dbfb3d
allow conf in exports-sources and export (#16034)
memsharded d579c0f
refactor apple_min_version_flag() (#16017)
memsharded ce4f5df
Allow to unhide git url (#16038)
shoeffner 2a87015
wip
memsharded c669576
wip
memsharded 875a995
Merge branch 'develop2' into feature/language
memsharded 0845c1f
wip
memsharded c4f7cad
Merge branch 'develop2' into feature/language
memsharded 846d78b
fix
memsharded bcb56ca
Merge branch 'develop2' into feature/language
memsharded a31f74c
Merge branch 'develop2' into feature/language
memsharded 0231553
wip
memsharded 7bdd372
Merge branch 'develop2' into feature/language
memsharded 0920369
merged develop2
memsharded d24f254
Merge branch 'develop2' into feature/language
memsharded 28e309e
Update conan/tools/build/cstd.py
memsharded fe8318d
Update conan/tools/build/cstd.py
memsharded 6c3a5b9
Update conan/tools/build/cstd.py
memsharded 642843a
conflicts solved
memsharded File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,165 @@ | ||
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): | ||
# TODO: Per-version support | ||
return ["99", "gnu99", "11", "gnu11", "17", "gnu17", "23", "gnu23"] | ||
|
||
|
||
def _msvc_supported_cstd(version): | ||
# TODO: Per-version support | ||
return ["11", "17"] | ||
memsharded marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def _clang_supported_cstd(version): | ||
# TODO: Per-version support | ||
return ["99", "gnu99", "11", "gnu11", "17", "gnu17", "23", "gnu23"] | ||
memsharded marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.