Skip to content

Commit fdd4d86

Browse files
authored
Pio support for SDK libs in new folder
2 parents 5a155ea + c523797 commit fdd4d86

File tree

6 files changed

+114
-8
lines changed

6 files changed

+114
-8
lines changed

build.sh

+7-1
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/"
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
@@ -212,4 +218,4 @@ fi
212218
if [ "$BUILD_TYPE" = "all" ]; then
213219
./tools/archive-build.sh
214220
if [ $? -ne 0 ]; then exit 1; fi
215-
fi
221+
fi

configs/pio_end.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"ESP32",
33
("F_CPU", "$BOARD_F_CPU"),
44
("ARDUINO", 10812),
5-
("ARDUINO_VARIANT", '\\"%s\\"' % env.BoardConfig().get("build.variant").replace('"', "")),
6-
("ARDUINO_BOARD", '\\"%s\\"' % env.BoardConfig().get("name").replace('"', "")),
7-
"ARDUINO_PARTITION_%s" % basename(env.BoardConfig().get(
5+
("ARDUINO_VARIANT", '\\"%s\\"' % board_config.get("build.variant").replace('"', "")),
6+
("ARDUINO_BOARD", '\\"%s\\"' % board_config.get("name").replace('"', "")),
7+
"ARDUINO_PARTITION_%s" % basename(board_config.get(
88
"build.partitions", "default.csv")).replace(".csv", "").replace("-", "_")
99
]
1010
)

configs/pio_start.txt

+5
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,10 @@ from SCons.Script import DefaultEnvironment
3131
env = DefaultEnvironment()
3232

3333
FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoespressif32")
34+
FRAMEWORK_SDK_DIR = env.PioPlatform().get_package_dir(
35+
"framework-arduinoespressif32-libs"
36+
)
37+
38+
board_config = env.BoardConfig()
3439

3540
env.Append(

tools/config.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ AR_TOOLS="$AR_OUT/tools"
5858
AR_PLATFORM_TXT="$AR_OUT/platform.txt"
5959
AR_GEN_PART_PY="$AR_TOOLS/gen_esp32part.py"
6060
AR_SDK="$AR_TOOLS/esp32-arduino-libs/$IDF_TARGET"
61-
PIO_SDK="FRAMEWORK_DIR, \"tools\", \"esp32-arduino-libs\", \"$IDF_TARGET\""
61+
PIO_SDK="FRAMEWORK_SDK_DIR, \"$IDF_TARGET\""
6262
TOOLS_JSON_OUT="$AR_TOOLS/esp32-arduino-libs"
6363
IDF_LIBS_DIR="$AR_ROOT/../esp32-arduino-libs"
6464

tools/copy-libs.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ for item; do
404404
done
405405
fi
406406
done
407-
echo " join($PIO_SDK, env.BoardConfig().get(\"build.arduino.memory_type\", (env.BoardConfig().get(\"build.flash_mode\", \"dio\") + \"_$OCT_PSRAM\")), \"include\")," >> "$AR_PLATFORMIO_PY"
408-
echo " join(FRAMEWORK_DIR, \"cores\", env.BoardConfig().get(\"build.core\"))" >> "$AR_PLATFORMIO_PY"
407+
echo " join($PIO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_$OCT_PSRAM\")), \"include\")," >> "$AR_PLATFORMIO_PY"
408+
echo " join(FRAMEWORK_DIR, \"cores\", board_config.get(\"build.core\"))" >> "$AR_PLATFORMIO_PY"
409409
echo " ]," >> "$AR_PLATFORMIO_PY"
410410
echo "" >> "$AR_PLATFORMIO_PY"
411411

@@ -429,7 +429,7 @@ done
429429
echo " LIBPATH=[" >> "$AR_PLATFORMIO_PY"
430430
echo " join($PIO_SDK, \"lib\")," >> "$AR_PLATFORMIO_PY"
431431
echo " join($PIO_SDK, \"ld\")," >> "$AR_PLATFORMIO_PY"
432-
echo " join($PIO_SDK, env.BoardConfig().get(\"build.arduino.memory_type\", (env.BoardConfig().get(\"build.flash_mode\", \"dio\") + \"_$OCT_PSRAM\")))" >> "$AR_PLATFORMIO_PY"
432+
echo " join($PIO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_$OCT_PSRAM\")))" >> "$AR_PLATFORMIO_PY"
433433
echo " ]," >> "$AR_PLATFORMIO_PY"
434434
echo "" >> "$AR_PLATFORMIO_PY"
435435

tools/gen_platformio_manifest.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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_line):
20+
"""A helper function that converts a custom IDF version string
21+
to a suitable SemVer alternative. For example:
22+
'release/v5.1 420ebd208a' becomes '5.1.0+sha.420ebd208a'
23+
"""
24+
25+
regex_pattern = r"^esp-idf:\s*release\/v(?P<IDF_VERSION>[\d\.]{3,5})\s*(?P<COMMIT_HASH>[0-9a-f]{5,40})"
26+
match = re.search(regex_pattern, version_line)
27+
if not match:
28+
sys.stderr.write(
29+
f"Failed to find a regex match for '{regex_pattern}' in '{version_line}'\n"
30+
)
31+
return ""
32+
33+
version = match.group("IDF_VERSION")
34+
commit = match.group("COMMIT_HASH")
35+
36+
assert version, f"Failed to parse version value from '{version_line}'"
37+
assert commit, f"Failed to parse commit hash value from '{version_line}'"
38+
39+
if version.count(".") < 2:
40+
# The most basic casting to a SemVer with three digits
41+
version = version + ".0"
42+
43+
return f"{version}+sha.{commit}"
44+
45+
46+
def main(dst_dir):
47+
# The "version.txt" file is expected to contain IDF version in the following format
48+
# "esp-idf: release/v$VERSION COMMIT_HASH".
49+
version_file = os.path.join("version.txt")
50+
51+
if not os.path.isfile(version_file):
52+
sys.stderr.write("Missing the 'version.txt' file.\n")
53+
return -1
54+
55+
version_line = ""
56+
with open(version_file, encoding="utf8") as fp:
57+
for line in fp.readlines():
58+
if not line.startswith("esp-idf"):
59+
continue
60+
version_line = line.strip()
61+
62+
if not version_line:
63+
sys.stderr.write("Failed to find ESP-IDF version in the 'version.txt' file!\n")
64+
return -1
65+
66+
converted_version = convert_version(version_line)
67+
if not converted_version:
68+
sys.stderr.write(
69+
f"Failed to convert version '{version_line}' from version.txt\n"
70+
)
71+
return -1
72+
73+
manifest_file_path = os.path.join(dst_dir, "package.json")
74+
with open(manifest_file_path, "w", encoding="utf8") as fp:
75+
MANIFEST_DATA["version"] = converted_version
76+
json.dump(MANIFEST_DATA, fp, indent=2)
77+
78+
print(
79+
f"Generated PlatformIO manifest file '{manifest_file_path}' with '{converted_version}' version"
80+
)
81+
return 0
82+
83+
84+
if __name__ == "__main__":
85+
parser = argparse.ArgumentParser()
86+
parser.add_argument(
87+
"-o",
88+
"--dst-dir",
89+
dest="dst_dir",
90+
required=True,
91+
help="Destination folder where the 'package.json' manifest will be located",
92+
)
93+
args = parser.parse_args()
94+
95+
sys.exit(main(args.dst_dir))

0 commit comments

Comments
 (0)