这是indexloc提供的服务,不要输入任何密码
Skip to content

[WIP]: Add termux_step_install_icons to generate and install application icons. #24920

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
35 changes: 22 additions & 13 deletions build-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ termux_step_post_make_install() {
return
}

# Generate application icons and place them in the package.
# shellcheck source=scripts/build/termux_step_install_icons.sh
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_icons.sh"

# Install hooks (alpm-hooks) and hook-scripts into the pacman package
# shellcheck source=scripts/build/termux_step_install_pacman_hooks.sh
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_pacman_hooks.sh"
Expand Down Expand Up @@ -645,19 +649,19 @@ for ((i=0; i<${#PACKAGE_LIST[@]}; i++)); do
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then
for arch in 'aarch64' 'arm' 'i686' 'x86_64'; do
env TERMUX_ARCH="$arch" TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh \
$(test "${TERMUX_CLEANUP_BUILT_PACKAGES_ON_LOW_DISK_SPACE:-}" = "true" && echo "-C") \
$(test "${TERMUX_DEBUG_BUILD:-}" = "true" && echo "-d") \
$(test "${TERMUX_IS_DISABLED:-}" = "true" && echo "-D") \
$({ test "${TERMUX_FORCE_BUILD:-}" = "true" && test "${TERMUX_FORCE_BUILD_DEPENDENCIES:-}" != "true"; } && echo "-f") \
$({ test "${TERMUX_FORCE_BUILD:-}" = "true" && test "${TERMUX_FORCE_BUILD_DEPENDENCIES:-}" = "true"; } && echo "-F") \
$({ test "${TERMUX_INSTALL_DEPS:-}" = "true" && test "${TERMUX_PKGS__BUILD__RM_ALL_PKGS_BUILT_MARKER_AND_INSTALL_FILES:-}" != "false"; } && echo "-i") \
$({ test "${TERMUX_INSTALL_DEPS:-}" = "true" && test "${TERMUX_PKGS__BUILD__RM_ALL_PKGS_BUILT_MARKER_AND_INSTALL_FILES:-}" = "false"; } && echo "-I") \
$(test "${TERMUX_GLOBAL_LIBRARY:-}" = "true" && echo "-L") \
$(test -n "${TERMUX_OUTPUT_DIR:-}" && echo "-o $TERMUX_OUTPUT_DIR") \
$(test "${TERMUX_PKGS__BUILD__RM_ALL_PKG_BUILD_DEPENDENT_DIRS:-}" = "true" && echo "-r") \
$(test "${TERMUX_WITHOUT_DEPVERSION_BINDING:-}" = "true" && echo "-w") \
$(test -n "${TERMUX_PACKAGE_FORMAT:-}" && echo "--format $TERMUX_PACKAGE_FORMAT") \
$(test -n "${TERMUX_PACKAGE_LIBRARY:-}" && echo "--library $TERMUX_PACKAGE_LIBRARY") \
$(test "${TERMUX_CLEANUP_BUILT_PACKAGES_ON_LOW_DISK_SPACE:-}" = "true" && echo "-C") \
$(test "${TERMUX_DEBUG_BUILD:-}" = "true" && echo "-d") \
$(test "${TERMUX_IS_DISABLED:-}" = "true" && echo "-D") \
$({ test "${TERMUX_FORCE_BUILD:-}" = "true" && test "${TERMUX_FORCE_BUILD_DEPENDENCIES:-}" != "true"; } && echo "-f") \
$({ test "${TERMUX_FORCE_BUILD:-}" = "true" && test "${TERMUX_FORCE_BUILD_DEPENDENCIES:-}" = "true"; } && echo "-F") \
$({ test "${TERMUX_INSTALL_DEPS:-}" = "true" && test "${TERMUX_PKGS__BUILD__RM_ALL_PKGS_BUILT_MARKER_AND_INSTALL_FILES:-}" != "false"; } && echo "-i") \
$({ test "${TERMUX_INSTALL_DEPS:-}" = "true" && test "${TERMUX_PKGS__BUILD__RM_ALL_PKGS_BUILT_MARKER_AND_INSTALL_FILES:-}" = "false"; } && echo "-I") \
$(test "${TERMUX_GLOBAL_LIBRARY:-}" = "true" && echo "-L") \
$(test -n "${TERMUX_OUTPUT_DIR:-}" && echo "-o $TERMUX_OUTPUT_DIR") \
$(test "${TERMUX_PKGS__BUILD__RM_ALL_PKG_BUILD_DEPENDENT_DIRS:-}" = "true" && echo "-r") \
$(test "${TERMUX_WITHOUT_DEPVERSION_BINDING:-}" = "true" && echo "-w") \
$(test -n "${TERMUX_PACKAGE_FORMAT:-}" && echo "--format $TERMUX_PACKAGE_FORMAT") \
$(test -n "${TERMUX_PACKAGE_LIBRARY:-}" && echo "--library $TERMUX_PACKAGE_LIBRARY") \
"${PACKAGE_LIST[i]}"
done
exit
Expand Down Expand Up @@ -740,6 +744,11 @@ for ((i=0; i<${#PACKAGE_LIST[@]}; i++)); do
termux_run_base_and_multilib_build_step termux_step_make_install
cd "$TERMUX_PKG_BUILDDIR"
termux_step_post_make_install
if [ -n "$TERMUX_PKG_ICONS" ]; then
cd "$TERMUX_PKG_SRCDIR"
termux_step_install_icons
cd "$TERMUX_PKG_BUILDDIR"
fi
termux_step_install_pacman_hooks
termux_step_install_service_scripts
termux_step_install_license
Expand Down
25 changes: 18 additions & 7 deletions packages/mpv/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ TERMUX_PKG_LICENSE="GPL-2.0-or-later"
TERMUX_PKG_MAINTAINER="Joshua Kahn @TomJo2000"
# Update both mpv and mpv-x to the same version in one PR.
TERMUX_PKG_VERSION="0.40.0"
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://github.com/mpv-player/mpv/archive/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=10a0f4654f62140a6dd4d380dcf0bbdbdcf6e697556863dc499c296182f081a3
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_DEPENDS="alsa-lib, ffmpeg, jack, libandroid-glob, libandroid-support, libarchive, libass, libcaca, libiconv, liblua52, libsixel, libuchardet, openal-soft, pulseaudio, rubberband, zlib, libplacebo"
TERMUX_PKG_RM_AFTER_INSTALL="share/icons share/applications"
TERMUX_PKG_ICONS="etc/mpv.svg, etc/mpv-gradient.svg, etc/mpv-symbolic.svg"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-Dlibmpv=true
-Dlua=lua52
Expand All @@ -31,22 +32,32 @@ TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-Dandroid-media-ndk=disabled
"

# shellcheck disable=SC2031
termux_step_post_get_source() {
# Version guard
local ver_m=${TERMUX_PKG_VERSION#*:}
local ver_x=$(. $TERMUX_SCRIPTDIR/x11-packages/mpv-x/build.sh; echo ${TERMUX_PKG_VERSION#*:})
if [ "${ver_m}" != "${ver_x}" ]; then
local ver_m ver_x
ver_m="${TERMUX_PKG_VERSION#*:}"
ver_x="$(. "$TERMUX_SCRIPTDIR/x11-packages/mpv-x/build.sh"; echo "${TERMUX_PKG_VERSION#*:}")"
if [[ "${ver_m}" != "${ver_x}" ]]; then
termux_error_exit "Version mismatch between mpv and mpv-x."
fi
}

termux_step_pre_configure() {
LDFLAGS+=" -landroid-glob"
sed -i "s/host_machine.system() == 'android'/false/" ${TERMUX_PKG_SRCDIR}/meson.build
sed -i "s/host_machine.system() == 'android'/false/" "${TERMUX_PKG_SRCDIR}/meson.build"
}

termux_step_post_make_install() {
# Use opensles audio out by default:
install -Dm600 -t $TERMUX_PREFIX/etc/mpv/ $TERMUX_PKG_BUILDER_DIR/mpv.conf
install -Dm600 -t $TERMUX_PREFIX/share/mpv/scripts/ $TERMUX_PKG_SRCDIR/TOOLS/lua/*
install -Dm600 -t "$TERMUX_PREFIX/etc/mpv/" "$TERMUX_PKG_BUILDER_DIR/mpv.conf"
install -Dm600 -t "$TERMUX_PREFIX/share/mpv/scripts/" "$TERMUX_PKG_SRCDIR/TOOLS/lua"/*

# shell completions
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/mpv.bash-completion" "$TERMUX_PREFIX/share/bash-completion/completions/mpv.bash"
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/mpv.fish" "$TERMUX_PREFIX/share/fish/vendor_completions.d/mpv.fish"
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/_mpv.zsh" "$TERMUX_PREFIX/share/zsh/site-functions/_mpv"

# desktop entry
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/mpv.desktop" "$TERMUX_PREFIX/share/applications/mpv.desktop"
}
27 changes: 10 additions & 17 deletions packages/yazi/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ TERMUX_PKG_DESCRIPTION="Blazing fast terminal file manager written in Rust, base
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="25.5.31"
TERMUX_PKG_REVISION=1
TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=https://github.com/sxyazi/yazi/archive/refs/tags/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=4d005e7c3f32b5574d51ab105597f3da3a4be2f7b5cd1bcb284143ad38253ed4
TERMUX_PKG_BUILD_DEPENDS='aosp-libs, imagemagick'
TERMUX_PKG_AUTO_UPDATE=true
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_ICONS="assets/logo.png"
TERMUX_PKG_ICON_NAMES="yazi"

termux_step_pre_configure() {
termux_setup_rust
[[ "$TERMUX_ON_DEVICE_BUILD" == "false" ]] && termux_setup_proot
# Fix for `TERMUX_ON_DEVICE_BUILD=true` builds
# To prevent `ld.lld: error: unable to find library -lgcc`
# Should have been fixed in Rust 1.54.0 (https://github.com/rust-lang/rust/pull/85806)
# But still seems to occur.
echo "INPUT(-lunwind)" > "${TERMUX_PKG_BUILDDIR}/libgcc.a"
local -u env_host="${CARGO_TARGET_NAME//-/_}"
export CARGO_TARGET_"${env_host}"_RUSTFLAGS+=" -L ${TERMUX_PKG_BUILDDIR}"
}

termux_step_make() {
Expand All @@ -34,20 +41,6 @@ termux_step_make_install() {

# desktop entry
install -Dm644 assets/yazi.desktop "$TERMUX_PREFIX/share/applications/yazi.desktop"

# application icons
local res
echo -n "Generating icons:"
for res in 16 24 32 48 64 128 256; do
mkdir -p "${TERMUX_PREFIX}/share/icons/hicolor/${res}x${res}/apps"
termux-proot-run magick assets/logo.png \
-resize "${res}x${res}" \
"${TERMUX_PREFIX}/share/icons/hicolor/${res}x${res}/apps/yazi.png"
[[ -e "${TERMUX_PREFIX}/share/icons/hicolor/${res}x${res}/apps/yazi.png" ]] && {
echo -n " ${res}x${res}"
}
done
echo
}

termux_step_create_debscripts() {
Expand Down
69 changes: 69 additions & 0 deletions scripts/build/termux_step_install_icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# shellcheck shell=bash
termux_step_install_icons() {
local termux_run_wrapper=''
# Check if we need to wrap calls to `imagemagick` with `termux-proot-run`.
if [[ "$TERMUX_ON_DEVICE_BUILD" != 'true' ]]; then
termux_setup_proot
termux_run_wrapper='termux-proot-run'
fi

local -a ICON_SIZES=() ICON_NAMES=() ICONS=()
local res icon_name icon idx

# defaults to (16 24 32 48 64 128 256)
while read -r res; do
ICON_SIZES+=("$res")
done <<< "${TERMUX_PKG_ICON_SIZES//,/$'\n'}"

while read -r icon; do
ICONS+=("$icon")
done <<< "${TERMUX_PKG_ICONS//,/$'\n'}"

if [[ -n "${TERMUX_PKG_ICON_NAMES}" ]]; then
while read -r icon_name; do
ICON_NAMES+=("$icon_name")
done <<< "${TERMUX_PKG_ICON_NAMES//,/$'\n'}"
else # If we have no names given just take off the extensions from the icon filenames.
for icon in "${ICONS[@]}"; do
: "$(basename "$icon")"
ICON_NAMES+=("${_%.*}")
done
fi

# Make sure we have a matching abmount of icons and icon names.
if (( ${#ICONS[*]} != ${#ICON_NAMES[*]} )); then
echo "termux_step_install_icons: error: mismatch between amount of icons and icon names"
echo "ICONS : (${#ICONS[*]}) ${ICONS[*]}"
echo "ICON_NAMES: (${#ICON_NAMES[*]}) ${ICON_NAMES[*]}"
return 1
fi

# Loop over the list of icons and put them in the appropriate directory
for (( idx = 0 ; idx < ${#ICONS[*]} ; idx++ )); do
printf '%s' "Generating icons for ${ICON_NAMES[$idx]}:"

# Is this a symbolic vector icon?
if [[ "${ICONS[$idx]}" == *'symbolic'*'.svg' ]]; then
install -Dm644 "${ICONS[$idx]}" "${TERMUX_PREFIX}/share/icons/hicolor/symbolic/apps/${ICON_NAMES[$idx]}.svg"
printf ' %s\n' "symbolic"
continue
fi

# Generate the different sizes
for res in "${ICON_SIZES[@]}"; do
# Make a ${res}x${res} version of the icon
mkdir -p "${TERMUX_PREFIX}/share/icons/hicolor/${res}x${res}/apps"
${termux_run_wrapper:-} magick "${ICONS[$idx]}" \
-resize "${res}x${res}" \
"${TERMUX_PREFIX}/share/icons/hicolor/${res}x${res}/apps/${ICON_NAMES[$idx]}.png"
printf ' %s' "${res}x${res}"
done

# Is this a vector icon?
if [[ "${ICONS[$idx]}" == *'.svg' ]]; then
install -Dm644 "${ICONS[$idx]}" "${TERMUX_PREFIX}/share/icons/hicolor/scalable/apps/${ICON_NAMES[$idx]}.svg"
printf ' %s' "scalable"
fi
echo
done
}
3 changes: 3 additions & 0 deletions scripts/build/termux_step_setup_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ termux_step_setup_variables() {
TERMUX_PKG_MESON_NATIVE=false
TERMUX_PKG_CMAKE_CROSSCOMPILING=true
TERMUX_PROOT_EXTRA_ENV_VARS="" # Extra environvent variables for proot command in termux_setup_proot
TERMUX_PKG_ICONS="" # Icon file(s) for this package (relative to the $TERMUX_PKG_SRCDIR)
TERMUX_PKG_ICON_NAMES="" # Icon names for this package
TERMUX_PKG_ICON_SIZES="16, 24, 32, 48, 64, 128, 256" # Default sizes to generate application icons for

unset CFLAGS CPPFLAGS LDFLAGS CXXFLAGS
unset TERMUX_MESON_ENABLE_SOVERSION # setenv to enable SOVERSION suffix for shared libs built with Meson
Expand Down
12 changes: 11 additions & 1 deletion scripts/buildorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ def parse_build_file_dependencies_with_vars(path, vars):

def parse_build_file_dependencies(path):
"Extract the dependencies of a build.sh or *.subpackage.sh file."
return parse_build_file_dependencies_with_vars(path, ('TERMUX_PKG_DEPENDS', 'TERMUX_PKG_BUILD_DEPENDS', 'TERMUX_SUBPKG_DEPENDS', 'TERMUX_PKG_DEVPACKAGE_DEPENDS'))
build_deps = parse_build_file_dependencies_with_vars(path, ('TERMUX_PKG_DEPENDS', 'TERMUX_PKG_BUILD_DEPENDS', 'TERMUX_SUBPKG_DEPENDS'))
# Add 'aosp-libs' and 'imagemagick' to the dependency list
# if we have icons to install as part of the build
with open(path, encoding="utf-8") as build_script:
for line in build_script:
if line.startswith('TERMUX_PKG_ICONS='):
build_deps.add('imagemagick')
if not os.getenv('TERMUX_ON_DEVICE_BUILD') == "true":
build_deps.add('aosp-libs')
break
return set(build_deps)

def parse_build_file_antidependencies(path):
"Extract the antidependencies of a build.sh file."
Expand Down
25 changes: 19 additions & 6 deletions x11-packages/mpv-x/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ TERMUX_PKG_LICENSE="GPL-2.0-or-later"
TERMUX_PKG_MAINTAINER="Joshua Kahn @TomJo2000"
# Update both mpv and mpv-x to the same version in one PR.
TERMUX_PKG_VERSION="0.40.0"
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://github.com/mpv-player/mpv/archive/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=10a0f4654f62140a6dd4d380dcf0bbdbdcf6e697556863dc499c296182f081a3
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_DEPENDS="alsa-lib, ffmpeg, jack, libandroid-glob, libandroid-shmem, libarchive, libass, libbluray, libcaca, libdrm, libdvdnav, libiconv, libjpeg-turbo, liblua52, libsixel, libuchardet, libx11, libxext, libxinerama, libxpresent, libxrandr, libxss, libzimg, littlecms, openal-soft, pipewire, pulseaudio, rubberband, zlib, libplacebo"
TERMUX_PKG_ICONS="etc/mpv.svg, etc/mpv-gradient.svg, etc/mpv-symbolic.svg"
TERMUX_PKG_CONFLICTS="mpv"
TERMUX_PKG_REPLACES="mpv"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
Expand All @@ -25,21 +27,32 @@ TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-Dandroid-media-ndk=disabled
"

# shellcheck disable=SC2031
termux_step_post_get_source() {
# Version guard
local ver_m=$(. $TERMUX_SCRIPTDIR/packages/mpv/build.sh; echo ${TERMUX_PKG_VERSION#*:})
local ver_x=${TERMUX_PKG_VERSION#*:}
if [ "${ver_m}" != "${ver_x}" ]; then
local ver_m ver_x
ver_x=${TERMUX_PKG_VERSION#*:}
ver_m="$(. "$TERMUX_SCRIPTDIR/packages/mpv/build.sh"; echo "${TERMUX_PKG_VERSION#*:}")"
if [[ "${ver_m}" != "${ver_x}" ]]; then
termux_error_exit "Version mismatch between mpv and mpv-x."
fi
}

termux_step_pre_configure() {
LDFLAGS+=" -landroid-glob -landroid-shmem"
sed -i "s/host_machine.system() == 'android'/false/" ${TERMUX_PKG_SRCDIR}/meson.build
sed -i "s/host_machine.system() == 'android'/false/" "${TERMUX_PKG_SRCDIR}/meson.build"
}

termux_step_post_make_install() {
install -Dm600 -t $TERMUX_PREFIX/etc/mpv/ $TERMUX_PKG_BUILDER_DIR/mpv.conf
install -Dm600 -t $TERMUX_PREFIX/share/mpv/scripts/ $TERMUX_PKG_SRCDIR/TOOLS/lua/*
# Use opensles audio out by default:
install -Dm600 -t "$TERMUX_PREFIX/etc/mpv/" "$TERMUX_PKG_BUILDER_DIR/mpv.conf"
install -Dm600 -t "$TERMUX_PREFIX/share/mpv/scripts/" "$TERMUX_PKG_SRCDIR/TOOLS/lua"/*

# shell completions
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/mpv.bash-completion" "$TERMUX_PREFIX/share/bash-completion/completions/mpv.bash"
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/mpv.fish" "$TERMUX_PREFIX/share/fish/vendor_completions.d/mpv.fish"
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/_mpv.zsh" "$TERMUX_PREFIX/share/zsh/site-functions/_mpv"

# desktop entry
install -Dm644 "$TERMUX_PKG_SRCDIR/etc/mpv.desktop" "$TERMUX_PREFIX/share/applications/mpv.desktop"
}