blob: 9f566cbc1a4aca98f752a3ca10c778f7542ddea6 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001#!/usr/bin/env python3.5
2
3import glob
4import collections
5import os
6
7Target = collections.namedtuple('Target', 'name prefix')
8
9targets = [Target("NEON", "NE"), Target("CL", "CL"), Target("CPP", "CPP")]
10
11armcv_path = "arm_compute"
12core_path = armcv_path + "/core/"
13runtime_path = armcv_path + "/runtime/"
14include_str = "#include \""
15
16
17def read_file(file):
18 with open(file, "r") as f:
19 lines = f.readlines()
20 return lines
21
22
23def write_file(file, lines):
24 with open(file, "w") as f:
25 for line in lines:
26 f.write(line)
27
28
29def remove_existing_includes(lines):
30 first_pos = next(i for i, line in enumerate(lines) if include_str in line)
31 return [x for x in lines if not x.startswith(include_str)], first_pos
32
33
34def add_updated_includes(lines, pos, includes):
35 lines[pos:pos] = includes
36 return lines
37
38
39def create_include_list(folder):
40 files_path = folder + "/*.h"
41 files = glob.glob(files_path)
42 updated_files = [include_str + folder + "/" + x.rsplit('/',1)[1] + "\"\n" for x in files]
43 updated_files.sort()
44 return updated_files
45
46
47def include_components(path, header_prefix, folder):
48 for t in targets:
49 target_path = path + t.name + "/"
50 components_file = target_path + t.prefix + header_prefix
51 if os.path.exists(components_file):
52 include_list = create_include_list(target_path + folder)
53 lines = read_file(components_file)
54 lines, first_pos = remove_existing_includes(lines)
55 lines = add_updated_includes(lines, first_pos, include_list)
56 write_file(components_file, lines)
57
58
59if __name__ == "__main__":
60 # Include kernels
61 include_components(core_path, "Kernels.h", "kernels")
62
63 # Include functions
64 include_components(runtime_path, "Functions.h", "functions")