From 0e3e128ffc4380672a5da6ea775de8a8c491692b Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Tue, 20 Feb 2024 16:20:20 +0100 Subject: [PATCH 1/4] Test stdlib is recognized in variant hash inputs Signed-off-by: Marcel Bargull --- tests/test_metadata.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 496af2d67b..be123cc183 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -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( @@ -256,7 +256,11 @@ 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"] + 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): From 6aabeeca9dbde5d9b20c7f3f7c31cd06b9969d22 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Tue, 20 Feb 2024 16:33:31 +0100 Subject: [PATCH 2/4] Fix stdlib being recognized in variant hash inputs Signed-off-by: Marcel Bargull --- conda_build/variants.py | 18 +++++++++--------- news/5195-fix-stdlib-variant | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 news/5195-fix-stdlib-variant diff --git a/conda_build/variants.py b/conda_build/variants.py index d798a6e79a..d3d8f2b6f6 100644 --- a/conda_build/variants.py +++ b/conda_build/variants.py @@ -727,15 +727,15 @@ 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 - ) - all_res.append(compiler_regex) + 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(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 = [ @@ -760,7 +760,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 diff --git a/news/5195-fix-stdlib-variant b/news/5195-fix-stdlib-variant new file mode 100644 index 0000000000..526692f286 --- /dev/null +++ b/news/5195-fix-stdlib-variant @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* Fix stdlib being recognized in variant hash inputs. (#5190 via #5195) + +### Deprecations + +* + +### Docs + +* + +### Other + +* From 0b1c990a9345fa1b2753e52e98c89b8592ab44fb Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Tue, 20 Feb 2024 16:40:56 +0100 Subject: [PATCH 3/4] 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 --- tests/test_metadata.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index be123cc183..b176d4103d 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -258,6 +258,7 @@ def test_native_stdlib_metadata( )[0][0] 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"] From d46b7f2d0fc3767552e45567a6a1d0b1f3e6f8f8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:43:27 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conda_build/variants.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conda_build/variants.py b/conda_build/variants.py index d3d8f2b6f6..2ece5f4bd6 100644 --- a/conda_build/variants.py +++ b/conda_build/variants.py @@ -732,7 +732,9 @@ def find_used_variables_in_text(variant, recipe_text, selectors_only=False): 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}[\"\'][^\{{]*?\}}" + target_regex = ( + rf"\{{\s*{target_kind}\([\'\"]{target_lang_regex}[\"\'][^\{{]*?\}}" + ) all_res.append(target_regex) variant_lines = [ line for line in recipe_lines if v in line or target_lang in line