From b5187d21a50c91fa37d3a54a8e4e9eecb5970286 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 17 Mar 2019 18:24:16 -0400 Subject: ob-applypatches: Track and skip applied patches --- diff --git a/NEWS b/NEWS index 29257bb..e1b3674 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ Utilities: * ob-unpacksource now supports decompression of xz-compressed upstream archives. + * ob-applypatches now tracks and skips applied patches, instead of + re-running the patch command and throwing an error. * Manual pages for all utilities have been updated/written and are now built and installed for the first time since opkhelper 1.0.0. * Utilities can now be run in-place without installation by setting diff --git a/TODO b/TODO index 48adcdc..62eb2ed 100644 --- a/TODO +++ b/TODO @@ -12,8 +12,6 @@ Functional Changes ------------------ * ob-installdocs: Handle non-directory non-regular files? - * ob-applypatches: Track and skip applied patches in `.opkbuild/patches` file: - - `ob-applypatches: Skipping applied patch "01_foo.patch"...` * Read `tmp/.substvars` files and use them when generating each specific binary package's `control` file. This is needed for automatic shared library dependencies. diff --git a/locale/en_US/opkbuild.sh b/locale/en_US/opkbuild.sh index 4da8922..c39c5bf 100644 --- a/locale/en_US/opkbuild.sh +++ b/locale/en_US/opkbuild.sh @@ -86,6 +86,7 @@ msg_opkbuild_cant_unpack_upstream='Can'\''t extract upstream source archive' msg_opkbuild_cant_move_native='Can'\''t move extracted upstream source directory' # src/ob-applypatches.sh +msg_opkbuild_skipping_patch='Skipping applied patch "%s"...' msg_opkbuild_applying_patch='Applying patch "%s"...' msg_opkbuild_cant_apply_patch='Can'\''t apply patch "%s"' msg_opkbuild_no_patches='No patches to be applied' diff --git a/src/ob-applypatches.sh b/src/ob-applypatches.sh index 999b0cd..28d667c 100644 --- a/src/ob-applypatches.sh +++ b/src/ob-applypatches.sh @@ -1,6 +1,6 @@ # Apply patches to source code # -# Copyright (C) 2012 Patrick McDermott +# Copyright (C) 2012, 2019 Patrick McDermott # # This file is part of opkbuild. # @@ -28,6 +28,10 @@ apply_patches() applied='false' if [ -d '../patches' ] && [ -d 'src' ]; then + mkdir -p '.opkbuild' + patches="${OB_LF}$(cat '.opkbuild/patches' 2>/dev/null || \ + :)${OB_LF}" + exec 3>>'.opkbuild/patches' cd 'src/' # Iterate over patches ordered alphabetically by name. # POSIX.1-2008 says that the results of a pathname expansion @@ -40,16 +44,23 @@ apply_patches() [ -f "${patch}" ] || continue LANG="${orig_lang}" patch="${patch#../../patches/}" + case "${patches}" in *"${OB_LF}${patch}${OB_LF}"*) + ob_info "$(ob_get_msg 'skipping_patch')" \ + "${patch}" + continue + esac ob_info "$(ob_get_msg 'applying_patch')" "${patch}" if ! patch -N -p 1 -u -i "../../patches/${patch}"; then ob_error "$(ob_get_msg 'cant_apply_patch')" \ "${patch}" return 1 fi + printf '%s\n' "${patch}" >&3 applied='true' done LANG="${orig_lang}" cd '../' + exec 3>&- fi ${applied} || ob_info "$(ob_get_msg 'no_patches')" diff --git a/tests/exe/ob-applypatches.sh b/tests/exe/ob-applypatches.sh index c652275..1fc1ab1 100755 --- a/tests/exe/ob-applypatches.sh +++ b/tests/exe/ob-applypatches.sh @@ -35,7 +35,7 @@ cmd_is 'patch applied' cat 'src/src/foo.sh' <<-EOF ${FOO_SH_PATCHED} EOF -command_ok_ 'ob-applypatches second run exit status' -D TODO -- ob-applypatches +command_ok_ 'ob-applypatches second run exit status' -- ob-applypatches cmd_is 'patch still applied' cat 'src/src/foo.sh' <<-EOF ${FOO_SH_PATCHED} EOF -- cgit v0.9.1