247 lines
6.2 KiB
Bash
Executable File
247 lines
6.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
job_start=0
|
|
|
|
job_start() {
|
|
# [*] job start - [target]:[job]
|
|
# bold
|
|
echo -e "\e[1m[*] job start - $1:$2\e[0m"
|
|
job_start=$(date +%s.%N)
|
|
}
|
|
job_success() {
|
|
# [*] success! [target]:[job] finished in 241.2s :)
|
|
end=$(date +%s.%N)
|
|
time=$( echo "$end - $job_start" | bc -l )
|
|
echo -e "\e[1m\e[32m[*] success! $1:$2 finished in $time seconds :)\e[0m"
|
|
}
|
|
job_fail() {
|
|
# [x] FAIL! [target]:[job] failed in 241.2s :(
|
|
end=$(date +%s.%N)
|
|
time=$( echo "$end - $job_start" | bc -l )
|
|
echo -e "\e[1m\e[31m[*] FAIL! $1:$2 failed in $time seconds :(\e[0m"
|
|
}
|
|
job_skip() {
|
|
# [-] skipped - [target]:[job] skipped in 241.2s
|
|
end=$(date +%s.%N)
|
|
time=$( echo "$end - $job_start" | bc -l )
|
|
echo -e "\e[1m\e[34m[-] skipped - $1:$2 skipped after $time seconds\e[0m"
|
|
}
|
|
|
|
sub_clone() {
|
|
job_start "scratch-blocks" "clone"
|
|
if [ -d "$(pwd)/scratch-blocks" ]; then
|
|
echo "Clone dir already exists"
|
|
job_skip "scratch-blocks" "clone"
|
|
else
|
|
git clone https://github.com/scratchfoundation/scratch-blocks scratch-blocks
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "scratch-blocks" "clone"
|
|
exit 1
|
|
fi
|
|
job_success "scratch-blocks" "clone"
|
|
fi
|
|
job_start "scratch-blocks" "checkout"
|
|
pbase=$(cat patches/blocks/PATCHBASE | tr -d '\n')
|
|
echo "Checking out scratch-blocks patchbase $pbase"
|
|
cd scratch-blocks || exit
|
|
git checkout "$pbase"
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "scratch-blocks" "checkout"
|
|
exit 1
|
|
fi
|
|
cd .. || exit
|
|
job_success "scratch-blocks" "checkout"
|
|
|
|
job_start "scratch-gui" "clone"
|
|
if [ -d "$(pwd)/scratch-gui" ]; then
|
|
echo "Clone dir already exists"
|
|
job_skip "scratch-gui" "clone"
|
|
else
|
|
git clone https://github.com/scratchfoundation/scratch-gui scratch-gui
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "scratch-gui" "clone"
|
|
exit 1
|
|
fi
|
|
job_success "scratch-gui" "clone"
|
|
fi
|
|
job_start "scratch-gui" "checkout"
|
|
pbase=$(cat patches/gui/PATCHBASE | tr -d '\n')
|
|
echo "Checking out scratch-gui patchbase $pbase"
|
|
cd scratch-gui || exit
|
|
git checkout "$pbase"
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "scratch-gui" "checkout"
|
|
exit 1
|
|
fi
|
|
cd .. || exit
|
|
job_success "scratch-gui" "checkout"
|
|
}
|
|
|
|
sub_patch() {
|
|
sub_clone
|
|
|
|
job_start "scratch-blocks" "patch"
|
|
|
|
cd scratch-blocks || exit
|
|
|
|
git am --abort >/dev/null 2>&1
|
|
|
|
git am --3way "../patches/blocks/"*.patch
|
|
if [ "$?" != "0" ]; then
|
|
echo "One or more patches did not apply cleanly to scratch-blocks. Check above message and try again".
|
|
job_fail "scratch-blocks" "patch"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[*] Patches applied cleanly to scratch-blocks"
|
|
|
|
cd .. || exit
|
|
|
|
job_success "scratch-blocks" "patch"
|
|
|
|
job_start "scratch-gui" "patch"
|
|
|
|
cd scratch-gui || exit
|
|
|
|
git am --abort >/dev/null 2>&1
|
|
|
|
git am --3way "../patches/gui/"*.patch
|
|
if [ "$?" != "0" ]; then
|
|
echo "One or more patches did not apply cleanly to scratch-gui. Check above message and try again".
|
|
job_fail "scratch-gui" "patch"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[*] Patches applied cleanly to scratch-gui"
|
|
|
|
cd .. || exit
|
|
|
|
job_success "scratch-gui" "patch"
|
|
}
|
|
|
|
sub_compile() {
|
|
sub_patch
|
|
|
|
job_start "scratch-blocks" "compile"
|
|
|
|
cd scratch-blocks || exit
|
|
|
|
NODE_OPTIONS=--openssl-legacy-provider npm i
|
|
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "scratch-blocks" "compile"
|
|
exit 1
|
|
fi
|
|
|
|
npm link
|
|
|
|
if [ "$?" != "0" ]; then
|
|
echo "Unable to configure scratch-gui to use scratch-blocks. Check above message and try again".
|
|
job_fail "scratch-blocks" "compile"
|
|
exit 1
|
|
fi
|
|
|
|
cd .. || exit
|
|
|
|
job_success "scratch-blocks" "compile"
|
|
|
|
job_start "scratch-gui" "compile"
|
|
|
|
cd scratch-gui || exit
|
|
|
|
npm link scratch-blocks
|
|
if [ "$?" != "0" ]; then
|
|
echo "Unable to configure scratch-gui to use scratch-blocks. Check above message and try again".
|
|
job_fail "scratch-gui" "compile"
|
|
exit 1
|
|
fi
|
|
npm i
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "scratch-gui" "compile"
|
|
exit 1
|
|
fi
|
|
|
|
cd .. || exit
|
|
|
|
job_success "scratch-gui" "compile"
|
|
}
|
|
|
|
sub_patchc() {
|
|
job_start "generic" "patch-create:collect-info"
|
|
read -rp "Enter the current project name: " project
|
|
read -rp "Enter the patchlist ID (blocks for scratch-blocks): " plist
|
|
job_success "generic" "patch-create:collect-info"
|
|
job_start "$project" "patch-create"
|
|
cd "$project" || exit
|
|
fname=$(git format-patch -1 HEAD -o ../patches/"$plist"/)
|
|
base=$(basename "$fname")
|
|
patchnumnp=$(find ../patches/"$plist" -type f -name "*.patch" | wc -l)
|
|
patchnum=$(printf "%04d" "$patchnumnp")
|
|
nonumfname="$(echo "$base" | cut -c 5-)"
|
|
newfname="$patchnum$nonumfname"
|
|
newpath=$(echo "$fname" | sed "s/$base/$newfname/" -)
|
|
mv "$fname" "$newpath"
|
|
echo "Wrote out patch file to $newfname"
|
|
job_success "$project" "patch-create"
|
|
echo "Checking that patch file applies cleanly"
|
|
job_start "$project" "patch-check"
|
|
cd .. || exit
|
|
sub_patch
|
|
job_success "$project" "patch-check"
|
|
}
|
|
|
|
sub_reset() {
|
|
sub_clone
|
|
}
|
|
|
|
sub_pkg() {
|
|
cd pyblocks-gui || exit
|
|
|
|
job_start "pyblocks-gui" "build:win"
|
|
yarn run package --x64 --ia32 --arm64 --win nsis portable
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "pyblocks-gui" "build:win"
|
|
exit 1
|
|
fi
|
|
job_success "pyblocks-gui" "build:win"
|
|
|
|
job_start "pyblocks-gui" "build:lin"
|
|
yarn run package --x64 --ia32 --armv7l --arm64 --linux AppImage flatpak snap deb rpm freebsd pacman p5p apk 7z zip tar.xz tar.lz tar.gz tar.bz2
|
|
if [ "$?" != "0" ]; then
|
|
job_fail "pyblocks-gui" "build:lin"
|
|
exit 1
|
|
fi
|
|
job_success "pyblocks-gui" "build:lin"
|
|
|
|
cd .. || exit
|
|
}
|
|
|
|
sub_help() {
|
|
echo "--- PyBlocks Build Tool ---"
|
|
echo "usage: ./pbt.sh [command]"
|
|
echo " clone - clone upstream source code"
|
|
echo " patch - (re)apply patches"
|
|
echo " compile - compile bundles"
|
|
echo " bundle - create prod bundles"
|
|
echo " patchc - create a patch for the current project"
|
|
echo " reset - reset to upstream patch base (equivalent to clone)"
|
|
echo " pkg - Create packages for every platform for gui"
|
|
}
|
|
|
|
subcommand=$1
|
|
case $subcommand in
|
|
"" | "-h" | "--help" | "help")
|
|
sub_help
|
|
;;
|
|
*)
|
|
echo "[*] Running build command $subcommand"
|
|
shift
|
|
sub_"${subcommand}" "$@"
|
|
if [ $? = 127 ]; then
|
|
echo "Error: '$subcommand' is not a known subcommand." >&2
|
|
echo " Run 'pbt.sh --help' for a list of known subcommands." >&2
|
|
exit 1
|
|
fi
|
|
;;
|
|
esac
|