From 673f15e1723d172e502cbfdea2b69699802ec914 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Wed, 17 May 2023 10:54:53 -0500
Subject: [PATCH v2 17/17] Remove Meson program options for specifying paths

Meson has a built-in way to override paths without polluting project
build options called machine files.

https://mesonbuild.com/Machine-files.html

To summarize, a replacement for these options would look something like
the following:

[binaries]
bison = 'path/to/bison'
flex = 'path/to/flex'

This tells Meson to use the pre-defined paths for the defined binaries.
This process is very similar for how cross builds are done in Meson too.

To use the native.ini file, all someone compiling Postgres has to do is
pass `--native-file native.ini` to `meson setup`.
---
 meson.build               | 30 +++++++++++-----------
 meson_options.txt         | 54 ---------------------------------------
 src/makefiles/meson.build |  2 +-
 src/timezone/meson.build  |  2 +-
 4 files changed, 17 insertions(+), 71 deletions(-)

diff --git a/meson.build b/meson.build
index dd559fa587..a9639007d8 100644
--- a/meson.build
+++ b/meson.build
@@ -327,22 +327,22 @@ endif
 ###############################################################
 
 # External programs
-perl = find_program(get_option('PERL'), required: true, native: true)
-python = find_program(get_option('PYTHON'), required: true, native: true)
-flex = find_program(get_option('FLEX'), native: true, version: '>= 2.5.35')
-bison = find_program(get_option('BISON'), native: true, version: '>= 2.3')
-sed = find_program(get_option('SED'), 'sed', native: true)
-prove = find_program(get_option('PROVE'), native: true, required: false)
-tar = find_program(get_option('TAR'), native: true)
-gzip = find_program(get_option('GZIP'), native: true)
-program_lz4 = find_program(get_option('LZ4'), native: true, required: false)
-openssl = find_program(get_option('OPENSSL'), native: true, required: false)
-program_zstd = find_program(get_option('ZSTD'), native: true, required: false)
-dtrace = find_program(get_option('DTRACE'), native: true, required: get_option('dtrace'))
+perl = find_program('perl', required: true, native: true)
+python = find_program('python3', 'python', required: true, native: true)
+flex = find_program('flex', 'win_flex', native: true, version: '>= 2.5.35')
+bison = find_program('bison', 'win_bison', native: true, version: '>= 2.3')
+sed = find_program('sed', native: true)
+prove = find_program('prove', native: true, required: false)
+tar = find_program('tar', native: true)
+gzip = find_program('gzip', native: true)
+program_lz4 = find_program('lz4', native: true, required: false)
+openssl = find_program('openssl', native: true, required: false)
+program_zstd = find_program('zstd', native: true, required: false)
+dtrace = find_program('dtrace', native: true, required: get_option('dtrace'))
 missing = find_program('config/missing', native: true)
 cp = find_program('cp', required: false, native: true)
-xmllint_bin = find_program(get_option('XMLLINT'), native: true, required: false)
-xsltproc_bin = find_program(get_option('XSLTPROC'), native: true, required: false)
+xmllint_bin = find_program('xmllint', native: true, required: false)
+xsltproc_bin = find_program('xlstproc', native: true, required: false)
 
 bison_flags = []
 if bison.found()
@@ -592,7 +592,7 @@ endif
 docs_pdf_opt = get_option('docs_pdf')
 docs_pdf_dep = not_found_dep
 if not docs_pdf_opt.disabled()
-  fop = find_program(get_option('FOP'), native: true, required: docs_pdf_opt)
+  fop = find_program('fop', native: true, required: docs_pdf_opt)
   if xmllint_bin.found() and xsltproc_bin.found() and fop.found()
     docs_pdf_dep = declare_dependency()
   elif docs_pdf_opt.enabled()
diff --git a/meson_options.txt b/meson_options.txt
index e9ac70766a..1760cf05f9 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -155,57 +155,3 @@ option('zlib', type: 'feature', value: 'auto',
 
 option('zstd', type: 'feature', value: 'auto',
   description: 'Enable zstd')
-
-
-# Programs
-
-option('BISON', type: 'array', value: ['bison', 'win_bison'],
-  description: 'Path to bison binary')
-
-option('DTRACE', type: 'string', value: 'dtrace',
-  description: 'Path to dtrace binary')
-
-option('FLEX', type: 'array', value: ['flex', 'win_flex'],
-  description: 'Path to flex binary')
-
-option('FOP', type: 'string', value: 'fop',
-  description: 'Path to fop binary')
-
-option('GZIP', type: 'string', value: 'gzip',
-  description: 'Path to gzip binary')
-
-option('LZ4', type: 'string', value: 'lz4',
-  description: 'Path to lz4 binary')
-
-option('OPENSSL', type: 'string', value: 'openssl',
-  description: 'Path to openssl binary')
-
-option('PERL', type: 'string', value: 'perl',
-  description: 'Path to perl binary')
-
-option('PROVE', type: 'string', value: 'prove',
-  description: 'Path to prove binary')
-
-option('PYTHON', type: 'array', value: ['python3', 'python'],
-  description: 'Path to python binary')
-
-option('SED', type: 'string', value: 'gsed',
-  description: 'Path to sed binary')
-
-option('STRIP', type: 'string', value: 'strip',
-  description: 'Path to strip binary, used for PGXS emulation')
-
-option('TAR', type: 'string', value: 'tar',
-  description: 'Path to tar binary')
-
-option('XMLLINT', type: 'string', value: 'xmllint',
-  description: 'Path to xmllint binary')
-
-option('XSLTPROC', type: 'string', value: 'xsltproc',
-  description: 'Path to xsltproc binary')
-
-option('ZSTD', type: 'string', value: 'zstd',
-  description: 'Path to zstd binary')
-
-option('ZIC', type: 'string', value: 'zic',
-  description: 'Path to zic binary, when cross-compiling')
diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build
index 13045cbd6e..b8ec848d74 100644
--- a/src/makefiles/meson.build
+++ b/src/makefiles/meson.build
@@ -5,7 +5,7 @@
 
 
 # Emulation of PGAC_CHECK_STRIP
-strip_bin = find_program(get_option('STRIP'), required: false, native: true)
+strip_bin = find_program('strip', required: false, native: true)
 strip_cmd = strip_bin.found() ? [strip_bin.path()] : [':']
 
 working_strip = false
diff --git a/src/timezone/meson.build b/src/timezone/meson.build
index 7b85a01c6b..8f6edb5110 100644
--- a/src/timezone/meson.build
+++ b/src/timezone/meson.build
@@ -28,7 +28,7 @@ if get_option('system_tzdata') == ''
   # build our zic. But for that we'd need to run a good chunk of the configure
   # tests both natively and cross. Unclear if it's worth it.
   if meson.is_cross_build()
-    zic = find_program(get_option('ZIC'), native: true, required: true)
+    zic = find_program('zic', native: true, required: true)
   else
     if host_system == 'windows'
       zic_sources += rc_bin_gen.process(win32ver_rc, extra_args: [
-- 
Tristan Partin
Neon (https://neon.tech)

