diff --git a/conda_smithy/linter/lints.py b/conda_smithy/linter/lints.py index a338b87fe..531b77997 100644 --- a/conda_smithy/linter/lints.py +++ b/conda_smithy/linter/lints.py @@ -796,8 +796,15 @@ def flatten_reqs(reqs): # this check needs to be done per output --> use separate (unflattened) requirements for build_reqs in all_build_reqs: has_compiler = any(pat_compiler_stub.match(rq) for rq in build_reqs) - stdlib_stub = "c_stdlib_stub" if recipe_version == 0 else "${{ stdlib" - if has_compiler and stdlib_stub not in build_reqs: + stdlib_regex = ( + # we need the C stdlib, not just any invocation of the stdlib jinja + "^(m2w64_)?c_stdlib_stub$" + if recipe_version == 0 + else r"\$\{\{ stdlib\(['\"](m2w64_)?c['\"]\)" + ) + if has_compiler and not any( + re.search(stdlib_regex, x) for x in build_reqs + ): if stdlib_lint not in lints: lints.append(stdlib_lint) diff --git a/news/2041-stdlib_corner_case.rst b/news/2041-stdlib_corner_case.rst new file mode 100644 index 000000000..c9eabdb78 --- /dev/null +++ b/news/2041-stdlib_corner_case.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed a corner-case in stdlib-linting (#2042) + +**Security:** + +* diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index d2515db1c..4759b1ccf 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -74,6 +74,27 @@ def test_stdlib_lint(comp_lang): assert any(lint.startswith(expected_message) for lint in lints) +def test_m2w64_stdlib_legal(): + # allow recipes that _only_ depend on {{ stdlib("m2w64_c") }} + avoid_message = "stdlib" + + with tmp_directory() as recipe_dir: + with open(os.path.join(recipe_dir, "meta.yaml"), "w") as fh: + fh.write( + """ + package: + name: foo + requirements: + build: + - {{ stdlib("m2w64_c") }} + - {{ compiler("m2w64_c") }} + """ + ) + + lints, _ = linter.main(recipe_dir, return_hints=True) + assert not any(avoid_message in lint for lint in lints) + + @pytest.mark.parametrize( "comp_lang", ["c", "cxx", "fortran", "rust", "m2w64_c", "m2w64_cxx", "m2w64_fortran"],