aboutsummaryrefslogtreecommitdiff
path: root/test cases/common
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 /test cases/common
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 'test cases/common')
-rw-r--r--test cases/common/241 get_file_contents/.gitattributes1
-rw-r--r--test cases/common/241 get_file_contents/VERSION1
-rw-r--r--test cases/common/241 get_file_contents/meson.build21
-rw-r--r--test cases/common/241 get_file_contents/other/meson.build3
-rw-r--r--test cases/common/241 get_file_contents/utf-16-textbin0 -> 150 bytes
5 files changed, 26 insertions, 0 deletions
diff --git a/test cases/common/241 get_file_contents/.gitattributes b/test cases/common/241 get_file_contents/.gitattributes
new file mode 100644
index 0000000..abec47d
--- /dev/null
+++ b/test cases/common/241 get_file_contents/.gitattributes
@@ -0,0 +1 @@
+utf-16-text binary
diff --git a/test cases/common/241 get_file_contents/VERSION b/test cases/common/241 get_file_contents/VERSION
new file mode 100644
index 0000000..26aaba0
--- /dev/null
+++ b/test cases/common/241 get_file_contents/VERSION
@@ -0,0 +1 @@
+1.2.0
diff --git a/test cases/common/241 get_file_contents/meson.build b/test cases/common/241 get_file_contents/meson.build
new file mode 100644
index 0000000..a8c68d6
--- /dev/null
+++ b/test cases/common/241 get_file_contents/meson.build
@@ -0,0 +1,21 @@
+project(
+ 'meson-fs-read-file',
+ [],
+ version: files('VERSION')
+)
+fs = import('fs')
+
+assert(fs.read('VERSION').strip() == meson.project_version(), 'file misread')
+
+expected = (
+ '∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i), ∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β)'
+)
+assert(
+ fs.read('utf-16-text', encoding: 'utf-16').strip() == expected,
+ 'file was not decoded correctly'
+)
+
+# Make sure we handle `files()` objects properly, too
+version_file = files('VERSION')
+
+subdir('other')
diff --git a/test cases/common/241 get_file_contents/other/meson.build b/test cases/common/241 get_file_contents/other/meson.build
new file mode 100644
index 0000000..9a7e4be
--- /dev/null
+++ b/test cases/common/241 get_file_contents/other/meson.build
@@ -0,0 +1,3 @@
+fs = import('fs')
+assert(fs.read(version_file).strip() == '1.2.0')
+assert(fs.read('../VERSION').strip() == '1.2.0')
diff --git a/test cases/common/241 get_file_contents/utf-16-text b/test cases/common/241 get_file_contents/utf-16-text
new file mode 100644
index 0000000..ed1fefe
--- /dev/null
+++ b/test cases/common/241 get_file_contents/utf-16-text
Binary files differ