aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Partin <tristan@neon.tech>2023-06-05 09:30:37 -0500
committerXavier Claessens <xclaesse@gmail.com>2023-06-06 10:07:36 -0400
commit58aa301accc2dc1f107c2e77b8187de94fb1bd0c (patch)
treef8a846a7388cad6aed20b7ce2cffc78b23dbe612
parente20717ed8f9f746a233e2bd2b3018997a3f73799 (diff)
downloadmeson-58aa301accc2dc1f107c2e77b8187de94fb1bd0c.zip
meson-58aa301accc2dc1f107c2e77b8187de94fb1bd0c.tar.gz
meson-58aa301accc2dc1f107c2e77b8187de94fb1bd0c.tar.bz2
Override find_program('meson')
This override transparently upgrades anyone using it to this better functionality. Fixes #8511
-rw-r--r--docs/markdown/snippets/override-find-program-meson.md38
-rw-r--r--docs/yaml/functions/find_program.yaml3
-rw-r--r--mesonbuild/interpreter/interpreter.py4
3 files changed, 45 insertions, 0 deletions
diff --git a/docs/markdown/snippets/override-find-program-meson.md b/docs/markdown/snippets/override-find-program-meson.md
new file mode 100644
index 0000000..5d281cd
--- /dev/null
+++ b/docs/markdown/snippets/override-find-program-meson.md
@@ -0,0 +1,38 @@
+## New override of `find_program('meson')`
+
+In some cases, it has been useful for build scripts to access the Meson command
+used to invoke the build script. This has led to various ad-hoc solutions that
+can be very brittle and project-specific.
+
+```meson
+meson_prog = find_program('meson')
+```
+
+This call will supply the build script with an external program pointing at the
+invoked Meson.
+
+Because Meson also uses `find_program` for program lookups internally, this
+override will also be handled in cases similar to the following:
+
+```meson
+custom_target(
+ # ...
+ command: [
+ 'meson',
+ ],
+ # ...
+)
+
+run_command(
+ 'meson',
+ # ...
+)
+
+run_target(
+ 'tgt',
+ command: [
+ 'meson',
+ # ...
+ ]
+)
+```
diff --git a/docs/yaml/functions/find_program.yaml b/docs/yaml/functions/find_program.yaml
index c0c13d2..537bbc5 100644
--- a/docs/yaml/functions/find_program.yaml
+++ b/docs/yaml/functions/find_program.yaml
@@ -42,6 +42,9 @@ description: |
setcap = find_program(['setcap', '/usr/sbin/setcap', '/sbin/setcap'], required : false)
```
+ *Since 1.2.0* `find_program('meson')` is automatically overridden to the Meson
+ command used to execute the build script.
+
The returned [[@external_program]] object also has documented methods.
posargs:
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 9ca7742..81a88e5 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -1665,6 +1665,10 @@ class Interpreter(InterpreterBase, HoldableObject):
if progobj:
return progobj
+ if args[0] == 'meson':
+ # Override find_program('meson') to return what we were invoked with
+ return ExternalProgram('meson', self.environment.get_build_command(), silent=True)
+
fallback = None
wrap_mode = self.coredata.get_option(OptionKey('wrap_mode'))
if wrap_mode != WrapMode.nofallback and self.environment.wrap_resolver: