1.1 --- a/scripts/functions Tue Jan 12 19:24:03 2010 +0100
1.2 +++ b/scripts/functions Thu Jan 14 20:54:47 2010 +0100
1.3 @@ -308,8 +308,8 @@
1.4 # we need to also check for an empty extension for those very
1.5 # peculiar components that don't have one (such as sstrip from
1.6 # buildroot).
1.7 - for ext in ${first_ext} .tar.gz .tar.bz2 .tgz .tar ''; do
1.8 - if [ -f "${CT_TARBALLS_DIR}/${file}${ext}" ]; then
1.9 + for ext in ${first_ext} .tar.gz .tar.bz2 .tgz .tar /.git ''; do
1.10 + if [ -e "${CT_TARBALLS_DIR}/${file}${ext}" ]; then
1.11 echo "${ext}"
1.12 exit 0
1.13 fi
1.14 @@ -470,6 +470,8 @@
1.15 fi
1.16
1.17 # Scan all URLs in turn, and try to grab a tarball from there
1.18 + # Do *not* try git trees (ext=/.git), this is handled in a specific
1.19 + # wrapper, below
1.20 for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
1.21 # Try all urls in turn
1.22 for url in ${URLS}; do
1.23 @@ -560,13 +562,46 @@
1.24 CT_DoExecLog ALL rm -rf "${tmp_dir}"
1.25 }
1.26
1.27 +# Clone a git tree
1.28 +# Tries the given URLs in turn until one can get cloned. No tarball will be created.
1.29 +# Prerequisites: either the server does not require password,
1.30 +# or the user has already taken any action to authenticate to the server.
1.31 +# The cloned tree will *not* be stored in the local tarballs dir!
1.32 +# Usage: CT_GetGit <basename> <url [url ...]>
1.33 +CT_GetGit() {
1.34 + local basename="$1"; shift
1.35 + local url
1.36 + local cloned=0
1.37 +
1.38 + # Do we have it in our tarballs dir?
1.39 + if [ -d "${CT_TARBALLS_DIR}/${basename}/.git" ]; then
1.40 + CT_DoLog EXTRA "Updating git tree '${basename}'"
1.41 + CT_Pushd "${CT_TARBALLS_DIR}/${basename}"
1.42 + CT_DoExecLog ALL git pull
1.43 + CT_Popd
1.44 + else
1.45 + CT_DoLog EXTRA "Retrieving git tree '${basename}'"
1.46 + for url in "${@}"; do
1.47 + CT_DoLog ALL "Trying to clone from '${url}'"
1.48 + CT_DoForceRmdir "${CT_TARBALLS_DIR}/${basename}"
1.49 + if git clone "${url}" "${CT_TARBALLS_DIR}/${basename}" 2>&1 |CT_DoLog ALL; then
1.50 + cloned=1
1.51 + break
1.52 + fi
1.53 + done
1.54 + CT_TestOrAbort "Could not clone '${basename}'" ${cloned} -ne 0
1.55 + fi
1.56 +}
1.57 +
1.58 # Extract a tarball
1.59 # Some tarballs need to be extracted in specific places. Eg.: glibc addons
1.60 # must be extracted in the glibc directory; uCLibc locales must be extracted
1.61 # in the extra/locale sub-directory of uClibc. This is taken into account
1.62 # by the caller, that did a 'cd' into the correct path before calling us
1.63 # and sets nochdir to 'nochdir'.
1.64 -# Usage: CT_Extract [nochdir] <basename>
1.65 +# Note also that this function handles the git trees!
1.66 +# Usage: CT_Extract <basename> [nochdir] [options]
1.67 +# where 'options' are dependent on the source (eg. git branch/tag...)
1.68 CT_Extract() {
1.69 local nochdir="$1"
1.70 local basename
1.71 @@ -583,7 +618,7 @@
1.72 shift
1.73
1.74 if ! ext="$(CT_GetFileExtension "${basename}")"; then
1.75 - CT_TestAndAbort "'${basename}' not found in '${CT_TARBALLS_DIR}'" -z "${ext}"
1.76 + CT_Abort "'${basename}' not found in '${CT_TARBALLS_DIR}'"
1.77 fi
1.78 local full_file="${CT_TARBALLS_DIR}/${basename}${ext}"
1.79
1.80 @@ -610,7 +645,8 @@
1.81 .tar.bz2) CT_DoExecLog ALL tar xvjf "${full_file}";;
1.82 .tar.gz|.tgz) CT_DoExecLog ALL tar xvzf "${full_file}";;
1.83 .tar) CT_DoExecLog ALL tar xvf "${full_file}";;
1.84 - *) CT_Abort "Don't know how to handle '${basename}${ext}': unknown extension" ;;
1.85 + /.git) CT_ExtractGit "${basename}" "${@}";;
1.86 + *) CT_Abort "Don't know how to handle '${basename}${ext}': unknown extension";;
1.87 esac
1.88
1.89 # Some tarballs have read-only files... :-(
1.90 @@ -618,12 +654,58 @@
1.91 # the src tree
1.92 CT_DoExecLog DEBUG chmod -R u+w "${CT_SRC_DIR}"
1.93
1.94 - CT_DoExecLog DEBUG touch "${CT_SRC_DIR}/.${basename}.extracted"
1.95 + # Don't mark as being extracted for git
1.96 + case "${ext}" in
1.97 + /.git) ;;
1.98 + *) CT_DoExecLog DEBUG touch "${CT_SRC_DIR}/.${basename}.extracted";;
1.99 + esac
1.100 CT_DoExecLog DEBUG rm -f "${CT_SRC_DIR}/.${basename}.extracting"
1.101
1.102 CT_Popd
1.103 }
1.104
1.105 +# Create a working git clone
1.106 +# Usage: CT_ExtractGit <basename> [ref]
1.107 +# where 'ref' is the reference to use:
1.108 +# the full name of a branch, like "remotes/origin/branch_name"
1.109 +# a date as understandable by git, like "YYYY-MM-DD[ hh[:mm[:ss]]]"
1.110 +# a tag name
1.111 +CT_ExtractGit() {
1.112 + local basename="${1}"
1.113 + local ref="${2}"
1.114 + local clone_dir
1.115 + local ref_type
1.116 +
1.117 + # pushd now to be able to get git revlist in case ref is a date
1.118 + clone_dir="${CT_TARBALLS_DIR}/${basename}"
1.119 + CT_Pushd "${clone_dir}"
1.120 +
1.121 + # What kind of reference is ${ref} ?
1.122 + if [ -z "${ref}" ]; then
1.123 + # Don't update the clone, keep as-is
1.124 + ref_type=none
1.125 + elif git tag |grep -E "^${ref}$" >/dev/null 2>&1; then
1.126 + ref_type=tag
1.127 + elif git branch -a --no-color |grep -E "^. ${ref}$" >/dev/null 2>&1; then
1.128 + ref_type=branch
1.129 + elif date -d "${ref}" >/dev/null 2>&1; then
1.130 + ref_type=date
1.131 + ref=$(git rev-list -n1 --before="${ref}")
1.132 + else
1.133 + CT_Abort "Reference '${ref}' is an incorrect git reference: neither tag, branch nor date"
1.134 + fi
1.135 +
1.136 + CT_DoExecLog DEBUG rm -f "${CT_SRC_DIR}/${basename}"
1.137 + CT_DoExecLog ALL ln -sf "${clone_dir}" "${CT_SRC_DIR}/${basename}"
1.138 +
1.139 + case "${ref_type}" in
1.140 + none) ;;
1.141 + *) CT_DoExecLog ALL git checkout "${ref}";;
1.142 + esac
1.143 +
1.144 + CT_Popd
1.145 +}
1.146 +
1.147 # Patches the specified component
1.148 # See CT_Extract, above, for explanations on 'nochdir'
1.149 # Usage: CT_Patch [nochdir] <basename>