Skip to content

Commit dbf19e2

Browse files
committed
Attempt at splitting SDK from Arduino
1 parent 08eef9c commit dbf19e2

File tree

3 files changed

+271
-51
lines changed

3 files changed

+271
-51
lines changed

tools/add_sdk_json.py

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
__author__ = "Hristo Gochkov"
6+
__version__ = "2023"
7+
8+
import os
9+
import shutil
10+
import errno
11+
import os.path
12+
import json
13+
import platform
14+
import sys
15+
import stat
16+
import argparse
17+
18+
if sys.version_info[0] == 3:
19+
unicode = lambda s: str(s)
20+
21+
if __name__ == '__main__':
22+
parser = argparse.ArgumentParser(
23+
prog = 'add_sdk_json',
24+
description = 'Update SDK in Arduino package index')
25+
parser.add_argument('-j', '--pkg-json', dest='arduino_json', required=True, help='path to package json')
26+
parser.add_argument('-n', '--name', dest='tool_name', required=True, help='name of the SDK package')
27+
parser.add_argument('-v', '--version', dest='tool_version', required=True, help='version of the new SDK')
28+
parser.add_argument('-u', '--url', dest='tool_url', required=True, help='url to the zip of the new SDK')
29+
parser.add_argument('-f', '--filename', dest='tool_filename', required=True, help='filename of the zip of the new SDK')
30+
parser.add_argument('-s', '--size', dest='tool_size', required=True, help='size of the zip of the new SDK')
31+
parser.add_argument('-c', '--sha', dest='tool_sha', required=True, help='sha256 of the zip of the new SDK')
32+
args = parser.parse_args()
33+
34+
print('Destination : {0}.'.format(args.arduino_json))
35+
print('Tool Name : {0}.'.format(args.tool_name))
36+
print('Tool Version : {0}.'.format(args.tool_version))
37+
print('Tool URL : {0}.'.format(args.tool_url))
38+
print('Tool File Name: {0}.'.format(args.tool_filename))
39+
print('Tool Size : {0}.'.format(args.tool_size))
40+
print('Tool SHA256 : {0}.'.format(args.tool_sha))
41+
42+
idf_path = args.idf_path;
43+
arduino_json = args.arduino_json;
44+
tool_name = args.tool_name;
45+
tool_version = args.tool_version;
46+
tool_url = args.tool_url;
47+
tool_filename = args.tool_filename;
48+
tool_size = args.tool_size;
49+
tool_sha = args.tool_sha;
50+
51+
# code start
52+
farray = {"packages":[{"platforms":[{"toolsDependencies":[]}],"tools":[]}]}
53+
if os.path.isfile(arduino_json) == True:
54+
farray = json.load(open(arduino_json))
55+
56+
dep_found = False
57+
dep_skip = False
58+
for dep in farray['packages'][0]['platforms'][0]['toolsDependencies']:
59+
if dep['name'] == tool_name:
60+
if dep['version'] == tool_version:
61+
print('Skipping {0}. Same version {1}'.format(tool_name, tool_version))
62+
dep_skip = True
63+
break
64+
print('Updating dependency version of {0} from {1} to {2}'.format(tool_name, dep['version'], tool_version))
65+
dep['version'] = tool_version
66+
dep_found = True
67+
break
68+
69+
if dep_skip == False:
70+
if dep_found == False:
71+
print('Adding new dependency: {0} version {1}'.format(tool_name, tool_version))
72+
deps = {
73+
"packager": "esp32",
74+
"name": tool_name,
75+
"version": tool_version
76+
}
77+
farray['packages'][0]['platforms'][0]['toolsDependencies'].append(deps)
78+
79+
systems = []
80+
system = {
81+
"host": '',
82+
"url": tool_url,
83+
"archiveFileName": tool_filename,
84+
"checksum": "SHA-256:"+tool_sha,
85+
"size": str(tool_size)
86+
}
87+
88+
system["host"] = "i686-mingw32";
89+
systems.append(system)
90+
system["host"] = "x86_64-mingw32";
91+
systems.append(system)
92+
system["host"] = "arm64-apple-darwin";
93+
systems.append(system)
94+
system["host"] = "x86_64-apple-darwin";
95+
systems.append(system)
96+
system["host"] = "x86_64-pc-linux-gnu";
97+
systems.append(system)
98+
system["host"] = "i686-pc-linux-gnu";
99+
systems.append(system)
100+
system["host"] = "aarch64-linux-gnu";
101+
systems.append(system)
102+
system["host"] = "arm-linux-gnueabihf";
103+
systems.append(system)
104+
105+
tool_found = False
106+
for t in farray['packages'][0]['tools']:
107+
if t['name'] == tool_name:
108+
t['version'] = tool_version
109+
t['systems'] = systems
110+
tool_found = True
111+
print('Updating systems of {0} to version {1}'.format(tool_name, tool_version))
112+
break
113+
114+
if tool_found == False:
115+
print('Adding new tool: {0} version {1}'.format(tool_name, tool_version))
116+
tools = {
117+
"name": tool_name,
118+
"version": tool_version,
119+
"systems": systems
120+
}
121+
farray['packages'][0]['tools'].append(tools)
122+
123+
json_str = json.dumps(farray, indent=2)
124+
with open(arduino_json, "w") as f:
125+
f.write(json_str+"\n")
126+
f.close()
127+
# print(json_str)
128+
print('{0} generated'.format(arduino_json))

tools/install-esp-idf.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ if [ "$GITHUB_EVENT_NAME" == "schedule" ] || [ "$GITHUB_EVENT_NAME" == "reposito
5858
AR_NEW_COMMIT_MESSAGE="IDF $IDF_COMMIT"
5959
AR_NEW_PR_TITLE="$AR_NEW_COMMIT_MESSAGE"
6060
fi
61+
LIBS_VERSION="idf-$IDF_BRANCH-$IDF_COMMIT"
6162

6263
AR_HAS_COMMIT=`git_commit_exists "$AR_COMPS/arduino" "$AR_NEW_COMMIT_MESSAGE"`
6364
AR_HAS_BRANCH=`git_branch_exists "$AR_COMPS/arduino" "$AR_NEW_BRANCH_NAME"`
@@ -80,11 +81,6 @@ if [ "$GITHUB_EVENT_NAME" == "schedule" ] || [ "$GITHUB_EVENT_NAME" == "reposito
8081
exit 0
8182
fi
8283

83-
# setup git for pushing
84-
git config --global github.user "$GITHUB_ACTOR"
85-
git config --global user.name "$GITHUB_ACTOR"
86-
git config --global user.email "$GITHUB_ACTOR@github.com"
87-
8884
export AR_NEW_BRANCH_NAME
8985
export AR_NEW_COMMIT_MESSAGE
9086
export AR_NEW_PR_TITLE
@@ -93,6 +89,7 @@ if [ "$GITHUB_EVENT_NAME" == "schedule" ] || [ "$GITHUB_EVENT_NAME" == "reposito
9389
export AR_HAS_BRANCH
9490
export AR_HAS_PR
9591

92+
export LIBS_VERSION
9693
export LIBS_HAS_COMMIT
9794
export LIBS_HAS_BRANCH
9895
fi

tools/push-to-arduino.sh

+141-46
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,71 @@ if ! [ -d "$AR_COMPS/arduino" ]; then
1111
exit 1
1212
fi
1313

14+
# setup git for pushing
15+
git config --global github.user "$GITHUB_ACTOR"
16+
git config --global user.name "$GITHUB_ACTOR"
17+
git config --global user.email "$GITHUB_ACTOR@github.com"
18+
1419
#
1520
# UPDATE FILES
1621
#
1722

18-
if [ $AR_HAS_COMMIT == "0" ]; then
19-
# create or checkout the branch
20-
if [ ! $AR_HAS_BRANCH == "0" ]; then
21-
echo "Switching to arduino branch '$AR_NEW_BRANCH_NAME'..."
22-
git -C "$AR_COMPS/arduino" checkout $AR_NEW_BRANCH_NAME
23-
else
24-
echo "Creating arduino branch '$AR_NEW_BRANCH_NAME'..."
25-
git -C "$AR_COMPS/arduino" checkout -b $AR_NEW_BRANCH_NAME
26-
fi
27-
if [ $? -ne 0 ]; then
28-
echo "ERROR: Checkout of branch '$AR_NEW_BRANCH_NAME' failed"
29-
exit 1
30-
fi
23+
# if [ $AR_HAS_COMMIT == "0" ]; then
24+
# # create or checkout the branch
25+
# if [ ! $AR_HAS_BRANCH == "0" ]; then
26+
# echo "Switching to arduino branch '$AR_NEW_BRANCH_NAME'..."
27+
# git -C "$AR_COMPS/arduino" checkout $AR_NEW_BRANCH_NAME
28+
# else
29+
# echo "Creating arduino branch '$AR_NEW_BRANCH_NAME'..."
30+
# git -C "$AR_COMPS/arduino" checkout -b $AR_NEW_BRANCH_NAME
31+
# fi
32+
# if [ $? -ne 0 ]; then
33+
# echo "ERROR: Checkout of branch '$AR_NEW_BRANCH_NAME' failed"
34+
# exit 1
35+
# fi
3136

32-
# make changes to the files
33-
echo "Patching files in branch '$AR_NEW_BRANCH_NAME'..."
34-
ESP32_ARDUINO="$AR_COMPS/arduino" ./tools/copy-to-arduino.sh
37+
# # make changes to the files
38+
# echo "Patching files in branch '$AR_NEW_BRANCH_NAME'..."
39+
# ESP32_ARDUINO="$AR_COMPS/arduino" ./tools/copy-to-arduino.sh
3540

36-
cd $AR_COMPS/arduino
41+
# cd $AR_COMPS/arduino
3742

38-
# did any of the files change?
39-
if [ -n "$(git status --porcelain)" ]; then
40-
echo "Pushing changes to branch '$AR_NEW_BRANCH_NAME'..."
41-
git add . && git commit --message "$AR_NEW_COMMIT_MESSAGE" && git push -u origin $AR_NEW_BRANCH_NAME
42-
if [ $? -ne 0 ]; then
43-
echo "ERROR: Pushing to branch '$AR_NEW_BRANCH_NAME' failed"
44-
exit 1
45-
fi
46-
else
47-
echo "No changes in branch '$AR_NEW_BRANCH_NAME'"
48-
if [ $AR_HAS_BRANCH == "0" ]; then
49-
echo "Delete created branch '$AR_NEW_BRANCH_NAME'"
50-
git branch -d $AR_NEW_BRANCH_NAME
51-
fi
52-
exit 0
53-
fi
43+
# # did any of the files change?
44+
# if [ -n "$(git status --porcelain)" ]; then
45+
# echo "Pushing changes to branch '$AR_NEW_BRANCH_NAME'..."
46+
# git add . && git commit --message "$AR_NEW_COMMIT_MESSAGE" && git push -u origin $AR_NEW_BRANCH_NAME
47+
# if [ $? -ne 0 ]; then
48+
# echo "ERROR: Pushing to branch '$AR_NEW_BRANCH_NAME' failed"
49+
# exit 1
50+
# fi
51+
# else
52+
# echo "No changes in branch '$AR_NEW_BRANCH_NAME'"
53+
# if [ $AR_HAS_BRANCH == "0" ]; then
54+
# echo "Delete created branch '$AR_NEW_BRANCH_NAME'"
55+
# git branch -d $AR_NEW_BRANCH_NAME
56+
# fi
57+
# exit 0
58+
# fi
5459

55-
# CREATE PULL REQUEST
56-
if [ "$AR_HAS_PR" == "0" ]; then
57-
echo "Creating PR '$AR_NEW_PR_TITLE'..."
58-
pr_created=`git_create_pr "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE" "$AR_PR_TARGET_BRANCH"`
59-
if [ $pr_created == "0" ]; then
60-
echo "ERROR: Failed to create PR '$AR_NEW_PR_TITLE': "`echo "$git_create_pr_res" | jq -r '.message'`": "`echo "$git_create_pr_res" | jq -r '.errors[].message'`
61-
exit 1
62-
fi
63-
else
64-
echo "PR '$AR_NEW_PR_TITLE' Already Exists"
65-
fi
66-
fi
60+
# # CREATE PULL REQUEST
61+
# if [ "$AR_HAS_PR" == "0" ]; then
62+
# echo "Creating PR '$AR_NEW_PR_TITLE'..."
63+
# pr_created=`git_create_pr "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE" "$AR_PR_TARGET_BRANCH"`
64+
# if [ $pr_created == "0" ]; then
65+
# echo "ERROR: Failed to create PR '$AR_NEW_PR_TITLE': "`echo "$git_create_pr_res" | jq -r '.message'`": "`echo "$git_create_pr_res" | jq -r '.errors[].message'`
66+
# exit 1
67+
# fi
68+
# else
69+
# echo "PR '$AR_NEW_PR_TITLE' Already Exists"
70+
# fi
71+
# fi
6772

6873
#
6974
# esp32-arduino-libs
7075
#
71-
cd "$AR_ROOT"
7276

7377
if [ $LIBS_HAS_COMMIT == "0" ]; then
78+
cd "$AR_ROOT"
7479
# create branch if necessary
7580
if [ "$LIBS_HAS_BRANCH" == "1" ]; then
7681
echo "Branch '$AR_NEW_BRANCH_NAME' Already Exists"
@@ -90,6 +95,9 @@ if [ $LIBS_HAS_COMMIT == "0" ]; then
9095
rm -rf $IDF_LIBS_DIR/sdk && cp -Rf $AR_TOOLS/sdk $IDF_LIBS_DIR/
9196

9297
cd $IDF_LIBS_DIR
98+
if [ -f "README.md" ]; then
99+
rm -rf "README.md"
100+
fi
93101

94102
# did any of the files change?
95103
if [ -n "$(git status --porcelain)" ]; then
@@ -99,6 +107,38 @@ if [ $LIBS_HAS_COMMIT == "0" ]; then
99107
echo "ERROR: Pushing to branch '$AR_NEW_BRANCH_NAME' failed"
100108
exit 1
101109
fi
110+
IDF_LIBS_COMMIT=`git rev-parse --verify HEAD`
111+
IDF_LIBS_DL_URL="https://github.com/espressif/esp32-arduino-libs/archive/$IDF_LIBS_COMMIT.zip"
112+
# ToDo: this URL needs to get into Arduino's package.json
113+
114+
# Download the file
115+
filename=$(basename "$IDF_LIBS_DL_URL")
116+
curl -s -O "$IDF_LIBS_DL_URL"
117+
118+
# Check if the download was successful
119+
if [ $? -ne 0 ]; then
120+
echo "Error downloading file from $IDF_LIBS_DL_URL"
121+
exit 1
122+
fi
123+
124+
# Calculate the size in bytes and SHA-256 sum
125+
size=$(stat -c%s "$filename")
126+
sha256sum=$(sha256sum "$filename" | awk '{print $1}')
127+
128+
# Clean up the downloaded file
129+
rm "$filename"
130+
131+
# Print the results
132+
echo "Tool: esp32-arduino-libs"
133+
echo "Version: $LIBS_VERSION"
134+
echo "URL: $IDF_LIBS_DL_URL"
135+
echo "File: $filename"
136+
echo "Size: $size bytes"
137+
echo "SHA-256: $sha256sum"
138+
echo "JSON: $AR_OUT/package_esp32_index.template.json"
139+
python3 tools/add_sdk_json.py -j "$AR_OUT/package_esp32_index.template.json" -n "esp32-arduino-libs" -v "$LIBS_VERSION" -u "$IDF_LIBS_DL_URL" -f "$filename" -s "$size" -c "$sha256sum"
140+
if [ $? -ne 0 ]; then exit 1; fi
141+
102142
else
103143
echo "No changes in esp32-arduino-libs branch '$AR_NEW_BRANCH_NAME'"
104144
if [ $LIBS_HAS_BRANCH == "0" ]; then
@@ -109,5 +149,60 @@ if [ $LIBS_HAS_COMMIT == "0" ]; then
109149
fi
110150
fi
111151

152+
# https://github.com/espressif/esp32-arduino-libs/archive/refs/heads/[branch].zip
153+
# https://github.com/espressif/esp32-arduino-libs/archive/refs/tags/[tag].zip
154+
# https://github.com/espressif/esp32-arduino-libs/archive/[commit_hash].zip
155+
156+
if [ $AR_HAS_COMMIT == "0" ]; then
157+
cd "$AR_ROOT"
158+
# create or checkout the branch
159+
if [ ! $AR_HAS_BRANCH == "0" ]; then
160+
echo "Switching to arduino branch '$AR_NEW_BRANCH_NAME'..."
161+
git -C "$AR_COMPS/arduino" checkout $AR_NEW_BRANCH_NAME
162+
else
163+
echo "Creating arduino branch '$AR_NEW_BRANCH_NAME'..."
164+
git -C "$AR_COMPS/arduino" checkout -b $AR_NEW_BRANCH_NAME
165+
fi
166+
if [ $? -ne 0 ]; then
167+
echo "ERROR: Checkout of branch '$AR_NEW_BRANCH_NAME' failed"
168+
exit 1
169+
fi
170+
171+
# make changes to the files
172+
echo "Patching files in branch '$AR_NEW_BRANCH_NAME'..."
173+
rm -rf "$AR_COMPS/arduino/tools/sdk"
174+
rm -rf "$AR_COMPS/arduino/package/package_esp32_index.template.json" && cp -f "$AR_OUT/package_esp32_index.template.json" "$AR_COMPS/arduino/package/package_esp32_index.template.json"
175+
176+
cd $AR_COMPS/arduino
177+
178+
# did any of the files change?
179+
if [ -n "$(git status --porcelain)" ]; then
180+
echo "Pushing changes to branch '$AR_NEW_BRANCH_NAME'..."
181+
git add . && git commit --message "$AR_NEW_COMMIT_MESSAGE" && git push -u origin $AR_NEW_BRANCH_NAME
182+
if [ $? -ne 0 ]; then
183+
echo "ERROR: Pushing to branch '$AR_NEW_BRANCH_NAME' failed"
184+
exit 1
185+
fi
186+
else
187+
echo "No changes in branch '$AR_NEW_BRANCH_NAME'"
188+
if [ $AR_HAS_BRANCH == "0" ]; then
189+
echo "Delete created branch '$AR_NEW_BRANCH_NAME'"
190+
git branch -d $AR_NEW_BRANCH_NAME
191+
fi
192+
exit 0
193+
fi
194+
195+
# CREATE PULL REQUEST
196+
if [ "$AR_HAS_PR" == "0" ]; then
197+
echo "Creating PR '$AR_NEW_PR_TITLE'..."
198+
pr_created=`git_create_pr "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE" "$AR_PR_TARGET_BRANCH"`
199+
if [ $pr_created == "0" ]; then
200+
echo "ERROR: Failed to create PR '$AR_NEW_PR_TITLE': "`echo "$git_create_pr_res" | jq -r '.message'`": "`echo "$git_create_pr_res" | jq -r '.errors[].message'`
201+
exit 1
202+
fi
203+
else
204+
echo "PR '$AR_NEW_PR_TITLE' Already Exists"
205+
fi
206+
fi
112207

113208
exit 0

0 commit comments

Comments
 (0)