From 172342c47ddf50b2f3d3a10b4d2fbdccd81f6558 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 26 Feb 2013 11:47:51 +0100 Subject: [PATCH 1/7] beesh: Change sourcesubdir handling add functions to set, append or prepend source subdirectories. add_sourcesubdir is now deprecated in favor of sourcesubdir_append --- conf/templates/fallback | 4 ++-- src/beesh.sh.in | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/conf/templates/fallback b/conf/templates/fallback index 3cd8086..e1e1f4f 100644 --- a/conf/templates/fallback +++ b/conf/templates/fallback @@ -34,9 +34,9 @@ ## bee cannot detect buildtypes specified in subdirectories. ## Sometimes packages "hide" the real sources in a subdirectory named ## 'src' or 'cmake' or .. -## use 'add_sourcesubdir' to specify this directory if known. +## use 'sourcesubdir_append' to specify this directory if known. -# add_sourcesubdir src +# sourcesubdir_append src @DEFAULT_PREFIX_VARS@ @BEE_DEFINES@ diff --git a/src/beesh.sh.in b/src/beesh.sh.in index 379012a..c484bad 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -181,9 +181,22 @@ function build_in_sourcedir() { } function add_sourcesubdir() { + print_warning "WARNING: add_sourcesubdir is deprecated in favor of sourcesubdir_append" + sourcesubdir_append "${@}" +} + +function sourcesubdir_set() { BEE_SOURCESUBDIR="${1}" } +function sourcesubdir_prepend() { + BEE_SOURCESUBDIR="${1}${BEE_SOURCESUBDIR:+/${BEE_SOURCESUBDIR}}" +} + +function sourcesubdir_append() { + BEE_SOURCESUBDIR="${BEE_SOURCESUBDIR:+${BEE_SOURCESUBDIR}/}{$1}" +} + #### bee_init_builddir() ###################################################### function bee_init_builddir() { From f19e194ca77ba48755091f338d1464840f66211a Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 26 Feb 2013 12:28:19 +0100 Subject: [PATCH 2/7] beesh: Add functions to extract tar source archives --- src/beesh.sh.in | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/beesh.sh.in b/src/beesh.sh.in index c484bad..3dd96d4 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -355,6 +355,20 @@ function bee_getsources() { #### bee_extract() ############################################################# +function bee_extract_do_tar() { + local file="${1}" + local dest="${2}" + + shift 2 + + start_cmd tar xof "${file}" -C "${dest}" "${@}" +} + +function bee_extract_do_tar0() { + bee_extract_do_tar "${@}" --strip-components "${BEE_EXTRACT_STRIP}" +} + + function bee_extract() { local bee_S bee_S=( "$@" ) @@ -373,13 +387,13 @@ function bee_extract() { s=${bee_S[0]} print_info " -> extracting main source ${s} .." - tar xof ${s} --strip-components ${BEE_EXTRACT_STRIP} -C ${S} + bee_extract_do_tar0 "${s}" "${S}" unset bee_S[0] for s in ${bee_S[@]} ; do print_info " -> extracting additional source ${s} .." - tar xof ${s} -C ${S} + bee_extract_do_tar "${s}" "${S}" done print_info " -> all sources extracted to: ${S} .." From 022645d897fe69aba8555304eda732fff974cadc Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 26 Feb 2013 12:40:08 +0100 Subject: [PATCH 3/7] beesh: Improve filename guessing for fetched source archives --- src/beesh.sh.in | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/beesh.sh.in b/src/beesh.sh.in index 3dd96d4..b8937bb 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -236,8 +236,15 @@ function bee_init_builddir() { # fetch_one_file [filename] function fetch_one_file() { - url=$1 - file=${2:-${url##*/}} + local url="${1}" + local file="${2}" + local guessed_filename="${url##*/}" + + guessed_filename=${guessed_filename%%\?*} + guessed_filename=${guessed_filename%%#*} + guessed_filename=${guessed_filename%/} + + : ${file:=${guessed_filename}} if [ "${url:0:8}" = "file:///" ] ; then url=${url:7} From 56270a9ede99e01a3781faf7606fa81e1187a2ee Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 26 Feb 2013 12:43:21 +0100 Subject: [PATCH 4/7] beesh: Minor cleanup --- src/beesh.sh.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/beesh.sh.in b/src/beesh.sh.in index b8937bb..8ec0766 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -392,12 +392,13 @@ function bee_extract() { return fi + # get first source archive and remove it from source archive array s=${bee_S[0]} + unset bee_S[0] + print_info " -> extracting main source ${s} .." bee_extract_do_tar0 "${s}" "${S}" - unset bee_S[0] - for s in ${bee_S[@]} ; do print_info " -> extracting additional source ${s} .." bee_extract_do_tar "${s}" "${S}" From c1c65da51a00725668bfd4b1c3097f66e5eeb8fb Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 26 Feb 2013 13:52:38 +0100 Subject: [PATCH 5/7] beesh: Add generic extraction functio bee_extract_do --- src/beesh.sh.in | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/beesh.sh.in b/src/beesh.sh.in index 8ec0766..2a91657 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -375,6 +375,39 @@ function bee_extract_do_tar0() { bee_extract_do_tar "${@}" --strip-components "${BEE_EXTRACT_STRIP}" } +function get_or_guess_mimetype() { + local file="${1}" + local mimetype="" + + if ! mimetype=$(file --mime --brief "${file}" 2>/dev/null) ; then + if [ "${file: -4}" = ".zip" ] ; then + mimetype="application/zip" + fi + fi + + echo ${mimetype%%;*} +} + +function bee_extract_do() { + local file="${1}" + local dest="${2}" + local mode="${3}" + local mimetype="" + + shift 3 + + mimetype=$(get_or_guess_mimetype "${file}") + + if [ "${mimetype}" = "application/zip" ] ; then + print_error "zip extraction not yet implemented" + fi + + if [ "${mode}" = "primary" ] ; then + bee_extract_do_tar0 "${file}" "${dest}" + else + bee_extract_do_tar "${file}" "${dest}" + fi +} function bee_extract() { local bee_S @@ -397,11 +430,11 @@ function bee_extract() { unset bee_S[0] print_info " -> extracting main source ${s} .." - bee_extract_do_tar0 "${s}" "${S}" + bee_extract_do "${s}" "${S}" "primary" for s in ${bee_S[@]} ; do print_info " -> extracting additional source ${s} .." - bee_extract_do_tar "${s}" "${S}" + bee_extract_do "${s}" "${S}" "secondary" done print_info " -> all sources extracted to: ${S} .." From 5d091b56fc62b08af481a64edbc701e526a5fa3f Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 26 Feb 2013 18:36:51 +0100 Subject: [PATCH 6/7] beesh: Change the way source sub directories are handled $S now points to the $W/source/souresubdirectory --- buildtypes/cmake.sh.in | 2 +- src/beesh.sh.in | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/buildtypes/cmake.sh.in b/buildtypes/cmake.sh.in index 2e6db42..f2a2bc4 100644 --- a/buildtypes/cmake.sh.in +++ b/buildtypes/cmake.sh.in @@ -22,7 +22,7 @@ # along with this program. If not, see . # -: ${BEE_BUILDTYPE_CMAKE_CMAKELISTSTXT:=${S}/${BEE_SOURCESUBDIR}/CMakeLists.txt} +: ${BEE_BUILDTYPE_CMAKE_CMAKELISTSTXT:=${S}/CMakeLists.txt} if [ ! -r "${BEE_BUILDTYPE_CMAKE_CMAKELISTSTXT}" ] ; then return diff --git a/src/beesh.sh.in b/src/beesh.sh.in index 2a91657..00879ae 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -215,21 +215,22 @@ function bee_init_builddir() { fi print_info " -> creating source dir ${S}" - mkdir -p ${S} + print_info " -> creating image dir ${D}" + mkdir -p ${D} +} +function bee_init_buildinsourcedir() { if [ "${B}" == "${S}" ] ; then link=${BEEWORKDIR}/build print_info " -> B=S linking build dir ${link} to source dir" - ln -s source ${link} + ln -s ${S#${W}/} ${link} else print_info " -> creating build dir ${B}" mkdir -p ${B} fi - print_info " -> creating image dir ${D}" - mkdir -p ${D} } #### bee_getsources() ######################################################### @@ -972,6 +973,19 @@ bee_run getsources bee_run extract ${bee_SOURCEFILES[@]} +: ${BEE_SOURCESUBDIR=""} + +if [ ! -d "${S}/${BEE_SOURCESUBDIR}" ] ; then + print_error "ERROR: directory specified as sourcesubdir (${S}/${BEE_SOURCESUBDIR}) does not exist." + exit 1 +fi + +if [ "${B}" = "${S}" ] ; then + B="${S}/${BEE_SOURCESUBDIR}" +fi + +S="${S}/${BEE_SOURCESUBDIR}" + print_info "changing to source directory: ${S}" cd ${S} @@ -990,13 +1004,6 @@ bee_buildmagic=$(${BEE_BINDIR}/beeuniq ${BEE_BUILDTYPE[@]} \ BEE_BUILDTYPE_DETECTED="" -: ${BEE_SOURCESUBDIR=""} - -if [ ! -d "${S}/${BEE_SOURCESUBDIR}" ] ; then - print_error "ERROR: directory specified with add_sourcesubdir does not exist." - exit 1 -fi - for t in ${bee_buildmagic[@]} ; do load_buildmagic ${t} if [ -n "${BEE_BUILDTYPE_DETECTED}" ] ; then @@ -1004,6 +1011,7 @@ for t in ${bee_buildmagic[@]} ; do fi done +bee_init_buildinsourcedir print_info "changing to build directory: ${B}" cd ${B} From d2c1aea0643f23dff161866abdcb70b5894c2a94 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 26 Feb 2013 18:38:35 +0100 Subject: [PATCH 7/7] beesh: Add support for zip source archives To emulate the strip-components behavior of tar we scan the extracted sources and prepend a sourcesubdirectory if the archive is extracted into a subdirectory. This is a much cleaner solution then to strip components out of pathnames within the archive. So tar extraction should be changed too in the future. --- src/beesh.sh.in | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/beesh.sh.in b/src/beesh.sh.in index 00879ae..43995bb 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -363,6 +363,22 @@ function bee_getsources() { #### bee_extract() ############################################################# +function bee_extract_do_zip() { + local file="${1}" + local dest="${2}" + local -a list + + shift 2 + + start_cmd unzip -q -o "${file}" -d "${dest}" "${@}" + + readarray -t list < <(ls -a "${dest}" | grep -vE '^\.(\.|)$' | head -2) + + if [ "${#list[@]}" = "1" ] ; then + sourcesubdir_prepend "${list[0]}" + fi +} + function bee_extract_do_tar() { local file="${1}" local dest="${2}" @@ -400,7 +416,8 @@ function bee_extract_do() { mimetype=$(get_or_guess_mimetype "${file}") if [ "${mimetype}" = "application/zip" ] ; then - print_error "zip extraction not yet implemented" + bee_extract_do_zip "${file}" "${dest}" + return fi if [ "${mode}" = "primary" ] ; then