Skip to content

Commit

Permalink
Fix stdlib being recognized in variant hash inputs (#5195)
Browse files Browse the repository at this point in the history
* Test stdlib is recognized in variant hash inputs
* Fix stdlib being recognized in variant hash inputs
* Test c_stdlib* inclusion in Metadata.get_used_vars

This function is used downstream in conda-forge's conda-smithy, so let's
test against this explicitly, too.

---------

Signed-off-by: Marcel Bargull <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
mbargull and pre-commit-ci[bot] authored Feb 28, 2024
1 parent 9b04330 commit 38fdc15
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
18 changes: 10 additions & 8 deletions conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,15 +727,17 @@ def find_used_variables_in_text(variant, recipe_text, selectors_only=False):
recipe_lines = recipe_text.splitlines()
for v in variant:
all_res = []
compiler_match = re.match(r"(.*?)_compiler(_version)?$", v)
if compiler_match and not selectors_only:
compiler_lang = compiler_match.group(1)
compiler_regex = r"\{\s*compiler\([\'\"]%s[\"\'][^\{]*?\}" % re.escape(
compiler_lang
target_match = re.match(r"(.*?)_(compiler|stdlib)(_version)?$", v)
if target_match and not selectors_only:
target_lang = target_match.group(1)
target_kind = target_match.group(2)
target_lang_regex = re.escape(target_lang)
target_regex = (
rf"\{{\s*{target_kind}\([\'\"]{target_lang_regex}[\"\'][^\{{]*?\}}"
)
all_res.append(compiler_regex)
all_res.append(target_regex)
variant_lines = [
line for line in recipe_lines if v in line or compiler_lang in line
line for line in recipe_lines if v in line or target_lang in line
]
else:
variant_lines = [
Expand All @@ -760,7 +762,7 @@ def find_used_variables_in_text(variant, recipe_text, selectors_only=False):
all_res = r"|".join(all_res)
if any(re.search(all_res, line) for line in variant_lines):
used_variables.add(v)
if v in ("c_compiler", "cxx_compiler"):
if v in ("c_stdlib", "c_compiler", "cxx_compiler"):
if "CONDA_BUILD_SYSROOT" in variant:
used_variables.add("CONDA_BUILD_SYSROOT")
return used_variables
Expand Down
19 changes: 19 additions & 0 deletions news/5195-fix-stdlib-variant
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fix stdlib being recognized in variant hash inputs. (#5190 via #5195)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
19 changes: 12 additions & 7 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,16 @@ def test_compiler_metadata_cross_compiler():


@pytest.mark.parametrize(
"platform,arch,stdlibs",
"platform,arch,stdlib,stdlib_version",
[
("linux", "64", {"sysroot_linux-64 2.12.*"}),
("linux", "aarch64", {"sysroot_linux-aarch64 2.17.*"}),
("osx", "64", {"macosx_deployment_target_osx-64 10.13.*"}),
("osx", "arm64", {"macosx_deployment_target_osx-arm64 11.0.*"}),
("linux", "64", "sysroot", "2.12"),
("linux", "aarch64", "sysroot", "2.17"),
("osx", "64", "macosx_deployment_target", "10.13"),
("osx", "arm64", "macosx_deployment_target", "11.0"),
],
)
def test_native_stdlib_metadata(
platform: str, arch: str, stdlibs: set[str], testing_config
platform: str, arch: str, stdlib: str, stdlib_version: str, testing_config
):
testing_config.platform = platform
metadata = api.render(
Expand All @@ -256,7 +256,12 @@ def test_native_stdlib_metadata(
bypass_env_check=True,
python="3.11", # irrelevant
)[0][0]
assert stdlibs <= set(metadata.meta["requirements"]["host"])
stdlib_req = f"{stdlib}_{platform}-{arch} {stdlib_version}.*"
assert stdlib_req in metadata.meta["requirements"]["host"]
assert {"c_stdlib", "c_stdlib_version"} <= metadata.get_used_vars()
hash_contents = metadata.get_hash_contents()
assert stdlib == hash_contents["c_stdlib"]
assert stdlib_version == hash_contents["c_stdlib_version"]


def test_hash_build_id(testing_metadata):
Expand Down

0 comments on commit 38fdc15

Please sign in to comment.