From 46e3480f7c675b140ca4496c658069696daa176d Mon Sep 17 00:00:00 2001 From: Luke Drummond Date: Tue, 3 Nov 2020 20:28:04 +0000 Subject: 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. --- docs/markdown/howtox.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'docs/markdown/howtox.md') 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 -- cgit v1.1