[damned-lies] Added basic support for reading variables in CMake makefiles
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Added basic support for reading variables in CMake makefiles
- Date: Sat, 5 Aug 2017 14:24:58 +0000 (UTC)
commit e6e2902a88d5b648f1ff4a26b650fa9479072f7f
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Aug 2 19:39:27 2017 +0200
Added basic support for reading variables in CMake makefiles
Fixes #785641. Evolution switched to CMake.
stats/tests/help_mallard/CMakeLists.txt | 5 +++++
stats/tests/tests.py | 8 ++++++++
stats/utils.py | 31 ++++++++++++++++++++++++++++++-
3 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/stats/tests/help_mallard/CMakeLists.txt b/stats/tests/help_mallard/CMakeLists.txt
new file mode 100644
index 0000000..eb7ff53
--- /dev/null
+++ b/stats/tests/help_mallard/CMakeLists.txt
@@ -0,0 +1,5 @@
+set(HELP_FILES
+ index.page
+ what-is.page
+ legal.xml
+)
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 02d61fd..024d9e0 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -553,6 +553,14 @@ class UtilsTests(TestCase):
['index.page', 'what-is.page', 'legal.xml']
)
+ def test_read_cmake_variables(self):
+ path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "help_mallard")
+ cmake_file = utils.MakefileWrapper.find_file([path], file_name='CMakeLists.txt')
+ self.assertEqual(
+ cmake_file.read_variable('HELP_FILES').split(),
+ ['index.page', 'what-is.page', 'legal.xml']
+ )
+
def test_generate_doc_potfile_docbook(self):
"""
Test Docbook-style help
diff --git a/stats/utils.py b/stats/utils.py
index 9befc15..d5ffd62 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -94,7 +94,7 @@ class DocFormat:
class MakefileWrapper:
- default_makefiles = ['Makefile.am', 'meson.build']
+ default_makefiles = ['Makefile.am', 'meson.build', 'CMakeLists.txt']
@classmethod
def find_file(cls, vcs_paths, file_name=None):
@@ -106,6 +106,8 @@ class MakefileWrapper:
if os.access(file_path, os.R_OK):
if file_name == 'meson.build':
return MesonfileWrapper(file_path)
+ elif file_name == 'CMakeLists.txt':
+ return CMakefileWrapper(file_path)
else:
return MakefileWrapper(file_path)
@@ -188,6 +190,33 @@ class MesonfileWrapper(MakefileWrapper):
return catched[var]
+class CMakefileWrapper(MakefileWrapper):
+ def read_variable(self, *variables):
+ # Try to read variables defined as: set(VAR_NAME content1 content2)
+ if self.content is None:
+ return None
+ non_terminated_content = ""
+ found = None
+ for line in self.content.splitlines():
+ line = line.strip()
+ if non_terminated_content:
+ line = non_terminated_content + " " + line
+ # Test if line is non terminated
+ if line.count('(') > line.count(')'):
+ non_terminated_content = line
+ else:
+ non_terminated_content = ""
+ # Search for variable
+ for var in variables:
+ match = re.search('set\s*\(%s\s*([^\)]*)\)' % var, line)
+ if match:
+ found = match.group(1).strip()
+ break
+ if found:
+ break
+ return found
+
+
def sort_object_list(lst, sort_meth):
""" Sort an object list with sort_meth (which should return a translated string) """
templist = [(getattr(obj_, sort_meth)().lower(), obj_) for obj_ in lst]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]