aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-05-29 10:19:34 -0700
committerDylan Baker <dylan@pnwbakers.com>2019-05-29 11:25:27 -0700
commit99b848f469671f43b3ec6b1de333d7154d0d59ea (patch)
treee34af6e70025425f1dbf1d08d37756bf05c52df2
parent2e2c3c968c02c3d8e87aa9e1547a842cd793f045 (diff)
downloadmeson-99b848f469671f43b3ec6b1de333d7154d0d59ea.zip
meson-99b848f469671f43b3ec6b1de333d7154d0d59ea.tar.gz
meson-99b848f469671f43b3ec6b1de333d7154d0d59ea.tar.bz2
dependencies/cmake: correctly handle spaces in variable names
-rw-r--r--mesonbuild/dependencies/base.py34
-rw-r--r--test cases/unit/61 cmake parser/meson.build8
2 files changed, 31 insertions, 11 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 86cc3f8..218ff10 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -1546,13 +1546,27 @@ class CMakeDependency(ExternalDependency):
return True
return False
- def _cmake_set(self, tline: CMakeTraceLine):
+ def _cmake_set(self, tline: CMakeTraceLine) -> None:
+ """Handler for the CMake set() function in all variaties.
+
+ comes in three flavors:
+ set(<var> <value> [PARENT_SCOPE])
+ set(<var> <value> CACHE <type> <docstring> [FORCE])
+ set(ENV{<var>} <value>)
+
+ We don't support the ENV variant, and any uses of it will be ignored
+ silently. the other two variates are supported, with some caveats:
+ - we don't properly handle scoping, so calls to set() inside a
+ function without PARENT_SCOPE set could incorrectly shadow the
+ outer scope.
+ - We don't honor the type of CACHE arguments
+ """
# DOC: https://cmake.org/cmake/help/latest/command/set.html
# 1st remove PARENT_SCOPE and CACHE from args
args = []
for i in tline.args:
- if i == 'PARENT_SCOPE' or len(i) == 0:
+ if not i or i == 'PARENT_SCOPE':
continue
# Discard everything after the CACHE keyword
@@ -1564,13 +1578,19 @@ class CMakeDependency(ExternalDependency):
if len(args) < 1:
raise self._gen_exception('CMake: set() requires at least one argument\n{}'.format(tline))
- if len(args) == 1:
+ # Now that we've removed extra arguments all that should be left is the
+ # variable identifier and the value, join the value back together to
+ # ensure spaces in the value are correctly handled. This assumes that
+ # variable names don't have spaces. Please don't do that...
+ identifier = args.pop(0)
+ value = ' '.join(args)
+
+ if not value:
# Same as unset
- if args[0] in self.vars:
- del self.vars[args[0]]
+ if identifier in self.vars:
+ del self.vars[identifier]
else:
- values = list(itertools.chain(*map(lambda x: x.split(';'), args[1:])))
- self.vars[args[0]] = values
+ self.vars[identifier] = value.split(';')
def _cmake_unset(self, tline: CMakeTraceLine):
# DOC: https://cmake.org/cmake/help/latest/command/unset.html
diff --git a/test cases/unit/61 cmake parser/meson.build b/test cases/unit/61 cmake parser/meson.build
index 1ca8387..62b9124 100644
--- a/test cases/unit/61 cmake parser/meson.build
+++ b/test cases/unit/61 cmake parser/meson.build
@@ -4,16 +4,16 @@ dep = dependency('mesontest')
# Test a bunch of variations of the set() command
assert(dep.get_variable(cmake : 'VAR_WITHOUT_SPACES') == 'NoSpaces', 'set() without spaces incorrect')
-#assert(dep.get_variable(cmake : 'VAR_WITH_SPACES') == 'With Spaces', 'set() with spaces incorrect')
+assert(dep.get_variable(cmake : 'VAR_WITH_SPACES') == 'With Spaces', 'set() with spaces incorrect')
assert(dep.get_variable(cmake : 'VAR_WITHOUT_SPACES_PS') == 'NoSpaces', 'set(PARENT_SCOPE) without spaces incorrect')
-#assert(dep.get_variable(cmake : 'VAR_WITH_SPACES_PS') == 'With Spaces', 'set(PARENT_SCOPE) with spaces incorrect')
+assert(dep.get_variable(cmake : 'VAR_WITH_SPACES_PS') == 'With Spaces', 'set(PARENT_SCOPE) with spaces incorrect')
assert(dep.get_variable(cmake : 'VAR_THAT_IS_UNSET', default_value : 'sentinal') == 'sentinal', 'set() to unset is incorrect')
assert(dep.get_variable(cmake : 'CACHED_STRING_NS') == 'foo', 'set(CACHED) without spaces is incorrect')
-#assert(dep.get_variable(cmake : 'CACHED_STRING_WS') == 'foo bar', 'set(CACHED STRING) with spaces is incorrect')
+assert(dep.get_variable(cmake : 'CACHED_STRING_WS') == 'foo bar', 'set(CACHED STRING) with spaces is incorrect')
assert(dep.get_variable(cmake : 'CACHED_STRING_ARRAY_NS') == ['foo', 'bar'], 'set(CACHED STRING) without spaces is incorrect')
-#assert(dep.get_variable(cmake : 'CACHED_STRING_ARRAY_WS') == ['foo', 'foo bar', 'bar'], 'set(CACHED STRING[]) with spaces is incorrect')
+assert(dep.get_variable(cmake : 'CACHED_STRING_ARRAY_WS') == ['foo', 'foo bar', 'bar'], 'set(CACHED STRING[]) with spaces is incorrect')
# We don't suppor this, so it should be unset.
assert(dep.get_variable(cmake : 'ENV{var}', default_value : 'sentinal') == 'sentinal', 'set(ENV) should be ignored') \ No newline at end of file