-
Notifications
You must be signed in to change notification settings - Fork 7.7k
feat(esptool): Upgrade to esptool v5 #11433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
me-no-dev
merged 4 commits into
espressif:release/v3.3.x
from
lucasssvaz:feat/esptool_v5
Jun 10, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
# Check version argument | ||
if [[ $# -ne 3 ]]; then | ||
echo "Usage: $0 <version> <base_folder> <json_path>" | ||
echo "Example: $0 5.0.dev1 /tmp/esptool /tmp/esptool-5.0.dev1.json" | ||
exit 1 | ||
fi | ||
|
||
VERSION=$1 | ||
BASE_FOLDER=$2 | ||
JSON_PATH=$3 | ||
|
||
export COPYFILE_DISABLE=1 | ||
|
||
shopt -s nullglob # So for loop doesn't run if no matches | ||
|
||
# Function to update JSON for a given host | ||
function update_json_for_host { | ||
local host=$1 | ||
local archive=$2 | ||
|
||
# Extract the old url from the JSON for this host, then replace only the filename | ||
old_url=$(jq -r --arg host "$host" ' | ||
.packages[].tools[] | select(.name == "esptool_py") | .systems[] | select(.host == $host) | .url // empty | ||
' "$tmp_json") | ||
if [[ -n "$old_url" ]]; then | ||
base_url="${old_url%/*}" | ||
url="$base_url/$archive" | ||
else | ||
echo "No old url found for $host" | ||
exit 1 | ||
fi | ||
|
||
archiveFileName="$archive" | ||
checksum="SHA-256:$(shasum -a 256 "$archive" | awk '{print $1}')" | ||
size=$(stat -f%z "$archive") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of 'stat -f%z' is BSD-specific and may not work on all platforms; consider using a more portable approach (e.g. 'stat -c %s') to obtain the file size. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
# Use jq to update the JSON | ||
jq --arg host "$host" \ | ||
--arg url "$url" \ | ||
--arg archiveFileName "$archiveFileName" \ | ||
--arg checksum "$checksum" \ | ||
--arg size "$size" \ | ||
' | ||
.packages[].tools[] | ||
|= if .name == "esptool_py" then | ||
.systems = ( | ||
((.systems // []) | map(select(.host != $host))) + [{ | ||
host: $host, | ||
url: $url, | ||
archiveFileName: $archiveFileName, | ||
checksum: $checksum, | ||
size: $size | ||
}] | ||
) | ||
else | ||
. | ||
end | ||
' "$tmp_json" > "$tmp_json.new" && mv "$tmp_json.new" "$tmp_json" | ||
} | ||
|
||
cd "$BASE_FOLDER" | ||
|
||
# Delete all archives before starting | ||
rm -f esptool-*.tar.gz esptool-*.zip | ||
|
||
for dir in esptool-*; do | ||
# Check if directory exists and is a directory | ||
if [[ ! -d "$dir" ]]; then | ||
continue | ||
fi | ||
|
||
base="${dir#esptool-}" | ||
|
||
# Add 'linux-' prefix if base doesn't contain linux/macos/win64 | ||
if [[ "$base" != *linux* && "$base" != *macos* && "$base" != *win64* ]]; then | ||
base="linux-${base}" | ||
fi | ||
|
||
if [[ "$dir" == esptool-win* ]]; then | ||
# Windows zip archive | ||
zipfile="esptool-v${VERSION}-${base}.zip" | ||
echo "Creating $zipfile from $dir ..." | ||
zip -r "$zipfile" "$dir" | ||
else | ||
# Non-Windows: set permissions and tar.gz archive | ||
tarfile="esptool-v${VERSION}-${base}.tar.gz" | ||
echo "Setting permissions and creating $tarfile from $dir ..." | ||
chmod -R u=rwx,g=rx,o=rx "$dir" | ||
tar -cvzf "$tarfile" "$dir" | ||
fi | ||
done | ||
|
||
# After the for loop, update the JSON for each archive | ||
# Create a temporary JSON file to accumulate changes | ||
tmp_json="${JSON_PATH}.tmp" | ||
cp "$JSON_PATH" "$tmp_json" | ||
|
||
for archive in esptool-v"${VERSION}"-*.tar.gz esptool-v"${VERSION}"-*.zip; do | ||
[ -f "$archive" ] || continue | ||
|
||
echo "Updating JSON for $archive" | ||
|
||
# Determine host from archive name | ||
case "$archive" in | ||
*linux-amd64*) host="x86_64-pc-linux-gnu" ;; | ||
*linux-armv7*) host="arm-linux-gnueabihf" ;; | ||
*linux-aarch64*) host="aarch64-linux-gnu" ;; | ||
*macos-amd64*) host="x86_64-apple-darwin" ;; | ||
*macos-arm64*) host="arm64-apple-darwin" ;; | ||
*win64*) hosts=("x86_64-mingw32" "i686-mingw32") ;; | ||
*) echo "Unknown host for $archive"; continue ;; | ||
esac | ||
|
||
# For win64, loop over both hosts; otherwise, use a single host | ||
if [[ "$archive" == *win64* ]]; then | ||
for host in "${hosts[@]}"; do | ||
update_json_for_host "$host" "$archive" | ||
done | ||
else | ||
update_json_for_host "$host" "$archive" | ||
fi | ||
done | ||
|
||
# After all archives are processed, move the temporary JSON to the final file | ||
mv "$tmp_json" "$JSON_PATH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain the arguments a bit. It is not clear what each one is. Is
base_folder
the output? Where doesjson_path
come from?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@me-no-dev I've reworked the script to be way more flexible and useful. PTAL if there is anything missing.