Dear Team,

I’ve just pushed [1] which fixes the detection of cmake variables inside 
strings when they’re not at the very first position in the string.

It makes the parser iterate at each character after a literal was detected, 
instead of the literal regexp catching the complete rest of the string.
This makes it possible for the variable detection pattern to match again later 
in the string.

--- a/function_collection/cmake_update_deps.py
+++ b/function_collection/cmake_update_deps.py
@@ -223,13 +223,13 @@ class CMakeParser(Parser):
     def t_string_VAR(self, t):
         r'\${'
         self.lexer.push_state('var')
         return t
 
     def t_string_ARG(self, t):
-        r'[^\\"]+'
+        r'[^\\"]'
         return t


It fixes dependency detection cases like [2] :
7:   set (RELEASE_SERVICE_VERSION 
"${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}")
…
130: find_package(KF6BalooWidgets ${RELEASE_SERVICE_VERSION})

or [3] :
70:    find_package(${KSANECORE_NAME} 
"${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}" REQUIRED)

and I’ve run it against a couple of complex packages like plasma-workspace and 
it gives the same results with the fix as before.

The change does have a negligible (on my machine) performance impact : analysis 
for plasma workspace ~1,14s -> 1,15s on several runs.
There’s probably better ways to implement the change so the parser still catchs 
all non-variable characters while still detecting all variables in a string. 
But since the change fixes the parser correctness for this case I won’t be 
looking into this any further myself.


I’m not (at all) an expert in the lex/yacc stack so this is a heads up in case 
you see anything funny as a consequence or want to come up with a better 
solution.


[1] 
https://salsa.debian.org/qt-kde-team/pkg-kde-dev-scripts/-/commit/1fec30740649193e22fe0abc9c1da0702a0e1db4
[2] 
https://invent.kde.org/system/dolphin/-/blob/master/CMakeLists.txt?ref_type=heads
[3] 
https://invent.kde.org/graphics/libksane/-/blob/master/CMakeLists.txt?ref_type=heads


Happy hacking,
--
Aurélien



-- 
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-kde-talk

Reply via email to