Bug 260079 - graphics/leptonica: update to 1.82.0
Summary: graphics/leptonica: update to 1.82.0
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Rainer Hurling
URL: https://github.com/DanBloomberg/lepto...
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-27 17:53 UTC by John Hein
Modified: 2022-01-07 08:12 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (hiroto.kagotani)


Attachments
[patch] update graphics/leptonica to 1.82.0, tweaks for portlint/portclippy (3.83 KB, patch)
2021-11-27 17:53 UTC, John Hein
jcfyecrayz: maintainer-approval? (hiroto.kagotani)
Details | Diff
CMake conversion (WIP) (5.68 KB, patch)
2021-11-29 12:50 UTC, Daniel Engberg
no flags Details | Diff
CMake conversion (WIP) v2 (12.27 KB, patch)
2021-11-30 01:40 UTC, Daniel Engberg
no flags Details | Diff
patch to add FindLeptonica.cmake file (1.64 KB, patch)
2021-11-30 19:36 UTC, Rainer Hurling
no flags Details | Diff
CMake conversion (WIP) v3 (9.11 KB, patch)
2021-12-05 00:54 UTC, Daniel Engberg
no flags Details | Diff
CMake conversion (WIP) v4 (7.99 KB, patch)
2022-01-06 00:09 UTC, Daniel Engberg
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Hein 2021-11-27 17:53:17 UTC
Created attachment 229758 [details]
[patch] update graphics/leptonica to 1.82.0, tweaks for portlint/portclippy

Update graphics/leptonica to 1.82.0 (Sep 2021) from 1.76.0 (May 2018).

Changes include run time bug fixes, build fixes, new features & tools (imagetops), improved tests: https://github.com/DanBloomberg/leptonica/blob/master/version-notes.html

Some run testing was done briefly with tesseract.  It would be great if users more familiar with leptonica could do more testing.  But 'make test' reports only one failed regression test out of 144 [1].

While here, make portlint & portclippy happy (just a couple changes for recommended sorting / grouping of variables).

QA for the update patch:
 - build with non-default LOCALBASE (ok)
 - brief run-time testing with text2image and back to image (with tesseract)
 - poudriere testport (ok - amd64,i386)
 - portlint (ok - no errors or warnings)
 - portclippy (no new recommended changes)
 - make test (143/144 regression tests succeeded [1])


[1] one failed test:

FAILURE: maze_reg
Failed to complete maze_reg

////////////////////////////////////////////////
////////////////   maze_reg   ///////////////
////////////////////////////////////////////////
leptonica-1.82.0 : libgif 5.2.1 : libjpeg 8d (libjpeg-turbo 2.1.2) : libpng 1.6.37+apng : libtiff 4.3
.0 : zlib 1.2.11 : libwebp 1.2.1
Info in pixSearchBinaryMaze:  No path found
Error in pixDisplayPta: pta not defined
Error in pixScaleBySampling: pixs not defined
Error in pixaAddPix: pix not defined
Error in regTestWritePixAndCheck: pix not defined
Time:   0.651 sec

This could be reported upstream.  I don't know how this compares to the 1.76.0 port.  Unless this is a critical piece, perhaps the update could be committed while investigating this test failure.
Comment 1 John Hein 2021-11-27 19:58:12 UTC
(In reply to John Hein from comment #0)
The maze_req test is failing for the 1.76.0 version of the port as well (at least 12/stable-amd64, probably others).  So that failure is not a new regression with 1.82.0.
Comment 2 Daniel Engberg freebsd_committer 2021-11-29 09:39:37 UTC
Any reason why we're not using upstream release archive?

http://www.leptonica.org/source/leptonica-1.82.0.tar.gz
https://github.com/DanBloomberg/leptonica/releases/download/1.82.0/leptonica-1.82.0.tar.gz

Switching to CMake would probably also improve builds times
Comment 3 Rainer Hurling freebsd_committer 2021-11-29 11:43:20 UTC
(In reply to Daniel Engberg from comment #2)

Thank you, Daniel, for the tips. I would also appreciate it if this update would switch to cmake right away.

Another concern on my part is that projects like graphics/opencv cannot use the graphics/tesseract and graphics/leptonica dependencies so far.

If graphics/tesseract is already installed on a system and then graphics/opencv is to be installed, OpenCV uses the script /usr/local/cmake/TesseractConfig.cmake to check for the presence of Leptonica and would like to use the FindLeptonica.cmake file under /usr/local/share/cmake/Modules, which does not exist in the system, for this purpose.

However, FindLeptonica.cmake is not yet included in the Leptonica sources. If my opinion is shared that the port graphics/leptonica should install this cmake file, there is a working example at https://github.com/yoisel/tesseract_winrt/blob/master/cmake/FindLeptonica.cmake. This file could be patched into the port and then installed from the Makefile under /usr/local/share/cmake/Modules. If this file would be present, ports like graphics/opencv could also find an installed Leptonica ;)

Any opinions on this? What does the maintainer say ;)
Comment 4 Daniel Engberg freebsd_committer 2021-11-29 12:46:42 UTC
Hmm... I did a quick change to CMake and it looks like we need to do some patching or possibly some ${RLN} magic but it looks like nothing major.

====> Compressing man pages (compress-man)
====> Checking for pkg-plist issues (check-plist)
===> Parsing plist
===> Checking for items in STAGEDIR missing from pkg-plist
Error: Orphaned: lib/cmake/leptonica/LeptonicaConfig-version.cmake
Error: Orphaned: lib/cmake/leptonica/LeptonicaConfig.cmake
Error: Orphaned: lib/cmake/leptonica/LeptonicaTargets-%%CMAKE_BUILD_TYPE%%.cmake
Error: Orphaned: lib/cmake/leptonica/LeptonicaTargets.cmake
Error: Orphaned: lib/libleptonica.so.1.82.0
Error: Orphaned: lib/libleptonica.so.5.4.0
===> Checking for items in pkg-plist which are not in STAGEDIR
Error: Missing: bin/imagetops
Error: Missing: lib/cmake/LeptonicaConfig-version.cmake
Error: Missing: lib/cmake/LeptonicaConfig.cmake
Error: Missing: lib/liblept.a
Error: Missing: lib/liblept.so
Error: Missing: lib/liblept.so.5
Error: Missing: lib/liblept.so.5.0.4
Error: Missing: lib/libleptonica.a
===> Error: Plist issues found.
*** Error code 1

I've uploaded a quick "WIP" patch, JPEG2000 and WEBP options needs to be sorted out correctly and plist needs to be updated accordingly.

Looking at other ports the general naming convention seems to be lib/cmake/${PORTNAME}/ so that should be followed for consistency.

As for the FindLeptonica.cmake I agree that it should be included and should also be submitted upstream.
Comment 5 Daniel Engberg freebsd_committer 2021-11-29 12:50:12 UTC
Created attachment 229788 [details]
CMake conversion (WIP)

Based on the patch by John Hein, always include zlib support as we always have zlib available via base.
Comment 6 Daniel Engberg freebsd_committer 2021-11-30 01:40:48 UTC
Created attachment 229806 [details]
CMake conversion (WIP) v2

A few more quick fixes, some things could be more tidy but I'm not going to rewrite all CMake files.

Library options now works as expected
No weird library symlinks
.pc (pkgconfig) file now reports version correctly

Stuff that needs fixing
* libdata/pkgconfig/lept.pc and/or libdata/pkgconfig/leptonica.pc for consistency ?
* Import CMake helper to find library
* Libs.private in .pc file lists no libraries at all
Comment 7 Rainer Hurling freebsd_committer 2021-11-30 19:36:25 UTC
Created attachment 229815 [details]
patch to add FindLeptonica.cmake file

Thanks Daniel, nice work :D

In one of the next patch versions, there could be something like the following in the ports Makefile to add 'FindLeptonica.cmake', as mentioned in comment #3:


# Workaround for a missing FindLeptonica.cmake
# (from https://github.com/yoisel/tesseract_winrt/blob/master/cmake/)
post-install:
	${MKDIR} ${STAGEDIR}${PREFIX}/share/cmake/Modules
	${INSTALL_DATA} ${WRKSRC}/cmake/FindLeptonica.cmake \
		${STAGEDIR}${PREFIX}/share/cmake/Modules/
Comment 8 John Hein 2021-11-30 21:44:52 UTC
Personally, I would prefer that we update to 1.82.0 first.  Then later consider switching to cmake.  If the maintainer and others agree on the switch to cmake, we could open a separate bug for the cmake switch.

Also it would be good to get the proposed patch for CMakeLists.txt accepted (or at least submitted for consideration) upstream.

A few observations on the cmake changes (v2) - why is imagetops not installed (maybe overlooked for cmake in upstream)?  Also the .a libs (maybe no one cares, but it's a change).  And there is a check-plist error.
Comment 9 Daniel Engberg freebsd_committer 2021-12-03 00:03:42 UTC
Why I think we should do it in one sweep otherwise is because it'll take good while before there's another attempt because "it works" and of course upstream the changes.
Comment 10 Daniel Engberg freebsd_committer 2021-12-04 18:03:28 UTC
Upstream PR: https://github.com/DanBloomberg/leptonica/pull/599
Comment 11 Daniel Engberg freebsd_committer 2021-12-05 00:54:36 UTC
Created attachment 229910 [details]
CMake conversion (WIP) v3

CMake "helper" imported
Libs.private pc file should be fine now
imagetops is now installed

This should fix all known issues, please test :-)
Comment 12 Rainer Hurling freebsd_committer 2021-12-05 07:07:36 UTC
(In reply to Daniel Engberg from comment #11)

Your patch v3 builds and installs fine for me. 

But, there is a name change of the libraries (from liblept.so to libleptonica.so) which causes errors for the graphics/tesseract and textproc/py-ocrmypdf dependencies. These two ports need to be fixed.

John had suggested in comment #8 to first make his changes (based on autoconf) and then switch to cmake. I can imagine to proceed like this.

Of course, it also works if we commit all the changes, including the pending dependent changes, in one go.

What do you both think?
Comment 13 Daniel Engberg freebsd_committer 2021-12-05 10:14:27 UTC
Thanks!

Regarding the conflicting names it seems to go way back
https://github.com/DanBloomberg/leptonica/issues/253

Personally I think it makes more sense to use the project name but either way we can just use RLN (symlinks) in post-install for compatibility reasons.

As for how we want to handle the update I'll leave it up to you but I don't see the benefit of going autotools then cmake though however I think we should wait on upstream (~1-2 weeks) before going ahead just to avoid diverging from upstream.
Comment 14 Rainer Hurling freebsd_committer 2021-12-06 10:00:01 UTC
(In reply to Daniel Engberg from comment #13)

Hi Daniel,

Thanks for the link to the project's thoughts on how to handle the different naming of the libraries under autoconf and cmake.

Since we have to wait at least for a reaction from the maintainer, I think it would be best to also wait for the Leptonica project's decisions on naming the libraries, as you suggested.
Comment 15 Daniel Engberg freebsd_committer 2022-01-01 04:38:53 UTC
PR finally merged (patch needs updating), upstream is still unsure about naming though...
Comment 16 Daniel Engberg freebsd_committer 2022-01-06 00:09:17 UTC
Created attachment 230746 [details]
CMake conversion (WIP) v4

This should be the final version

John and Rainer, can you give this a try?
Comment 17 Rainer Hurling freebsd_committer 2022-01-07 08:12:07 UTC
(In reply to Daniel Engberg from comment #16)

The newest patch (WIP4) applies, builds and installs fine for me. Dependents like textproc/py-ocrmypdf and graphics/opencv also install as usual.

Thanks, Daniel :)