Remove comments when pulling cl kernels files as raw strings

ComputeLibrary integrates the cl kernel implementation files during
build as raw strings to reduce dependencies when deploying.
Remove all the C comments to reduce the total size that these consume to
the end binary file.
Reduces binary size of CL-only build by 35%.

Resolves: COMPMID-4017

Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com>
Change-Id: I28dcdfa0ca64f99621f98bbe38ec9e24ba76b61b
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4624
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
diff --git a/SConscript b/SConscript
index 8bff84b..f1fe9b2 100644
--- a/SConscript
+++ b/SConscript
@@ -55,6 +55,17 @@
     Default(obj)
     return obj
 
+def remove_incode_comments(code):
+    def replace_with_empty(match):
+        s = match.group(0)
+        if s.startswith('/'):
+            return " "
+        else:
+            return s
+
+    comment_regex = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
+    return re.sub(comment_regex, replace_with_empty, code)
+
 def resolve_includes(target, source, env):
     # File collection
     FileEntry = collections.namedtuple('FileEntry', 'target_name file_contents')
@@ -67,7 +78,8 @@
     for i in range(len(source)):
         src = source[i]
         dst = target[i]
-        contents = src.get_contents().decode('utf-8').splitlines()
+        contents = src.get_contents().decode('utf-8')
+        contents = remove_incode_comments(contents).splitlines()
         entry = FileEntry(target_name=dst, file_contents=contents)
         files.append((os.path.basename(src.get_path()),entry))