|
| 1 | +#!/usr/bin/env python |
| 2 | +# python tools/gen_tools_json.py -i $IDF_PATH -j components/arduino/package/package_esp32_index.template.json -o out/ |
| 3 | + |
| 4 | +from __future__ import print_function |
| 5 | + |
| 6 | +__author__ = "Hristo Gochkov" |
| 7 | +__version__ = "2023" |
| 8 | + |
| 9 | +import os |
| 10 | +import shutil |
| 11 | +import errno |
| 12 | +import os.path |
| 13 | +import json |
| 14 | +import platform |
| 15 | +import sys |
| 16 | +import stat |
| 17 | +import argparse |
| 18 | + |
| 19 | +if sys.version_info[0] == 3: |
| 20 | + unicode = lambda s: str(s) |
| 21 | + |
| 22 | +if __name__ == '__main__': |
| 23 | + |
| 24 | + parser = argparse.ArgumentParser( |
| 25 | + prog = 'gen_tools_json', |
| 26 | + description = 'Update Arduino package index with the tolls found in ESP-IDF') |
| 27 | + parser.add_argument('-i', '--esp-idf', dest='idf_path', required=True, help='Path to ESP-IDF') |
| 28 | + parser.add_argument('-j', '--pkg-json', dest='arduino_json', required=True, help='path to Arduino package json') |
| 29 | + parser.add_argument('-o', '--out-path', dest='out_path', required=True, help='Output path to store the update package json') |
| 30 | + args = parser.parse_args() |
| 31 | + |
| 32 | + idf_path = args.idf_path; |
| 33 | + arduino_json = args.arduino_json; |
| 34 | + out_path = args.out_path; |
| 35 | + |
| 36 | + # settings |
| 37 | + arduino_tools = ["xtensa-esp32-elf","xtensa-esp32s2-elf","xtensa-esp32s3-elf","riscv32-esp-elf","openocd-esp32"] |
| 38 | + |
| 39 | + # code start |
| 40 | + farray = json.load(open(arduino_json)) |
| 41 | + |
| 42 | + idf_tools = json.load(open(idf_path + '/tools/tools.json')) |
| 43 | + for tool in idf_tools['tools']: |
| 44 | + try: |
| 45 | + tool_index = arduino_tools.index(tool['name']) |
| 46 | + except: |
| 47 | + continue |
| 48 | + tool_name = tool['name'] |
| 49 | + tool_version = tool['versions'][0]['name'] |
| 50 | + if tool_name.endswith('-elf'): |
| 51 | + tool_name += '-gcc' |
| 52 | + print('Found {0}, version: {1}'.format(tool_name, tool_version)) |
| 53 | + |
| 54 | + dep_found = False |
| 55 | + dep_skip = False |
| 56 | + for dep in farray['packages'][0]['platforms'][0]['toolsDependencies']: |
| 57 | + if dep['name'] == tool_name: |
| 58 | + if dep['version'] == tool_version: |
| 59 | + print('Skipping {0}. Same version {1}'.format(tool_name, tool_version)) |
| 60 | + dep_skip = True |
| 61 | + break |
| 62 | + print('Updating dependency version of {0} from {1} to {2}'.format(tool_name, dep['version'], tool_version)) |
| 63 | + dep['version'] = tool_version |
| 64 | + dep_found = True |
| 65 | + if dep_skip == True: |
| 66 | + continue |
| 67 | + if dep_found == False: |
| 68 | + print('Adding new dependency: {0} version {1}'.format(tool_name, tool_version)) |
| 69 | + deps = { |
| 70 | + "packager": "esp32", |
| 71 | + "name": tool_name, |
| 72 | + "version": tool_version |
| 73 | + } |
| 74 | + farray['packages'][0]['platforms'][0]['toolsDependencies'].append(deps) |
| 75 | + |
| 76 | + systems = [] |
| 77 | + for arch in tool['versions'][0]: |
| 78 | + if arch == 'name' or arch == 'status': |
| 79 | + continue |
| 80 | + tool_data = tool['versions'][0][arch] |
| 81 | + |
| 82 | + system = { |
| 83 | + "host": '', |
| 84 | + "url": tool_data['url'], |
| 85 | + "archiveFileName": os.path.basename(tool_data['url']), |
| 86 | + "checksum": "SHA-256:"+tool_data['sha256'], |
| 87 | + "size": tool_data['size'] |
| 88 | + } |
| 89 | + |
| 90 | + if arch == "win32": |
| 91 | + system["host"] = "i686-mingw32"; |
| 92 | + elif arch == "win64": |
| 93 | + system["host"] = "x86_64-mingw32"; |
| 94 | + elif arch == "macos-arm64": |
| 95 | + system["host"] = "arm64-apple-darwin"; |
| 96 | + elif arch == "macos": |
| 97 | + system["host"] = "x86_64-apple-darwin"; |
| 98 | + elif arch == "linux-amd64": |
| 99 | + system["host"] = "x86_64-pc-linux-gnu"; |
| 100 | + elif arch == "linux-i686": |
| 101 | + system["host"] = "i686-pc-linux-gnu"; |
| 102 | + elif arch == "linux-arm64": |
| 103 | + system["host"] = "aarch64-linux-gnu"; |
| 104 | + elif arch == "linux-armel": |
| 105 | + system["host"] = "arm-linux-gnueabihf"; |
| 106 | + elif arch == "linux-armhf": |
| 107 | + # system["host"] = "arm-linux-gnueabihf"; |
| 108 | + continue |
| 109 | + else : |
| 110 | + continue |
| 111 | + |
| 112 | + systems.append(system) |
| 113 | + |
| 114 | + tool_found = False |
| 115 | + for t in farray['packages'][0]['tools']: |
| 116 | + if t['name'] == tool_name: |
| 117 | + t['version'] = tool_version |
| 118 | + t['systems'] = systems |
| 119 | + tool_found = True |
| 120 | + print('Updating binaries of {0} to version {1}'.format(tool_name, tool_version)) |
| 121 | + if tool_found == False: |
| 122 | + print('Adding new tool: {0} version {1}'.format(tool_name, tool_version)) |
| 123 | + tools = { |
| 124 | + "name": tool_name, |
| 125 | + "version": tool_version, |
| 126 | + "systems": systems |
| 127 | + } |
| 128 | + farray['packages'][0]['tools'].append(tools) |
| 129 | + |
| 130 | + json_str = json.dumps(farray, indent=2) |
| 131 | + out_file = out_path + os.path.basename(arduino_json) |
| 132 | + with open(out_file, "w") as f: |
| 133 | + f.write(json_str+"\n") |
| 134 | + f.close() |
| 135 | + # print(json_str) |
| 136 | + print('{0} generated'.format(out_file)) |
0 commit comments