Repository navigation
Avoid unexpected line breaks in version_string.inc - #14026
Conversation
alalek
left a comment
There was a problem hiding this comment.
As a "bugfix" this patch should go into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly).
So, please:
- change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
- rebase your commits from master onto 3.4 branch. For example:
git rebase -i --onto upstream/3.4 upstream/master
(check list of your commits, save and quit (Esc + "wq" + Enter)
whereupstreamis configured by following this GitHub guide and fetched (git fetch upstream). - push rebased commits into source branch of your fork (with
--forceoption)
Note: no needs to re-open PR, apply changes "inplace".
| message(STATUS "${msg}") | ||
| string(REPLACE "\\" "\\\\" msg "${msg}") | ||
| string(REPLACE "\"" "\\\"" msg "${msg}") | ||
| string(REPLACE "\n" "" msg "${msg}") |
There was a problem hiding this comment.
Concatenation of multiple lines doesn't looks as a good idea.
Consider handling of them properly, but drop leading and trailing "new-lines":
string(REGEX REPLACE "^\n+|\n+$" "" msg "${msg}")
string(REPLACE "\n" "\\n" msg "${msg}")
There was a problem hiding this comment.
My understanding is that the ocv_output_status function should be invoked for every line inserted in the version_string.inc file. I've come across this issue when the generated version_string.inc has an unexpected line break (look at (ver 161.4479499)
" Documentation: NO\n"
" Non-free algorithms: NO\n"
"\n"
" Android NDK: /hdd1.0TB_a/data/projects/fingerprint/deploy/toolchains/android-ndk-r16b (ver 161.4479499
)\n"
" Android ABI: armeabi-v7a\n"
Using your suggested solution this version_string.inc would be:
" Documentation: NO\n"
" Non-free algorithms: NO\n"
"\n"
" Android NDK: /hdd1.0TB_a/data/projects/fingerprint/deploy/toolchains/android-ndk-r16b (ver 161.4479499\n"
")\n"
" Android ABI: armeabi-v7a\n"
Am I right?
There was a problem hiding this comment.
Your understanding is correct.
Multiline message is not expected here. Perhaps we need some check with warning/error here.
161.4479499
Looks like there is a bug with detection of Android NDK version. It should be 16.1.4479499 (with dot after 16). And without "\n" in the end.
Perhaps we should fix it too.
Could you please dump ANDROID_NDK_REVISION before this line:
message(STATUS "ANDROID_NDK_REVISION='${ANDROID_NDK_REVISION}'")
and check if it is entered entered into "if" block.
There was a problem hiding this comment.
On my system with NDK 16b this code
message(STATUS "!!!before ANDROID_NDK_REVISION='${ANDROID_NDK_REVISION}'")
if(DEFINED ANDROID_NDK_REVISION AND ANDROID_NDK_REVISION MATCHES "(1[56])([0-9]+)\\.([^\n]+)\n")
message(STATUS "!!!FIX ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
set(ANDROID_NDK_REVISION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
set(ANDROID_NDK_REVISION "${ANDROID_NDK_REVISION}" CACHE INTERNAL "Android NDK revision")
endif()
message(STATUS "!!!after ANDROID_NDK_REVISION='${ANDROID_NDK_REVISION}'")
dumps this:
-- !!!before ANDROID_NDK_REVISION='161.4479499
'
-- !!!FIX 16.1.4479499
-- !!!after ANDROID_NDK_REVISION='16.1.4479499'
So, workaround works for me.
Question is why this fixup doesn't work on your machine?
There was a problem hiding this comment.
I haven't been able to display messages in OpenCVDetectAndroidSDK.cmake for some motive, I even tried producing a fatal error, it seems that this script isn't executed. Here are the cmake flags I've used:
cmake ../.. -DBUILD_ZLIB=ON -DBUILD_TIFF=ON -DBUILD_JPEG=ON \
-DBUILD_PNG=ON -DBUILD_JASPER=OFF -DBUILD_OPENEXR=OFF -DBUILD_WEBP=OFF \
-DBUILD_TBB=ON -DBUILD_IPP_IW=ON -DBUILD_ITT=OFF -DWITH_1394=OFF \
-DWITH_AVFOUNDATION=OFF -DWITH_CARBON=OFF -DWITH_CAROTENE=OFF -DWITH_CPUFEATURES=OFF \
-DWITH_VTK=OFF -DWITH_CUDA=OFF -DWITH_CUFFT=OFF -DWITH_CUBLAS=OFF \
-DWITH_NVCUVID=OFF -DWITH_EIGEN=OFF -DWITH_VFW=OFF -DWITH_FFMPEG=OFF \
-DWITH_GSTREAMER=OFF -DWITH_GSTREAMER_0_10=OFF -DWITH_GTK=OFF -DWITH_GTK_2_X=OFF \
-DWITH_IPP=OFF -DWITH_HALIDE=OFF -DWITH_INF_ENGINE=OFF -DWITH_JASPER=OFF \
-DWITH_JPEG=OFF -DWITH_WEBP=OFF -DWITH_OPENEXR=OFF -DWITH_OPENGL=OFF \
-DWITH_OPENVX=OFF -DWITH_OPENNI=OFF -DWITH_OPENNI2=OFF -DWITH_PNG=OFF \
-DWITH_GDCM=OFF -DWITH_PVAPI=OFF -DWITH_GIGEAPI=OFF -DWITH_ARAVIS=OFF \
-DWITH_QT=OFF -DWITH_WIN32UI=OFF -DWITH_QUICKTIME=OFF -DWITH_QTKIT=OFF \
-DWITH_TBB=OFF -DWITH_OPENMP=OFF -DWITH_CSTRIPES=OFF -DWITH_PTHREADS_PF=OFF \
-DWITH_TIFF=OFF -DWITH_UNICAP=OFF -DWITH_V4L=OFF -DWITH_LIBV4L=OFF \
-DWITH_DSHOW=OFF -DWITH_MSMF=OFF -DWITH_XIMEA=OFF -DWITH_XINE=OFF \
-DWITH_CLP=OFF -DWITH_OPENCL=OFF -DWITH_OPENCL_SVM=OFF -DWITH_OPENCLAMDFFT=OFF \
-DWITH_OPENCLAMDBLAS=OFF -DWITH_DIRECTX=OFF -DWITH_INTELPERC=OFF -DWITH_MATLAB=OFF \
-DWITH_VA=OFF -DWITH_VA_INTEL=OFF -DWITH_MFX=OFF -DWITH_GDAL=OFF \
-DWITH_GPHOTO2=OFF -DWITH_LAPACK=OFF -DWITH_ITT=OFF -DWITH_PROTOBUF=OFF \
-DWITH_IMGCODEC_HDR=OFF -DWITH_IMGCODEC_SUNRASTER=OFF -DWITH_IMGCODEC_PXM=OFF -DBUILD_SHARED_LIBS=OFF \
-DBUILD_opencv_apps=OFF -DBUILD_opencv_js=OFF -DBUILD_ANDROID_PROJECTS=OFF -DBUILD_ANDROID_EXAMPLES=OFF \
-DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_PACKAGE=OFF -DBUILD_PERF_TESTS=OFF \
-DBUILD_TESTS=OFF -DBUILD_WITH_DEBUG_INFO=OFF -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_WITH_DYNAMIC_IPP=OFF \
-DBUILD_FAT_JAVA_LIB=OFF -DBUILD_ANDROID_SERVICE=OFF -DBUILD_CUDA_STUBS=OFF -DBUILD_JAVA=OFF \
-DINSTALL_TESTS=OFF -DENABLE_CCACHE=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DENABLE_SOLUTION_FOLDERS=OFF \
-DENABLE_PROFILING=OFF -DENABLE_COVERAGE=OFF -DENABLE_OMIT_FRAME_POINTER=OFF -DENABLE_POWERPC=OFF \
-DENABLE_VSX=OFF -DENABLE_FAST_MATH=ON -DENABLE_NEON=OFF -DENABLE_VFPV3=OFF \
-DENABLE_NOISY_WARNINGS=OFF -DOPENCV_WARNINGS_ARE_ERRORS=OFF -DANDROID_EXAMPLES_WITH_LIBS=OFF -DENABLE_IMPL_COLLECTION=OFF \
-DENABLE_INSTRUMENTATION=OFF -DENABLE_GNU_STL_DEBUG=OFF -DENABLE_BUILD_HARDENING=OFF -DENABLE_LTO=OFF \
-DENABLE_PYLINT=OFF -DENABLE_FLAKE8=OFF -DANDROID_NDK="$ANDROID_NDK" -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI="$ANDROID_ABI" -DANDROID_NATIVE_API_LEVEL="$ANDROID_API_LEVEL" -DANDROID_CPP_FEATURES="rtti exceptions" \
-DCMAKE_BUILD_TYPE=Release
There was a problem hiding this comment.
Except for the malformed version_string.inc I can successfully build and link a native opencv library for android using the NDK only. I don't see any reason to force the SDK as a dependency in this case.
Do you known where the ANDROID_NDK_REVISION is set before calling OpenCVDetectAndroidSDK.cmake ?
Edit: Never mind, it is in the 16b NDK itself as you stated.
There was a problem hiding this comment.
Ok, mystery solved, so I think would be a good idea to display a warning when calling ocv_output_status with a string that has a line break in the middle and use your proposed solution.
There was a problem hiding this comment.
I'm thinking of this solution (inside ocv_output_status):
string(REGEX REPLACE "^\n+|\n+$" "" msg "${msg}")
if(msg MATCHES "\n")
string(REPLACE "\n" "\\n" msg "${msg}")
message(WARNING "String to be inserted to version_string.inc has an unexpected line break: ${msg}")
endif()
Comments?
There was a problem hiding this comment.
ANDROID_NDK_REVISION comes from NDK toolchain file (${ANDROID_NDK}/build/cmake/android.toolchain.cmake).
This bug has been fixed in NDK 17: https://android-review.googlesource.com/c/platform/ndk/+/585851/5/build/cmake/android.toolchain.cmake
display a warning
Agreed!
Please swap string(REPLACE) and message(WARNING) statement to show "corrupted" message as is (additionally add ' to show message's start/end: '${msg}').
Please use 2 spaces indentation in CMake files.
|
OK, I'll rebase into 3.4. Thanks! |
db7051a to
b4f1381
Compare
The Android NDK 16b has a bug that sets the ANDROID_NDK_REVISION variable incorrectly, generating an unexpected line break in the middle of the string. This breaks the build as the generated version_string.inc presents an invalid C string. Remove leading and trailing line breaks, warns for line breaks in the middle of 'msg' and escape them before appending to OPENCV_BUILD_INFO_STR.
For some motive I've been experiencing build errors when using the
Android NDK 16b (I don't know if this is specific to this version or
it has some to do with cmake). The error is caused by an unexpected
line break in the middle of a string.
This commit adds a check to remove any line break '\n' before
appending the status string to OPENCV_BUILD_INFO_STR.