Compress OpenCL kernel files using zlib for Android

Kernel files are embedded into the binary as the default option when
building which leads to binary size bloating.

Add `compress_kernels` option and utilize zlib for further compressing
the text kernel files and reduce the overall binary size. We use a
base64 encoding/decoding to ensure that the strings can be easily
embedded. This adds to the binary size but still the overall reduction
is significant.
Maximum compression level 9 is used.

Option is currently restricted to Android builds as android toolchain
provides a zlib library.

Initial experimentations indicate a binary size reduction of 50%

Resolves: COMPMID-4017

Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com>
Change-Id: Iee81b8c00391b26a5f41642699692928a4d6bd6e
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4958
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
diff --git a/SConscript b/SConscript
index 6b727f5..7e09240 100644
--- a/SConscript
+++ b/SConscript
@@ -23,6 +23,9 @@
 import os.path
 import re
 import subprocess
+import zlib
+import base64
+import string
 
 VERSION = "v0.0-unreleased"
 LIBRARY_VERSION_MAJOR = 21
@@ -112,15 +115,17 @@
             tmp_file = updated_file
 
         # Append and prepend string literal identifiers and add expanded file to final list
-        tmp_file.insert(0, "R\"(\n")
-        tmp_file.append("\n)\"")
         entry = FileEntry(target_name=file[1].target_name, file_contents=tmp_file)
         final_files.append((file[0], entry))
 
     # Write output files
     for file in final_files:
         with open(file[1].target_name.get_path(), 'w+') as out_file:
-            out_file.write( "\n".join( file[1].file_contents ))
+            file_to_write = "\n".join( file[1].file_contents )
+            if env['compress_kernels']:
+                file_to_write = zlib.compress(file_to_write, 9).encode("base64").replace("\n", "")
+            file_to_write = "R\"(" + file_to_write + ")\""
+            out_file.write(file_to_write)
 
 def create_version_file(target, source, env):
 # Generate string with build options library version to embed in the library: