|
| 1 | +import argparse |
| 2 | +import json |
| 3 | +import os |
| 4 | +import re |
| 5 | +import sys |
| 6 | + |
| 7 | +MANIFEST_DATA = { |
| 8 | + "name": "framework-arduinoespressif32-libs", |
| 9 | + "description": "Precompiled libraries for Arduino Wiring-based Framework for the Espressif ESP32 series of SoCs", |
| 10 | + "keywords": ["framework", "arduino", "espressif", "esp32"], |
| 11 | + "license": "LGPL-2.1-or-later", |
| 12 | + "repository": { |
| 13 | + "type": "git", |
| 14 | + "url": "https://github.com/espressif/esp32-arduino-libs", |
| 15 | + }, |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | +def convert_version(version_string): |
| 20 | + """A helper function that converts a custom IDF version string |
| 21 | + extracted from a Git repository to a suitable SemVer alternative. For example: |
| 22 | + 'release/v5.1' becomes '5.1.0', |
| 23 | + 'v7.7.7' becomes '7.7.7' |
| 24 | + """ |
| 25 | + |
| 26 | + regex_pattern = ( |
| 27 | + r"v(?P<MAJOR>0|[1-9]\d*)\.(?P<MINOR>0|[1-9]\d*)\.*(?P<PATCH>0|[1-9]\d*)*" |
| 28 | + ) |
| 29 | + match = re.search(regex_pattern, version_string) |
| 30 | + if not match: |
| 31 | + sys.stderr.write( |
| 32 | + f"Failed to find a regex match for '{regex_pattern}' in '{version_string}'\n" |
| 33 | + ) |
| 34 | + return "" |
| 35 | + |
| 36 | + major, minor, patch = match.groups() |
| 37 | + if not patch: |
| 38 | + patch = "0" |
| 39 | + |
| 40 | + return ".".join((major, minor, patch)) |
| 41 | + |
| 42 | + |
| 43 | +def main(dst_dir, version_string, commit_hash): |
| 44 | + |
| 45 | + converted_version = convert_version(version_string) |
| 46 | + if not converted_version: |
| 47 | + sys.stderr.write(f"Failed to convert version '{version_string}'\n") |
| 48 | + return -1 |
| 49 | + |
| 50 | + manifest_file_path = os.path.join(dst_dir, "package.json") |
| 51 | + with open(manifest_file_path, "w", encoding="utf8") as fp: |
| 52 | + MANIFEST_DATA["version"] = f"{converted_version}+sha.{commit_hash}" |
| 53 | + json.dump(MANIFEST_DATA, fp, indent=2) |
| 54 | + |
| 55 | + print( |
| 56 | + f"Generated PlatformIO manifest file '{manifest_file_path}' with '{converted_version}' version" |
| 57 | + ) |
| 58 | + return 0 |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + parser = argparse.ArgumentParser() |
| 63 | + parser.add_argument( |
| 64 | + "-o", |
| 65 | + "--dst-dir", |
| 66 | + dest="dst_dir", |
| 67 | + required=True, |
| 68 | + help="Destination folder where the 'package.json' manifest will be located", |
| 69 | + ) |
| 70 | + parser.add_argument( |
| 71 | + "-s", |
| 72 | + "--version-string", |
| 73 | + dest="version_string", |
| 74 | + required=True, |
| 75 | + help="ESP-IDF version string used for compiling libraries", |
| 76 | + ) |
| 77 | + parser.add_argument( |
| 78 | + "-c", |
| 79 | + "--commit-hash", |
| 80 | + dest="commit_hash", |
| 81 | + required=True, |
| 82 | + help="ESP-IDF revision in form of a commit hash", |
| 83 | + ) |
| 84 | + args = parser.parse_args() |
| 85 | + |
| 86 | + sys.exit(main(args.dst_dir, args.version_string, args.commit_hash)) |
0 commit comments