[arch-projects] [devtools] [PATCH] makechrootpkg: Copy VCS sources too
Jan Alexander Steffens (heftig)
jan.steffens at gmail.com
Mon Apr 8 19:19:30 EDT 2013
From: "Jan Alexander Steffens (heftig)" <jan.steffens at gmail.com>
Steal some functions from makepkg in order to parse the PKGBUILD
---
makechrootpkg.in | 55 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 47 insertions(+), 8 deletions(-)
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 7796298..fbca3f3 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -237,14 +237,53 @@ export CARCH
# Copy PKGBUILD and sources
cp PKGBUILD "$copydir/build/"
(
+ # 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%%://*}"
+ 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 = 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}"
+ }
+
source PKGBUILD
for file in "${source[@]}"; do
- file="${file%%::*}"
- file="${file##*://*/}"
- if [[ -f $file ]]; then
- cp "$file" "$copydir/srcdest/"
- elif [[ -f $SRCDEST/$file ]]; then
- cp "$SRCDEST/$file" "$copydir/srcdest/"
+ file="$(get_filename "$file")"
+ if [[ -e $file ]]; then
+ cp -a "$file" "$copydir/srcdest/"
+ elif [[ -e $SRCDEST/$file ]]; then
+ cp -a "$SRCDEST/$file" "$copydir/srcdest/"
fi
done
@@ -312,8 +351,8 @@ else
fi
for f in "$copydir"/srcdest/*; do
- chown "$src_owner" "$f"
- mv "$f" "$SRCDEST"
+ chown -R "$src_owner" "$f"
+ cp -af "$f" "$SRCDEST/"
done
if $temp_chroot; then
--
1.8.2
More information about the arch-projects
mailing list