meson: Make detection of python more robust
authorAndres Freund <[email protected]>
Fri, 20 Oct 2023 18:11:36 +0000 (11:11 -0700)
committerAndres Freund <[email protected]>
Fri, 20 Oct 2023 18:11:36 +0000 (11:11 -0700)
Previously we errored out if no python installation could be found (but we did
handle not having enough of python installed to build plpython
against). Presumably nobody hit this so far, as python is likely installed due
to meson requiring python.

Author: Tristan Partin <[email protected]>
Discussion: https://postgr.es/m/CSPIJVUDZFKX.3KHMOAVGF94RV@c3po
Backpatch: 16-, where meson support was added

meson.build

index 9e01066ef147d225c832fbd97f57953a80730c80..84cf893d100057bc905dc57a3334d0175d960dc1 100644 (file)
@@ -1052,15 +1052,17 @@ endif
 ###############################################################
 
 pyopt = get_option('plpython')
+python3_dep = not_found_dep
 if not pyopt.disabled()
   pm = import('python')
   python3_inst = pm.find_installation(required: pyopt)
-  python3_dep = python3_inst.dependency(embed: true, required: pyopt)
-  if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt)
-    python3_dep = not_found_dep
+  if python3_inst.found()
+    python3_dep = python3_inst.dependency(embed: true, required: pyopt)
+    # Remove this check after we depend on Meson >= 1.1.0
+    if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt)
+      python3_dep = not_found_dep
+    endif
   endif
-else
-  python3_dep = not_found_dep
 endif