blob: 80d1fb28e95a3e20b6f250375878efb0113b22c4 [file] [log] [blame]
Gian Marco Iodice16824302017-09-28 15:41:37 +01001#!/usr/bin/env python
Anthony Barbier2fe7d1c2017-09-15 13:07:36 +01002#FIXME: Remove this file before the release
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003
4import glob
5import collections
6import os
7
8Target = collections.namedtuple('Target', 'name prefix')
9
Anthony Barbier14e7d142017-09-14 12:05:05 +010010targets = [Target("NEON", "NE"), Target("CL", "CL"), Target("CPP", "CPP"), Target("GLES_COMPUTE", "GC")]
Anthony Barbier6ff3b192017-09-04 18:44:23 +010011
12armcv_path = "arm_compute"
13core_path = armcv_path + "/core/"
14runtime_path = armcv_path + "/runtime/"
15include_str = "#include \""
16
17
18def read_file(file):
19 with open(file, "r") as f:
20 lines = f.readlines()
21 return lines
22
23
24def write_file(file, lines):
25 with open(file, "w") as f:
26 for line in lines:
27 f.write(line)
28
29
30def remove_existing_includes(lines):
31 first_pos = next(i for i, line in enumerate(lines) if include_str in line)
32 return [x for x in lines if not x.startswith(include_str)], first_pos
33
34
35def add_updated_includes(lines, pos, includes):
36 lines[pos:pos] = includes
37 return lines
38
39
40def create_include_list(folder):
41 files_path = folder + "/*.h"
42 files = glob.glob(files_path)
43 updated_files = [include_str + folder + "/" + x.rsplit('/',1)[1] + "\"\n" for x in files]
44 updated_files.sort()
45 return updated_files
46
47
Anthony Barbier6a5627a2017-09-26 14:42:02 +010048def include_components(path, header_prefix, folder, subfolders=None):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049 for t in targets:
50 target_path = path + t.name + "/"
51 components_file = target_path + t.prefix + header_prefix
52 if os.path.exists(components_file):
53 include_list = create_include_list(target_path + folder)
Anthony Barbier6a5627a2017-09-26 14:42:02 +010054 for s in subfolders or []:
55 include_list += create_include_list( target_path + folder + "/" + s)
56 include_list.sort()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057 lines = read_file(components_file)
58 lines, first_pos = remove_existing_includes(lines)
59 lines = add_updated_includes(lines, first_pos, include_list)
60 write_file(components_file, lines)
61
62
63if __name__ == "__main__":
64 # Include kernels
Anthony Barbier6a5627a2017-09-26 14:42:02 +010065 include_components(core_path, "Kernels.h", "kernels", ["arm32", "arm64"])
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066
67 # Include functions
68 include_components(runtime_path, "Functions.h", "functions")