Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix, build] Don't fail quietly on patching failure #895

Merged
merged 9 commits into from
Apr 20, 2019

Conversation

Frenzie
Copy link
Member

@Frenzie Frenzie commented Apr 19, 2019

It's a vestigial property from before we switched to CMake.

See #892 (comment) for discussion.

@Frenzie Frenzie added the bug label Apr 19, 2019
@Frenzie Frenzie changed the title [fix, build] Don't fail quietly on patch fail [fix, build] Don't fail quietly on patching failure Apr 19, 2019
@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

@NiLuJe Hm, apparently I was wrongish. I'll look into it a little deeper in any case, because this || true is freaking terrible.

-- Build files have been written to: /home/frans/src/kobo/koreader/base/thirdparty/luajit/build/x86_64-linux-gnu-debug
[1/5] Performing patch step for 'luajit'
FAILED: luajit-prefix/src/luajit-stamp/luajit-patch 
cd /home/frans/src/kobo/koreader/base/thirdparty/luajit/build/x86_64-linux-gnu-debug/luajit-prefix/src/luajit && sh -c "patch -N -p1 < /home/frans/src/kobo/koreader/base/thirdparty/luajit/koreader-luajit-makefile-tweaks.patch" && /usr/bin/cmake -E touch /home/frans/src/kobo/koreader/base/thirdparty/luajit/build/x86_64-linux-gnu-debug/luajit-prefix/src/luajit-stamp/luajit-patch
patching file src/Makefile
Reversed (or previously applied) patch detected!  Skipping patch.
4 out of 4 hunks ignored -- saving rejects to file src/Makefile.rej
ninja: build stopped: subcommand failed.

@NiLuJe
Copy link
Member

NiLuJe commented Apr 19, 2019

Hide it away in a utility function in our cmake bag of tricks?

Would have to take a list for projects with multiple patches and we'd just have to feed the filename?

(Similar to how Gentoo ebuilds use a PATCHES bash array).

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

It looks like it might be really easy to handle. The error code for previously applied is 1, and for actual errors it's greater than 1.

@NiLuJe
Copy link
Member

NiLuJe commented Apr 19, 2019

Oh, wait, that wouldn't solve the "silent failure" issue, though -_-".

EDIT: Ha, too slow ;).

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

I think there's an easier solution: --merge.

@NiLuJe
Copy link
Member

NiLuJe commented Apr 19, 2019

Not supported on macOS ;).

patch: unrecognized option `--merge'

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

@NiLuJe Could you check the error codes?

@NiLuJe
Copy link
Member

NiLuJe commented Apr 19, 2019

In which instances?

(Right now, it return 2 for unsupported option ;)).

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

Like I said above, 1 is previously applied, greater than 1 is other (actual) errors.

@NiLuJe
Copy link
Member

NiLuJe commented Apr 19, 2019

Yep, that holds true on macOS, too.

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

Alright, in that case I'll write a simple wrapper script.

It's GNU Patch only. ;-;

This reverts commit 93abe3e.
@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

@NiLuJe Something like this work on Mac OS?

#!/bin/sh

# depends on input from stdin

patch -p1 -N --dry-run --silent 2>/dev/null

exit_status=$?

if [ $exit_status -eq 0 ]; then
    echo "Applying patch."
    patch -p1 -N
    exit $?
elif [ $exit_status -eq 1 ]; then
    echo "Previously applied patch, ignoring."
    exit 0
fi

exit $?
diff --git a/thirdparty/cmake_modules/koreader_thirdparty_common.cmake b/thirdparty/cmake_modules/koreader_thirdparty_common.cmake
index fff09c2..1be801a 100644
--- a/thirdparty/cmake_modules/koreader_thirdparty_common.cmake
+++ b/thirdparty/cmake_modules/koreader_thirdparty_common.cmake
@@ -24,6 +24,8 @@ else()
     set(KO_MAKE_RECURSIVE make)
 endif()
 
+set(KO_PATCH "sh ${CMAKE_MODULE_PATH}/patch-wrapper.sh")
+
 macro(assert_var_defined varName)
     if(NOT DEFINED ${varName})
         message(FATAL_ERROR "${varName} variable not defined!")

@NiLuJe
Copy link
Member

NiLuJe commented Apr 19, 2019

That looks sane, but I'll double-check when I'm back on the laptop later ;)

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

I'll update the PR to include that. The basic strategy seems right even if some minor details in the script itself could need tweaking for Mac OS. This way it seems more elegant to me, but the same thing can always be done without the dry-run part.

PS I think sdcv is working out because it's handled completely by CMake, and the conflicts arise because for whatever reason the patching process is a bit weird for ExternalProject. The CMake source just says that it can be hard to write a good patch command, roflmao.

@NiLuJe
Copy link
Member

NiLuJe commented Apr 19, 2019

CMake being helpful, as always :D.

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

https://github.com/Kitware/CMake/blob/0793464d95c3dbbe9ed87bb5882d29efb7a8e3c3/Modules/ExternalProject.cmake#L352-L358

    ``PATCH_COMMAND <cmd>...``
      Specifies a custom command to patch the sources after an update. By
      default, no patch command is defined. Note that it can be quite difficult
      to define an appropriate patch command that performs robustly, especially
      for download methods such as git where changing the ``GIT_TAG`` will not
      discard changes from a previous patch, but the patch command will be
called again after updating to the new tag.

@Frenzie
Copy link
Member Author

Frenzie commented Apr 19, 2019

@NiLuJe Not 100 % sure, but I think the problem may be localized to BUILD_IN_SOURCE 1. (luajit, mupdf, openssl)

@Frenzie
Copy link
Member Author

Frenzie commented Apr 20, 2019

@NiLuJe In other news, introducing a failure (on purpose here for testing) still returns an exit status of 0 for the OpenSSL configure script? O_o

-- Build files have been written to: /home/frans/src/kobo/koreader-base/thirdparty/openssl/build/x86_64-linux-gnu
[1/4] Performing configure step for 'openssl'
Operating system: x86_64-whatever-linux2

Failure!  build file wasn't produced.
Please read INSTALL and associated NOTES files.  You may also have to look over
your available compiler tool chain or change your configuration.

***** Unsupported options: no-r5
0
[2/4] Performing build step for 'openssl'
make[1]: Entering directory '/home/frans/src/kobo/koreader-base/thirdparty/openssl/build/x86_64-linux-gnu/openssl-prefix/src/openssl'
make[1]: Leaving directory '/home/frans/src/kobo/koreader-base/thirdparty/openssl/build/x86_64-linux-gnu/openssl-prefix/src/openssl'
make[1]: Entering directory '/home/frans/src/kobo/koreader-base/thirdparty/openssl/build/x86_64-linux-gnu/openssl-prefix/src/openssl'
make _build_libs
make[2]: Entering directory '/home/frans/src/kobo/koreader-base/thirdparty/openssl/build/x86_64-linux-gnu/openssl-prefix/src/openssl'
make[2]: Nothing to be done for '_build_libs'.
make[2]: Leaving directory '/home/frans/src/kobo/koreader-base/thirdparty/openssl/build/x86_64-linux-gnu/openssl-prefix/src/openssl'
make[1]: Leaving directory '/home/frans/src/kobo/koreader-base/thirdparty/openssl/build/x86_64-linux-gnu/openssl-prefix/src/openssl'
[4/4] Completed 'openssl'

@Frenzie
Copy link
Member Author

Frenzie commented Apr 20, 2019

Darn, you also get an exit code of 1 for hunks failed to apply. @NiLuJe Does Mac OS have the -b flag?

NB Only returning false success in some instances is still better than always returning success.

@Frenzie
Copy link
Member Author

Frenzie commented Apr 20, 2019

@NiLuJe I think this updated script is pretty fool-proof.

#!/bin/sh

if [ $# -eq 0 ]; then
    echo "Patch file required as argument."
    exit 1
fi

PATCH_FILE=$1

# Reverse patch will succeed if the patch is already applied.
# In case of failure, it means we should try to apply the patch.
if ! patch -R -p1 -N --dry-run <"${PATCH_FILE}" >/dev/null 2>&1; then
    # Now patch for real.
    patch -p1 -N <"${PATCH_FILE}"
    exit $?
fi

So if the reverse patch doesn't succeed, try to patch, and return the exit status. If the reverse patch succeeds, it means the patch was already successfully applied previously.

@Frenzie Frenzie merged commit ec77fe8 into koreader:master Apr 20, 2019
@Frenzie Frenzie deleted the fail-patches branch April 20, 2019 12:31
Frenzie added a commit to Frenzie/koreader that referenced this pull request Apr 20, 2019
koreader/koreader-base#896
* Bump HarfBuzz to 2.4.0
* Bump K2pdfopt to pickup the CJK thingy
* Bump libpng to 1.6.37
* Bump FBInk to 1.15.0

[fix, build] Don't fail quietly on patching failure koreader/koreader-base#895
@NiLuJe
Copy link
Member

NiLuJe commented Apr 20, 2019 via email

Frenzie added a commit to koreader/koreader that referenced this pull request Apr 20, 2019
koreader/koreader-base#896
* Bump HarfBuzz to 2.4.0
* Bump K2pdfopt to pickup the CJK thingy
* Bump libpng to 1.6.37
* Bump FBInk to 1.15.0

[fix, build] Don't fail quietly on patching failure koreader/koreader-base#895
@houqp
Copy link
Member

houqp commented Apr 21, 2019

nice work on the patch wrapper 👍

mwoz123 pushed a commit to mwoz123/koreader that referenced this pull request Mar 29, 2020
koreader/koreader-base#896
* Bump HarfBuzz to 2.4.0
* Bump K2pdfopt to pickup the CJK thingy
* Bump libpng to 1.6.37
* Bump FBInk to 1.15.0

[fix, build] Don't fail quietly on patching failure koreader/koreader-base#895
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants