Skip to content
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

enhance(main/dart): enable auto updates #21508

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 64 additions & 35 deletions packages/dart/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,54 @@ TERMUX_PKG_DESCRIPTION="Dart is a general-purpose programming language"
TERMUX_PKG_LICENSE="BSD"
TERMUX_PKG_LICENSE_FILE="sdk/LICENSE"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=3.4.4
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_VERSION=3.5.3
TERMUX_PKG_SRCURL=https://github.com/dart-lang/sdk/archive/refs/tags/${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=ee2cfea26c9eb22a5e7df5f68e13863d4e55ff14c06a286bf98d866f7b85652d
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_AUTO_UPDATE=true
TERMUX_PKG_UPDATE_TAG_TYPE='newest-tag'
TERMUX_PKG_UPDATE_VERSION_REGEXP='^\d+.\d+.\d+$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this regex pattern is valid but it's not sed compatible (like \d is not supported, + should be \+).

Prefer [0-9]\+\.[0-9]\+\.[0-9]\+.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That check is done here.

# If needed, filter version numbers using grep regexp.
if [[ -n "${TERMUX_PKG_UPDATE_VERSION_REGEXP:-}" ]]; then
# Extract version numbers.
local OLD_LATEST_VERSION="${LATEST_VERSION}"
LATEST_VERSION="$(grep -oP "${TERMUX_PKG_UPDATE_VERSION_REGEXP}" <<< "${LATEST_VERSION}" || true)"
if [[ -z "${LATEST_VERSION:-}" ]]; then
termux_error_exit <<-EndOfError
ERROR: failed to filter version numbers using regexp '${TERMUX_PKG_UPDATE_VERSION_REGEXP}'.
Ensure that it works correctly with ${OLD_LATEST_VERSION}.
EndOfError
fi
unset OLD_LATEST_VERSION
fi


# Dart uses tar and gzip to extract downloaded packages.
# Busybox-based versions of such utilities cause issues so
# complete ones should be used.
TERMUX_PKG_DEPENDS="gzip, tar"

termux_step_get_source() {
mkdir -p $TERMUX_PKG_SRCDIR
cd $TERMUX_PKG_SRCDIR
termux_pkg_auto_update() {
# Taken from packages/taplo

# Get latest release tag:
local api_url="https://api.github.com/repos/dart-lang/sdk/git/refs/tags"
Comment on lines +22 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION (official) instead of the GitHub API to fetch latest stable dart version.

The response of that GitHub API URL is too large and you've to filter the latest release later in which case it's not ideal.

local latest_refs_tags
latest_refs_tags=$(curl -s "${api_url}" | jq '.[].ref' | sed -ne "s|.*${TERMUX_PKG_UPDATE_VERSION_REGEXP}\"|\1|p")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm facing an error with the sed expression.

sed: -e expression #1, char 23: invalid reference \1 on `s' command's RHS

Perhaps, you've forgotten to add the group construct? i.e

"s|.*\(${TERMUX_PKG_UPDATE_VERSION_REGEXP}\)\"|\1|p"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh crap I completely forgot about this PR.

if [[ -z "${latest_refs_tags}" ]]; then
echo "WARN: Unable to get latest refs tags from upstream. Try again later." >&2
return
fi

local latest_version
latest_version=$(tail -n1 <<< "$latest_refs_tags")
if [[ "${latest_version}" == "${TERMUX_PKG_VERSION}" ]]; then
echo "INFO: No update needed. Already at version '${TERMUX_PKG_VERSION}'."
return
fi

# We want to avoid re-filtering the version.
# It's already cleaned up, so unset the regexp.
# See: https://github.com/termux/termux-packages/issues/20836
unset TERMUX_PKG_UPDATE_VERSION_REGEXP

termux_pkg_upgrade_version "${latest_version}"
}

termux_step_post_get_source() {
git clone --depth=1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
mkdir -p depot_tools/fakebin
ln -sfr /usr/bin/python depot_tools/fakebin/python
export PATH="$(pwd)/depot_tools/fakebin:$(pwd)/depot_tools:${PATH}"
export PATH="${PWD}/depot_tools/fakebin:${PWD}/depot_tools:${PATH}"

fetch dart

cd sdk
git checkout $TERMUX_PKG_VERSION
cd ../

echo "target_os = ['android']" >> .gclient
gclient sync -D --force --reset
}
Expand All @@ -47,35 +70,41 @@ termux_step_make_install() {

rm -f ./out/*/args.gn

if [ $TERMUX_ARCH = "arm" ]; then
python3 ./tools/build.py --no-goma --mode release --arch=arm --os=android create_sdk
chmod +x ./out/ReleaseAndroidARM/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidARM/dart-sdk ${TERMUX_PREFIX}/lib
elif [ $TERMUX_ARCH = "i686" ]; then
python3 ./tools/build.py --no-goma --mode release --arch=ia32 --os=android create_sdk
chmod +x ./out/ReleaseAndroidIA32/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidIA32/dart-sdk ${TERMUX_PREFIX}/lib
elif [ $TERMUX_ARCH = "aarch64" ]; then
python3 ./tools/build.py --no-goma --mode release --arch=arm64c --os=android create_sdk
chmod +x ./out/ReleaseAndroidARM64C/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidARM64C/dart-sdk ${TERMUX_PREFIX}/lib
elif [ $TERMUX_ARCH = "x86_64" ]; then
python3 ./tools/build.py --no-goma --mode release --arch=x64c --os=android create_sdk
chmod +x ./out/ReleaseAndroidX64C/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidX64C/dart-sdk ${TERMUX_PREFIX}/lib
else
termux_error_exit "Unsupported arch '$TERMUX_ARCH'"
fi
case "$TERMUX_ARCH" in
"arm")
python3 ./tools/build.py --no-rbe --mode release --arch=arm --os=android create_sdk
chmod +x ./out/ReleaseAndroidARM/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidARM/dart-sdk "${TERMUX_PREFIX}/lib"
;;
"i686")
python3 ./tools/build.py --no-rbe --mode release --arch=ia32 --os=android create_sdk
chmod +x ./out/ReleaseAndroidIA32/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidIA32/dart-sdk "${TERMUX_PREFIX}/lib"
;;
"aarch64")
python3 ./tools/build.py --no-rbe --mode release --arch=arm64c --os=android create_sdk
chmod +x ./out/ReleaseAndroidARM64C/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidARM64C/dart-sdk "${TERMUX_PREFIX}/lib"
;;
"x86_64")
python3 ./tools/build.py --no-rbe --mode release --arch=x64c --os=android create_sdk
chmod +x ./out/ReleaseAndroidX64C/dart-sdk/bin/*
cp -r ./out/ReleaseAndroidX64C/dart-sdk "${TERMUX_PREFIX}/lib"
;;
*)
termux_error_exit "Unsupported arch '$TERMUX_ARCH'"
;;
esac

for file in ${TERMUX_PREFIX}/lib/dart-sdk/bin/*; do
for file in "${TERMUX_PREFIX}/lib/dart-sdk/bin"/*; do
if [[ -f "$file" ]]; then
echo -e "#!${TERMUX_PREFIX}/bin/sh\nexec $file \"\$@\"" > ${TERMUX_PREFIX}/bin/$(basename $file)
chmod +x ${TERMUX_PREFIX}/bin/$(basename $file)
echo -e "#!${TERMUX_PREFIX}/bin/sh\nexec $file \"\$@\"" > "${TERMUX_PREFIX}/bin/$(basename "$file")"
chmod +x "${TERMUX_PREFIX}/bin/$(basename "$file")"
fi
done
}

termux_step_post_make_install() {
install -Dm600 $TERMUX_PKG_BUILDER_DIR/dart-pub-bin.sh \
$TERMUX_PREFIX/etc/profile.d/dart-pub-bin.sh
install -Dm600 "$TERMUX_PKG_BUILDER_DIR/dart-pub-bin.sh" \
"$TERMUX_PREFIX/etc/profile.d/dart-pub-bin.sh"
}