Skip to content

Commit f7ccc89

Browse files
authored
Autogenerate PlatformIO manifest file for prebuilt SDK libs (#119)
* Autogenerate PlatformIO manifest file for prebuilt SDK libs - Add a special Python script that generates "package.json" with IDF revision from the "version.txt" according to SemVer * Tidy up * Refactor manifest generator Now IDF version and commit hash are passed directly from Git client instead of reading from a pregenerated "version.txt" file
1 parent 2cd35e7 commit f7ccc89

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

Diff for: build.sh

+6
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ if [ "$BUILD_TYPE" = "all" ]; then
197197
if [ $? -ne 0 ]; then exit 1; fi
198198
fi
199199

200+
# Generate PlatformIO manifest file
201+
if [ "$BUILD_TYPE" = "all" ]; then
202+
python3 ./tools/gen_platformio_manifest.py -o "$TOOLS_JSON_OUT/" -s $(git -C "$IDF_PATH" symbolic-ref --short HEAD || git -C "$IDF_PATH" tag --points-at HEAD) -c $(git -C "$IDF_PATH" rev-parse --short HEAD)
203+
if [ $? -ne 0 ]; then exit 1; fi
204+
fi
205+
200206
# copy everything to arduino-esp32 installation
201207
if [ $COPY_OUT -eq 1 ] && [ -d "$ESP32_ARDUINO" ]; then
202208
./tools/copy-to-arduino.sh

Diff for: tools/gen_platformio_manifest.py

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)