blob: 074f7949b8f2170e3315b5da52d8d87a87362c3d [file] [log] [blame]
Gian Marco Iodice16824302017-09-28 15:41:37 +01001#!/usr/bin/env python
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002import glob
3import collections
4import os
5
6Target = collections.namedtuple('Target', 'name prefix')
7
Anthony Barbier14e7d142017-09-14 12:05:05 +01008targets = [Target("NEON", "NE"), Target("CL", "CL"), Target("CPP", "CPP"), Target("GLES_COMPUTE", "GC")]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01009
10armcv_path = "arm_compute"
11core_path = armcv_path + "/core/"
12runtime_path = armcv_path + "/runtime/"
13include_str = "#include \""
14
15
16def read_file(file):
17 with open(file, "r") as f:
18 lines = f.readlines()
19 return lines
20
21
22def write_file(file, lines):
23 with open(file, "w") as f:
24 for line in lines:
25 f.write(line)
26
27
28def remove_existing_includes(lines):
29 first_pos = next(i for i, line in enumerate(lines) if include_str in line)
30 return [x for x in lines if not x.startswith(include_str)], first_pos
31
32
33def add_updated_includes(lines, pos, includes):
34 lines[pos:pos] = includes
35 return lines
36
37
38def create_include_list(folder):
39 files_path = folder + "/*.h"
40 files = glob.glob(files_path)
41 updated_files = [include_str + folder + "/" + x.rsplit('/',1)[1] + "\"\n" for x in files]
42 updated_files.sort()
43 return updated_files
44
45
Anthony Barbier6a5627a2017-09-26 14:42:02 +010046def include_components(path, header_prefix, folder, subfolders=None):
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047 for t in targets:
48 target_path = path + t.name + "/"
49 components_file = target_path + t.prefix + header_prefix
50 if os.path.exists(components_file):
51 include_list = create_include_list(target_path + folder)
Anthony Barbier6a5627a2017-09-26 14:42:02 +010052 for s in subfolders or []:
53 include_list += create_include_list( target_path + folder + "/" + s)
54 include_list.sort()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 lines = read_file(components_file)
56 lines, first_pos = remove_existing_includes(lines)
57 lines = add_updated_includes(lines, first_pos, include_list)
58 write_file(components_file, lines)
59
60
61if __name__ == "__main__":
62 # Include kernels
Anthony Barbier6a5627a2017-09-26 14:42:02 +010063 include_components(core_path, "Kernels.h", "kernels", ["arm32", "arm64"])
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064
65 # Include functions
66 include_components(runtime_path, "Functions.h", "functions")