Bug 297217 - devel/coccinelle: fix wrong pkg-config module for libpython
Summary: devel/coccinelle: fix wrong pkg-config module for libpython
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Olivier Cochard
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-08-01 08:26 UTC by Olivier Cochard
Modified: 2026-08-04 12:19 UTC (History)
1 user (show)

See Also:
freebsd: maintainer-feedback+


Attachments
patch (2.63 KB, patch)
2026-08-01 08:26 UTC, Olivier Cochard
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Cochard freebsd_committer freebsd_triage 2026-08-01 08:26:56 UTC
Created attachment 273377 [details]
patch

spatch from coccinelle 1.3.1 dies on any semantic patch with a @script:python@ rule:

Py.find_library_path: unable to parse the output of pkg-config '-L/usr/local/lib'
exit: 255

Cause: bundled pyml (bundles/pyml/pyml-current/py.ml) probes pkg-config --libs python-3.12 to find libpython.
That module has an empty Libs: (it's for building extensions).
The -lpython lives in the sibling -embed module, same package:

$ pkg-config --libs python-3.12         # -L/usr/local/lib
$ pkg-config --libs python-3.12-embed   # -L/usr/local/lib -lpython3.12

pyml finds no -l, raises, and spatch aborts.


Fix:
query the -embed module. One-line patch, no new dependency (the .pc ships in the same pythonXY package).

Reproduce / verify:

cat > /tmp/mini.cocci <<'EOF'
@r@
identifier f;
position p;
@@
f@p(...)
@script:python@
p << r.p;
@@
print("hit: %s:%s" % (p[0].file, p[0].line))
EOF

printf 'void foo(void) { bar(1); }\n' > /tmp/mini.c
spatch --very-quiet --sp-file /tmp/mini.cocci /tmp/mini.c; echo "exit: $?"

Before the patch:
unable to parse... / exit 255.

After the patch:
hit: /tmp/mini.c:1 / exit 0.
Comment 1 Benjamin Jacobs 2026-08-01 11:38:44 UTC
(In reply to Olivier Cochard from comment #0)

Nice one, thank you!
Feel free to take over maintenance if you wish so.
Comment 2 Benjamin Jacobs 2026-08-01 11:47:22 UTC
BTW, I'm not sure why you woould want to use the post-test target (I'd assume do-test is fine) but either way that works for you is good. The upstream test suite could be hooked up also, while at it.
Comment 3 Benjamin Jacobs 2026-08-01 11:51:12 UTC
Also please use the cannonical ${SETENVI} ${WRK_ENV} ${TEST_ENV} for running the test(s). Thank you.
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-08-04 12:18:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=bdc565d085e3379eb5f5d6b005a2690878c68d6a

commit bdc565d085e3379eb5f5d6b005a2690878c68d6a
Author:     Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-08-04 10:01:40 +0000
Commit:     Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-08-04 12:15:56 +0000

    devel/coccinelle: Fix python scripting

    spatch could not load libpython, so all Python scripting failed silently.

    PR:             297217
    Approved by:    Benjamin Jacobs <freebsd@dev.thsi.be> (maintainer)
    Sponsored by:   Netflix

 devel/coccinelle/Makefile                          | 28 +++++++++++++++++++++-
 .../patch-bundles_pyml_pyml-current_py.ml (new)    | 16 +++++++++++++
 devel/coccinelle/files/regress-python.c (new)      |  1 +
 devel/coccinelle/files/regress-python.cocci (new)  | 10 ++++++++
 4 files changed, 54 insertions(+), 1 deletion(-)
Comment 5 Olivier Cochard freebsd_committer freebsd_triage 2026-08-04 12:19:38 UTC
I don’t think I’m expert enough in coccinelle to take maintainership.