From 2a1935f3ad41d360dd3d96a1b0486083293651dd Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 2 Dec 2017 12:23:31 -0800 Subject: Retire old scripts for handling patches Also rename test-packages -> manage-packages, it is no longer just testing. Signed-off-by: Alexey Neyman diff --git a/maintainer/manage-packages.sh b/maintainer/manage-packages.sh new file mode 100755 index 0000000..336237c --- /dev/null +++ b/maintainer/manage-packages.sh @@ -0,0 +1,308 @@ +#!/bin/bash + +selected= + +usage() +{ + cat <&2; exit 1; } + selected="${1}" + ;; + --signature|-S) + signature=y + ;; + --help|-?) + usage + exit 0 + ;; + *) + echo "Unknown option ${1}" >&2 + exit 1 + ;; + esac + shift +done + +if [ -z "${download_pkgs}${create_digests}${verify_urls}" ]; then + echo "No action selected" >&2 + exit 1 +fi + +CT_LIB_DIR=`pwd` +CT_TOP_DIR=`pwd` +CT_TARBALLS_DIR=`pwd`/temp.tarballs +CT_COMMON_SRC_DIR=`pwd`/temp.src +CT_SRC_DIR=`pwd`/temp.src +CT_LOG_LEVEL_MAX=EXTRA +CT_TEMP_PATCH_DIR=`pwd`/temp.patches +mkdir -p ${CT_TARBALLS_DIR} + +# Does not matter, just to make the scripts load +CT_ARCH=arm +CT_KERNEL=bare-metal +CT_BINUTILS=binutils +CT_LIBC=none +CT_CC=gcc + +. paths.sh +. scripts/functions + +rm -f build.log +CT_LogEnable + +check_pkg_urls() +{ + local e m mh url + + for e in ${archive_formats}; do + local -A mirror_status=( ) + + CT_DoStep EXTRA "Looking for ${archive_filename}${e}" + for m in ${mirrors}; do + url="${m}/${archive_filename}${e}" + case "${url}" in + # WGET always returns success for FTP URLs in spider mode :( + ftp://*) CT_DoLog DEBUG "Skipping '${url}': FTP not supported"; continue;; + esac + mh="${url#*://}" + mh="${mh%%[:/]*}" + if [ -n "${mirror_status[${mh}]}" ]; then + CT_DoLog DEBUG "Skipping '${url}': already found on this host at '${mirror_status[${mh}]}'" + continue + fi + if CT_DoExecLog ALL wget --spider "${url}"; then + mirror_status[${mh}]="${url}" + else + mirror_status[${mh}]= + fi + done + for mh in "${!mirror_status[@]}"; do + if [ -n "${mirror_status[${mh}]}" ]; then + CT_DoLog EXTRA "OK ${mh} [${archive_filename}${e}]" + else + CT_DoLog ERROR "FAIL ${mh} [${archive_filename}${e}]" + fi + done + CT_EndStep + done +} + +create_digests() +{ + local e m url alg chksum + local save_archive_formats="${archive_formats}" + + # Remove stale digests - we'll create them anew below + CT_DoExecLog ALL rm -f "${CT_LIB_DIR}/packages/${pkg_name}/${version}/chksum" + for e in ${save_archive_formats}; do + CT_DoStep EXTRA "Downloading ${archive_filename}${e}" + archive_formats="${e}" + CT_DoFetch + CT_Pushd "${CT_LOCAL_TARBALLS_DIR}" + for alg in md5 sha1 sha256 sha512; do + CT_DoLog EXTRA "Creating ${alg^^} digest for ${archive_filename}${e}" + chksum=`${alg}sum "${archive_filename}${e}"` + if [ "$?" != 0 ]; then + CT_DoExecLog ALL rm -f "${CT_LIB_DIR}/packages/${pkg_name}/${version}/chksum" + CT_Abort "${alg}sum failed" + fi + echo "${alg} ${archive_filename}${e} ${chksum%%[[:space:]]*}" >> \ + "${CT_LIB_DIR}/packages/${pkg_name}/${version}/chksum" + done + CT_Popd + CT_EndStep + done + archive_formats="${save_archive_formats}" +} + +update_patches() +{ + local masterpfx="${1}" + local pkgdir="${CT_LIB_DIR}/packages/${pkg_name}/${version}" + local p i base newname + + CT_DoExecLog ALL rm -rf "${CT_TEMP_PATCH_DIR}" + CT_DoExecLog ALL mkdir -p "${CT_TEMP_PATCH_DIR}" + + # Move old patches so that CT_DoExtractPatch produces a clean directory + for p in "${pkgdir}"/*.patch; do + if [ "${p}" = "${pkgdir}/*.patch" ]; then + return # No patches + fi + CT_DoExecLog ALL mv "${p}" "${CT_TEMP_PATCH_DIR}" + done + # NOTE: we're already inside CT_PackageRun, so use CT_DoExtractPatch rather + # than CT_ExtractPatch, so that we keep the variable modified by it. + CT_DoExtractPatch + CT_DoLog EXTRA "Pushing patches into quilt" + CT_Pushd "${src_dir}/${dir_name}" + export QUILT_PATCHES=ct-ng.patches + CT_DoExecLog ALL mkdir -p ${QUILT_PATCHES} + CT_DoExecLog ALL touch ${QUILT_PATCHES}/series + CT_DoExecLog ALL quilt --quiltrc - setup ct-ng.patches/series + for p in "${CT_TEMP_PATCH_DIR}"/*.patch; do + # By now we know we have a non-empty set of patches + CT_DoExecLog ALL quilt --quiltrc - import "${p}" + CT_DoExecLog ALL quilt --quiltrc - push + CT_DoExecLog ALL quilt --quiltrc - refresh -p ab --no-timestamps --no-index --diffstat + done + # Now publish the patches back into the package's directory, renumbering them + # in the process. + CT_DoLog EXTRA "Saving updated patches" + i=0 + for p in `quilt --quiltrc - applied`; do + # Strip index separated by dash or underscore + base=`echo "${p}" | sed 's#^[0-9]\{2,4\}[-_]##'` + newname=`printf "%04u-%s" "${i}" "${base}"` + i=$[i+1] + CT_DoExecLog ALL mv "${QUILT_PATCHES}/${p}" "${pkgdir}/${newname}" + done + CT_Popd +} + +run_pkgversion() +{ + while [ -n "${1}" ]; do + eval "local ${1}" + shift + done + + if [ -n "${selected}" ]; then + case "${selected}" in + ${pkg_name}|${pkg_name}-${ver}) + ;; + *) + return + ;; + esac + fi + + CT_DoStep INFO "Handling ${pkg_name}-${ver}" + + # Create a temporary configuration head file + cat >temp.in <temp.defconfig </dev/null + + CT_LoadConfig + rm -f .config .config.old temp.defconfig temp.in + if [ -n "${verify_urls}" ]; then + CT_DoLog EXTRA "Verifying URLs for ${pkg_name}-${ver}" + CT_PackageRun "${masterpfx}" check_pkg_urls + fi + if [ -n "${create_digests}" ]; then + CT_DoLog EXTRA "Creating digests for ${pkg_name}-${ver}" + CT_PackageRun "${masterpfx}" create_digests + fi + if [ -n "${download_pkgs}" ]; then + CT_DoLog EXTRA "Downloading ${pkg_name}-${ver}" + CT_Fetch "${masterpfx}" + fi + if [ -n "${apply_patches}" ]; then + CT_DoExecLog ALL rm -rf ${CT_COMMON_SRC_DIR} + CT_DoExecLog ALL mkdir -p ${CT_COMMON_SRC_DIR} + CT_ExtractPatch "${masterpfx}" + fi + if [ -n "${update_patches}" ]; then + CT_DoExecLog ALL rm -rf ${CT_COMMON_SRC_DIR} + CT_DoExecLog ALL mkdir -p ${CT_COMMON_SRC_DIR} + CT_PackageRun "${masterpfx}" update_patches + fi + + CT_EndStep +} + +[ -r .config ] && mv .config .config-saved +. maintainer/package-versions +[ -r .config-saved ] && mv .config-saved .config + +CT_DoExecLog ALL rm -rf ${CT_TARBALLS_DIR} ${CT_COMMON_SRC_DIR} ${CT_TEMP_PATCH_DIR} diff --git a/maintainer/patch-renumber.sh b/maintainer/patch-renumber.sh deleted file mode 100755 index c9650ce..0000000 --- a/maintainer/patch-renumber.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/sh -# Yes, this intends to be a true POSIX script file. -set -e - -myname="$0" - -# Parse the tools' paths configuration -# It is expected that this script is only to be run from the -# source directory of crosstool-NG, so it is trivial to find -# paths.sh (we can't use ". paths.sh", as POSIX states that -# $PATH should be searched for, and $PATH most probably doe -# not include "."), hence the "./". -. "./paths.sh" - -doUsage() { - cat <<_EOF_ -Usage: ${myname} [sed_re] - Renumbers all patches found in 'src_dir', starting at 'base', with an - increment of 'inc', and puts the renumbered patches in 'dst_dir'. - Leading digits are replaced with the new indexes, and a subsequent '_' - is replaced with a '-'. - If 'sed_re' is given, it is interpreted as a valid sed expression, and - is be applied to the patch name. - If the environment variable FAKE is set to 'y', then nothing gets done, - the command to run is only be printed, and not executed (so you can - check beforehand). - 'dst_dir' must not yet exist. - Eg.: - patch-renumber.sh patches/gcc/4.2.3 patches/gcc/4.2.4 100 10 - patch-renumber.sh /some/dir/my-patches patches/gcc/4.3.1 100 10 's/(all[_-])*(gcc[-_])*//;' -_EOF_ -} - -[ $# -lt 4 -o $# -gt 5 ] && { doUsage; exit 1; } - -src="${1}" -dst="${2}" -cpt="${3}" -inc="${4}" -sed_re="${5}" -if [ ! -d "${src}" ]; then - printf "%s: '%s': not a directory\n" "${myname}" "${src}" - exit 1 -fi -if [ -d "${dst}" ]; then - printf "%s: '%s': directory already exists\n" "${myname}" "${dst}" - exit 1 -fi - -Q= -if [ -n "${FAKE}" ]; then - printf "%s: won't do anything: FAKE='%s'\n" "${myname}" "${FAKE}" - Q="echo" -fi - -${Q} mkdir -pv "${dst}" -for p in "${src}/"*.patch*; do - [ -e "${p}" ] || { echo "No such file '${p}'"; exit 1; } - newname="$(printf "%03d-%s" \ - "${cpt}" \ - "$( basename "${p}" \ - |${sed} -r -e 's/^[[:digit:]]+[-_]//' \ - -e "${sed_re}" \ - )" \ - )" - ${Q} cp -v "${p}" "${dst}/${newname}" - cpt=$((cpt+inc)) -done diff --git a/maintainer/patch-rework.sh b/maintainer/patch-rework.sh deleted file mode 100755 index d05d2c1..0000000 --- a/maintainer/patch-rework.sh +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/sh - -# Get our required options -base="$1" -src="$2" -dst="$3" -shift 3 - -# The remainder is for diff -diff="$@" - -do_help() { - cat <<-_EOF_ - ${0##*/}: transform a patchset of non-p1 patches into -p1 patches - - Usage: - ${0##*/} [diffopts ...] - - Where: - basedir - points to the directory of the component to patch - - src - points to the directory containing the existing patchset - to transform - - dst - points to the directory where to put transformed patches - - diffopts - optional options to pass to diff, for debug purposes. You - should not need it - - Example: - Transform Gentoo patches against gcc-4.4.2 (some of which are - -p0, -p1 or even -p2 patches) into all -p1 patches: - - tar xjf gcc-4.4.2.tar.bz2 - patch-rework.sh gcc-4.4.2 \\ - /path/to/gentoo/gcc/patches \\ - gcc-4.4.2.patches - _EOF_ -} - -# Sanity checks -if [ -z "${base}" \ - -o ! -d "${base}" \ - -o ! -d "${src}" \ - -o -e "${dst}" -a ! -d "${dst}" \ - ]; then - do_help - exit 1 -fi - -mkdir -p "${dst}" -base="${base%%/}" -src="$( cd "${src}"; pwd )" -dst="$( cd "${dst}"; pwd )" - -# This function checks that the files listed in the file in "$1" -# do exist, at the given depth-stripping level (aka diff -p#) -do_check_files_at_depth() { - local flist="$1" - local depth="$2" - local ret=0 # 0: OK, !0: KO - - exec 6<&0 - exec 7<"${flist}" - - while read f; do - f="$( echo "${f}" |sed -r -e "s:^([^/]+/){${depth}}::;" )" - [ -f "${f}" ] || ret=1 - done =NF-5;i--) { $(i) = ""; } print; }' \ - |sort \ - >"diffstat.orig" - printf " done\n" - - cd "${base}" - - # Check all files exist, up to depth 3 - printf " checking depth:" - d=0 - while [ $d -lt 4 ]; do - printf " ${d}" - if do_check_files_at_depth "../diffstat.orig" ${d}; then - printf " ok, using depth '${d}'\n" - break - fi - d=$((d + 1)) - done - if [ ${d} -ge 4 ]; then - printf "\n" - printf " checking depth failed\n" - read -p " --> enter patch depth (or Ctrl-C to abort): " d - fi - - # Store the original list of files touched by the patch, - # removing the $d leading components - sed -r -e "s:^([^/]+/){${d}}::;" "../diffstat.orig" >"${dst}/${pname}.diffstat.orig" - - # Apply the patch proper, and check it applied cleanly. - # We can't check with --dry-run because of patches that - # contain multiple accumulated patches onto a single file. - printf " applying patch..." - if ! patch -g0 -F1 -f -p${d} <"${p}" >"../patch.out" 2>&1; then - printf " ERROR\n\n" - cd - >/dev/null - printf "There was an error while applying:\n --> ${p} <--\n" - printf "'${base}' was restored to the state it was prior to applying this faulty patch.\n" - printf "Here's the 'patch' command, and its output:\n" - printf " ----8<----\n" - printf " patch -g0 -F1 -f -p${d} <'${p}'\n" - sed -r -e 's/^/ /;' "patch.out" - printf " ----8<----\n" - exit 1 - fi - printf " done\n" - - printf " removing '.orig' files..." - find . -type f -name '*.orig' -exec rm -f {} + - printf " done\n" - - cd - >/dev/null - - printf " re-diffing the patch..." - printf "%s\n\n" "${comment}" >"${dst}/${pname}" - diff -durN "${base}.orig" "${base}" >>"${dst}/${pname}" - printf " done\n" - - if [ -n "${diff}" ]; then - printf " applying diff filter..." - filterdiff -x "${diff}" "${dst}/${pname}" >"tmp-diff" - mv "tmp-diff" "${dst}/${pname}" - printf " done\n" - fi - - printf " creating new patched file list..." - diffstat -f 4 -r 2 -u -p 1 "${dst}/${pname}" \ - |head -n -1 \ - |awk '{ for(i=NF;i>=NF-5;i--) { $(i) = ""; } print; }' \ - |sort \ - >"${dst}/${pname}.diffstat.new" - printf " done\n" - - printf " removing temporary files/dirs..." - rm -f "patch.out" - rm -f "diffstat.tmp" - rm -f "diffstat.orig" - rm -rf "${base}.orig" - printf " done\n" -done - -# Scan all new patches to see if they touch -# more files than the original patches -printf "\nChecking resulting patchset:\n" -for p in "${dst}/"*.patch; do - pname="$( basename "${p}" )" - - if ! cmp "${p}.diffstat.orig" "${p}.diffstat.new" >/dev/null; then - printf " --> '${pname}' differ in touched files <--\n" - else - rm -f "${p}.diffstat.orig" "${p}.diffstat.new" - fi -done -printf " done.\n" diff --git a/maintainer/test-packages.sh b/maintainer/test-packages.sh deleted file mode 100755 index 336237c..0000000 --- a/maintainer/test-packages.sh +++ /dev/null @@ -1,308 +0,0 @@ -#!/bin/bash - -selected= - -usage() -{ - cat <&2; exit 1; } - selected="${1}" - ;; - --signature|-S) - signature=y - ;; - --help|-?) - usage - exit 0 - ;; - *) - echo "Unknown option ${1}" >&2 - exit 1 - ;; - esac - shift -done - -if [ -z "${download_pkgs}${create_digests}${verify_urls}" ]; then - echo "No action selected" >&2 - exit 1 -fi - -CT_LIB_DIR=`pwd` -CT_TOP_DIR=`pwd` -CT_TARBALLS_DIR=`pwd`/temp.tarballs -CT_COMMON_SRC_DIR=`pwd`/temp.src -CT_SRC_DIR=`pwd`/temp.src -CT_LOG_LEVEL_MAX=EXTRA -CT_TEMP_PATCH_DIR=`pwd`/temp.patches -mkdir -p ${CT_TARBALLS_DIR} - -# Does not matter, just to make the scripts load -CT_ARCH=arm -CT_KERNEL=bare-metal -CT_BINUTILS=binutils -CT_LIBC=none -CT_CC=gcc - -. paths.sh -. scripts/functions - -rm -f build.log -CT_LogEnable - -check_pkg_urls() -{ - local e m mh url - - for e in ${archive_formats}; do - local -A mirror_status=( ) - - CT_DoStep EXTRA "Looking for ${archive_filename}${e}" - for m in ${mirrors}; do - url="${m}/${archive_filename}${e}" - case "${url}" in - # WGET always returns success for FTP URLs in spider mode :( - ftp://*) CT_DoLog DEBUG "Skipping '${url}': FTP not supported"; continue;; - esac - mh="${url#*://}" - mh="${mh%%[:/]*}" - if [ -n "${mirror_status[${mh}]}" ]; then - CT_DoLog DEBUG "Skipping '${url}': already found on this host at '${mirror_status[${mh}]}'" - continue - fi - if CT_DoExecLog ALL wget --spider "${url}"; then - mirror_status[${mh}]="${url}" - else - mirror_status[${mh}]= - fi - done - for mh in "${!mirror_status[@]}"; do - if [ -n "${mirror_status[${mh}]}" ]; then - CT_DoLog EXTRA "OK ${mh} [${archive_filename}${e}]" - else - CT_DoLog ERROR "FAIL ${mh} [${archive_filename}${e}]" - fi - done - CT_EndStep - done -} - -create_digests() -{ - local e m url alg chksum - local save_archive_formats="${archive_formats}" - - # Remove stale digests - we'll create them anew below - CT_DoExecLog ALL rm -f "${CT_LIB_DIR}/packages/${pkg_name}/${version}/chksum" - for e in ${save_archive_formats}; do - CT_DoStep EXTRA "Downloading ${archive_filename}${e}" - archive_formats="${e}" - CT_DoFetch - CT_Pushd "${CT_LOCAL_TARBALLS_DIR}" - for alg in md5 sha1 sha256 sha512; do - CT_DoLog EXTRA "Creating ${alg^^} digest for ${archive_filename}${e}" - chksum=`${alg}sum "${archive_filename}${e}"` - if [ "$?" != 0 ]; then - CT_DoExecLog ALL rm -f "${CT_LIB_DIR}/packages/${pkg_name}/${version}/chksum" - CT_Abort "${alg}sum failed" - fi - echo "${alg} ${archive_filename}${e} ${chksum%%[[:space:]]*}" >> \ - "${CT_LIB_DIR}/packages/${pkg_name}/${version}/chksum" - done - CT_Popd - CT_EndStep - done - archive_formats="${save_archive_formats}" -} - -update_patches() -{ - local masterpfx="${1}" - local pkgdir="${CT_LIB_DIR}/packages/${pkg_name}/${version}" - local p i base newname - - CT_DoExecLog ALL rm -rf "${CT_TEMP_PATCH_DIR}" - CT_DoExecLog ALL mkdir -p "${CT_TEMP_PATCH_DIR}" - - # Move old patches so that CT_DoExtractPatch produces a clean directory - for p in "${pkgdir}"/*.patch; do - if [ "${p}" = "${pkgdir}/*.patch" ]; then - return # No patches - fi - CT_DoExecLog ALL mv "${p}" "${CT_TEMP_PATCH_DIR}" - done - # NOTE: we're already inside CT_PackageRun, so use CT_DoExtractPatch rather - # than CT_ExtractPatch, so that we keep the variable modified by it. - CT_DoExtractPatch - CT_DoLog EXTRA "Pushing patches into quilt" - CT_Pushd "${src_dir}/${dir_name}" - export QUILT_PATCHES=ct-ng.patches - CT_DoExecLog ALL mkdir -p ${QUILT_PATCHES} - CT_DoExecLog ALL touch ${QUILT_PATCHES}/series - CT_DoExecLog ALL quilt --quiltrc - setup ct-ng.patches/series - for p in "${CT_TEMP_PATCH_DIR}"/*.patch; do - # By now we know we have a non-empty set of patches - CT_DoExecLog ALL quilt --quiltrc - import "${p}" - CT_DoExecLog ALL quilt --quiltrc - push - CT_DoExecLog ALL quilt --quiltrc - refresh -p ab --no-timestamps --no-index --diffstat - done - # Now publish the patches back into the package's directory, renumbering them - # in the process. - CT_DoLog EXTRA "Saving updated patches" - i=0 - for p in `quilt --quiltrc - applied`; do - # Strip index separated by dash or underscore - base=`echo "${p}" | sed 's#^[0-9]\{2,4\}[-_]##'` - newname=`printf "%04u-%s" "${i}" "${base}"` - i=$[i+1] - CT_DoExecLog ALL mv "${QUILT_PATCHES}/${p}" "${pkgdir}/${newname}" - done - CT_Popd -} - -run_pkgversion() -{ - while [ -n "${1}" ]; do - eval "local ${1}" - shift - done - - if [ -n "${selected}" ]; then - case "${selected}" in - ${pkg_name}|${pkg_name}-${ver}) - ;; - *) - return - ;; - esac - fi - - CT_DoStep INFO "Handling ${pkg_name}-${ver}" - - # Create a temporary configuration head file - cat >temp.in <temp.defconfig </dev/null - - CT_LoadConfig - rm -f .config .config.old temp.defconfig temp.in - if [ -n "${verify_urls}" ]; then - CT_DoLog EXTRA "Verifying URLs for ${pkg_name}-${ver}" - CT_PackageRun "${masterpfx}" check_pkg_urls - fi - if [ -n "${create_digests}" ]; then - CT_DoLog EXTRA "Creating digests for ${pkg_name}-${ver}" - CT_PackageRun "${masterpfx}" create_digests - fi - if [ -n "${download_pkgs}" ]; then - CT_DoLog EXTRA "Downloading ${pkg_name}-${ver}" - CT_Fetch "${masterpfx}" - fi - if [ -n "${apply_patches}" ]; then - CT_DoExecLog ALL rm -rf ${CT_COMMON_SRC_DIR} - CT_DoExecLog ALL mkdir -p ${CT_COMMON_SRC_DIR} - CT_ExtractPatch "${masterpfx}" - fi - if [ -n "${update_patches}" ]; then - CT_DoExecLog ALL rm -rf ${CT_COMMON_SRC_DIR} - CT_DoExecLog ALL mkdir -p ${CT_COMMON_SRC_DIR} - CT_PackageRun "${masterpfx}" update_patches - fi - - CT_EndStep -} - -[ -r .config ] && mv .config .config-saved -. maintainer/package-versions -[ -r .config-saved ] && mv .config-saved .config - -CT_DoExecLog ALL rm -rf ${CT_TARBALLS_DIR} ${CT_COMMON_SRC_DIR} ${CT_TEMP_PATCH_DIR} -- cgit v0.10.2-6-g49f6