aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown/howtox.md
diff options
context:
space:
mode:
authorLuke Drummond <ldrumm@rtps.co>2020-11-03 20:28:04 +0000
committerJussi Pakkanen <jpakkane@gmail.com>2021-02-04 17:34:11 +0000
commit46e3480f7c675b140ca4496c658069696daa176d (patch)
tree7968ab2078864ecf71212cf291abb462d081596f /docs/markdown/howtox.md
parent95c079071118abc9078b0931ee86f51b1b4f8e05 (diff)
downloadmeson-46e3480f7c675b140ca4496c658069696daa176d.zip
meson-46e3480f7c675b140ca4496c658069696daa176d.tar.gz
meson-46e3480f7c675b140ca4496c658069696daa176d.tar.bz2
Introduce `fs.read` to read a file as a string
Following #7890, this patch introduces the ability to read the contents of a file to the fs module. This patch introduces the ability to read files at configure time, but has some restrictions: - binary files are not supported (I don't think this will prove a problem, and if people are wanting to do something with binary files, they should probably be shelling out to their own script). - Only files outside the build directory allowed. This limitation should prevent build loops. Given that reading an arbitrary file at configure time can affect the configuration in almost arbitrary ways, meson should force a reconfigure when the given file changes. This is non-configurable, but this can easily be changed with a future keyword argument.
Diffstat (limited to 'docs/markdown/howtox.md')
-rw-r--r--docs/markdown/howtox.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/markdown/howtox.md b/docs/markdown/howtox.md
index f05f3e8..8c8c0c0 100644
--- a/docs/markdown/howtox.md
+++ b/docs/markdown/howtox.md
@@ -139,6 +139,23 @@ cdata.set('SOMETHING', txt)
configure_file(...)
```
+## Generate configuration data from files
+
+`The [fs module](#Fs-modules) offers the `read` function` which enables adding
+the contents of arbitrary files to configuration data (among other uses):
+
+```meson
+fs = import('fs')
+cdata = configuration_data()
+copyright = fs.read('LICENSE')
+cdata.set('COPYRIGHT', copyright)
+if build_machine.system() == 'linux'
+ os_release = fs.read('/etc/os-release')
+ cdata.set('LINUX_BUILDER', os_release)
+endif
+configure_file(...)
+```
+
## Generate a runnable script with `configure_file`
`configure_file` preserves metadata so if your template file has