Termux Packages

repository·master·Indexed 12 days ago

https://github.com/termux/termux-packages

Scripts and patches used to build software packages for the Termux Android application environment. Includes documentation on package management, build configurations for packages like calc, and internal shell functions for managing scoped environment variables and app version information.

Tokens
7.9K
Snippets
19
Records
26
Agent score
93%

What's inside Termux Packages

  1. How package auto-updates work

    master

    The update process follows a specific lifecycle to ensure stability and efficiency:

    1. Pre-fetching: The tool identifies all packages to be processed and uses GraphQL (for GitHub) or Repology data to fetch the latest available versions in bulk.
    2. Filtering: Packages are skipped if:
      • They do not have TERMUX_PKG_AUTO_UPDATE=true in their build.sh.
      • An open GitHub issue already exists with the label auto update failing for that package.
      • The package is already at the latest version.
    3. Dependency Resolution: For any package requiring an update, the tool uses scripts/buildorder.py to find its dependencies and ensures they are updated first.
    4. Execution: The termux_pkg_auto_update() function (defined in the package's build.sh) is called to perform the actual version upgrade logic.
    5. Failure Handling: If an update fails during a GitHub Action run, the tool creates a new GitHub issue titled Auto update failing for <package_name> with the error logs included in a collapsible <details> block.
  2. Configure Readline dependencies for calc

    master

    When building calc, you can specify the location and flags for the Readline library to ensure proper terminal interaction support.

    Variables:

    • READLINE_LIB: The library flags for linking. Defaults to -L${PREFIX}/lib -lreadline.
    • READLINE_EXTRAS: Additional library flags. Defaults to -lhistory -lncurses.
    • READLINE_INCLUDE: The include path for Readline headers. Defaults to -I${PREFIX}/include.
    READLINE_LIB= -L${PREFIX}/lib -lreadline
    READLINE_EXTRAS= -lhistory -lncurses
    READLINE_INCLUDE= -I${PREFIX}/include
  3. Configure installation paths for calc

    master

    The calc package Makefile uses several variables to define the installation hierarchy. Most paths are relative to PREFIX. If you are building the package, you can override these variables to redirect the installation.

    Key installation variables:

    • PREFIX: The base installation directory. Defaults to /usr/local.
    • BINDIR: The directory for executable binaries. Defaults to ${PREFIX}/bin.
    • LIBDIR: The directory for libraries. Defaults to ${PREFIX}/lib.
    • INCDIR: The directory for header files. Defaults to ${PREFIX}/include.
    • CALC_SHAREDIR: The directory for shared data. Defaults to ${PREFIX}/lib/calc.
    • MANDIR: The directory for man section 1 pages. Defaults to ${PREFIX}/share/man/man1.
    • T: The top-level directory under which calc will be installed. This is set to ${DESTDIR} by default.
    PREFIX ?= /usr/local
    BINDIR= ${PREFIX}/bin
    LIBDIR= ${PREFIX}/lib
    INCDIR= ${PREFIX}/include
    CALC_SHAREDIR= ${PREFIX}/lib/calc
    MANDIR= ${PREFIX}/share/man/man1
    T=${DESTDIR}
  4. Configure update-packages via environment variables

    master

    The update-packages script is highly configurable through environment variables. These allow you to control the build process, update logic, and automation behavior.

    Build & Git Control

    • BUILD_PACKAGES: If set to true, the script will attempt to build the updated packages.
    • GIT_COMMIT_PACKAGES: If set to true, the script will commit changes to Git.
    • GIT_PUSH_PACKAGES: If set to true, the script will push changes to the remote repository.
    • CREATE_ISSUE: If set to true (and running in GitHub Actions), the script will create a GitHub issue if an update fails.

    Update Logic

    • TERMUX_PKG_AUTO_UPDATE: Set to true to enable auto-updates. Disabled by default.
    • TERMUX_PKG_UPDATE_METHOD: Force a specific update method: repology, github, or gitlab.
    • TERMUX_PKG_UPDATE_TAG_TYPE: Specify the tag type to use: latest-release-tag, latest-regex, or newest-tag.
    • TERMUX_PKG_UPDATE_VERSION_REGEXP: Regexp used to extract the version with grep -oP.
    • TERMUX_PKG_UPDATE_VERSION_SED_REGEXP: Regexp used to extract the version with sed.

    Architecture & Platform

    • TERMUX_ARCH: The architecture to test updates for (default: aarch64).
    • GITHUB_TOKEN: Required for GitHub GraphQL API calls and interacting with GitHub issues via the gh CLI.
  5. Convert a command string to a bash array with termux_core__bash__set_shell_command_args_array

    master

    The termux_core__bash__set_shell_command_args_array function converts a shell-style command argument string into a properly formatted bash indexed array. It handles complex cases involving spaces and shell special characters by using xargs to ensure correct parsing.

    Usage

    termux_core__bash__set_shell_command_args_array <command_args_array_variable_name> <command_args_label> <command_args_string>
    • <command_args_array_variable_name>: The name of the bash array variable to be populated.
    • <command_args_label>: A label used for error reporting.
    • <command_args_string>: The raw string containing the command arguments.

    Behavior

    • If the string contains only simple whitespace, it uses standard shell splitting.
    • If the string contains shell special characters (e.g., ", ', *, ?, !, \[, \], +) or spaces that require quoting, it uses xargs to parse the arguments correctly.
    • It validates that the xargs implementation in the current environment is capable of correct parsing before proceeding.
    • It returns an error if the input string contains newline characters.
    # Example: Converting a complex string to an array
    my_args=()
    cmd_str="'arg with space' 'arg with \"quotes\"'" 
    termux_core__bash__set_shell_command_args_array my_args "my_command" "$cmd_str"
    
    # my_args is now an array: ("arg with space" "arg with \"quotes\"")
  6. revbump CLI reference

    master

    Commands and Flags

    FlagArgumentDescription
    <package> ...RequiredIncrements TERMUX_PKG_REVISION for the specified package(s).
    --dependencies <package>RequiredIncrements TERMUX_PKG_REVISION for all packages that list <package> in their TERMUX_PKG_DEPENDS, TERMUX_PKG_BUILD_DEPENDS, or TERMUX_SUBPKG_DEPENDS variables.
    -d <package>RequiredAlias for --dependencies.
    --help or -hOptionalDisplays the usage guide.
  7. Reference: Scoped variable scope modes

    master

    When using the get-value command, the <scoped_var_scope_mode> argument must match one of the following patterns to correctly identify the environment variable scope:

    PatternDescription
    s=[A-Z]*_APP__Environment variable scope starting with s= and ending with _APP__
    ss=APP__Sub-scope mode
    ss=[A-Z]*_APP__Sub-scope mode starting with ss= and ending with _APP__
    cn=[a-z]*-appSupported component name starting with cn= and ending with -app
    s=[A-Z]*_APP__
    ss=APP__
    ss=[A-Z]*_APP__
    cn=[a-z]*-app
  8. Configure build toolchain utilities

    master

    The build process uses standard system utilities. You can override these if necessary:

    • RANLIB: The utility used to perform actions on a *.a link library. Defaults to ranlib.
    • AR: The archiver utility. Defaults to ar.
    • LDCONFIG: The utility to configure dynamic linker run-time bindings. Note that in this configuration, it is explicitly set to an empty string (LDCONFIG=).
    RANLIB?=ranlib
    AR?= ar
    LDCONFIG=
  9. Supported component scope modes (cn=)

    master

    When using the cn= prefix in the <scoped_var_scope_mode> argument, the function maps the component to a specific sub-scope prefix. This ensures variables are correctly namespaced according to the Termux component they belong to.

    ModeSub-scope Prefix
    cn=termux_
    cn=termux-appAPP__
    cn=termux-api-appAPI_APP__
    cn=termux-float-appFLOAT_APP__
    cn=termux-gui-appGUI_APP__
    cn=termux-tasker-appTASKER_APP__
    cn=termux-widget-appWIDGET_APP__
    cn=termux-x11-appX11_APP__
    cn=termux-coreCORE__
    cn=termux-execEXEC__
  10. Reference: termux_core__sh__termux_apps_info_env_variable exit codes

    master

    The following exit codes are returned by the function:

    CodeConstantDescription
    64EX__USAGEInvalid argument count or invalid command/scope mode provided
    69EX__UNAVAILABLEThe termux-apps-info.env file is missing or cannot be sourced
    64 # EX__USAGE
    69 # EX__UNAVAILABLE
  11. Error codes for termux_apps_info_app_version_name

    master

    When using the termux_core__sh__termux_apps_info_app_version_name function, the following exit codes are returned:

    • 64 (EX__USAGE): Returned when invalid arguments are passed, an unknown option is used, or the required argument count is not met.
    • 81 (C_EX__NOT_FOUND): Returned when a valid version name cannot be found for the specified scope. In this case, if an output_mode variable was provided, it is set to an empty string.