aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Elliott <luke.b.elliott@gmail.com>2021-01-10 11:57:59 +0000
committerJussi Pakkanen <jpakkane@gmail.com>2021-01-12 17:42:57 +0000
commit9efcdba0d59a95d9c5ddd9c32f7870ac2183c5ea (patch)
treec3b39ce46052047687b729e6f569af2d5f47bc56
parent5ff1a3ab25504563f87ac064ce21826cb0b936aa (diff)
downloadmeson-9efcdba0d59a95d9c5ddd9c32f7870ac2183c5ea.zip
meson-9efcdba0d59a95d9c5ddd9c32f7870ac2183c5ea.tar.gz
meson-9efcdba0d59a95d9c5ddd9c32f7870ac2183c5ea.tar.bz2
Allow '//' as project function id due to git bash path conversion.
See https://stackoverflow.com/questions/54258996/git-bash-string-parameter-with-at-start-is-being-expanded-to-a-file-path
-rw-r--r--docs/markdown/Rewriter.md5
-rw-r--r--docs/markdown/snippets/rewrite_allow_double_slash_project_id.md7
-rw-r--r--mesonbuild/rewriter.py8
-rwxr-xr-xrun_unittests.py4
-rw-r--r--test cases/rewrite/3 kwargs/add.json9
-rw-r--r--test cases/rewrite/3 kwargs/remove.json11
-rw-r--r--test cases/rewrite/3 kwargs/remove_regex.json9
-rw-r--r--test cases/rewrite/3 kwargs/set.json2
8 files changed, 49 insertions, 6 deletions
diff --git a/docs/markdown/Rewriter.md b/docs/markdown/Rewriter.md
index 6414480..20b741f 100644
--- a/docs/markdown/Rewriter.md
+++ b/docs/markdown/Rewriter.md
@@ -97,6 +97,11 @@ Currently, only the following function types are supported:
For more information see the help output of the rewrite kwargs command.
+Note msys bash may expand `/` to a path. Passing `//` will be converted to
+`/` by msys bash but in order to keep usage shell-agnostic, the rewrite command
+also allows `//` as the function ID such that it will work in both msys bash
+and other shells.
+
### Setting the project default options
For setting and deleting default options, use the following command:
diff --git a/docs/markdown/snippets/rewrite_allow_double_slash_project_id.md b/docs/markdown/snippets/rewrite_allow_double_slash_project_id.md
new file mode 100644
index 0000000..9448ce6
--- /dev/null
+++ b/docs/markdown/snippets/rewrite_allow_double_slash_project_id.md
@@ -0,0 +1,7 @@
+## `//` is now allowed as a function id for `meson rewrite`.
+
+msys bash may expand `/` to a path, breaking
+`meson rewrite kwargs set project / ...`. Passing `//` will be converted to
+`/` by msys bash but in order to keep usage shell-agnostic, also allow `//`
+as the id such that `meson rewrite kwargs set project // ...` will work in
+both msys bash and other shells.
diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py
index 6b7a987..9cd9ad0 100644
--- a/mesonbuild/rewriter.py
+++ b/mesonbuild/rewriter.py
@@ -500,8 +500,12 @@ class Rewriter:
node = None
arg_node = None
if cmd['function'] == 'project':
- if cmd['id'] != '/':
- mlog.error('The ID for the function type project must be "/"', *self.on_error())
+ # msys bash may expand '/' to a path. It will mangle '//' to '/'
+ # but in order to keep usage shell-agnostic, also allow `//` as
+ # the function ID such that it will work in both msys bash and
+ # other shells.
+ if {'/', '//'}.isdisjoint({cmd['id']}):
+ mlog.error('The ID for the function type project must be "/" or "//" not "' + cmd['id'] + '"', *self.on_error())
return self.handle_error()
node = self.interpreter.project_node
arg_node = node.args
diff --git a/run_unittests.py b/run_unittests.py
index 21b6608..bf6a7ad 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -7918,7 +7918,7 @@ class RewriterTests(BasePlatformTests):
out = self.rewrite(self.builddir, os.path.join(self.builddir, 'info.json'))
expected = {
'kwargs': {
- 'project#/': {'version': '0.0.1', 'license': ['GPL', 'MIT', 'BSD']},
+ 'project#/': {'version': '0.0.1', 'license': ['GPL', 'MIT', 'BSD', 'Boost']},
'target#tgt1': {'build_by_default': True},
'dependency#dep1': {'required': False}
}
@@ -7944,7 +7944,7 @@ class RewriterTests(BasePlatformTests):
out = self.rewrite(self.builddir, os.path.join(self.builddir, 'info.json'))
expected = {
'kwargs': {
- 'project#/': {'version': '0.0.1', 'default_options': ['buildtype=release', 'debug=true']},
+ 'project#/': {'version': '0.0.1', 'default_options': 'debug=true'},
'target#tgt1': {'build_by_default': True},
'dependency#dep1': {'required': False}
}
diff --git a/test cases/rewrite/3 kwargs/add.json b/test cases/rewrite/3 kwargs/add.json
index 2148a1e..5b3ce0b 100644
--- a/test cases/rewrite/3 kwargs/add.json
+++ b/test cases/rewrite/3 kwargs/add.json
@@ -25,5 +25,14 @@
"kwargs": {
"license": "BSD"
}
+ },
+ {
+ "type": "kwargs",
+ "function": "project",
+ "id": "//",
+ "operation": "add",
+ "kwargs": {
+ "license": "Boost"
+ }
}
]
diff --git a/test cases/rewrite/3 kwargs/remove.json b/test cases/rewrite/3 kwargs/remove.json
index 5dc7836..e33cb66 100644
--- a/test cases/rewrite/3 kwargs/remove.json
+++ b/test cases/rewrite/3 kwargs/remove.json
@@ -5,7 +5,7 @@
"id": "/",
"operation": "set",
"kwargs": {
- "license": ["GPL", "MIT", "BSD"]
+ "license": ["GPL", "MIT", "BSD", "Boost"]
}
},
{
@@ -25,5 +25,14 @@
"kwargs": {
"license": "BSD"
}
+ },
+ {
+ "type": "kwargs",
+ "function": "project",
+ "id": "//",
+ "operation": "remove",
+ "kwargs": {
+ "license": "Boost"
+ }
}
]
diff --git a/test cases/rewrite/3 kwargs/remove_regex.json b/test cases/rewrite/3 kwargs/remove_regex.json
index 1043101..07fa58e 100644
--- a/test cases/rewrite/3 kwargs/remove_regex.json
+++ b/test cases/rewrite/3 kwargs/remove_regex.json
@@ -16,5 +16,14 @@
"kwargs": {
"default_options": ["cpp_std=.*"]
}
+ },
+ {
+ "type": "kwargs",
+ "function": "project",
+ "id": "//",
+ "operation": "remove_regex",
+ "kwargs": {
+ "default_options": ["buildtype=.*"]
+ }
}
]
diff --git a/test cases/rewrite/3 kwargs/set.json b/test cases/rewrite/3 kwargs/set.json
index a56c599..6ca2ee4 100644
--- a/test cases/rewrite/3 kwargs/set.json
+++ b/test cases/rewrite/3 kwargs/set.json
@@ -2,7 +2,7 @@
{
"type": "kwargs",
"function": "project",
- "id": "/",
+ "id": "//",
"operation": "set",
"kwargs": {
"version": "0.0.2",