Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 04 Aug 2026 12:17:38 +0000
From:      Olivier Cochard <olivier@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: bdc565d085e3 - main - devel/coccinelle: Fix python scripting
Message-ID:  <6a71d862.21fd0.6545ceb8@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by olivier:

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 +++++++++++++++++++++-
 .../files/patch-bundles_pyml_pyml-current_py.ml    | 16 +++++++++++++
 devel/coccinelle/files/regress-python.c            |  1 +
 devel/coccinelle/files/regress-python.cocci        | 10 ++++++++
 4 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/devel/coccinelle/Makefile b/devel/coccinelle/Makefile
index 2fd3e5ae53e1..48d286d9895e 100644
--- a/devel/coccinelle/Makefile
+++ b/devel/coccinelle/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	coccinelle
 DISTVERSION=	1.3.1
+PORTREVISION=	1
 CATEGORIES=	devel
 MASTER_SITES=	https://coccinelle.gitlabpages.inria.fr/website/distrib/
 DISTFILES=	${DISTNAME}${EXTRACT_SUFX}
@@ -22,11 +23,36 @@ USES=		autoreconf gmake ocaml:build,camlp4 perl5 pkgconfig:build python shebangf
 USE_PERL5=	build
 SHEBANG_FILES=	tools/pycocci scripts/cpptests.sh
 GNU_CONFIGURE=	yes
-CONFIGURE_ENV=	PYTHON="${PYTHON_CMD}" PYVER="${PYTHON_VER}"
+# --with-python bakes the interpreter path into cocciconfig.ml so spatch can
+# derive the Python version and load libpython; configure ignores env PYTHON,
+# and its "python" default does not exist on FreeBSD.
+CONFIGURE_ARGS=	--with-python=${PYTHON_CMD}
+CONFIGURE_ENV=	PYVER="${PYTHON_VER}"
 MAKE_ARGS=	PYTHON_VERSION="${PYTHON_VER}"
 BINARY_ALIAS=	make=${GMAKE}
 TEST_TARGET=	check check-cpp
 
+# Run the upstream suite, then exercise @script:python@ scripting: the
+# upstream suite doesn't, and it regressed silently when the embedded
+# interpreter failed to load libpython.  The optimized build only produces
+# spatch.opt, but check-cpp's cpptests.sh and the smoke test both invoke a
+# plain ./spatch, so alias it first.
+do-test:
+	@${LN} -sf spatch.opt ${TEST_WRKSRC}/spatch
+	@cd ${TEST_WRKSRC} && ${SETENVI} ${WRK_ENV} ${TEST_ENV} \
+		${MAKE_CMD} ${MAKE_FLAGS} ${MAKEFILE} \
+		${TEST_ARGS:N${DESTDIRNAME}=*} ${TEST_TARGET}
+	@cd ${WRKSRC} && \
+		out=$$(${SETENVI} ${WRK_ENV} ${TEST_ENV} ./spatch --very-quiet \
+			--sp-file ${FILESDIR}/regress-python.cocci \
+			${FILESDIR}/regress-python.c) && \
+		case "$$out" in \
+		*"hit: ${FILESDIR}/regress-python.c:1"*) \
+			${ECHO_MSG} "===>  @script:python@ smoke test PASSED" ;; \
+		*) ${ECHO_MSG} "===>  @script:python@ smoke test FAILED: $$out"; \
+			exit 1 ;; \
+		esac
+
 OPTIONS_DEFINE=		EMACS VIM
 OPTIONS_DEFAULT=	EMACS VIM
 OPTIONS_SUB=	yes
diff --git a/devel/coccinelle/files/patch-bundles_pyml_pyml-current_py.ml b/devel/coccinelle/files/patch-bundles_pyml_pyml-current_py.ml
new file mode 100644
index 000000000000..512bc9968c6a
--- /dev/null
+++ b/devel/coccinelle/files/patch-bundles_pyml_pyml-current_py.ml
@@ -0,0 +1,16 @@
+Query the python-M.N-embed pkg-config module for libpython. The bare
+python-M.N module ships an empty Libs: on FreeBSD (extension-building
+metadata), so it lacks the -lpython needed to embed the interpreter and
+find_library_path aborts with "unable to parse the output of pkg-config".
+
+--- bundles/pyml/pyml-current/py.ml.orig
++++ bundles/pyml/pyml-current/py.ml
+@@ -376,7 +376,7 @@
+
+ let libpython_from_pkg_config version_major version_minor =
+   let command =
+-    Printf.sprintf "pkg-config --libs python-%d.%d" version_major
++    Printf.sprintf "pkg-config --libs python-%d.%d-embed" version_major
+       version_minor in
+   match run_command_opt command false with
+     Some (words :: _) ->
diff --git a/devel/coccinelle/files/regress-python.c b/devel/coccinelle/files/regress-python.c
new file mode 100644
index 000000000000..261e6289e0e8
--- /dev/null
+++ b/devel/coccinelle/files/regress-python.c
@@ -0,0 +1 @@
+void foo(void) { bar(1); }
diff --git a/devel/coccinelle/files/regress-python.cocci b/devel/coccinelle/files/regress-python.cocci
new file mode 100644
index 000000000000..c83d408803b8
--- /dev/null
+++ b/devel/coccinelle/files/regress-python.cocci
@@ -0,0 +1,10 @@
+@r@
+identifier f;
+position p;
+@@
+f@p(...)
+
+@script:python@
+p << r.p;
+@@
+print("hit: %s:%s" % (p[0].file, p[0].line))


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a71d862.21fd0.6545ceb8>