From: Jan Rękorajski Date: Mon, 23 Mar 2020 16:42:43 +0000 (+0100) Subject: - package apertium-get in as source instead of fetching it at build time X-Git-Tag: auto/th/apertium-3.5.2-2~2 X-Git-Url: https://git.pld-linux.org/?p=packages%2Fapertium.git;a=commitdiff_plain;h=5a34afb91c06d6b544a0ab70979581de635c5e2c - package apertium-get in as source instead of fetching it at build time --- diff --git a/apertium-get b/apertium-get new file mode 100644 index 0000000..0bf2d31 --- /dev/null +++ b/apertium-get @@ -0,0 +1,474 @@ +#!/bin/bash + +[[ "${BASH_SOURCE[0]}" != "${0}" ]] || set -e -u + +### Globals: + +declare -r gitroot=https://raw.githubusercontent.com/apertium +declare -ar pmodules=(trunk staging nursery incubator) +declare -ar lmodules=(languages incubator) + +declare -r svnroot_giella=https://victorio.uit.no/langtech/trunk + + +### Functions: +discover_url_apertium () { + local -r dir=$1 + local url= + local -a modules + if [[ ${dir} = *-*-* ]]; then + modules=( "${pmodules[@]}" ) + else + modules=( "${lmodules[@]}" ) + fi + for module in "${modules[@]}"; do + submodules=$(curl -Ss --fail "${gitroot}/apertium-${module}/master/.gitmodules") + # url="${svnroot}${module}/${dir}" + if url=$(grep "[[:space:]]*url = .*/${dir}.git$" <<<"${submodules}"); then + url=${url#*url = } + # TODO: Option to use ssh urls? + url=${url/git@github.com:/https:\/\/github.com\/} + echo "Assuming git url of ${dir} is ${url}" >&2 + echo "${url}" + return 0 + fi + done + echo "WARNING: Couldn't find git url of ${dir}" >&2 + if ! msg=$(curl -Ss --fail "${gitroot}/apertium-languages/master/.gitmodules"); then + printf "\n%s\n\n" "${msg}" >&2 + echo "You may want to see http://wiki.apertium.org/wiki/Using_SVN#Host_not_found_when_using_proxy" >&2 + echo "or make sure you have a working internet connection." >&2 + fi + return 1 +} +discover_url_giella () { + local -r dir=$1 + local -r url="${svnroot_giella}/${dir}" + echo "Assuming SVN url of ${dir} is ${url}" >&2 + echo "${url}" +} + +dir_of_dep () { + if [[ $1 = giella-* ]]; then + echo "langs/${1##giella-}" + else + echo "$1" + fi +} +bins_of_dep () { + if [[ $1 = giella-* ]]; then + echo "langs/${1##giella-}/tools/mt/apertium" + else + echo "$1" + fi +} + +make_dep () { + local -r dep=$1 + local -r dir=$(dir_of_dep "${dep}") + # Let cwd be GTHOME from here on in; langs should exist under this dir: + GTHOME=$(pwd) + GTCORE=$GTHOME/gtcore + export GTHOME + export GTCORE + ( + cd "${dir}" + pwd + ./autogen.sh + if [[ ${dep} = giella-* ]]; then + ./configure --enable-apertium --with-hfst --enable-syntax + V=1 make # giella so memory hungry, -j1 + elif [[ ${dep} = gtcore ]]; then + ./configure + make -j3 + else + make -j3 + fi + ) +} + +is_dep_updated () { + local -r dep=$1 + local -r dir=$(dir_of_dep "${dep}") + if [[ -d ${dir} ]]; then + if [[ -d "${dir}/.git" ]]; then + if [[ -z "$(cd "${dir}" && git fetch --dry-run)" ]]; then + echo yes + return 0 + else + echo no + return 0 + fi + fi + if [[ -z $(svn status -qu "${dir}") ]]; then + echo yes + return 0 + fi + fi + echo no +} + +get_dep () { + local -r depth=$1 + local -r dep=$2 + local -r dir=$(dir_of_dep "${dep}") + local url= + if [[ -d ${dir} ]]; then + ( + cd "${dir}" + printf "Updating existing %s (%s)\n" "${dir}" "$(pwd)" + if [[ -d .git ]]; then + git pull + else + svn up + fi + ) + else + if [[ ${dep} = giella-* || ${dep} = gtcore ]]; then + url=$(discover_url_giella "${dir}") && svn checkout "${url}" "${dir}" + else + url=$(discover_url_apertium "${dir}") && if [[ $depth -gt 0 ]]; then + git clone --depth "${depth}" "${url}" "${dir}" + else + git clone "${url}" "${dir}" + fi + fi + fi +} + +in_array () { + local e + for e in "${@:2}"; do + [[ "$e" == "$1" ]] && return 0 + done + return 1 +} + +get_pair () { + local -r depth=$1 + local -r keep_going=$2 + local -r skip_if_up_to_date=$3 + local -r pair=apertium-${4##apertium-} + # shellcheck disable=SC2124 + local -r skip="${@:5}" # intentionally assigning array to string + + if [[ ${skip_if_up_to_date} == true && $(is_dep_updated "${pair}") == "yes" ]]; then + printf "Existing pair %s is already up to date. Skipping build step.\\n" "${pair}" + return 0 + fi + + get_dep "${depth}" "${pair}" + # Mac has ancient bash, so no declare -A for us + local -a deps=() + local -a depn=() + while read -r n dep; do + local orglang + orglang=$(split_org_langs "${dep}") + local lang=${orglang##* } + # shellcheck disable=SC2068 + if in_array "${lang}" ${skip[@]}; then # intentionally unquoted skip + echo + echo "Skipping data ${dep} as instructed." + echo + else + deps+=( "${dep}" ) + depn+=( "${n}" ) + fi + done < <(awk -F'[][[:space:]]+' '/^ *AP_CHECK_LING\(/ && $2 && $4 {print $2, $4}' "${pair}"/configure.ac) + + if [[ ${#deps[@]} -ne 0 ]]; then + for dep in "${deps[@]}"; do + if ! get_data "${depth}" "${skip_if_up_to_date}" "${keep_going}" "${dep}"; then + echo + echo "WARNING: Couldn't get dependency ${dep}; pair ${pair} might not get set up correctly." + echo + if ${keep_going}; then + echo "WARNING: Continuing on as if nothing happened ..." + echo + sleep 1 + else + exit 1 + fi + fi + done + fi + cd "${pair}" + autogen="./autogen.sh " + for i in "${!depn[@]}"; do + binsdir=$(bins_of_dep "${deps[i]}") + autogen="${autogen} --with-lang${depn[i]}=../${binsdir}" + done + ${autogen} + make -j3 + make test || echo "make test failed, but that's probably fine." + + cat <&2 + echo >&2 + show_help >&2 + exit 1 + fi + done + + for module in "${modules[@]}"; do + echo "# Pairs in ${module}:" + list_modules "${module}" |grep -e '-' + echo + done +} + +list_language_modules() { + local -a modules=("$@") + local module + + # Defaulting to all modules: + if [[ ${#modules[@]} -eq 0 ]]; then + modules=( "${lmodules[@]}" ) + fi + # Sanity-check input: + for module in "${modules[@]}"; do + if ! is_in "${module}" "${lmodules[@]}"; then + echo "ERROR: '${module}' not recognised as an language module module"'!' >&2 + echo >&2 + show_help >&2 + exit 1 + fi + done + + for module in "${modules[@]}"; do + echo "# Language modules in ${module}:" + list_modules "${module}" | grep -ve '-' + done +} + +sanity_check () { + if ! command -V git >/dev/null; then + cat >&2 <&2 + echo >&2 + show_help >&2 + exit 1 + ;; + esac + done + shift "$((OPTIND-1))" + + if ${do_list_pairs}; then + list_pairs "$@" + elif ${do_list_language_modules}; then + list_language_modules "$@" + else + if [[ $# -lt 1 ]]; then + echo "ERROR: No language pair specified." >&2 + echo >&2 + show_help >&2 + exit 1 + fi + for d in "$@"; do + get_data "${depth}" "${keep_going}" "${skip_if_up_to_date}" "$d" "${skip[@]:-}" + done + fi +} + +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + echo "${BASH_SOURCE[0]} is being sourced; chmod +x and use ./${BASH_SOURCE[0]} to actually run." >&2 +else + main "$@" +fi diff --git a/apertium.spec b/apertium.spec index e1d4171..386643f 100644 --- a/apertium.spec +++ b/apertium.spec @@ -7,6 +7,9 @@ License: GPL v2+ Group: Applications/Text Source0: http://downloads.sourceforge.net/apertium/%{name}-%{version}.tar.gz # Source0-md5: 9cce54e577dd4a1cc6f834e1bdd0bf73 +Source1: https://raw.githubusercontent.com/apertium/apertium-get/master/apertium-get +# Source1-md5: e5c863207affed7db787138ae878ad56 +Patch0: no-apertium-get.patch URL: http://www.apertium.org/ BuildRequires: autoconf >= 2.52 BuildRequires: automake @@ -81,6 +84,8 @@ rm -rf $RPM_BUILD_ROOT %{__make} install \ DESTDIR=$RPM_BUILD_ROOT +cp -p %{SOURCE1} $RPM_BUILD_ROOT/%{_bindir} + %clean rm -rf $RPM_BUILD_ROOT diff --git a/no-apertium-get.patch b/no-apertium-get.patch new file mode 100644 index 0000000..2d13752 --- /dev/null +++ b/no-apertium-get.patch @@ -0,0 +1,11 @@ +--- apertium-3.5.2/apertium/Makefile.am~ 2018-08-04 17:52:54.000000000 +0200 ++++ apertium-3.5.2/apertium/Makefile.am 2020-03-23 17:37:06.996686819 +0100 +@@ -237,7 +237,7 @@ + apertium-tmxbuild \ + apertium-transfer + +-bin_SCRIPTS = $(GENERATEDSCRIPTS) apertium-get/apertium-get ++bin_SCRIPTS = $(GENERATEDSCRIPTS) + + # Workaround for git-svn clone not getting externals; should do + # nothing in normal SVN checkouts