Skip to content

Commit

Permalink
backport patch for stdlib fix
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Feb 28, 2024
1 parent c780ba8 commit 0d3515b
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 7 deletions.
7 changes: 5 additions & 2 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ source:
url: https://github.com/conda/{{ name }}/archive/refs/tags/{{ version }}.tar.gz
sha256: c534d2cccfba8d8bab85ae54cd02ffc1c02037dbbea394dda3b55b668ab35f1f
patches:
- patches/gh4867.patch
# backport https://github.com/conda/conda-build/pull/4867
- patches/0001-add-warning-and-return-empty-string.patch
# backport https://github.com/conda/conda-build/pull/5195
- patches/0002-Fix-stdlib-being-recognized-in-variant-hash-inputs-5.patch

build:
number: 0
number: 1
script: {{ PYTHON }} -m pip install . --no-deps --no-build-isolation -vv
entry_points:
- conda-build = conda_build.cli.main_build:execute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
From 74c48facd64e9c682e9387b186ef0b08a9b52548 Mon Sep 17 00:00:00 2001
From 8be2f4af1a0df2505df81319ce151953b622e952 Mon Sep 17 00:00:00 2001
From: Finn Womack <[email protected]>
Date: Thu, 20 Apr 2023 13:58:00 -0700
Subject: [PATCH 1/8] add warning and return empty string
Subject: [PATCH 1/2] add warning and return empty string

---
conda_build/windows.py | 5 +++++
1 file changed, 5 insertions(+)
conda_build/windows.py | 3 +++
news/4867-arm64-msvc-env-cmd-no-op | 19 +++++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 news/4867-arm64-msvc-env-cmd-no-op

diff --git a/conda_build/windows.py b/conda_build/windows.py
index 84da4a0f..1639c554 100644
index ba53abf8..e3828d1e 100644
--- a/conda_build/windows.py
+++ b/conda_build/windows.py
@@ -110,6 +110,9 @@ def msvc_env_cmd(bits, config, override=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
From f3ff2a6ef575363e919d3249b8b3e9e8429186ee Mon Sep 17 00:00:00 2001
From: Marcel Bargull <[email protected]>
Date: Wed, 28 Feb 2024 17:06:00 +0100
Subject: [PATCH 2/2] Fix stdlib being recognized in variant hash inputs
(#5195)

* 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>
---
conda_build/variants.py | 18 ++++++++++--------
news/5195-fix-stdlib-variant | 19 +++++++++++++++++++
tests/test_metadata.py | 19 ++++++++++++-------
3 files changed, 41 insertions(+), 15 deletions(-)
create mode 100644 news/5195-fix-stdlib-variant

diff --git a/conda_build/variants.py b/conda_build/variants.py
index d798a6e7..2ece5f4b 100644
--- a/conda_build/variants.py
+++ b/conda_build/variants.py
@@ -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 = [
@@ -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
diff --git a/news/5195-fix-stdlib-variant b/news/5195-fix-stdlib-variant
new file mode 100644
index 00000000..526692f2
--- /dev/null
+++ b/news/5195-fix-stdlib-variant
@@ -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>
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
index 05e67b54..e89cb5fe 100644
--- a/tests/test_metadata.py
+++ b/tests/test_metadata.py
@@ -230,16 +230,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(
@@ -253,7 +253,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):

0 comments on commit 0d3515b

Please sign in to comment.