aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown/snippets
diff options
context:
space:
mode:
authorTristan Partin <tristan@partin.io>2023-08-07 12:30:15 -0500
committerXavier Claessens <xclaesse@gmail.com>2023-08-17 17:05:49 -0400
commitf52bcaa27fc125ab9ae583af466ba99c164169f3 (patch)
tree34ecddd4e69581075035f405ff1fddcada6f252f /docs/markdown/snippets
parentcbf8e67f19e384e5f8eb7f65d3020551769de545 (diff)
downloadmeson-f52bcaa27fc125ab9ae583af466ba99c164169f3.zip
meson-f52bcaa27fc125ab9ae583af466ba99c164169f3.tar.gz
meson-f52bcaa27fc125ab9ae583af466ba99c164169f3.tar.bz2
Add fs.relative_to()
Returns a relative path from arg 2 to arg 1 similar to os.path.relpath().
Diffstat (limited to 'docs/markdown/snippets')
-rw-r--r--docs/markdown/snippets/fs_relative_to.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/markdown/snippets/fs_relative_to.md b/docs/markdown/snippets/fs_relative_to.md
new file mode 100644
index 0000000..82e6a42
--- /dev/null
+++ b/docs/markdown/snippets/fs_relative_to.md
@@ -0,0 +1,17 @@
+## `fs.relative_to()`
+
+The `fs` module now has a `relative_to` method. The method will return the
+relative path from argument one to argument two, if one exists. Otherwise, the
+absolute path to argument one is returned.
+
+```meson
+assert(fs.relative_to('c:\\prefix\\lib', 'c:\\prefix\\bin') == '..\\lib')
+assert(fs.relative_to('c:\\proj1\\foo', 'd:\\proj1\\bar') == 'c:\\proj1\\foo')
+assert(fs.relative_to('prefix\\lib\\foo', 'prefix') == 'lib\\foo')
+
+assert(fs.relative_to('/prefix/lib', '/prefix/bin') == '../lib')
+assert(fs.relative_to('prefix/lib/foo', 'prefix') == 'lib/foo')
+```
+
+In addition to strings, it can handle files, custom targets, custom target
+indices, and build targets.