PhilterPaper / Perl-PDF-Builder

Extended version of the popular PDF::API2 Perl-based PDF library for creating, reading, and modifying PDF documents
https://www.catskilltech.com/FreeSW/product/PDF%2DBuilder/title/PDF%3A%3ABuilder/freeSW_full
Other
6 stars 7 forks source link

Optional package installation failure #160

Closed PhilterPaper closed 3 years ago

PhilterPaper commented 3 years ago

While installing fresh copies of PDF::Builder 3.022 in Perl 5.22 and 5.32 (for increased testing), I noticed that the "optional" libraries (Graphics::TIFF, Image::PNG::Libpng, HarfBuzz::Shaper) were not being installed, even though the default selection in Makefile.PL is to install all of them. I can see that the resulting Makefile lists all three under "recommends" (as opposed to "required"). I thought this had tested as working a number of releases ago, but when I tried the new installs, no joy. The "recommends" list is ignored. It was suppose to have installed it, but if an install failed, to carry on anyway.

Has anyone else noticed this? Since I'm asking the user what they want to install, I suppose I could move these three packages (if requested by the user) over to "required" status, which will install them. If one or more fails, the user simply retries with that package unselected. However, I don't know what this is going to do with automated installations that default to "all" optional packages requested, such as for CPANTS (the CPAN testers). We could end up seeing a significant number of those fail to install, which would not be good.

It's not fatal to omit installing any of these optional packages, and any or all can always be installed manually later. Some t-tests will be skipped, and some features will be unavailable without the optional packages. It would be nice to see them always installed, which is why I made it the default. For manual installation of Builder, the inability to install an optional package is no big problem, but for an automated installation (such as CPAN testing), it wouldn't look good to fail on a large scale.

Thoughts?

carygravel commented 3 years ago

The only time I ever use the CPAN installer is inside the Github CI for Windows, where there is no distro-level package manager.

Once #159 is fixed I have a branch set up to add this to the CI in master.

PhilterPaper commented 3 years ago

Note to self: find another package that installs "required, optional" prereqs and see how they set up their Makefile.PL (possibly not "recommends"). Also look again for documentation on how to do optional packages -- there must be something somewhere!

PhilterPaper commented 3 years ago

So far I have found recommends and (weaker) suggests entries. Apparently, in both cases, there is no attempt to install these modules, unless some sort of "policy" flag has been set. It's not clear from what I've found so far whether I can set this flag in Makefile.PL, to apply to all installations, or whether it only applies to my own local installation (not really useful here). Also, it sounds like setting the policy flag to "true" will make optional packages a hard requirement (i.e., installation fails if any of these packages fail to install).

Makefile.PL uses ExtUtils::MakeMaker 6.55+ to create the Makefile and some JSON and YML metadata files. I can see a "recommends" section in the resulting Makefile, but it appears to be ignored. What I want to accomplish is for a suite of optional packages used by PDF::Builder (nice, but not absolutely mandatory) to be installed/updated if possible, but not to fail the whole installation if one or more of these optional prerequisites fails to install. For example, Graphics::TIFF requires libtiff.a (or the equivalent on non-Strawberry Perl systems), and so may not install on all systems. If you don't intend to do anything with TIFF image files, no big deal -- it will skip the appropriate t-tests and will fall back to slow (and buggy) built-in pure Perl code if you should happen to try using a TIFF file. You can always manually install Graphics::TIFF later and make full use of its capabilities.

If anyone can suggest how to modify Makefile.PL to try to install the "optional" prerequisites, and not fail if any or all of them fail, I'd appreciate any suggestions. Note that Makefile.PL already gives you the option to install any subset of the optionals, and the default (used in non-interactive installations) is to install all of them. I just don't want to list these optionals as mandatory prerequisites, so that the entire installation would fail if any of them failed to install! I could check if they're already installed, before listing them in the output Makefile, but that doesn't really accomplish anything in the way of getting them installed.

PhilterPaper commented 3 years ago

I decided to handle this by putting the optionals under "recommends", and adding META.json and META.yml files with "dynamic_config" set to 1. This will always attempt to install the optional packages (but not fail the job if one or more fails to install). To give the user a choice in what to install, you can use the "optional_update.pl" tool to remove (or re-add) the optional packages in the various build files that make use of them, and then manually run Makefile.PL etc. As always, you can remove/uninstall optional packages that you don't want, after the installation of PDF::Builder. The choice of which optionals to install has been removed from Makefile.PL.

carygravel commented 3 years ago

The recommends bit I agree with, but I don't think you need dynamic_config, as the packages which are recommended or required are known beforehand. dynamic_config is only needed by Graphics::TIFF, as Alien::libtiff is only required for Windows, and you only know whether you have Windows or not at the point at which the Makefile.PL is executed.

PhilterPaper commented 3 years ago

Well, unless it causes trouble I'll just leave dynamic_config in for now. I thought the make process wasn't working without it, but it's possible that changing something else fixed the build. As long as it doesn't cause any problems, I'll leave it in. I just wish all this build stuff was better documented (a "cookbook" approach), and I didn't have to do extensive trial-and-error to see what works.