Skip to content

Commit b0aa14b

Browse files
committed
extra: package_tool.sh: add script to build and package tools in distrib/
1 parent 98ec98d commit b0aa14b

File tree

5 files changed

+79
-24
lines changed

5 files changed

+79
-24
lines changed

.github/workflows/package_core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
uses: actions/upload-artifact@v4
5656
with:
5757
name: ${{ env.CORE_ARTIFACT }}
58-
path: ${{ env.CORE_ARTIFACT }}.tar.bz2
58+
path: distrib/${{ env.CORE_ARTIFACT }}.tar.bz2
5959

6060
test-core:
6161
name: Test ${{ matrix.board }} board

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extra/post_build_tool/distrib/
21
build/
2+
distrib/
33
venv/
4-
ArduinoCore-zephyr-*.tar.bz2

extra/package_core.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ extra/get_board_details.sh | jq -cr '.[]' | while read -r item; do
2727
ls firmwares/zephyr-${variant}.* >> ${TEMP_LIST}
2828
done
2929
cat ${TEMP_LIST}
30-
tar -cjhf ${PACKAGE}-${VERSION}.tar.bz2 -X extra/package_core.exc -T ${TEMP_LIST} --transform "s,^,${PACKAGE}/,"
30+
mkdir -p distrib
31+
tar -cjhf distrib/${PACKAGE}-${VERSION}.tar.bz2 -X extra/package_core.exc -T ${TEMP_LIST} --transform "s,^,${PACKAGE}/,"
3132
rm -f ${TEMP_LIST}

extra/package_tool.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
TOOL_NAME=$(basename $1)
6+
VERSION=$2
7+
8+
BASE_DIR=$(readlink -f $(dirname $0)/..)
9+
TOOL_DIR="$BASE_DIR/extra/$TOOL_NAME"
10+
if ! [ -d "$TOOL_DIR" ] || [ -z "$VERSION" ] ; then
11+
echo "Usage: $0 <tool_name> <version>"
12+
exit 1
13+
fi
14+
15+
DIR=${BASE_DIR}/distrib
16+
17+
hash_file() {
18+
plat=$1
19+
file=$2
20+
name=$(basename $file)
21+
hash=$(sha256sum $file | cut -d ' ' -f 1)
22+
len=$(stat -c %s $file)
23+
cat << EOF
24+
{
25+
"host": "$plat",
26+
"url": "https://downloads.arduino.cc/tools/$name",
27+
"archiveFileName": "$name",
28+
"checksum": "SHA-256:$hash",
29+
"size": "$len"
30+
}
31+
EOF
32+
}
33+
34+
build_for_arch() {
35+
local os=$1
36+
local arch=$2
37+
local plat=$3
38+
39+
if [ "$os" == "windows" ]; then
40+
app_ext=".exe"
41+
pkg_ext=".zip"
42+
pkg_cmd="zip -qr"
43+
else
44+
app_ext=""
45+
pkg_ext=".tar.gz"
46+
pkg_cmd="tar -czf"
47+
fi
48+
49+
local tool_stem="$DIR/$TOOL_NAME-$VERSION"
50+
local build_dir="$tool_stem/$plat"
51+
local build_file="$TOOL_NAME$app_ext"
52+
local package_file="$tool_stem-$plat$pkg_ext"
53+
54+
echo "Building $TOOL_NAME for $os/$arch ($plat)"
55+
mkdir -p "$build_dir"
56+
(cd $BASE_DIR/extra/$TOOL_NAME && GOOS="$os" GOARCH="$arch" go build -o "$build_dir/$build_file")
57+
(cd "$tool_stem" && $pkg_cmd "$package_file" $plat/)
58+
hash_file $plat "$package_file" > $build_dir.json
59+
}
60+
61+
build_json() {
62+
temp_file=$(mktemp)
63+
echo "{ \"packages\": [ { \"tools\": [ { \"name\": \"$TOOL_NAME\", \"version\": \"$VERSION\", \"systems\":" > $temp_file
64+
ls $DIR/$TOOL_NAME-$VERSION/*.json | sort | xargs cat | jq -s . >> $temp_file
65+
echo "} ] } ] }" >> $temp_file
66+
jq . $temp_file > $DIR/$TOOL_NAME-$VERSION.json
67+
rm -f $temp_file $DIR/$TOOL_NAME-$VERSION/*.json
68+
}
69+
70+
build_for_arch "linux" "amd64" "x86_64-linux-gnu"
71+
build_for_arch "linux" "arm64" "aarch64-linux-gnu"
72+
build_for_arch "darwin" "amd64" "i386-apple-darwin11"
73+
build_for_arch "windows" "386" "i686-mingw32"
74+
build_json
75+
echo "Build completed for $TOOL_NAME $VERSION: $DIR/$TOOL_NAME-$VERSION.json"

extra/zephyr-sketch-tool/build.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)