blob: 074f7949b8f2170e3315b5da52d8d87a87362c3d [file] [log] [blame]
Jenkins6a7771e2020-05-28 11:28:36 +01001#!/usr/bin/env python
2import glob
3import collections
4import os
5
6Target = collections.namedtuple('Target', 'name prefix')
7
8targets = [Target("NEON", "NE"), Target("CL", "CL"), Target("CPP", "CPP"), Target("GLES_COMPUTE", "GC")]
9
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
46def include_components(path, header_prefix, folder, subfolders=None):
47 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)
52 for s in subfolders or []:
53 include_list += create_include_list( target_path + folder + "/" + s)
54 include_list.sort()
55 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
63 include_components(core_path, "Kernels.h", "kernels", ["arm32", "arm64"])
64
65 # Include functions
66 include_components(runtime_path, "Functions.h", "functions")