[pacman-dev] [PATCH 1/5] libmakepkg: extract more utility functions
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/libmakepkg/util/util.sh | 32 +++++++++++++++++++++++++++++++- scripts/makepkg.sh.in | 30 ------------------------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/scripts/libmakepkg/util/util.sh b/scripts/libmakepkg/util/util.sh index 307464e..d2378bb 100644 --- a/scripts/libmakepkg/util/util.sh +++ b/scripts/libmakepkg/util/util.sh @@ -19,7 +19,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -[ -n "$LIBMAKEPKG_UTIL_UTIL_SH" ] && return +[[ -n "$LIBMAKEPKG_UTIL_UTIL_SH" ]] && return LIBMAKEPKG_UTIL_UTIL_SH=1 @@ -36,3 +36,33 @@ in_array() { done return 1 # Not Found } + +# Canonicalize a directory path if it exists +canonicalize_path() { + local path="$1"; + + if [[ -d $path ]]; then + ( + cd_safe "$path" + pwd -P + ) + else + printf "%s\n" "$path" + fi +} + +dir_is_empty() { + ( + shopt -s dotglob nullglob + files=("$1"/*) + (( ${#files} == 0 )) + ) +} + +cd_safe() { + if ! cd "$1"; then + error "$(gettext "Failed to change to directory %s")" "$1" + plain "$(gettext "Aborting...")" + exit 1 + fi +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 2d64997..f88ec3c 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1415,14 +1415,6 @@ error_function() { exit 2 # $E_BUILD_FAILED } -cd_safe() { - if ! cd "$1"; then - error "$(gettext "Failed to change to directory %s")" "$1" - plain "$(gettext "Aborting...")" - exit 1 - fi -} - source_safe() { shopt -u extglob if ! source "$@"; then @@ -2380,28 +2372,6 @@ print_all_package_names() { done } -# Canonicalize a directory path if it exists -canonicalize_path() { - local path="$1"; - - if [[ -d $path ]]; then - ( - cd_safe "$path" - pwd -P - ) - else - printf "%s\n" "$path" - fi -} - -dir_is_empty() { - ( - shopt -s dotglob nullglob - files=("$1"/*) - (( ${#files} == 0 )) - ) -} - m4_include(library/parseopts.sh) usage() { -- 2.4.1
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/libmakepkg/util/pkgbuild.sh | 47 ++++++++++++++++++++++++++++++++++++- scripts/makepkg.sh.in | 45 ----------------------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/scripts/libmakepkg/util/pkgbuild.sh b/scripts/libmakepkg/util/pkgbuild.sh index 17e4cc5..2423a83 100644 --- a/scripts/libmakepkg/util/pkgbuild.sh +++ b/scripts/libmakepkg/util/pkgbuild.sh @@ -18,7 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -[ -n "$LIBMAKEPKG_UTIL_PKGBUILD_SH" ] && return +[[ -n "$LIBMAKEPKG_UTIL_PKGBUILD_SH" ]] && return LIBMAKEPKG_UTIL_PKGBUILD_SH=1 @@ -144,3 +144,48 @@ get_pkg_arch() { fi fi } + +print_all_package_names() { + local version=$(get_full_version) + local architecture pkg opts a + for pkg in ${pkgname[@]}; do + get_pkgbuild_attribute "$pkg" 'arch' 1 architecture + get_pkgbuild_attribute "$pkg" 'options' 1 opts + for a in ${architecture[@]}; do + printf "%s-%s-%s\n" "$pkg" "$version" "$a" + if in_opt_array "debug" ${opts[@]} && in_opt_array "strip" ${opts[@]}; then + printf "%s-%s-%s-%s\n" "$pkg" "@DEBUGSUFFIX@" "$version" "$a" + fi + done + done +} + +get_all_sources() { + local aggregate l a + + if array_build l 'source'; then + aggregate+=("${l[@]}") + fi + + for a in "${arch[@]}"; do + if array_build l "source_$a"; then + aggregate+=("${l[@]}") + fi + done + + array_build "$1" "aggregate" +} + +get_all_sources_for_arch() { + local aggregate l + + if array_build l 'source'; then + aggregate+=("${l[@]}") + fi + + if array_build l "source_$CARCH"; then + aggregate+=("${l[@]}") + fi + + array_build "$1" "aggregate" +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index f88ec3c..cc1fea4 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -739,36 +739,6 @@ extract_svn() { cp -au "$dir" "$srcdir" } -get_all_sources() { - local aggregate l a - - if array_build l 'source'; then - aggregate+=("${l[@]}") - fi - - for a in "${arch[@]}"; do - if array_build l "source_$a"; then - aggregate+=("${l[@]}") - fi - done - - array_build "$1" "aggregate" -} - -get_all_sources_for_arch() { - local aggregate l - - if array_build l 'source'; then - aggregate+=("${l[@]}") - fi - - if array_build l "source_$CARCH"; then - aggregate+=("${l[@]}") - fi - - array_build "$1" "aggregate" -} - download_sources() { local netfile all_sources local get_source_fn=get_all_sources_for_arch get_vcs=1 @@ -2357,21 +2327,6 @@ run_split_packaging() { pkgname=${pkgname_backup[@]} } -print_all_package_names() { - local version=$(get_full_version) - local architecture pkg opts a - for pkg in ${pkgname[@]}; do - get_pkgbuild_attribute "$pkg" 'arch' 1 architecture - get_pkgbuild_attribute "$pkg" 'options' 1 opts - for a in ${architecture[@]}; do - printf "%s-%s-%s\n" "$pkg" "$version" "$a" - if in_opt_array "debug" ${opts[@]} && in_opt_array "strip" ${opts[@]}; then - printf "%s-%s-%s-%s\n" "$pkg" "@DEBUGSUFFIX@" "$version" "$a" - fi - done - done -} - m4_include(library/parseopts.sh) usage() { -- 2.4.1
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/libmakepkg/util/message.sh | 2 +- scripts/libmakepkg/util/option.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/libmakepkg/util/message.sh b/scripts/libmakepkg/util/message.sh index 15208ef..c2c1982 100644 --- a/scripts/libmakepkg/util/message.sh +++ b/scripts/libmakepkg/util/message.sh @@ -19,7 +19,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -[ -n "$LIBMAKEPKG_UTIL_MESSAGE_SH" ] && return +[[ -n "$LIBMAKEPKG_UTIL_MESSAGE_SH" ]] && return LIBMAKEPKG_UTIL_MESSAGE_SH=1 diff --git a/scripts/libmakepkg/util/option.sh b/scripts/libmakepkg/util/option.sh index fc64928..1b2d94d 100644 --- a/scripts/libmakepkg/util/option.sh +++ b/scripts/libmakepkg/util/option.sh @@ -18,7 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -[ -n "$LIBMAKEPKG_UTIL_OPTION_SH" ] && return +[[ -n "$LIBMAKEPKG_UTIL_OPTION_SH" ]] && return LIBMAKEPKG_UTIL_OPTION_SH=1 -- 2.4.1
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/Makefile.am | 3 +- scripts/libmakepkg/.gitignore | 1 + scripts/libmakepkg/util/source.sh.in | 144 +++++++++++++++++++++++++++++++++++ scripts/makepkg.sh.in | 119 ----------------------------- scripts/po/POTFILES.in | 1 + 5 files changed, 148 insertions(+), 120 deletions(-) create mode 100644 scripts/libmakepkg/util/source.sh.in diff --git a/scripts/Makefile.am b/scripts/Makefile.am index fb32f16..5cced98 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -83,7 +83,8 @@ LIBMAKEPKG_IN = \ libmakepkg/tidy/strip.sh \ libmakepkg/tidy/upx.sh \ libmakepkg/tidy/zipman.sh \ - libmakepkg/util.sh + libmakepkg/util.sh \ + libmakepkg/util/source.sh LIBMAKEPKG_DIST = \ $(LIBMAKEPKG) \ diff --git a/scripts/libmakepkg/.gitignore b/scripts/libmakepkg/.gitignore index 0b8f88f..18442a8 100644 --- a/scripts/libmakepkg/.gitignore +++ b/scripts/libmakepkg/.gitignore @@ -5,3 +5,4 @@ lint_pkgbuild/*.sh tidy.sh tidy/*.sh /util.sh +util/source.sh \ No newline at end of file diff --git a/scripts/libmakepkg/util/source.sh.in b/scripts/libmakepkg/util/source.sh.in new file mode 100644 index 0000000..0a4f671 --- /dev/null +++ b/scripts/libmakepkg/util/source.sh.in @@ -0,0 +1,144 @@ +#!/bin/bash +# +# source.sh - functions to extract information from source URLs +# +# Copyright (c) 2010-2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_UTIL_SOURCE_SH" ]] && return +LIBMAKEPKG_UTIL_SOURCE_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" + + +# a source entry can have two forms : +# 1) "filename::http://path/to/file" +# 2) "http://path/to/file" + +# extract the URL from a source entry +get_url() { + # strip an eventual filename + printf "%s\n" "${1#*::}" +} + +# extract the protocol from a source entry - return "local" for local sources +get_protocol() { + if [[ $1 = *://* ]]; then + # strip leading filename + local proto="${1#*::}" + printf "%s\n" "${proto%%://*}" + elif [[ $1 = *lp:* ]]; then + local proto="${1#*::}" + printf "%s\n" "${proto%%lp:*}" + else + printf "%s\n" local + fi +} + +# extract the filename from a source entry +get_filename() { + local netfile=$1 + + # if a filename is specified, use it + if [[ $netfile = *::* ]]; then + printf "%s\n" ${netfile%%::*} + return + fi + + local proto=$(get_protocol "$netfile") + + case $proto in + bzr*|git*|hg*|svn*) + filename=${netfile%%#*} + filename=${filename%/} + filename=${filename##*/} + if [[ $proto = bzr* ]]; then + filename=${filename#*lp:} + fi + if [[ $proto = git* ]]; then + filename=${filename%%.git*} + fi + ;; + *) + # if it is just an URL, we only keep the last component + filename="${netfile##*/}" + ;; + esac + printf "%s\n" "${filename}" +} + +# Return the absolute filename of a source entry +get_filepath() { + local file="$(get_filename "$1")" + local proto="$(get_protocol "$1")" + + case $proto in + bzr*|git*|hg*|svn*) + if [[ -d "$startdir/$file" ]]; then + file="$startdir/$file" + elif [[ -d "$SRCDEST/$file" ]]; then + file="$SRCDEST/$file" + else + return 1 + fi + ;; + *) + if [[ -f "$startdir/$file" ]]; then + file="$startdir/$file" + elif [[ -f "$SRCDEST/$file" ]]; then + file="$SRCDEST/$file" + else + return 1 + fi + ;; + esac + + printf "%s\n" "$file" +} + +get_downloadclient() { + local proto=$1 + + # loop through DOWNLOAD_AGENTS variable looking for protocol + local i + for i in "${DLAGENTS[@]}"; do + local handler="${i%%::*}" + if [[ $proto = "$handler" ]]; then + local agent="${i#*::}" + break + fi + done + + # if we didn't find an agent, return an error + if [[ -z $agent ]]; then + error "$(gettext "Unknown download protocol: %s")" "$proto" + plain "$(gettext "Aborting...")" + exit 1 # $E_CONFIG_ERROR + fi + + # ensure specified program is installed + local program="${agent%% *}" + if [[ ! -x $program ]]; then + local baseprog="${program##*/}" + error "$(gettext "The download program %s is not installed.")" "$baseprog" + plain "$(gettext "Aborting...")" + exit 1 # $E_MISSING_PROGRAM + fi + + printf "%s\n" "$agent" +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index cc1fea4..140bb1a 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -170,130 +170,11 @@ clean_up() { remove_deps } - enter_fakeroot() { msg "$(gettext "Entering %s environment...")" "fakeroot" fakeroot -- $0 -F "${ARGLIST[@]}" || exit $? } - -# a source entry can have two forms : -# 1) "filename::http://path/to/file" -# 2) "http://path/to/file" - -# Return the absolute filename of a source entry -get_filepath() { - local file="$(get_filename "$1")" - local proto="$(get_protocol "$1")" - - case $proto in - bzr*|git*|hg*|svn*) - if [[ -d "$startdir/$file" ]]; then - file="$startdir/$file" - elif [[ -d "$SRCDEST/$file" ]]; then - file="$SRCDEST/$file" - else - return 1 - fi - ;; - *) - if [[ -f "$startdir/$file" ]]; then - file="$startdir/$file" - elif [[ -f "$SRCDEST/$file" ]]; then - file="$SRCDEST/$file" - else - return 1 - fi - ;; - esac - - printf "%s\n" "$file" -} - -# extract the filename from a source entry -get_filename() { - local netfile=$1 - - # if a filename is specified, use it - if [[ $netfile = *::* ]]; then - printf "%s\n" ${netfile%%::*} - return - fi - - local proto=$(get_protocol "$netfile") - - case $proto in - bzr*|git*|hg*|svn*) - filename=${netfile%%#*} - filename=${filename%/} - filename=${filename##*/} - if [[ $proto = bzr* ]]; then - filename=${filename#*lp:} - fi - if [[ $proto = git* ]]; then - filename=${filename%%.git*} - fi - ;; - *) - # if it is just an URL, we only keep the last component - filename="${netfile##*/}" - ;; - esac - printf "%s\n" "${filename}" -} - -# extract the URL from a source entry -get_url() { - # strip an eventual filename - printf "%s\n" "${1#*::}" -} - -# extract the protocol from a source entry - return "local" for local sources -get_protocol() { - if [[ $1 = *://* ]]; then - # strip leading filename - local proto="${1#*::}" - printf "%s\n" "${proto%%://*}" - elif [[ $1 = *lp:* ]]; then - local proto="${1#*::}" - printf "%s\n" "${proto%%lp:*}" - else - printf "%s\n" local - fi -} - -get_downloadclient() { - local proto=$1 - - # loop through DOWNLOAD_AGENTS variable looking for protocol - local i - for i in "${DLAGENTS[@]}"; do - local handler="${i%%::*}" - if [[ $proto = "$handler" ]]; then - local agent="${i#*::}" - break - fi - done - - # if we didn't find an agent, return an error - if [[ -z $agent ]]; then - error "$(gettext "Unknown download protocol: %s")" "$proto" - plain "$(gettext "Aborting...")" - exit 1 # $E_CONFIG_ERROR - fi - - # ensure specified program is installed - local program="${agent%% *}" - if [[ ! -x $program ]]; then - local baseprog="${program##*/}" - error "$(gettext "The download program %s is not installed.")" "$baseprog" - plain "$(gettext "Aborting...")" - exit 1 # $E_MISSING_PROGRAM - fi - - printf "%s\n" "$agent" -} - download_local() { local netfile=$1 local filepath=$(get_filepath "$netfile") diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in index 43916c0..30bc3f4 100644 --- a/scripts/po/POTFILES.in +++ b/scripts/po/POTFILES.in @@ -39,5 +39,6 @@ scripts/libmakepkg/tidy/strip.sh.in scripts/libmakepkg/tidy/upx.sh.in scripts/libmakepkg/tidy/zipman.sh.in scripts/libmakepkg/util/message.sh +scripts/libmakepkg/util/source.sh.in scripts/library/output_format.sh scripts/library/parseopts.sh -- 2.4.1
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/Makefile.am | 8 + scripts/libmakepkg/source.sh.in | 113 ++++++++ scripts/libmakepkg/source/bzr.sh.in | 106 +++++++ scripts/libmakepkg/source/file.sh.in | 147 ++++++++++ scripts/libmakepkg/source/git.sh.in | 127 ++++++++ scripts/libmakepkg/source/hg.sh.in | 104 +++++++ scripts/libmakepkg/source/local.sh.in | 42 +++ scripts/libmakepkg/source/svn.sh.in | 93 ++++++ scripts/makepkg.sh.in | 524 ---------------------------------- scripts/po/POTFILES.in | 7 + 10 files changed, 747 insertions(+), 524 deletions(-) create mode 100644 scripts/libmakepkg/source.sh.in create mode 100644 scripts/libmakepkg/source/bzr.sh.in create mode 100644 scripts/libmakepkg/source/file.sh.in create mode 100644 scripts/libmakepkg/source/git.sh.in create mode 100644 scripts/libmakepkg/source/hg.sh.in create mode 100644 scripts/libmakepkg/source/local.sh.in create mode 100644 scripts/libmakepkg/source/svn.sh.in diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 5cced98..907dc4f 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -43,6 +43,7 @@ libmakepkgdir = $(datarootdir)/makepkg LIBMAKEPKGDIRS = \ lint_package \ lint_pkgbuild \ + source \ tidy \ util @@ -73,6 +74,13 @@ LIBMAKEPKG_IN = \ libmakepkg/lint_pkgbuild/provides.sh \ libmakepkg/lint_pkgbuild/source.sh \ libmakepkg/lint_pkgbuild/util.sh \ + libmakepkg/source.sh \ + libmakepkg/source/bzr.sh \ + libmakepkg/source/file.sh \ + libmakepkg/source/git.sh \ + libmakepkg/source/hg.sh \ + libmakepkg/source/local.sh \ + libmakepkg/source/svn.sh \ libmakepkg/tidy.sh \ libmakepkg/tidy/docs.sh \ libmakepkg/tidy/emptydirs.sh \ diff --git a/scripts/libmakepkg/source.sh.in b/scripts/libmakepkg/source.sh.in new file mode 100644 index 0000000..93a69b4 --- /dev/null +++ b/scripts/libmakepkg/source.sh.in @@ -0,0 +1,113 @@ +#!/bin/bash +# +# source.sh - functions for downloading and extracting sources +# +# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_SOURCE_SH" ]] && return +LIBMAKEPKG_SOURCE_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/pkgbuild.sh" +source "$LIBRARY/util/source.sh" + + +for lib in "$LIBRARY/source/"*.sh; do + source "$lib" +done + + +download_sources() { + local netfile all_sources + local get_source_fn=get_all_sources_for_arch get_vcs=1 + + msg "$(gettext "Retrieving sources...")" + + while true; do + case $1 in + allarch) + get_source_fn=get_all_sources + ;; + novcs) + get_vcs=0 + ;; + *) + break 2 + ;; + esac + shift + done + + "$get_source_fn" 'all_sources' + for netfile in "${all_sources[@]}"; do + pushd "$SRCDEST" &>/dev/null + + local proto=$(get_protocol "$netfile") + case "$proto" in + local) + download_local "$netfile" + ;; + bzr*) + (( get_vcs )) && download_bzr "$netfile" + ;; + git*) + (( get_vcs )) && download_git "$netfile" + ;; + hg*) + (( get_vcs )) && download_hg "$netfile" + ;; + svn*) + (( get_vcs )) && download_svn "$netfile" + ;; + *) + download_file "$netfile" + ;; + esac + + popd &>/dev/null + done +} + +extract_sources() { + msg "$(gettext "Extracting sources...")" + local netfile all_sources + + get_all_sources_for_arch 'all_sources' + for netfile in "${all_sources[@]}"; do + local file=$(get_filename "$netfile") + local proto=$(get_protocol "$netfile") + case "$proto" in + bzr*) + extract_bzr "$netfile" + ;; + git*) + extract_git "$netfile" + ;; + hg*) + extract_hg "$netfile" + ;; + svn*) + extract_svn "$netfile" + ;; + *) + extract_file "$file" + ;; + esac + done +} diff --git a/scripts/libmakepkg/source/bzr.sh.in b/scripts/libmakepkg/source/bzr.sh.in new file mode 100644 index 0000000..e8da28b --- /dev/null +++ b/scripts/libmakepkg/source/bzr.sh.in @@ -0,0 +1,106 @@ +#!/bin/bash +# +# bzr.sh - function for handling the download and "extraction" of Bazaar sources +# +# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_SOURCE_BZR_SH" ]] && return +LIBMAKEPKG_SOURCE_BZR_SH=1 + + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/pkgbuild.sh" + + +download_bzr() { + local netfile=$1 + + local url=$(get_url "$netfile") + if [[ $url != bzr+ssh* ]]; then + url=${url#bzr+} + fi + url=${url%%#*} + + local repo=$(get_filename "$netfile") + local displaylocation="$url" + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then + msg2 "$(gettext "Branching %s ...")" "${displaylocation}" + if ! bzr branch "$url" "$dir" --no-tree --use-existing-dir; then + error "$(gettext "Failure while branching %s")" "${displaylocation}" + plain "$(gettext "Aborting...")" + exit 1 + fi + elif (( ! HOLDVER )); then + msg2 "$(gettext "Pulling %s ...")" "${displaylocation}" + cd_safe "$dir" + if ! bzr pull "$url"; then + # only warn on failure to allow offline builds + warning "$(gettext "Failure while pulling %s")" "${displaylocation}" + fi + fi +} + +extract_bzr() { + local netfile=$1 + + local repo=$(get_filename "$netfile") + local fragment=${netfile#*#} + if [[ $fragment = "$netfile" ]]; then + unset fragment + fi + + rev="last:1" + if [[ -n $fragment ]]; then + case ${fragment%%=*} in + revision) + rev="${fragment#*=}" + displaylocation="$url -r ${fragment#*=}" + ;; + *) + error "$(gettext "Unrecognized reference: %s")" "${fragment}" + plain "$(gettext "Aborting...")" + exit 1 + esac + fi + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "bzr" + pushd "$srcdir" &>/dev/null + + if [[ -d "${dir##*/}" ]]; then + cd_safe "${dir##*/}" + if ! (bzr pull "$dir" -q --overwrite -r "$rev" && bzr clean-tree -q --detritus --force); then + error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "bzr" + plain "$(gettext "Aborting...")" + exit 1 + fi + elif ! bzr checkout "$dir" -r "$rev"; then + error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr" + plain "$(gettext "Aborting...")" + exit 1 + fi + + popd &>/dev/null +} diff --git a/scripts/libmakepkg/source/file.sh.in b/scripts/libmakepkg/source/file.sh.in new file mode 100644 index 0000000..03dabe6 --- /dev/null +++ b/scripts/libmakepkg/source/file.sh.in @@ -0,0 +1,147 @@ +#!/bin/bash +# +# file.sh - function for handling the download and extraction of source files +# +# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_SOURCE_FILE_SH" ]] && return +LIBMAKEPKG_SOURCE_FILE_SH=1 + + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/pkgbuild.sh" + + +download_file() { + local netfile=$1 + + local filepath=$(get_filepath "$netfile") + if [[ -n "$filepath" ]]; then + msg2 "$(gettext "Found %s")" "${filepath##*/}" + return + fi + + local proto=$(get_protocol "$netfile") + + # find the client we should use for this URL + local -a cmdline + IFS=' ' read -a cmdline < <(get_downloadclient "$proto") + (( ${#cmdline[@]} )) || exit + + local filename=$(get_filename "$netfile") + local url=$(get_url "$netfile") + + if [[ $proto = "scp" ]]; then + # scp downloads should not pass the protocol in the url + url="${url##*://}" + fi + + msg2 "$(gettext "Downloading %s...")" "$filename" + + # temporary download file, default to last component of the URL + local dlfile="${url##*/}" + + # replace %o by the temporary dlfile if it exists + if [[ ${cmdline[*]} = *%o* ]]; then + dlfile=$filename.part + cmdline=("${cmdline[@]//%o/$dlfile}") + fi + # add the URL, either in place of %u or at the end + if [[ ${cmdline[*]} = *%u* ]]; then + cmdline=("${cmdline[@]//%u/$url}") + else + cmdline+=("$url") + fi + + if ! command -- "${cmdline[@]}" >&2; then + [[ ! -s $dlfile ]] && rm -f -- "$dlfile" + error "$(gettext "Failure while downloading %s")" "$filename" + plain "$(gettext "Aborting...")" + exit 1 + fi + + # rename the temporary download file to the final destination + if [[ $dlfile != "$filename" ]]; then + mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename" + fi +} + +extract_file() { + local file=$1 + + local filepath=$(get_filepath "$file") + rm -f "$srcdir/${file}" + ln -s "$filepath" "$srcdir/" + + if in_array "$file" "${noextract[@]}"; then + # skip source files in the noextract=() array + # these are marked explicitly to NOT be extracted + return 0 + fi + + # do not rely on extension for file type + local file_type=$(file -bizL "$file") + local ext=${file##*.} + local cmd='' + case "$file_type" in + *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*) + cmd="bsdtar" ;; + *application/x-gzip*) + case "$ext" in + gz|z|Z) cmd="gzip" ;; + *) return;; + esac ;; + *application/x-bzip*) + case "$ext" in + bz2|bz) cmd="bzip2" ;; + *) return;; + esac ;; + *application/x-xz*) + case "$ext" in + xz) cmd="xz" ;; + *) return;; + esac ;; + *) + # See if bsdtar can recognize the file + if bsdtar -tf "$file" -q '*' &>/dev/null; then + cmd="bsdtar" + else + return 0 + fi ;; + esac + + local ret=0 + msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd" + if [[ $cmd = "bsdtar" ]]; then + $cmd -xf "$file" || ret=$? + else + rm -f -- "${file%.*}" + $cmd -dcf "$file" > "${file%.*}" || ret=$? + fi + if (( ret )); then + error "$(gettext "Failed to extract %s")" "$file" + plain "$(gettext "Aborting...")" + exit 1 + fi + + if (( EUID == 0 )); then + # change perms of all source files to root user & root group + chown -R 0:0 "$srcdir" + fi +} diff --git a/scripts/libmakepkg/source/git.sh.in b/scripts/libmakepkg/source/git.sh.in new file mode 100644 index 0000000..4d2f2d7 --- /dev/null +++ b/scripts/libmakepkg/source/git.sh.in @@ -0,0 +1,127 @@ +#!/bin/bash +# +# git.sh - function for handling the download and "extraction" of Git sources +# +# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_SOURCE_GIT_SH" ]] && return +LIBMAKEPKG_SOURCE_GIT_SH=1 + + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/pkgbuild.sh" + + +download_git() { + local netfile=$1 + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + local repo=$(get_filename "$netfile") + + local url=$(get_url "$netfile") + url=${url#git+} + url=${url%%#*} + + if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then + msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git" + if ! git clone --mirror "$url" "$dir"; then + error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git" + plain "$(gettext "Aborting...")" + exit 1 + fi + elif (( ! HOLDVER )); then + cd_safe "$dir" + # Make sure we are fetching the right repo + if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then + error "$(gettext "%s is not a clone of %s")" "$dir" "$url" + plain "$(gettext "Aborting...")" + exit 1 + fi + msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git" + if ! git fetch --all -p; then + # only warn on failure to allow offline builds + warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git" + fi + fi +} + +extract_git() { + local netfile=$1 + + local fragment=${netfile#*#} + if [[ $fragment = "$netfile" ]]; then + unset fragment + fi + + local repo=${netfile##*/} + repo=${repo%%#*} + repo=${repo%%.git*} + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "git" + pushd "$srcdir" &>/dev/null + + local updating=0 + if [[ -d "${dir##*/}" ]]; then + updating=1 + cd_safe "${dir##*/}" + if ! git fetch; then + error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "git" + plain "$(gettext "Aborting...")" + exit 1 + fi + cd_safe "$srcdir" + elif ! git clone "$dir" "${dir##*/}"; then + error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git" + plain "$(gettext "Aborting...")" + exit 1 + fi + + cd_safe "${dir##*/}" + + local ref=origin/HEAD + if [[ -n $fragment ]]; then + case ${fragment%%=*} in + commit|tag) + ref=${fragment##*=} + ;; + branch) + ref=origin/${fragment##*=} + ;; + *) + error "$(gettext "Unrecognized reference: %s")" "${fragment}" + plain "$(gettext "Aborting...")" + exit 1 + esac + fi + + if [[ $ref != "origin/HEAD" ]] || (( updating )) ; then + if ! git checkout --force --no-track -B makepkg $ref; then + error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git" + plain "$(gettext "Aborting...")" + exit 1 + fi + fi + + popd &>/dev/null +} diff --git a/scripts/libmakepkg/source/hg.sh.in b/scripts/libmakepkg/source/hg.sh.in new file mode 100644 index 0000000..6b21dad --- /dev/null +++ b/scripts/libmakepkg/source/hg.sh.in @@ -0,0 +1,104 @@ +#!/bin/bash +# +# hg.sh - function for handling the download and "extraction" of Mercurial sources +# +# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_SOURCE_HG_SH" ]] && return +LIBMAKEPKG_SOURCE_HG_SH=1 + + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/pkgbuild.sh" + + +download_hg() { + local netfile=$1 + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + local repo=$(get_filename "$netfile") + + local url=$(get_url "$netfile") + url=${url#hg+} + url=${url%%#*} + + if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then + msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "hg" + if ! hg clone -U "$url" "$dir"; then + error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg" + plain "$(gettext "Aborting...")" + exit 1 + fi + elif (( ! HOLDVER )); then + msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "hg" + cd_safe "$dir" + if ! hg pull; then + # only warn on failure to allow offline builds + warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "hg" + fi + fi +} + +extract_hg() { + local netfile=$1 + + local fragment=${netfile#*#} + if [[ $fragment = "$netfile" ]]; then + unset fragment + fi + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + local repo=${netfile##*/} + repo=${repo%%#*} + + msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "hg" + pushd "$srcdir" &>/dev/null + + local ref=tip + if [[ -n $fragment ]]; then + case ${fragment%%=*} in + branch|revision|tag) + ref="${fragment##*=}" + ;; + *) + error "$(gettext "Unrecognized reference: %s")" "${fragment}" + plain "$(gettext "Aborting...")" + exit 1 + esac + fi + + if [[ -d "${dir##*/}" ]]; then + cd_safe "${dir##*/}" + if ! (hg pull && hg update -C -r "$ref"); then + error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "hg" + plain "$(gettext "Aborting...")" + exit 1 + fi + elif ! hg clone -u "$ref" "$dir" "${dir##*/}"; then + error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "hg" + plain "$(gettext "Aborting...")" + exit 1 + fi + + popd &>/dev/null +} diff --git a/scripts/libmakepkg/source/local.sh.in b/scripts/libmakepkg/source/local.sh.in new file mode 100644 index 0000000..bf65993 --- /dev/null +++ b/scripts/libmakepkg/source/local.sh.in @@ -0,0 +1,42 @@ +#!/bin/bash +# +# local.sh - function for handling the "download" of local sources +# +# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_SOURCE_LOCAL_SH" ]] && return +LIBMAKEPKG_SOURCE_LOCAL_SH=1 + + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/pkgbuild.sh" + + +download_local() { + local netfile=$1 + local filepath=$(get_filepath "$netfile") + + if [[ -n "$filepath" ]]; then + msg2 "$(gettext "Found %s")" "${filepath##*/}" + else + local filename=$(get_filename "$netfile") + error "$(gettext "%s was not found in the build directory and is not a URL.")" "$filename" + exit 1 # $E_MISSING_FILE + fi +} diff --git a/scripts/libmakepkg/source/svn.sh.in b/scripts/libmakepkg/source/svn.sh.in new file mode 100644 index 0000000..d706cac --- /dev/null +++ b/scripts/libmakepkg/source/svn.sh.in @@ -0,0 +1,93 @@ +#!/bin/bash +# +# svn.sh - function for handling the download and "extraction" of Subversion sources +# +# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +[[ -n "$LIBMAKEPKG_SOURCE_SVN_SH" ]] && return +LIBMAKEPKG_SOURCE_SVN_SH=1 + + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/pkgbuild.sh" + + +download_svn() { + local netfile=$1 + + local fragment=${netfile#*#} + if [[ $fragment = "$netfile" ]]; then + unset fragment + fi + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + local repo=$(get_filename "$netfile") + + local url=$(get_url "$netfile") + if [[ $url != svn+ssh* ]]; then + url=${url#svn+} + fi + url=${url%%#*} + + local ref=HEAD + if [[ -n $fragment ]]; then + case ${fragment%%=*} in + revision) + ref="${fragment##*=}" + ;; + *) + error "$(gettext "Unrecognized reference: %s")" "${fragment}" + plain "$(gettext "Aborting...")" + exit 1 + esac + fi + + if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then + msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn" + mkdir -p "$dir/.makepkg" + if ! svn checkout -r ${ref} --config-dir "$dir/.makepkg" "$url" "$dir"; then + error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn" + plain "$(gettext "Aborting...")" + exit 1 + fi + elif (( ! HOLDVER )); then + msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn" + cd_safe "$dir" + if ! svn update -r ${ref}; then + # only warn on failure to allow offline builds + warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn" + fi + fi +} + +extract_svn() { + local netfile=$1 + + local dir=$(get_filepath "$netfile") + [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" + + local repo=${netfile##*/} + repo=${repo%%#*} + + msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "svn" + + cp -au "$dir" "$srcdir" +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 140bb1a..c74e84a 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -175,502 +175,6 @@ enter_fakeroot() { fakeroot -- $0 -F "${ARGLIST[@]}" || exit $? } -download_local() { - local netfile=$1 - local filepath=$(get_filepath "$netfile") - - if [[ -n "$filepath" ]]; then - msg2 "$(gettext "Found %s")" "${filepath##*/}" - else - local filename=$(get_filename "$netfile") - error "$(gettext "%s was not found in the build directory and is not a URL.")" "$filename" - exit 1 # $E_MISSING_FILE - fi -} - -download_file() { - local netfile=$1 - - local filepath=$(get_filepath "$netfile") - if [[ -n "$filepath" ]]; then - msg2 "$(gettext "Found %s")" "${filepath##*/}" - return - fi - - local proto=$(get_protocol "$netfile") - - # find the client we should use for this URL - local -a cmdline - IFS=' ' read -a cmdline < <(get_downloadclient "$proto") - (( ${#cmdline[@]} )) || exit - - local filename=$(get_filename "$netfile") - local url=$(get_url "$netfile") - - if [[ $proto = "scp" ]]; then - # scp downloads should not pass the protocol in the url - url="${url##*://}" - fi - - msg2 "$(gettext "Downloading %s...")" "$filename" - - # temporary download file, default to last component of the URL - local dlfile="${url##*/}" - - # replace %o by the temporary dlfile if it exists - if [[ ${cmdline[*]} = *%o* ]]; then - dlfile=$filename.part - cmdline=("${cmdline[@]//%o/$dlfile}") - fi - # add the URL, either in place of %u or at the end - if [[ ${cmdline[*]} = *%u* ]]; then - cmdline=("${cmdline[@]//%u/$url}") - else - cmdline+=("$url") - fi - - if ! command -- "${cmdline[@]}" >&2; then - [[ ! -s $dlfile ]] && rm -f -- "$dlfile" - error "$(gettext "Failure while downloading %s")" "$filename" - plain "$(gettext "Aborting...")" - exit 1 - fi - - # rename the temporary download file to the final destination - if [[ $dlfile != "$filename" ]]; then - mv -f "$SRCDEST/$dlfile" "$SRCDEST/$filename" - fi -} - -extract_file() { - local file=$1 - - local filepath=$(get_filepath "$file") - rm -f "$srcdir/${file}" - ln -s "$filepath" "$srcdir/" - - if in_array "$file" "${noextract[@]}"; then - # skip source files in the noextract=() array - # these are marked explicitly to NOT be extracted - return 0 - fi - - # do not rely on extension for file type - local file_type=$(file -bizL "$file") - local ext=${file##*.} - local cmd='' - case "$file_type" in - *application/x-tar*|*application/zip*|*application/x-zip*|*application/x-cpio*) - cmd="bsdtar" ;; - *application/x-gzip*) - case "$ext" in - gz|z|Z) cmd="gzip" ;; - *) return;; - esac ;; - *application/x-bzip*) - case "$ext" in - bz2|bz) cmd="bzip2" ;; - *) return;; - esac ;; - *application/x-xz*) - case "$ext" in - xz) cmd="xz" ;; - *) return;; - esac ;; - *) - # See if bsdtar can recognize the file - if bsdtar -tf "$file" -q '*' &>/dev/null; then - cmd="bsdtar" - else - return 0 - fi ;; - esac - - local ret=0 - msg2 "$(gettext "Extracting %s with %s")" "$file" "$cmd" - if [[ $cmd = "bsdtar" ]]; then - $cmd -xf "$file" || ret=$? - else - rm -f -- "${file%.*}" - $cmd -dcf "$file" > "${file%.*}" || ret=$? - fi - if (( ret )); then - error "$(gettext "Failed to extract %s")" "$file" - plain "$(gettext "Aborting...")" - exit 1 - fi - - if (( EUID == 0 )); then - # change perms of all source files to root user & root group - chown -R 0:0 "$srcdir" - fi -} - -download_bzr() { - local netfile=$1 - - local url=$(get_url "$netfile") - if [[ $url != bzr+ssh* ]]; then - url=${url#bzr+} - fi - url=${url%%#*} - - local repo=$(get_filename "$netfile") - local displaylocation="$url" - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then - msg2 "$(gettext "Branching %s ...")" "${displaylocation}" - if ! bzr branch "$url" "$dir" --no-tree --use-existing-dir; then - error "$(gettext "Failure while branching %s")" "${displaylocation}" - plain "$(gettext "Aborting...")" - exit 1 - fi - elif (( ! HOLDVER )); then - msg2 "$(gettext "Pulling %s ...")" "${displaylocation}" - cd_safe "$dir" - if ! bzr pull "$url"; then - # only warn on failure to allow offline builds - warning "$(gettext "Failure while pulling %s")" "${displaylocation}" - fi - fi -} - -extract_bzr() { - local netfile=$1 - - local repo=$(get_filename "$netfile") - local fragment=${netfile#*#} - if [[ $fragment = "$netfile" ]]; then - unset fragment - fi - - rev="last:1" - if [[ -n $fragment ]]; then - case ${fragment%%=*} in - revision) - rev="${fragment#*=}" - displaylocation="$url -r ${fragment#*=}" - ;; - *) - error "$(gettext "Unrecognized reference: %s")" "${fragment}" - plain "$(gettext "Aborting...")" - exit 1 - esac - fi - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "bzr" - pushd "$srcdir" &>/dev/null - - if [[ -d "${dir##*/}" ]]; then - cd_safe "${dir##*/}" - if ! (bzr pull "$dir" -q --overwrite -r "$rev" && bzr clean-tree -q --detritus --force); then - error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "bzr" - plain "$(gettext "Aborting...")" - exit 1 - fi - elif ! bzr checkout "$dir" -r "$rev"; then - error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "bzr" - plain "$(gettext "Aborting...")" - exit 1 - fi - - popd &>/dev/null -} - -download_git() { - local netfile=$1 - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - local repo=$(get_filename "$netfile") - - local url=$(get_url "$netfile") - url=${url#git+} - url=${url%%#*} - - if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then - msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git" - if ! git clone --mirror "$url" "$dir"; then - error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git" - plain "$(gettext "Aborting...")" - exit 1 - fi - elif (( ! HOLDVER )); then - cd_safe "$dir" - # Make sure we are fetching the right repo - if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then - error "$(gettext "%s is not a clone of %s")" "$dir" "$url" - plain "$(gettext "Aborting...")" - exit 1 - fi - msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git" - if ! git fetch --all -p; then - # only warn on failure to allow offline builds - warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git" - fi - fi -} - -extract_git() { - local netfile=$1 - - local fragment=${netfile#*#} - if [[ $fragment = "$netfile" ]]; then - unset fragment - fi - - local repo=${netfile##*/} - repo=${repo%%#*} - repo=${repo%%.git*} - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "git" - pushd "$srcdir" &>/dev/null - - local updating=0 - if [[ -d "${dir##*/}" ]]; then - updating=1 - cd_safe "${dir##*/}" - if ! git fetch; then - error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "git" - plain "$(gettext "Aborting...")" - exit 1 - fi - cd_safe "$srcdir" - elif ! git clone "$dir" "${dir##*/}"; then - error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git" - plain "$(gettext "Aborting...")" - exit 1 - fi - - cd_safe "${dir##*/}" - - local ref=origin/HEAD - if [[ -n $fragment ]]; then - case ${fragment%%=*} in - commit|tag) - ref=${fragment##*=} - ;; - branch) - ref=origin/${fragment##*=} - ;; - *) - error "$(gettext "Unrecognized reference: %s")" "${fragment}" - plain "$(gettext "Aborting...")" - exit 1 - esac - fi - - if [[ $ref != "origin/HEAD" ]] || (( updating )) ; then - if ! git checkout --force --no-track -B makepkg $ref; then - error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "git" - plain "$(gettext "Aborting...")" - exit 1 - fi - fi - - popd &>/dev/null -} - -download_hg() { - local netfile=$1 - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - local repo=$(get_filename "$netfile") - - local url=$(get_url "$netfile") - url=${url#hg+} - url=${url%%#*} - - if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then - msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "hg" - if ! hg clone -U "$url" "$dir"; then - error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg" - plain "$(gettext "Aborting...")" - exit 1 - fi - elif (( ! HOLDVER )); then - msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "hg" - cd_safe "$dir" - if ! hg pull; then - # only warn on failure to allow offline builds - warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "hg" - fi - fi -} - -extract_hg() { - local netfile=$1 - - local fragment=${netfile#*#} - if [[ $fragment = "$netfile" ]]; then - unset fragment - fi - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - local repo=${netfile##*/} - repo=${repo%%#*} - - msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "hg" - pushd "$srcdir" &>/dev/null - - local ref=tip - if [[ -n $fragment ]]; then - case ${fragment%%=*} in - branch|revision|tag) - ref="${fragment##*=}" - ;; - *) - error "$(gettext "Unrecognized reference: %s")" "${fragment}" - plain "$(gettext "Aborting...")" - exit 1 - esac - fi - - if [[ -d "${dir##*/}" ]]; then - cd_safe "${dir##*/}" - if ! (hg pull && hg update -C -r "$ref"); then - error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "hg" - plain "$(gettext "Aborting...")" - exit 1 - fi - elif ! hg clone -u "$ref" "$dir" "${dir##*/}"; then - error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "hg" - plain "$(gettext "Aborting...")" - exit 1 - fi - - popd &>/dev/null -} - -download_svn() { - local netfile=$1 - - local fragment=${netfile#*#} - if [[ $fragment = "$netfile" ]]; then - unset fragment - fi - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - local repo=$(get_filename "$netfile") - - local url=$(get_url "$netfile") - if [[ $url != svn+ssh* ]]; then - url=${url#svn+} - fi - url=${url%%#*} - - local ref=HEAD - if [[ -n $fragment ]]; then - case ${fragment%%=*} in - revision) - ref="${fragment##*=}" - ;; - *) - error "$(gettext "Unrecognized reference: %s")" "${fragment}" - plain "$(gettext "Aborting...")" - exit 1 - esac - fi - - if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then - msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "svn" - mkdir -p "$dir/.makepkg" - if ! svn checkout -r ${ref} --config-dir "$dir/.makepkg" "$url" "$dir"; then - error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "svn" - plain "$(gettext "Aborting...")" - exit 1 - fi - elif (( ! HOLDVER )); then - msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "svn" - cd_safe "$dir" - if ! svn update -r ${ref}; then - # only warn on failure to allow offline builds - warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "svn" - fi - fi -} - -extract_svn() { - local netfile=$1 - - local dir=$(get_filepath "$netfile") - [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")" - - local repo=${netfile##*/} - repo=${repo%%#*} - - msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "svn" - - cp -au "$dir" "$srcdir" -} - -download_sources() { - local netfile all_sources - local get_source_fn=get_all_sources_for_arch get_vcs=1 - - msg "$(gettext "Retrieving sources...")" - - while true; do - case $1 in - allarch) - get_source_fn=get_all_sources - ;; - novcs) - get_vcs=0 - ;; - *) - break 2 - ;; - esac - shift - done - - "$get_source_fn" 'all_sources' - for netfile in "${all_sources[@]}"; do - pushd "$SRCDEST" &>/dev/null - - local proto=$(get_protocol "$netfile") - case "$proto" in - local) - download_local "$netfile" - ;; - bzr*) - (( get_vcs )) && download_bzr "$netfile" - ;; - git*) - (( get_vcs )) && download_git "$netfile" - ;; - hg*) - (( get_vcs )) && download_hg "$netfile" - ;; - svn*) - (( get_vcs )) && download_svn "$netfile" - ;; - *) - download_file "$netfile" - ;; - esac - - popd &>/dev/null - done -} - # Automatically update pkgver variable if a pkgver() function is provided # Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver update_pkgver() { @@ -1226,34 +730,6 @@ check_source_integrity() { fi } -extract_sources() { - msg "$(gettext "Extracting sources...")" - local netfile all_sources - - get_all_sources_for_arch 'all_sources' - for netfile in "${all_sources[@]}"; do - local file=$(get_filename "$netfile") - local proto=$(get_protocol "$netfile") - case "$proto" in - bzr*) - extract_bzr "$netfile" - ;; - git*) - extract_git "$netfile" - ;; - hg*) - extract_hg "$netfile" - ;; - svn*) - extract_svn "$netfile" - ;; - *) - extract_file "$file" - ;; - esac - done -} - error_function() { if [[ -p $logpipe ]]; then rm "$logpipe" diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in index 30bc3f4..00cb1b8 100644 --- a/scripts/po/POTFILES.in +++ b/scripts/po/POTFILES.in @@ -28,6 +28,13 @@ scripts/libmakepkg/lint_pkgbuild/pkgver.sh.in scripts/libmakepkg/lint_pkgbuild/provides.sh.in scripts/libmakepkg/lint_pkgbuild/source.sh.in scripts/libmakepkg/lint_pkgbuild/util.sh.in +scripts/libmakepkg/source.sh.in +scripts/libmakepkg/source/bzr.sh.in +scripts/libmakepkg/source/file.sh.in +scripts/libmakepkg/source/git.sh.in +scripts/libmakepkg/source/hg.sh.in +scripts/libmakepkg/source/local.sh.in +scripts/libmakepkg/source/svn.sh.in scripts/libmakepkg/tidy.sh.in scripts/libmakepkg/tidy/docs.sh.in scripts/libmakepkg/tidy/emptydirs.sh.in -- 2.4.1
participants (1)
-
Allan McRae