From f605bd202afb861c95693e9cefd34f8b063f107b Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 26 Nov 2020 11:55:09 +0000 Subject: 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 Change-Id: I28dcdfa0ca64f99621f98bbe38ec9e24ba76b61b Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4624 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins --- SConscript | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/SConscript b/SConscript index 8bff84ba6d..f1fe9b288c 100644 --- a/SConscript +++ b/SConscript @@ -55,6 +55,17 @@ def build_library(name, sources, static=False, libs=[]): 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 @@ def resolve_includes(target, source, env): 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)) -- cgit v1.2.1