Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
Anthony Barbier | 2fe7d1c | 2017-09-15 13:07:36 +0100 | [diff] [blame] | 2 | #FIXME: Remove this file before the release |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | |
| 4 | import glob |
| 5 | import collections |
| 6 | import os |
| 7 | |
| 8 | Target = collections.namedtuple('Target', 'name prefix') |
| 9 | |
Anthony Barbier | 14e7d14 | 2017-09-14 12:05:05 +0100 | [diff] [blame] | 10 | targets = [Target("NEON", "NE"), Target("CL", "CL"), Target("CPP", "CPP"), Target("GLES_COMPUTE", "GC")] |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 11 | |
| 12 | armcv_path = "arm_compute" |
| 13 | core_path = armcv_path + "/core/" |
| 14 | runtime_path = armcv_path + "/runtime/" |
| 15 | include_str = "#include \"" |
| 16 | |
| 17 | |
| 18 | def read_file(file): |
| 19 | with open(file, "r") as f: |
| 20 | lines = f.readlines() |
| 21 | return lines |
| 22 | |
| 23 | |
| 24 | def write_file(file, lines): |
| 25 | with open(file, "w") as f: |
| 26 | for line in lines: |
| 27 | f.write(line) |
| 28 | |
| 29 | |
| 30 | def 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 | |
| 35 | def add_updated_includes(lines, pos, includes): |
| 36 | lines[pos:pos] = includes |
| 37 | return lines |
| 38 | |
| 39 | |
| 40 | def 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 Barbier | 6a5627a | 2017-09-26 14:42:02 +0100 | [diff] [blame] | 48 | def include_components(path, header_prefix, folder, subfolders=None): |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 49 | 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 Barbier | 6a5627a | 2017-09-26 14:42:02 +0100 | [diff] [blame] | 54 | for s in subfolders or []: |
| 55 | include_list += create_include_list( target_path + folder + "/" + s) |
| 56 | include_list.sort() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 57 | 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 | |
| 63 | if __name__ == "__main__": |
| 64 | # Include kernels |
Anthony Barbier | 6a5627a | 2017-09-26 14:42:02 +0100 | [diff] [blame] | 65 | include_components(core_path, "Kernels.h", "kernels", ["arm32", "arm64"]) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 66 | |
| 67 | # Include functions |
| 68 | include_components(runtime_path, "Functions.h", "functions") |