From 3792eea42e4dcef39b5c8d99f63deb8091ef9c46 Mon Sep 17 00:00:00 2001
From: Christoph Berg <myon@debian.org>
Date: Wed, 19 Mar 2025 15:45:00 +0100
Subject: [PATCH] pg_virtualenv: Use PG18's extension_control_path to find
 extensions in temporary build paths instead of our custom extension_destdir
 patch.

---
 debian/changelog |  7 +++++++
 pg_virtualenv    | 20 ++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 9401318e..6e85a2ca 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+postgresql-common (276) UNRELEASED; urgency=medium
+
+  * pg_virtualenv: Use PG18's extension_control_path to find extensions in
+    temporary build paths instead of our custom extension_destdir patch.
+
+ -- Christoph Berg <myon@debian.org>  Wed, 19 Mar 2025 15:43:16 +0100
+
 postgresql-common (275) unstable; urgency=medium
 
   [ Christoph Berg ]
diff --git a/pg_virtualenv b/pg_virtualenv
index f4cfe038..537bc289 100755
--- a/pg_virtualenv
+++ b/pg_virtualenv
@@ -189,12 +189,20 @@ fi
 for v in $PG_VERSIONS; do
     # create temporary cluster
     if [ "${PACKAGE:-}" ]; then
-        if ! grep -q 'extension_destdir' /usr/share/postgresql/$v/postgresql.conf.sample; then
-            echo "$0: This PostgreSQL $v installation does not support 'extension_destdir', skipping this version"
-            [ "$PG_VERSIONS" = "$v" ] && exit 0 # only one version requested
-            continue
-        fi
-        PKGARGS="--pgoption extension_destdir=$PWD/debian/$PACKAGE --pgoption dynamic_library_path=$PWD/debian/$PACKAGE/usr/lib/postgresql/$v/lib:/usr/lib/postgresql/$v/lib"
+        case $v in
+            18|19|[2-7]*) # find extension using extension_control_path
+                PKGARGS="--pgoption extension_control_path=$PWD/debian/$PACKAGE/usr/share/postgresql/$v/extension:\$system --pgoption dynamic_library_path=$PWD/debian/$PACKAGE/usr/lib/postgresql/$v/lib:/usr/lib/postgresql/$v/lib"
+                ;;
+            *) # older versions have a Debian-specific patch
+                if grep -q 'extension_destdir' /usr/share/postgresql/$v/postgresql.conf.sample; then
+                    PKGARGS="--pgoption extension_destdir=$PWD/debian/$PACKAGE --pgoption dynamic_library_path=$PWD/debian/$PACKAGE/usr/lib/postgresql/$v/lib:/usr/lib/postgresql/$v/lib"
+                else
+                    echo "$0: This PostgreSQL $v installation does not support 'extension_destdir', skipping this version"
+                    [ "$PG_VERSIONS" = "$v" ] && exit 0 # only one version requested
+                    continue
+                fi
+                ;;
+        esac
     fi
     # we chdir to / so programs don't throw "could not change directory to ..."
     (
-- 
GitLab