FFI-CheckLib-0.31/000755 000000 000000 00000000000 14315571125 013465 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/Changes000644 000000 000000 00000012015 14315571125 014757 0ustar00rootroot000000 000000 Revision history for FFI-CheckLib 0.31 2022-09-30 07:42:44 -0600 - Better support for Homebrew and MacPorts on macOS (gh#46 cdalvaro++) - New environment variable FFI_CHECKLIB_PACKAGE (gh#46) - New environment variable FFI_CHECKLIB_PATH (gh#50, gh#52) - Documentation improvements (gh#49, gh#52) 0.30 2022-09-22 04:24:26 -0600 - [ BREAKING CHANGE ] If the alien option is provided, the libraries provided by aliens will be preferred over the system libraries (gh#47, gh#48) 0.29 2022-09-10 01:46:05 -0600 - Handle Windows DLLs using underscores instead of dashes in version numbers (gh#44, gh#45, shawnlaffan++) 0.28 2021-05-16 15:10:34 -0600 - Avoid undef warning from File::Spec->catpath (gh#30, gh#33) - The alien option now works in fallback mode; if one or more of the Aliens are not installed then they will be ignored, previously this module would throw whatever exception was produced by require (gh#23, gh#34) - Move to PerlFFI org on GitHub (previously this dist lived in Perl5-FFI) (gh#24) 0.27 2020-05-11 14:24:08 -0400 - Added a FAQ section to the documentation (gh#22) 0.26 2020-01-22 05:54:02 -0700 - Name check on alien option is always done, even if the Alien is already loaded (gh#21) - Remove dependency on Module::Load (gh#21) 0.25 2019-06-25 12:27:58 -0400 - Add support for Alien::Base with alien option (gh#18) 0.24 2019-04-27 09:14:34 -0400 - Add try_linker_script option (gh#13, gh#15) 0.23 2018-11-18 00:07:49 -0500 - Handle DLLs on Windows with "dashed" version numbers (example: foo-1-2-3.dll) (gh#10, gh#11, SLAFFAN++) 0.22 2018-10-13 22:24:46 -0400 - Production version identical to 0.21_01 0.21_01 2018-10-11 22:53:43 -0400 - Documentation fixes - Handle DLLs with upper-case characters in extension on MSWin32 (gh#9) 0.20 2018-06-04 18:18:09 -0400 - Add system_path function. 0.19 2018-05-30 21:09:32 -0400 - Administrative release to note that this dist is moving its repository to the Perl5-FFI org on github.com 0.18 2017-10-25 10:00:47 -0400 - Production version identical to 0.17_02 0.17_02 2017-10-14 01:03:04 -0400 - Fix Windows testing regression introduced in 0.17_01 0.17_01 2017-10-13 15:58:30 -0400 - Filter out broken and recursive symlinks - Better handle symlinked .so files on platforms that support that. Previously, we preferred the longer .so names (ie, libfoo.so.1.2.3) over the shorter .so names (libfoo.so) since the latter is usually a symlink, and the former may have useful "version" information in the filename. That is a problem when a system is using symlinks to indicate a preference, (for example, if there are both libfoo.so.1.2.3, libfoo.so.1.2.4 and libfoo.so is a symlink to one of those). Now we still endevour to return the long .so name, but use the short name to see which one is preferred by the operating system, or user. In the absense of any symlinks to disambiguate two libraries with the same name, we prefer the one with a newer version number. That is libfoo.so.2.3.4 would be preferred over libfoo.so.1.2.3 - Slightly more consistent diagnostic messages. - Added functions: which, where, has_symbols None are exported by default, but may be requested. 0.16 2017-08-08 10:24:49 -0400 - Tentative support for msys 0.15 2016-05-05 19:53:32 -0400 - Add MSYS2 support 0.14 2015-09-09 08:25:15 -0400 - Version identical to 0.12 (0.12 was accidentally removed from CPAN) 0.12 2015-08-06 16:09:32 -0400 - Switch to MakeMaker since we are not using any features that require Module::Build 0.11 2015-02-13 08:45:23 -0500 - New recursive option - The experimental _r option will be keept beiefly then removed - The lib option allows '*' to match any library - New systempath option 0.10 2015-02-12 18:52:54 -0500 - Add experimental and undocumented _r option intended for use with Alien::Base only. 0.09 2015-01-28 17:10:53 -0500 - Skip undef found in system library path. (thanks bakkiaraj gh#3) On Windows this was causing a undef'd variable warning if %PATH% has a trailing ; 0.08 2015-01-25 04:54:37 -0500 - Prefer FFI::Platypus in documentation over other FFI systems 0.07 2015-01-16 10:22:22 -0500 - bugfix: forgot to export find_lib_or_die 0.06 2015-01-13 12:07:19 -0500 - add function find_lib_or_die 0.05 2015-01-10 17:31:34 -0500 - add function find_lib_or_exit (GH#2) - [API CHANGE] find_lib returns first library found if called in scalar context, instead of the number of libraries found. - better diagnostics for failure (GH#1) 0.04 2015-01-02 11:21:59 -0500 - works with .bundle files on OS X (previously only with .dylib files) 0.03 2014-10-26 16:35:22 -0400 - use DynaLoader for symbol resolution instead actual FFI - add verify option 0.02 2014-10-26 13:18:14 -0400 - first release to CPAN 0.01 2014-10-26 11:34:58 -0400 - initial version FFI-CheckLib-0.31/INSTALL000644 000000 000000 00000004553 14315571125 014525 0ustar00rootroot000000 000000 This is the Perl distribution FFI-CheckLib. Installing FFI-CheckLib is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm FFI::CheckLib If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan FFI::CheckLib ## Manual installation As a last resort, you can manually install it. If you have not already downloaded the release tarball, you can find the download link on the module's MetaCPAN page: https://metacpan.org/pod/FFI::CheckLib Untar the tarball, install configure prerequisites (see below), then build it: % perl Makefile.PL % make && make test Then install it: % make install On Windows platforms, you should use `dmake` or `nmake`, instead of `make`. If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Configure Prerequisites This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json. ## Other Prerequisites This distribution may require additional modules to be installed after running Makefile.PL. Look for prerequisites in the following phases: * to run make, PHASE = build * to use the module code itself, PHASE = runtime * to run tests, PHASE = test They can all be found in the "PHASE_requires" key of MYMETA.yml or the "{prereqs}{PHASE}{requires}" key of MYMETA.json. ## Documentation FFI-CheckLib documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc FFI::CheckLib For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html FFI-CheckLib-0.31/LICENSE000644 000000 000000 00000043667 14315571125 014512 0ustar00rootroot000000 000000 This software is copyright (c) 2014-2022 by Graham Ollis. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2014-2022 by Graham Ollis. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014-2022 by Graham Ollis. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End FFI-CheckLib-0.31/MANIFEST000644 000000 000000 00000005467 14315571125 014632 0ustar00rootroot000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.025. Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README author.yml corpus/cygwin/bin/cygapatosaurus-0.dll corpus/cygwin/bin/cygdinosaur.dll corpus/darwin/custom/libfoo.dylib corpus/darwin/foo-1.00/src/libs/libbar.dylib corpus/darwin/foo-1.00/src/libs/libbaz.dylib corpus/darwin/foo-1.00/src/libs/libfoo.dylib corpus/darwin/lib/libfoo.dylib corpus/darwin/lib/libfoo.dylib.2 corpus/darwin/lib/libfoo.dylib.2.3 corpus/darwin/lib/libfoo.dylib.2.3.4 corpus/darwin/usr/lib/libbar.dylib corpus/darwin/usr/lib/libbar.dylib.1 corpus/darwin/usr/lib/libbar.dylib.1.2 corpus/darwin/usr/lib/libbar.dylib.1.2.3 corpus/darwin/usr/lib/libfoo.a corpus/darwin/usr/lib/libfoo.dylib corpus/darwin/usr/lib/libfoo.dylib.1 corpus/darwin/usr/lib/libfoo.dylib.1.2 corpus/darwin/usr/lib/libfoo.dylib.1.2.3 corpus/generic.dll corpus/lib/Alien/libbar.pm corpus/unix/custom/libfoo.so corpus/unix/foo-1.00/src/libs/libbar.so corpus/unix/foo-1.00/src/libs/libbaz.so corpus/unix/foo-1.00/src/libs/libfoo.so corpus/unix/lib/libfoo.so corpus/unix/lib/libfoo.so.2 corpus/unix/lib/libfoo.so.2.3 corpus/unix/lib/libfoo.so.2.3.4 corpus/unix/path/path1/libfoo.so.1 corpus/unix/path/path2/libfoo.so.2 corpus/unix/path/path3/libfoo.so.3 corpus/unix/usr/lib/libbar.so corpus/unix/usr/lib/libbar.so.1 corpus/unix/usr/lib/libbar.so.1.2 corpus/unix/usr/lib/libbar.so.1.2.3 corpus/unix/usr/lib/libcrypto.so.0.9.8 corpus/unix/usr/lib/libcrypto.so.1.0.0 corpus/unix/usr/lib/libfoo.a corpus/unix/usr/lib/libfoo.so corpus/unix/usr/lib/libfoo.so.1 corpus/unix/usr/lib/libfoo.so.1.2 corpus/unix/usr/lib/libfoo.so.1.2.3 corpus/unix/usr/lib/libxor.so corpus/unix/usr/lib/libxor.so.1 corpus/unix/usr/lib/libxor.so.1.2 corpus/unix/usr/lib/libxor.so.1.2.3 corpus/unix/usr/lib/libxor.so.1.2.4 corpus/windows/bin/dinosaur.dll corpus/windows/bin/dromornis_planei-3.0-7-0.dll corpus/windows/bin/libapatosaurus-0.dll corpus/windows/bin/libapatosaurus_ajax.dll corpus/windows/bin/libbrevipalatus_mcculloughi_9_1__.dll corpus/windows/bin/libmaiasaura-3-7-0.dll corpus/windows/bin/libthylacaleo_carnifex-3-7___.dll corpus/windows/bincase/LIBbar.DLL corpus/windows/bincase/foo.DLL dist.ini example/wheredll.pl example/whichdll.pl lib/FFI/CheckLib.pm maint/cip-before-install perlcriticrc t/00_diag.t t/ci.t t/ffi_checklib.t t/ffi_checklib__exit.t t/ffi_checklib__os_cygwin.t t/ffi_checklib__os_darwin.t t/ffi_checklib__os_mswin32.t t/ffi_checklib__os_msys.t t/ffi_checklib__os_unix.t t/lib/Test2/Plugin/FauxOS.pm t/lib/Test2/Tools/FauxDynaLoader.pm t/lib/Test2/Tools/NoteStderr.pm xt/author/critic.t xt/author/eol.t xt/author/no_tabs.t xt/author/pod.t xt/author/pod_coverage.t xt/author/pod_link.t xt/author/pod_spelling_common.t xt/author/pod_spelling_system.t xt/author/strict.t xt/author/version.t xt/release/changes.t xt/release/fixme.t FFI-CheckLib-0.31/META.json000644 000000 000000 00000015607 14315571125 015117 0ustar00rootroot000000 000000 { "abstract" : "Check that a library is available for FFI", "author" : [ "Graham Ollis " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.025, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "FFI-CheckLib", "no_index" : { "directory" : [ "corpus" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "perl" : "5.006" } }, "develop" : { "recommends" : { "Dist::Zilla::Plugin::Author::Plicease::Thanks" : "0", "Dist::Zilla::Plugin::Author::Plicease::Upload" : "0", "Dist::Zilla::Plugin::MetaNoIndex" : "0", "Dist::Zilla::Plugin::RemovePrereqs" : "0", "Dist::Zilla::PluginBundle::Author::Plicease" : "2.72", "Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep" : "0", "Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit" : "0", "Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep" : "0", "Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap" : "0", "Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA" : "0", "Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless" : "0", "Perl::Critic::Policy::CodeLayout::ProhibitHardTabs" : "0", "Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace" : "0", "Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines" : "0", "Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames" : "0", "Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions" : "0", "Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode" : "0", "Perl::Critic::Policy::Freenode::ArrayAssignAref" : "0", "Perl::Critic::Policy::Freenode::BarewordFilehandles" : "0", "Perl::Critic::Policy::Freenode::ConditionalDeclarations" : "0", "Perl::Critic::Policy::Freenode::ConditionalImplicitReturn" : "0", "Perl::Critic::Policy::Freenode::DeprecatedFeatures" : "0", "Perl::Critic::Policy::Freenode::DiscouragedModules" : "0", "Perl::Critic::Policy::Freenode::DollarAB" : "0", "Perl::Critic::Policy::Freenode::Each" : "0", "Perl::Critic::Policy::Freenode::IndirectObjectNotation" : "0", "Perl::Critic::Policy::Freenode::LexicalForeachIterator" : "0", "Perl::Critic::Policy::Freenode::LoopOnHash" : "0", "Perl::Critic::Policy::Freenode::ModPerl" : "0", "Perl::Critic::Policy::Freenode::OpenArgs" : "0", "Perl::Critic::Policy::Freenode::OverloadOptions" : "0", "Perl::Critic::Policy::Freenode::POSIXImports" : "0", "Perl::Critic::Policy::Freenode::PackageMatchesFilename" : "0", "Perl::Critic::Policy::Freenode::PreferredAlternatives" : "0", "Perl::Critic::Policy::Freenode::StrictWarnings" : "0", "Perl::Critic::Policy::Freenode::Threads" : "0", "Perl::Critic::Policy::Freenode::WarningsSwitch" : "0", "Perl::Critic::Policy::Freenode::WhileDiamondDefaultAssignment" : "0", "Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles" : "0", "Perl::Critic::Policy::InputOutput::ProhibitJoinedReadline" : "0", "Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen" : "0", "Perl::Critic::Policy::Miscellanea::ProhibitFormats" : "0", "Perl::Critic::Policy::Miscellanea::ProhibitUselessNoCritic" : "0", "Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements" : "0", "Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish" : "0", "Perl::Critic::Policy::Objects::ProhibitIndirectSyntax" : "0", "Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic" : "0", "Perl::Critic::Policy::Subroutines::ProhibitNestedSubs" : "0", "Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros" : "0", "Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators" : "0", "Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator" : "0", "Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator" : "0", "Perl::Critic::Policy::Variables::ProhibitPerl4PackageNames" : "0", "Perl::Critic::Policy::Variables::ProhibitUnusedVariables" : "0", "Software::License::Perl_5" : "0" }, "requires" : { "FindBin" : "0", "Perl::Critic" : "0", "Test2::Require::EnvVar" : "0.000121", "Test2::Require::Module" : "0.000121", "Test2::Tools::PerlCritic" : "0", "Test2::V0" : "0.000121", "Test::CPAN::Changes" : "0", "Test::EOL" : "0", "Test::Fixme" : "0.07", "Test::More" : "0.98", "Test::NoTabs" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "Test::Pod::LinkCheck::Lite" : "0", "Test::Pod::Spelling::CommonMistakes" : "0", "Test::Spelling" : "0", "Test::Strict" : "0", "YAML" : "0" } }, "runtime" : { "requires" : { "File::Which" : "0", "List::Util" : "1.33", "perl" : "5.006" } }, "test" : { "requires" : { "Test2::API" : "1.302015", "Test2::Require::EnvVar" : "0.000121", "Test2::Require::Module" : "0.000121", "Test2::V0" : "0.000121", "perl" : "5.006" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/PerlFFI/FFI-CheckLib/issues" }, "homepage" : "https://metacpan.org/pod/FFI::CheckLib", "repository" : { "type" : "git", "url" : "git://github.com/PerlFFI/FFI-CheckLib.git", "web" : "https://github.com/PerlFFI/FFI-CheckLib" }, "x_IRC" : "irc://irc.perl.org/#native" }, "version" : "0.31", "x_contributors" : [ "Graham Ollis ", "Bakkiaraj Murugesan (bakkiaraj)", "Dan Book (grinnz, DBOOK)", "Ilya Pavlov (Ilya, ILUX)", "Shawn Laffan (SLAFFAN)", "Petr P\u00edsa\u0159 (ppisar)", "Michael R. Davis (MRDVT)", "Shawn Laffan (SLAFFAN)", "Carlos D. \u00c1lvaro (cdalvaro)" ], "x_generated_by_perl" : "v5.36.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.30", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later", "x_use_unsafe_inc" : 0 } FFI-CheckLib-0.31/META.yml000644 000000 000000 00000002500 14315571125 014733 0ustar00rootroot000000 000000 --- abstract: 'Check that a library is available for FFI' author: - 'Graham Ollis ' build_requires: Test2::API: '1.302015' Test2::Require::EnvVar: '0.000121' Test2::Require::Module: '0.000121' Test2::V0: '0.000121' perl: '5.006' configure_requires: ExtUtils::MakeMaker: '0' perl: '5.006' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.025, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: FFI-CheckLib no_index: directory: - corpus requires: File::Which: '0' List::Util: '1.33' perl: '5.006' resources: IRC: irc://irc.perl.org/#native bugtracker: https://github.com/PerlFFI/FFI-CheckLib/issues homepage: https://metacpan.org/pod/FFI::CheckLib repository: git://github.com/PerlFFI/FFI-CheckLib.git version: '0.31' x_contributors: - 'Graham Ollis ' - 'Bakkiaraj Murugesan (bakkiaraj)' - 'Dan Book (grinnz, DBOOK)' - 'Ilya Pavlov (Ilya, ILUX)' - 'Shawn Laffan (SLAFFAN)' - 'Petr Písař (ppisar)' - 'Michael R. Davis (MRDVT)' - 'Shawn Laffan (SLAFFAN)' - 'Carlos D. Álvaro (cdalvaro)' x_generated_by_perl: v5.36.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' x_use_unsafe_inc: 0 FFI-CheckLib-0.31/Makefile.PL000644 000000 000000 00000003256 14315571125 015445 0ustar00rootroot000000 000000 BEGIN { use strict; use warnings; unless(eval q{ use 5.006; 1}) { print "Perl 5.006 or better required\n"; exit; } } # This file was automatically generated by Dist::Zilla::Plugin::Author::Plicease::MakeMaker v2.72. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Check that a library is available for FFI", "AUTHOR" => "Graham Ollis ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "FFI-CheckLib", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "FFI::CheckLib", "PM" => { "lib/FFI/CheckLib.pm" => "\$(INST_LIB)/FFI/CheckLib.pm" }, "PREREQ_PM" => { "File::Which" => 0, "List::Util" => "1.33" }, "TEST_REQUIRES" => { "Test2::API" => "1.302015", "Test2::Require::EnvVar" => "0.000121", "Test2::Require::Module" => "0.000121", "Test2::V0" => "0.000121" }, "VERSION" => "0.31", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "File::Which" => 0, "List::Util" => "1.33", "Test2::API" => "1.302015", "Test2::Require::EnvVar" => "0.000121", "Test2::Require::Module" => "0.000121", "Test2::V0" => "0.000121" ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs);FFI-CheckLib-0.31/README000644 000000 000000 00000026457 14315571125 014363 0ustar00rootroot000000 000000 NAME FFI::CheckLib - Check that a library is available for FFI VERSION version 0.31 SYNOPSIS use FFI::CheckLib; check_lib_or_exit( lib => 'jpeg', symbol => 'jinit_memory_mgr' ); check_lib_or_exit( lib => [ 'iconv', 'jpeg' ] ); # or prompt for path to library and then: print "where to find jpeg library: "; my $path = ; check_lib_or_exit( lib => 'jpeg', libpath => $path ); DESCRIPTION This module checks whether a particular dynamic library is available for FFI to use. It is modeled heavily on Devel::CheckLib, but will find dynamic libraries even when development packages are not installed. It also provides a find_lib function that will return the full path to the found dynamic library, which can be feed directly into FFI::Platypus or another FFI system. Although intended mainly for FFI modules via FFI::Platypus and similar, this module does not actually use any FFI to do its detection and probing. This module does not have any non-core runtime dependencies. The test suite does depend on Test2::Suite. FUNCTIONS All of these take the same named parameters and are exported by default. find_lib my(@libs) = find_lib(%args); This will return a list of dynamic libraries, or empty list if none were found. [version 0.05] If called in scalar context it will return the first library found. Arguments are key value pairs with these keys: lib Must be either a string with the name of a single library or a reference to an array of strings of library names. Depending on your platform, CheckLib will prepend lib or append .dll or .so when searching. [version 0.11] As a special case, if * is specified then any libs found will match. libpath A string or array of additional paths to search for libraries. systempath [version 0.11] A string or array of system paths to search for instead of letting FFI::CheckLib determine the system path. You can set this to [] in order to not search any system paths. symbol A string or a list of symbol names that must be found. verify A code reference used to verify a library really is the one that you want. It should take two arguments, which is the name of the library and the full path to the library pathname. It should return true if it is acceptable, and false otherwise. You can use this in conjunction with FFI::Platypus to determine if it is going to meet your needs. Example: use FFI::CheckLib; use FFI::Platypus; my($lib) = find_lib( lib => 'foo', verify => sub { my($name, $libpath) = @_; my $ffi = FFI::Platypus->new; $ffi->lib($libpath); my $f = $ffi->function('foo_version', [] => 'int'); return $f->call() >= 500; # we accept version 500 or better }, ); recursive [version 0.11] Recursively search for libraries in any non-system paths (those provided via libpath above). try_linker_script [version 0.24] Some vendors provide .so files that are linker scripts that point to the real binary shared library. These linker scripts can be used by gcc or clang, but are not directly usable by FFI::Platypus and friends. On select platforms, this options will use the linker command (ld) to attempt to resolve the real .so for non-binary files. Since there is extra overhead this is off by default. An example is libyaml on Red Hat based Linux distributions. On Debian these are handled with symlinks and no trickery is required. alien [version 0.25] If no libraries can be found, try the given aliens instead. The Alien classes specified must provide the Alien::Base interface for dynamic libraries, which is to say they should provide a method called dynamic_libs that returns a list of dynamic libraries. [version 0.28] In 0.28 and later, if the Alien is not installed then it will be ignored and this module will search in system or specified directories only. This module will still throw an exception, if the Alien doesn't look like a module name or if it does not provide a dynamic_libs method (which is implemented by all Alien::Base subclasses). [version 0.30] [breaking change] Starting with version 0.30, libraries provided by Aliens is preferred over the system libraries. The original thinking was that you want to prefer the system libraries because they are more likely to get patched with regular system updates. Unfortunately, the reason a module needs to install an Alien is likely because the system library is not new enough, so we now prefer the Aliens instead. assert_lib assert_lib(%args); This behaves exactly the same as find_lib, except that instead of returning empty list of failure it throws an exception. check_lib_or_exit check_lib_or_exit(%args); This behaves exactly the same as assert_lib, except that instead of dying, it warns (with exactly the same error message) and exists. This is intended for use in Makefile.PL or Build.PL find_lib_or_exit [version 0.05] my(@libs) = find_lib_or_exit(%args); This behaves exactly the same as find_lib, except that if the library is not found, it will call exit with an appropriate diagnostic. find_lib_or_die [version 0.06] my(@libs) = find_lib_or_die(%args); This behaves exactly the same as find_lib, except that if the library is not found, it will die with an appropriate diagnostic. check_lib my $bool = check_lib(%args); This behaves exactly the same as find_lib, except that it returns true (1) on finding the appropriate libraries or false (0) otherwise. which [version 0.17] my $path = which($name); Return the path to the first library that matches the given name. Not exported by default. where [version 0.17] my @paths = where($name); Return the paths to all the libraries that match the given name. Not exported by default. has_symbols [version 0.17] my $bool = has_symbols($path, @symbol_names); Returns true if all of the symbols can be found in the dynamic library located at the given path. Can be useful in conjunction with verify with find_lib above. Not exported by default. system_path [version 0.20] my $path = FFI::CheckLib::system_path; Returns the system path as a list reference. On some systems, this is PATH on others it might be LD_LIBRARY_PATH on still others it could be something completely different. So although you may add items to this list, you should probably do some careful consideration before you do so. This function is not exportable, even on request. ENVIRONMENT FFI::CheckLib responds to these environment variables: FFI_CHECKLIB_PACKAGE On macOS platforms with Homebrew and/or MacPorts installed, their corresponding lib paths will be automatically appended to $system_path. In case of having both managers installed, Homebrew will appear before. This behaviour can be overridden using the environment variable FFI_CHECKLIB_PACKAGE. Allowed values are: - none: Won't use either Homebrew's path nor MacPorts - homebrew: Will append $(brew --prefix)/lib to the system paths - macports: Will append port's default lib path A comma separated list is also valid: export FFI_CHECKLIB_PACKAGE=macports,homebrew Order matters. So in this example, MacPorts' lib path appears before Homebrew's path. FFI_CHECKLIB_PATH List of directories that will be considered by FFI::CheckLib as additional "system directories". They will be searched before other system directories but after libpath. The variable is colon separated on Unix and semicolon separated on Windows. If you use this variable, FFI_CHECKLIB_PACKAGE will be ignored. PATH On Windows the PATH environment variable will be used as a search path for libraries. On some operating systems LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH or others may be used as part of the search for dynamic libraries and may be used (indirectly) by FFI::CheckLib as well. FAQ Why not just use dlopen? Calling dlopen on a library name and then dlclose immediately can tell you if you have the exact name of a library available on a system. It does have a number of drawbacks as well. No absolute or relative path It only tells you that the library is somewhere on the system, not having the absolute or relative path makes it harder to generate useful diagnostics. POSIX only This doesn't work on non-POSIX systems like Microsoft Windows. If you are using a POSIX emulation layer on Windows that provides dlopen, like Cygwin, there are a number of gotchas there as well. Having a layer written in Perl handles this means that developers on Unix can develop FFI that will more likely work on these platforms without special casing them. inconsistent implementations Even on POSIX systems you have inconsistent implementations. OpenBSD for example don't usually include symlinks for .so files meaning you need to know the exact .so version. non-system directories By default dlopen only works for libraries in the system paths. Most platforms have a way of configuring the search for different non-system paths, but none of them are portable, and are usually discouraged anyway. Alien and friends need to do searches for dynamic libraries in non-system directories for share installs. My 64-bit Perl is misconfigured and has 32-bit libraries in its search path. Is that a bug in FFI::CheckLib? Nope. The way FFI::CheckLib is implemented it won't work on AIX, HP-UX, OpenVMS or Plan 9. I know for a fact that it doesn't work on AIX as currently implemented because I used to develop on AIX in the early 2000s, and I am aware of some of the technical challenges. There are probably other systems that it won't work on. I would love to add support for these platforms. Realistically these platforms have a tiny market share, and absent patches from users or the companies that own these operating systems (patches welcome), or hardware / CPU time donations, these platforms are unsupportable anyway. SEE ALSO FFI::Platypus Call library functions dynamically without a compiler. Dist::Zilla::Plugin::FFI::CheckLib Dist::Zilla plugin for this module. AUTHOR Author: Graham Ollis Contributors: Bakkiaraj Murugesan (bakkiaraj) Dan Book (grinnz, DBOOK) Ilya Pavlov (Ilya, ILUX) Shawn Laffan (SLAFFAN) Petr Písař (ppisar) Michael R. Davis (MRDVT) Shawn Laffan (SLAFFAN) Carlos D. Álvaro (cdalvaro) COPYRIGHT AND LICENSE This software is copyright (c) 2014-2022 by Graham Ollis. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. FFI-CheckLib-0.31/author.yml000644 000000 000000 00000001163 14315571125 015513 0ustar00rootroot000000 000000 --- pod_spelling_system: skip: 0 # list of words that are spelled correctly # (regardless of what spell check thinks) stopwords: - libpath - Bakkiaraj - Murugesan - bakkiaraj - libs - systempath - grinnz - DBOOK - ILUX - Laffan - SLAFFAN - libyaml - Petr - Písař - ppisar - UX - MRDVT - macOS - Homebrew - MacPorts - cdalvaro - lvaro pod_coverage: skip: 0 # format is "Class#method" or "Class", regex allowed # for either Class or method. private: [] unused_vars: skip: 0 global: ignore_vars: [] module: {} FFI-CheckLib-0.31/corpus/000755 000000 000000 00000000000 14315571125 015000 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/cygwin/000755 000000 000000 00000000000 14315571125 016300 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/cygwin/bin/000755 000000 000000 00000000000 14315571125 017050 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/cygwin/bin/cygapatosaurus-0.dll000644 000000 000000 00000000106 14315571125 022751 0ustar00rootroot000000 000000 apatosaurus 1.2.3 apatosaurus_init apatosaurus_new apatosaurus_delete FFI-CheckLib-0.31/corpus/cygwin/bin/cygdinosaur.dll000644 000000 000000 00000000072 14315571125 022073 0ustar00rootroot000000 000000 dinosaur 1.2.3 dinosaur_init dinosaur_new dinosaur_delete FFI-CheckLib-0.31/corpus/darwin/000755 000000 000000 00000000000 14315571125 016264 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/custom/000755 000000 000000 00000000000 14315571125 017576 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/custom/libfoo.dylib000644 000000 000000 00000000013 14315571125 022067 0ustar00rootroot000000 000000 foo 1.2.3a FFI-CheckLib-0.31/corpus/darwin/foo-1.00/000755 000000 000000 00000000000 14315571125 017423 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/foo-1.00/src/000755 000000 000000 00000000000 14315571125 020212 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/foo-1.00/src/libs/000755 000000 000000 00000000000 14315571125 021143 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/foo-1.00/src/libs/libbar.dylib000644 000000 000000 00000000000 14315571125 023411 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/foo-1.00/src/libs/libbaz.dylib000644 000000 000000 00000000000 14315571125 023421 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/foo-1.00/src/libs/libfoo.dylib000644 000000 000000 00000000000 14315571125 023430 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/lib/000755 000000 000000 00000000000 14315571125 017032 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/lib/libfoo.dylib000644 000000 000000 00000000012 14315571125 021322 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/darwin/lib/libfoo.dylib.2000644 000000 000000 00000000012 14315571125 021462 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/darwin/lib/libfoo.dylib.2.3000644 000000 000000 00000000012 14315571125 021623 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/darwin/lib/libfoo.dylib.2.3.4000644 000000 000000 00000000012 14315571125 021765 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/darwin/usr/000755 000000 000000 00000000000 14315571125 017075 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/usr/lib/000755 000000 000000 00000000000 14315571125 017643 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/darwin/usr/lib/libbar.dylib000644 000000 000000 00000000012 14315571125 022114 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/darwin/usr/lib/libbar.dylib.1000644 000000 000000 00000000012 14315571125 022253 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/darwin/usr/lib/libbar.dylib.1.2000644 000000 000000 00000000012 14315571125 022413 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/darwin/usr/lib/libbar.dylib.1.2.3000644 000000 000000 00000000012 14315571125 022554 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/darwin/usr/lib/libfoo.a000644 000000 000000 00000000004 14315571125 021251 0ustar00rootroot000000 000000 bad FFI-CheckLib-0.31/corpus/darwin/usr/lib/libfoo.dylib000644 000000 000000 00000000046 14315571125 022142 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/darwin/usr/lib/libfoo.dylib.1000644 000000 000000 00000000046 14315571125 022301 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/darwin/usr/lib/libfoo.dylib.1.2000644 000000 000000 00000000046 14315571125 022441 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/darwin/usr/lib/libfoo.dylib.1.2.3000644 000000 000000 00000000046 14315571125 022602 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/generic.dll000644 000000 000000 00000000032 14315571125 017104 0ustar00rootroot000000 000000 generic 1.2.3 foo bar baz FFI-CheckLib-0.31/corpus/lib/000755 000000 000000 00000000000 14315571125 015546 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/lib/Alien/000755 000000 000000 00000000000 14315571125 016576 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/lib/Alien/libbar.pm000644 000000 000000 00000000165 14315571125 020371 0ustar00rootroot000000 000000 package Alien::libbar; use strict; use warnings; sub dynamic_libs { 'corpus/unix/usr/lib/libbar.so.1.2.3'; } 1; FFI-CheckLib-0.31/corpus/unix/000755 000000 000000 00000000000 14315571125 015763 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/custom/000755 000000 000000 00000000000 14315571125 017275 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/custom/libfoo.so000644 000000 000000 00000000013 14315571125 021104 0ustar00rootroot000000 000000 foo 1.2.3a FFI-CheckLib-0.31/corpus/unix/foo-1.00/000755 000000 000000 00000000000 14315571125 017122 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/foo-1.00/src/000755 000000 000000 00000000000 14315571125 017711 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/foo-1.00/src/libs/000755 000000 000000 00000000000 14315571125 020642 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/foo-1.00/src/libs/libbar.so000644 000000 000000 00000000000 14315571125 022426 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/foo-1.00/src/libs/libbaz.so000644 000000 000000 00000000000 14315571125 022436 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/foo-1.00/src/libs/libfoo.so000644 000000 000000 00000000000 14315571125 022445 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/lib/000755 000000 000000 00000000000 14315571125 016531 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/lib/libfoo.so000644 000000 000000 00000000012 14315571125 020337 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/unix/lib/libfoo.so.2000644 000000 000000 00000000012 14315571125 020477 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/unix/lib/libfoo.so.2.3000644 000000 000000 00000000012 14315571125 020640 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/unix/lib/libfoo.so.2.3.4000644 000000 000000 00000000012 14315571125 021002 0ustar00rootroot000000 000000 foo 2.3.4 FFI-CheckLib-0.31/corpus/unix/path/000755 000000 000000 00000000000 14315571125 016717 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/path/path1/000755 000000 000000 00000000000 14315571125 017734 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/path/path1/libfoo.so.1000644 000000 000000 00000000006 14315571125 021704 0ustar00rootroot000000 000000 path1 FFI-CheckLib-0.31/corpus/unix/path/path2/000755 000000 000000 00000000000 14315571125 017735 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/path/path2/libfoo.so.2000644 000000 000000 00000000006 14315571125 021706 0ustar00rootroot000000 000000 path2 FFI-CheckLib-0.31/corpus/unix/path/path3/000755 000000 000000 00000000000 14315571125 017736 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/path/path3/libfoo.so.3000644 000000 000000 00000000002 14315571125 021704 0ustar00rootroot000000 000000 3 FFI-CheckLib-0.31/corpus/unix/usr/000755 000000 000000 00000000000 14315571125 016574 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/usr/lib/000755 000000 000000 00000000000 14315571125 017342 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/unix/usr/lib/libbar.so000644 000000 000000 00000000012 14315571125 021131 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/unix/usr/lib/libbar.so.1000644 000000 000000 00000000012 14315571125 021270 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/unix/usr/lib/libbar.so.1.2000644 000000 000000 00000000012 14315571125 021430 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/unix/usr/lib/libbar.so.1.2.3000644 000000 000000 00000000012 14315571125 021571 0ustar00rootroot000000 000000 bar 1.2.3 FFI-CheckLib-0.31/corpus/unix/usr/lib/libcrypto.so.0.9.8000644 000000 000000 00000000036 14315571125 022366 0ustar00rootroot000000 000000 crypto 0.9.8 _OpenSSL_VERSION FFI-CheckLib-0.31/corpus/unix/usr/lib/libcrypto.so.1.0.0000644 000000 000000 00000000036 14315571125 022346 0ustar00rootroot000000 000000 crypto 1.0.0 PEM_read_bio_CMS FFI-CheckLib-0.31/corpus/unix/usr/lib/libfoo.a000644 000000 000000 00000000004 14315571125 020750 0ustar00rootroot000000 000000 bad FFI-CheckLib-0.31/corpus/unix/usr/lib/libfoo.so000644 000000 000000 00000000046 14315571125 021157 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/unix/usr/lib/libfoo.so.1000644 000000 000000 00000000046 14315571125 021316 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/unix/usr/lib/libfoo.so.1.2000644 000000 000000 00000000046 14315571125 021456 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/unix/usr/lib/libfoo.so.1.2.3000644 000000 000000 00000000046 14315571125 021617 0ustar00rootroot000000 000000 foo 1.2.3 foo_init foo_new foo_delete FFI-CheckLib-0.31/corpus/unix/usr/lib/libxor.so000644 000000 000000 00000000016 14315571125 021201 0ustar00rootroot000000 000000 xor 1.2.3 ben FFI-CheckLib-0.31/corpus/unix/usr/lib/libxor.so.1000644 000000 000000 00000000016 14315571125 021340 0ustar00rootroot000000 000000 xor 1.2.3 ben FFI-CheckLib-0.31/corpus/unix/usr/lib/libxor.so.1.2000644 000000 000000 00000000016 14315571125 021500 0ustar00rootroot000000 000000 xor 1.2.3 ben FFI-CheckLib-0.31/corpus/unix/usr/lib/libxor.so.1.2.3000644 000000 000000 00000000020 14315571125 021634 0ustar00rootroot000000 000000 xor 1.2.3 roger FFI-CheckLib-0.31/corpus/unix/usr/lib/libxor.so.1.2.4000644 000000 000000 00000000016 14315571125 021642 0ustar00rootroot000000 000000 xor 1.2.3 ben FFI-CheckLib-0.31/corpus/windows/000755 000000 000000 00000000000 14315571125 016472 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/windows/bin/000755 000000 000000 00000000000 14315571125 017242 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/windows/bin/dinosaur.dll000644 000000 000000 00000000072 14315571125 021562 0ustar00rootroot000000 000000 dinosaur 1.2.3 dinosaur_init dinosaur_new dinosaur_delete FFI-CheckLib-0.31/corpus/windows/bin/dromornis_planei-3.0-7-0.dll000644 000000 000000 00000000072 14315571125 024101 0ustar00rootroot000000 000000 dinosaur 1.2.3 dinosaur_init dinosaur_new dinosaur_delete FFI-CheckLib-0.31/corpus/windows/bin/libapatosaurus-0.dll000644 000000 000000 00000000106 14315571125 023127 0ustar00rootroot000000 000000 apatosaurus 1.2.3 apatosaurus_init apatosaurus_new apatosaurus_delete FFI-CheckLib-0.31/corpus/windows/bin/libapatosaurus_ajax.dll000644 000000 000000 00000000106 14315571125 023775 0ustar00rootroot000000 000000 apatosaurus 1.2.3 apatosaurus_init apatosaurus_new apatosaurus_delete FFI-CheckLib-0.31/corpus/windows/bin/libbrevipalatus_mcculloughi_9_1__.dll000644 000000 000000 00000000077 14315571125 026474 0ustar00rootroot000000 000000 dinosaur 1.2.3 dinosaur_init dinosaur_new dinosaur_delete FFI-CheckLib-0.31/corpus/windows/bin/libmaiasaura-3-7-0.dll000644 000000 000000 00000000072 14315571125 023031 0ustar00rootroot000000 000000 dinosaur 1.2.3 dinosaur_init dinosaur_new dinosaur_delete FFI-CheckLib-0.31/corpus/windows/bin/libthylacaleo_carnifex-3-7___.dll000644 000000 000000 00000000072 14315571125 025372 0ustar00rootroot000000 000000 dinosaur 1.2.3 dinosaur_init dinosaur_new dinosaur_delete FFI-CheckLib-0.31/corpus/windows/bincase/000755 000000 000000 00000000000 14315571125 020076 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/windows/bincase/LIBbar.DLL000644 000000 000000 00000000000 14315571125 021514 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/corpus/windows/bincase/foo.DLL000644 000000 000000 00000000000 14315571125 021204 0ustar00rootroot000000 000000 FFI-CheckLib-0.31/dist.ini000644 000000 000000 00000002350 14315571125 015131 0ustar00rootroot000000 000000 name = FFI-CheckLib author = Graham Ollis license = Perl_5 copyright_holder = Graham Ollis copyright_year = 2014-2022 version = 0.31 [@Author::Plicease] :version = 2.72 release_tests = 1 irc = irc://irc.perl.org/#native test2_v0 = 1 diag = +Test2::Tools::Process diag = +DynaLoader diag = +FFI::Platypus github_user = PerlFFI github_repo = FFI-CheckLib workflow = static workflow = linux workflow = macos workflow = cygwin [RemovePrereqs] remove = strict remove = warnings remove = constant remove = lib remove = base remove = Env remove = Carp remove = Exporter remove = File::Spec remove = File::Basename remove = DynaLoader remove = FFI::Platypus remove = Test2::Tools::Process [Author::Plicease::Upload] cpan = 1 [Author::Plicease::Thanks] current = Graham Ollis contributor = Bakkiaraj Murugesan (bakkiaraj) contributor = Dan Book (grinnz, DBOOK) contributor = Ilya Pavlov (Ilya, ILUX) contributor = Shawn Laffan (SLAFFAN) contributor = Petr Písař (ppisar) contributor = Michael R. Davis (MRDVT) contributor = Shawn Laffan (SLAFFAN) contributor = Carlos D. Álvaro (cdalvaro) [MetaNoIndex] directory = corpus FFI-CheckLib-0.31/example/000755 000000 000000 00000000000 14315571125 015120 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/example/wheredll.pl000644 000000 000000 00000000461 14315571125 017264 0ustar00rootroot000000 000000 use strict; use warnings; use FFI::CheckLib; my($name) = shift @ARGV; unless(defined $name) { print STDERR "usage: $0 name\n"; } my(@path) = find_lib( lib => '*', verify => sub { $_[0] eq $name } ); if(@path) { print "$_\n" for @path; exit 0; } else { print STDERR "not found.\n"; exit 2; } FFI-CheckLib-0.31/example/whichdll.pl000644 000000 000000 00000000412 14315571125 017250 0ustar00rootroot000000 000000 use strict; use warnings; use FFI::CheckLib; my($name) = shift @ARGV; unless(defined $name) { print STDERR "usage: $0 name\n"; } my($path) = find_lib( lib => $name ); if($path) { print "$path\n"; exit 0; } else { print STDERR "not found.\n"; exit 2; } FFI-CheckLib-0.31/lib/000755 000000 000000 00000000000 14315571125 014233 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/lib/FFI/000755 000000 000000 00000000000 14315571125 014637 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/lib/FFI/CheckLib.pm000644 000000 000000 00000051122 14315571125 016642 0ustar00rootroot000000 000000 package FFI::CheckLib; use strict; use warnings; use File::Spec; use List::Util 1.33 qw( any ); use Carp qw( croak carp ); use Env qw( @FFI_CHECKLIB_PATH ); use base qw( Exporter ); our @EXPORT = qw( find_lib assert_lib check_lib check_lib_or_exit find_lib_or_exit find_lib_or_die ); our @EXPORT_OK = qw( which where has_symbols ); # ABSTRACT: Check that a library is available for FFI our $VERSION = '0.31'; # VERSION our $system_path = []; our $os ||= $^O; my $try_ld_on_text = 0; sub _homebrew_lib_path { require File::Which; return undef unless File::Which::which('brew'); chomp(my $brew_path = (qx`brew --prefix`)[0]); return "$brew_path/lib"; } sub _macports_lib_path { require File::Which; my $port_path = File::Which::which('port'); return undef unless $port_path; $port_path =~ s|bin/port|lib|; return $port_path; } sub _darwin_extra_paths { my $pkg_managers = lc( $ENV{FFI_CHECKLIB_PACKAGE} || 'homebrew,macports' ); return () if $pkg_managers eq 'none'; my $supported_managers = { homebrew => \&_homebrew_lib_path, macports => \&_macports_lib_path }; my @extra_paths = (); foreach my $pkg_manager (split( /,/, $pkg_managers )) { if (my $lib_path = $supported_managers->{$pkg_manager}()) { push @extra_paths, $lib_path; } } return @extra_paths; } my @extra_paths = (); if($os eq 'MSWin32' || $os eq 'msys') { $system_path = eval { require Env; Env->import('@PATH'); \our @PATH; }; die $@ if $@; } else { $system_path = eval { require DynaLoader; no warnings 'once'; \@DynaLoader::dl_library_path; }; die $@ if $@; @extra_paths = _darwin_extra_paths() if $os eq 'darwin'; } our $pattern = [ qr{^lib(.*?)\.so(?:\.([0-9]+(?:\.[0-9]+)*))?$} ]; our $version_split = qr/\./; if($os eq 'cygwin') { push @$pattern, qr{^cyg(.*?)(?:-([0-9])+)?\.dll$}; } elsif($os eq 'msys') { # doesn't seem as though msys uses psudo libfoo.so files # in the way that cygwin sometimes does. we can revisit # this if we find otherwise. $pattern = [ qr{^msys-(.*?)(?:-([0-9])+)?\.dll$} ]; } elsif($os eq 'MSWin32') { # handle cases like libgeos-3-7-0___.dll, libproj_9_1.dll and libgtk-2.0-0.dll $pattern = [ qr{^(?:lib)?(\w+?)(?:[_-]([0-9\-\._]+))?_*\.dll$}i ]; $version_split = qr/[_\-]/; } elsif($os eq 'darwin') { push @$pattern, qr{^lib(.*?)(?:\.([0-9]+(?:\.[0-9]+)*))?\.(?:dylib|bundle)$}; } elsif($os eq 'linux') { if(-e '/etc/redhat-release' && -x '/usr/bin/ld') { $try_ld_on_text = 1; } } sub _matches { my($filename, $path) = @_; foreach my $regex (@$pattern) { return [ $1, # 0 capture group 1 library name File::Spec->catfile($path, $filename), # 1 full path to library defined $2 ? (split $version_split, $2) : (), # 2... capture group 2 library version ] if $filename =~ $regex; } return (); } sub _cmp { my($A,$B) = @_; return $A->[0] cmp $B->[0] if $A->[0] ne $B->[0]; my $i=2; while(1) { return 0 if !defined($A->[$i]) && !defined($B->[$i]); return -1 if !defined $A->[$i]; return 1 if !defined $B->[$i]; return $B->[$i] <=> $A->[$i] if $A->[$i] != $B->[$i]; $i++; } } my $diagnostic; sub _is_binary { -B $_[0] } sub find_lib { my(%args) = @_; undef $diagnostic; croak "find_lib requires lib argument" unless defined $args{lib}; my $recursive = $args{_r} || $args{recursive} || 0; # make arguments be lists. foreach my $arg (qw( lib libpath symbol verify alien )) { next if ref $args{$arg} eq 'ARRAY'; if(defined $args{$arg}) { $args{$arg} = [ $args{$arg} ]; } else { $args{$arg} = []; } } if(defined $args{systempath} && !ref($args{systempath})) { $args{systempath} = [ $args{systempath} ]; } my @path = @{ $args{libpath} }; @path = map { _recurse($_) } @path if $recursive; if(defined $args{systempath}) { push @path, grep { defined } @{ $args{systempath} } } else { # This is a little convaluted, but: # 1. These are modifications of what we consider the "system" path # if systempath isn't explicitly passed in as systempath # 2. FFI_CHECKLIB_PATH is considered an authortative modification # so it goes first and overrides FFI_CHECKLIB_PACKAGE # 3. otherwise FFI_CHECKLIB_PACKAGE does its thing and goes on # the end because homebrew does a good job of not replacing # anything in the system by default. # 4. We finally add what we consider the "system" path to the end of # the search path so that libpath will be searched first. my @system_path = @$system_path; if($ENV{FFI_CHECKLIB_PATH}) { @system_path = (@FFI_CHECKLIB_PATH, @system_path); } else { foreach my $extra_path (@extra_paths) { push @path, $extra_path unless any { $_ eq $extra_path } @path; } } push @path, @system_path; } my $any = any { $_ eq '*' } @{ $args{lib} }; my %missing = map { $_ => 1 } @{ $args{lib} }; my %symbols = map { $_ => 1 } @{ $args{symbol} }; my @found; delete $missing{'*'}; alien: foreach my $alien (reverse @{ $args{alien} }) { unless($alien =~ /^([A-Za-z_][A-Za-z_0-9]*)(::[A-Za-z_][A-Za-z_0-9]*)*$/) { croak "Doesn't appear to be a valid Alien name $alien"; } unless(eval { $alien->can('dynamic_libs') }) { { my $pm = "$alien.pm"; $pm =~ s/::/\//g; local $@ = ''; eval { require $pm }; next alien if $@; } unless(eval { $alien->can('dynamic_libs') }) { croak "Alien $alien doesn't provide a dynamic_libs method"; } } unshift @path, [$alien->dynamic_libs]; } foreach my $path (@path) { next if ref $path ne 'ARRAY' && ! -d $path; my @maybe = # make determinist based on names and versions sort { _cmp($a,$b) } # Filter out the items that do not match the name that we are looking for # Filter out any broken symbolic links grep { ($any || $missing{$_->[0]} ) && (-e $_->[1]) } ref $path eq 'ARRAY' ? do { map { my($v, $d, $f) = File::Spec->splitpath($_); _matches($f, File::Spec->catpath($v,$d,'')); } @$path; } : do { my $dh; opendir $dh, $path; # get [ name, full_path ] mapping, # each entry is a 2 element list ref map { _matches($_,$path) } readdir $dh; }; if($try_ld_on_text && $args{try_linker_script}) { # This is tested in t/ci.t only @maybe = map { -B $_->[1] ? $_ : do { my($name, $so) = @$_; my $output = `/usr/bin/ld -t $so -o /dev/null -shared`; $output =~ /\((.*?lib.*\.so.*?)\)/ ? [$name, $1] : die "unable to parse ld output"; } } @maybe; } midloop: foreach my $lib (@maybe) { next unless $any || $missing{$lib->[0]}; foreach my $verify (@{ $args{verify} }) { next midloop unless $verify->(@$lib); } delete $missing{$lib->[0]}; if(%symbols) { require DynaLoader; my $dll = DynaLoader::dl_load_file($lib->[1],0); foreach my $symbol (keys %symbols) { if(DynaLoader::dl_find_symbol($dll, $symbol) ? 1 : 0) { delete $symbols{$symbol} } } DynaLoader::dl_unload_file($dll); } my $found = $lib->[1]; unless($any) { while(-l $found) { require File::Basename; my $dir = File::Basename::dirname($found); $found = File::Spec->rel2abs( readlink($found), $dir ); } } push @found, $found; } } if(%missing) { my @missing = sort keys %missing; if(@missing > 1) { $diagnostic = "libraries not found: @missing" } else { $diagnostic = "library not found: @missing" } } elsif(%symbols) { my @missing = sort keys %symbols; if(@missing > 1) { $diagnostic = "symbols not found: @missing" } else { $diagnostic = "symbol not found: @missing" } } return if %symbols; return $found[0] unless wantarray; return @found; } sub _recurse { my($dir) = @_; return unless -d $dir; my $dh; opendir $dh, $dir; my @list = grep { -d $_ } map { File::Spec->catdir($dir, $_) } grep !/^\.\.?$/, readdir $dh; closedir $dh; ($dir, map { _recurse($_) } @list); } sub assert_lib { croak $diagnostic || 'library not found' unless check_lib(@_); } sub check_lib_or_exit { unless(check_lib(@_)) { carp $diagnostic || 'library not found'; exit; } } sub find_lib_or_exit { my(@libs) = find_lib(@_); unless(@libs) { carp $diagnostic || 'library not found'; exit; } return unless @libs; wantarray ? @libs : $libs[0]; } sub find_lib_or_die { my(@libs) = find_lib(@_); unless(@libs) { croak $diagnostic || 'library not found'; } return unless @libs; wantarray ? @libs : $libs[0]; } sub check_lib { find_lib(@_) ? 1 : 0; } sub which { my($name) = @_; croak("cannot which *") if $name eq '*'; scalar find_lib( lib => $name ); } sub where { my($name) = @_; $name eq '*' ? find_lib(lib => '*') : find_lib(lib => '*', verify => sub { $_[0] eq $name }); } sub has_symbols { my($path, @symbols) = @_; require DynaLoader; my $dll = DynaLoader::dl_load_file($path, 0); my $ok = 1; foreach my $symbol (@symbols) { unless(DynaLoader::dl_find_symbol($dll, $symbol)) { $ok = 0; last; } } DynaLoader::dl_unload_file($dll); $ok; } sub system_path { $system_path; } 1; __END__ =pod =encoding UTF-8 =head1 NAME FFI::CheckLib - Check that a library is available for FFI =head1 VERSION version 0.31 =head1 SYNOPSIS use FFI::CheckLib; check_lib_or_exit( lib => 'jpeg', symbol => 'jinit_memory_mgr' ); check_lib_or_exit( lib => [ 'iconv', 'jpeg' ] ); # or prompt for path to library and then: print "where to find jpeg library: "; my $path = ; check_lib_or_exit( lib => 'jpeg', libpath => $path ); =head1 DESCRIPTION This module checks whether a particular dynamic library is available for FFI to use. It is modeled heavily on L, but will find dynamic libraries even when development packages are not installed. It also provides a L function that will return the full path to the found dynamic library, which can be feed directly into L or another FFI system. Although intended mainly for FFI modules via L and similar, this module does not actually use any FFI to do its detection and probing. This module does not have any non-core runtime dependencies. The test suite does depend on L. =head1 FUNCTIONS All of these take the same named parameters and are exported by default. =head2 find_lib my(@libs) = find_lib(%args); This will return a list of dynamic libraries, or empty list if none were found. [version 0.05] If called in scalar context it will return the first library found. Arguments are key value pairs with these keys: =over 4 =item lib Must be either a string with the name of a single library or a reference to an array of strings of library names. Depending on your platform, C will prepend C or append C<.dll> or C<.so> when searching. [version 0.11] As a special case, if C<*> is specified then any libs found will match. =item libpath A string or array of additional paths to search for libraries. =item systempath [version 0.11] A string or array of system paths to search for instead of letting L determine the system path. You can set this to C<[]> in order to not search I system paths. =item symbol A string or a list of symbol names that must be found. =item verify A code reference used to verify a library really is the one that you want. It should take two arguments, which is the name of the library and the full path to the library pathname. It should return true if it is acceptable, and false otherwise. You can use this in conjunction with L to determine if it is going to meet your needs. Example: use FFI::CheckLib; use FFI::Platypus; my($lib) = find_lib( lib => 'foo', verify => sub { my($name, $libpath) = @_; my $ffi = FFI::Platypus->new; $ffi->lib($libpath); my $f = $ffi->function('foo_version', [] => 'int'); return $f->call() >= 500; # we accept version 500 or better }, ); =item recursive [version 0.11] Recursively search for libraries in any non-system paths (those provided via C above). =item try_linker_script [version 0.24] Some vendors provide C<.so> files that are linker scripts that point to the real binary shared library. These linker scripts can be used by gcc or clang, but are not directly usable by L and friends. On select platforms, this options will use the linker command (C) to attempt to resolve the real C<.so> for non-binary files. Since there is extra overhead this is off by default. An example is libyaml on Red Hat based Linux distributions. On Debian these are handled with symlinks and no trickery is required. =item alien [version 0.25] If no libraries can be found, try the given aliens instead. The Alien classes specified must provide the L interface for dynamic libraries, which is to say they should provide a method called C that returns a list of dynamic libraries. [version 0.28] In 0.28 and later, if the L is not installed then it will be ignored and this module will search in system or specified directories only. This module I still throw an exception, if the L doesn't look like a module name or if it does not provide a C method (which is implemented by all L subclasses). [version 0.30] [breaking change] Starting with version 0.30, libraries provided by Ls is preferred over the system libraries. The original thinking was that you want to prefer the system libraries because they are more likely to get patched with regular system updates. Unfortunately, the reason a module needs to install an Alien is likely because the system library is not new enough, so we now prefer the Ls instead. =back =head2 assert_lib assert_lib(%args); This behaves exactly the same as L, except that instead of returning empty list of failure it throws an exception. =head2 check_lib_or_exit check_lib_or_exit(%args); This behaves exactly the same as L, except that instead of dying, it warns (with exactly the same error message) and exists. This is intended for use in C or C =head2 find_lib_or_exit [version 0.05] my(@libs) = find_lib_or_exit(%args); This behaves exactly the same as L, except that if the library is not found, it will call exit with an appropriate diagnostic. =head2 find_lib_or_die [version 0.06] my(@libs) = find_lib_or_die(%args); This behaves exactly the same as L, except that if the library is not found, it will die with an appropriate diagnostic. =head2 check_lib my $bool = check_lib(%args); This behaves exactly the same as L, except that it returns true (1) on finding the appropriate libraries or false (0) otherwise. =head2 which [version 0.17] my $path = which($name); Return the path to the first library that matches the given name. Not exported by default. =head2 where [version 0.17] my @paths = where($name); Return the paths to all the libraries that match the given name. Not exported by default. =head2 has_symbols [version 0.17] my $bool = has_symbols($path, @symbol_names); Returns true if I of the symbols can be found in the dynamic library located at the given path. Can be useful in conjunction with C with C above. Not exported by default. =head2 system_path [version 0.20] my $path = FFI::CheckLib::system_path; Returns the system path as a list reference. On some systems, this is C on others it might be C on still others it could be something completely different. So although you I add items to this list, you should probably do some careful consideration before you do so. This function is not exportable, even on request. =head1 ENVIRONMENT L responds to these environment variables: =over 4 =item FFI_CHECKLIB_PACKAGE On macOS platforms with L and/or L installed, their corresponding lib paths will be automatically appended to C<$system_path>. In case of having both managers installed, Homebrew will appear before. This behaviour can be overridden using the environment variable C. Allowed values are: - C: Won't use either Homebrew's path nor MacPorts - C: Will append C<$(brew --prefix)/lib> to the system paths - C: Will append C's default lib path A comma separated list is also valid: export FFI_CHECKLIB_PACKAGE=macports,homebrew Order matters. So in this example, MacPorts' lib path appears before Homebrew's path. =item FFI_CHECKLIB_PATH List of directories that will be considered by L as additional "system directories". They will be searched before other system directories but after C. The variable is colon separated on Unix and semicolon separated on Windows. If you use this variable, C will be ignored. =item PATH On Windows the C environment variable will be used as a search path for libraries. =back On some operating systems C, C, C or others I be used as part of the search for dynamic libraries and I be used (indirectly) by L as well. =head1 FAQ =over 4 =item Why not just use C? Calling C on a library name and then C immediately can tell you if you have the exact name of a library available on a system. It does have a number of drawbacks as well. =over 4 =item No absolute or relative path It only tells you that the library is I on the system, not having the absolute or relative path makes it harder to generate useful diagnostics. =item POSIX only This doesn't work on non-POSIX systems like Microsoft Windows. If you are using a POSIX emulation layer on Windows that provides C, like Cygwin, there are a number of gotchas there as well. Having a layer written in Perl handles this means that developers on Unix can develop FFI that will more likely work on these platforms without special casing them. =item inconsistent implementations Even on POSIX systems you have inconsistent implementations. OpenBSD for example don't usually include symlinks for C<.so> files meaning you need to know the exact C<.so> version. =item non-system directories By default C only works for libraries in the system paths. Most platforms have a way of configuring the search for different non-system paths, but none of them are portable, and are usually discouraged anyway. L and friends need to do searches for dynamic libraries in non-system directories for C installs. =back =item My 64-bit Perl is misconfigured and has 32-bit libraries in its search path. Is that a bug in L? Nope. =item The way L is implemented it won't work on AIX, HP-UX, OpenVMS or Plan 9. I know for a fact that it doesn't work on AIX I because I used to develop on AIX in the early 2000s, and I am aware of some of the technical challenges. There are probably other systems that it won't work on. I would love to add support for these platforms. Realistically these platforms have a tiny market share, and absent patches from users or the companies that own these operating systems (patches welcome), or hardware / CPU time donations, these platforms are unsupportable anyway. =back =head1 SEE ALSO =over 4 =item L Call library functions dynamically without a compiler. =item L L plugin for this module. =back =head1 AUTHOR Author: Graham Ollis Eplicease@cpan.orgE Contributors: Bakkiaraj Murugesan (bakkiaraj) Dan Book (grinnz, DBOOK) Ilya Pavlov (Ilya, ILUX) Shawn Laffan (SLAFFAN) Petr Písař (ppisar) Michael R. Davis (MRDVT) Shawn Laffan (SLAFFAN) Carlos D. Álvaro (cdalvaro) =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014-2022 by Graham Ollis. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut FFI-CheckLib-0.31/maint/000755 000000 000000 00000000000 14315571125 014575 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/maint/cip-before-install000755 000000 000000 00000001124 14315571125 020200 0ustar00rootroot000000 000000 #!/bin/bash set -ex if echo $CIP_TAG | grep -q -- -alpine ; then echo alpine cip sudo apk add cmake cip sudo apk add libffi-dev cip sudo apk add yaml-dev elif echo $CIP_TAG | grep -q -- -centos ; then echo CentOS cip sudo yum install libffi-devel libyaml-devel -y elif echo $CIP_TAG | grep -q -- -fedora ; then echo Fedora cip sudo yum install cmake libffi-devel libyaml-devel -y else cip sudo apt-get update cip sudo apt-get -y install libffi-dev libyaml-dev fi cip exec cpanm -n FFI::Platypus if [ $CIP_TAG != "5.8" ]; then cip exec cpanm -n Test2::Tools::Process fi FFI-CheckLib-0.31/perlcriticrc000644 000000 000000 00000003643 14315571125 016103 0ustar00rootroot000000 000000 severity = 1 only = 1 [Freenode::ArrayAssignAref] [Freenode::BarewordFilehandles] [Freenode::ConditionalDeclarations] [Freenode::ConditionalImplicitReturn] [Freenode::DeprecatedFeatures] [Freenode::DiscouragedModules] [Freenode::DollarAB] [Freenode::Each] [Freenode::IndirectObjectNotation] [Freenode::LexicalForeachIterator] [Freenode::LoopOnHash] [Freenode::ModPerl] [Freenode::OpenArgs] [Freenode::OverloadOptions] [Freenode::POSIXImports] [Freenode::PackageMatchesFilename] [Freenode::PreferredAlternatives] [Freenode::StrictWarnings] extra_importers = Test2::V0 [Freenode::Threads] ;[Freenode::Wantarray] [Freenode::WarningsSwitch] [Freenode::WhileDiamondDefaultAssignment] [BuiltinFunctions::ProhibitBooleanGrep] ;[BuiltinFunctions::ProhibitStringyEval] [BuiltinFunctions::ProhibitStringySplit] [BuiltinFunctions::ProhibitVoidGrep] [BuiltinFunctions::ProhibitVoidMap] [ClassHierarchies::ProhibitExplicitISA] [ClassHierarchies::ProhibitOneArgBless] [CodeLayout::ProhibitHardTabs] allow_leading_tabs = 0 [CodeLayout::ProhibitTrailingWhitespace] [CodeLayout::RequireConsistentNewlines] [ControlStructures::ProhibitLabelsWithSpecialBlockNames] [ControlStructures::ProhibitMutatingListFunctions] [ControlStructures::ProhibitUnreachableCode] [InputOutput::ProhibitBarewordFileHandles] [InputOutput::ProhibitJoinedReadline] [InputOutput::ProhibitTwoArgOpen] [Miscellanea::ProhibitFormats] [Miscellanea::ProhibitUselessNoCritic] [Modules::ProhibitConditionalUseStatements] ;[Modules::RequireEndWithOne] [Modules::RequireNoMatchVarsWithUseEnglish] [Objects::ProhibitIndirectSyntax] [RegularExpressions::ProhibitUselessTopic] [Subroutines::ProhibitNestedSubs] [ValuesAndExpressions::ProhibitLeadingZeros] [ValuesAndExpressions::ProhibitMixedBooleanOperators] [ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator] [ValuesAndExpressions::RequireUpperCaseHeredocTerminator] [Variables::ProhibitPerl4PackageNames] [Variables::ProhibitUnusedVariables] FFI-CheckLib-0.31/t/000755 000000 000000 00000000000 14315571125 013730 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/t/00_diag.t000644 000000 000000 00000002614 14315571125 015323 0ustar00rootroot000000 000000 use Test2::V0 -no_srand => 1; use Config; eval { require 'Test/More.pm' }; # This .t file is generated. # make changes instead to dist.ini my %modules; my $post_diag; $modules{$_} = $_ for qw( DynaLoader ExtUtils::MakeMaker FFI::Platypus File::Which List::Util Test2::API Test2::Require::EnvVar Test2::Require::Module Test2::Tools::Process Test2::V0 ); my @modules = sort keys %modules; sub spacer () { diag ''; diag ''; diag ''; } pass 'okay'; my $max = 1; $max = $_ > $max ? $_ : $max for map { length $_ } @modules; our $format = "%-${max}s %s"; spacer; my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV; if(@keys > 0) { diag "$_=$ENV{$_}" for @keys; if($ENV{PERL5LIB}) { spacer; diag "PERL5LIB path"; diag $_ for split $Config{path_sep}, $ENV{PERL5LIB}; } elsif($ENV{PERLLIB}) { spacer; diag "PERLLIB path"; diag $_ for split $Config{path_sep}, $ENV{PERLLIB}; } spacer; } diag sprintf $format, 'perl', "$] $^O $Config{archname}"; foreach my $module (sort @modules) { my $pm = "$module.pm"; $pm =~ s{::}{/}g; if(eval { require $pm; 1 }) { my $ver = eval { $module->VERSION }; $ver = 'undef' unless defined $ver; diag sprintf $format, $module, $ver; } else { diag sprintf $format, $module, '-'; } } if($post_diag) { spacer; $post_diag->(); } spacer; done_testing; FFI-CheckLib-0.31/t/ci.t000644 000000 000000 00000002341 14315571125 014510 0ustar00rootroot000000 000000 use Test2::Require::EnvVar 'CIPSOMETHING'; use Test2::V0 -no_srand => 1; use FFI::CheckLib qw( find_lib ); use FFI::Platypus; # This test should only run under ci in a docker container with # libffi and libyaml development packages installed subtest 'libffi' => sub { my @ffi; is( [@ffi = find_lib lib => 'ffi'], bag { item match qr/libffi\.so/; etc; }, 'have ffi', ); note "lib = $_" for @ffi; my $ffi = FFI::Platypus->new; $ffi->lib(@ffi); my $ffi_raw_call = eval { $ffi->function('ffi_raw_call' => [] => 'void') }; ok $ffi_raw_call, "has symbol ffi_raw_call"; }; subtest 'yaml' => sub { my @yaml; is( [@yaml = find_lib lib => 'yaml', try_linker_script => 1], bag { item match qr/libyaml.*\.so/; etc; }, 'have yaml', ); note "lib = $_" for @yaml; my $ffi = FFI::Platypus->new; $ffi->lib(@yaml); my $yaml_get_version_string = eval { $ffi->function('yaml_get_version_string' => [] => 'string') }; ok $yaml_get_version_string, "has symbol yaml_get_version_string"; return unless $yaml_get_version_string; ok $yaml_get_version_string->(), "has a version yo"; note "yaml_get_version_string = ", $yaml_get_version_string->(); }; done_testing; FFI-CheckLib-0.31/t/ffi_checklib.t000644 000000 000000 00000011111 14315571125 016500 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::V0 -no_srand => 1; use Test2::Plugin::FauxOS 'linux'; use Test2::Tools::FauxDynaLoader; use File::Spec; use File::Basename qw( basename ); use FFI::CheckLib qw( find_lib which where has_symbols ); subtest 'recursive' => sub { $FFI::CheckLib::system_path = []; my @libs = find_lib( libpath => File::Spec->catdir( 'corpus', 'unix', 'foo-1.00' ), lib => 'foo', recursive => 1, ); is scalar(@libs), 1, "libs = @libs"; like $libs[0], qr{libfoo.so}, "libs[0] = $libs[0]"; }; subtest 'star' => sub { $FFI::CheckLib::system_path = []; my @libs = find_lib( libpath => File::Spec->catdir( 'corpus', 'unix', 'foo-1.00' ), lib => '*', recursive => 1, ); is scalar(@libs), 3, "libs = @libs"; my @fn = sort map { (File::Spec->splitpath($_))[2] } @libs; is \@fn, [qw( libbar.so libbaz.so libfoo.so )], "fn = @fn"; }; subtest 'which' => sub { my %find_lib_args; my $mock = mock 'FFI::CheckLib' => ( override => [ find_lib => sub { %find_lib_args = @_; my @ret = qw( /usr/lib/libfoo.so.1.2.3 /usr/lib/libbar.so.1.2.3 ); wantarray ? @ret : $ret[0]; }, ], ); is( which('foo'), '/usr/lib/libfoo.so.1.2.3' ); is( \%find_lib_args, hash { field 'lib' => 'foo'; end; } ); }; subtest 'which' => sub { my %find_lib_args; my $mock = mock 'FFI::CheckLib' => ( override => [ find_lib => sub { %find_lib_args = @_; my @ret = qw( /usr/lib/libfoo.so.1.2.3 /usr/lib/libbar.so.1.2.3 ); wantarray ? @ret : $ret[0]; }, ], ); subtest 'with name' => sub { is( [where('foo')], ['/usr/lib/libfoo.so.1.2.3','/usr/lib/libbar.so.1.2.3'] ); is( \%find_lib_args, hash { field 'lib' => '*'; field 'verify' => T(); end; } ); }; subtest 'with wildcard' => sub { is( [where('*')], ['/usr/lib/libfoo.so.1.2.3','/usr/lib/libbar.so.1.2.3'] ); is( \%find_lib_args, hash { field 'lib' => '*'; end; } ); }; }; subtest 'has_symbols' => sub { my $mock = mock_dynaloader; is( has_symbols('corpus/generic.dll'), T(), ); is( has_symbols('corpus/generic.dll', qw( foo bar baz)), T(), ); is( has_symbols('corpus/generic.dll', qw( foo bar )), T(), ); is( has_symbols('corpus/generic.dll', qw( foo )), T(), ); is( has_symbols('corpus/generic.dll', qw( foo bar baz bogus )), F(), ); is( has_symbols('corpus/generic.dll', qw( bogus )), F(), ); }; subtest 'system_path' => sub { @{ $FFI::CheckLib::system_path } = (qw( /foo /bar /baz )); is( FFI::CheckLib::system_path(), [ qw( /foo /bar /baz ) ], ); }; subtest 'alien' => sub { @{ $FFI::CheckLib::system_path } = (); subtest 'preloaded' => sub { my $alien = mock 'Alien::libfoo' => ( add => [ dynamic_libs => sub { 'corpus/unix/lib/libfoo.so.2.3.4', }, ], ); is( [FFI::CheckLib::find_lib( lib => 'foo', alien => ['Alien::libfoo'])], array { item 0 => match qr/foo/; end; }, ); }; subtest 'autoload' => sub { local @INC = @INC; unshift @INC, 'corpus/lib'; is( [FFI::CheckLib::find_lib( lib => 'bar', alien => ['Alien::libbar'])], array { item 0 => match qr/bar/; end; }, ); }; subtest 'invalid name' => sub { is dies { FFI::CheckLib::find_lib( lib => 'bar', alien => ['x..y']) }, match qr/Doesn't appear to be a valid Alien name x\.\.y/; }; subtest 'no dynamic_libs method' => sub { { package Alien::libbaz; $INC{'Alien/libbaz.pm'} = __PACKAGE__; } is dies { FFI::CheckLib::find_lib( lib => 'baz', alien => ['Alien::libbaz']) }, match qr/Alien Alien::libbaz doesn't provide a dynamic_libs method/; }; subtest 'not installed' => sub { try_ok { FFI::CheckLib::find_lib( lib => 'baz', alien => ['Alien::libnotinstalled']); }; }; }; subtest 'FFI_CHECKLIB_PATH' => sub { $FFI::CheckLib::system_path = [File::Spec->rel2abs('corpus/unix/path/path1')]; $ENV{FFI_CHECKLIB_PATH} = File::Spec->rel2abs('corpus/unix/path/path2'); note "system_path = @{[ @$FFI::CheckLib::system_path ]}"; note "FFI_CHECKLIB_PATH = $ENV{FFI_CHECKLIB_PATH}"; my $lib = FFI::CheckLib::find_lib( lib => 'foo' ); note "lib=$lib"; is(basename($lib), "libfoo.so.2"); $lib = FFI::CheckLib::find_lib( lib => 'foo', libpath => 'corpus/unix/path/path3' ); note "lib=$lib"; is(basename($lib), "libfoo.so.3"); }; done_testing; FFI-CheckLib-0.31/t/ffi_checklib__exit.t000644 000000 000000 00000001575 14315571125 017705 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Require::Module 'Test2::Tools::Process'; use Test2::V0 -no_srand => 1; use Test2::Plugin::FauxOS 'linux'; use Test2::Tools::NoteStderr qw( note_stderr ); use Test2::Tools::Process; use FFI::CheckLib; @$FFI::CheckLib::system_path = ( 'corpus/unix/usr/lib', 'corpus/unix/lib', ); subtest 'check_lib_or_exit' => sub { subtest 'found' => sub { process { check_lib_or_exit( lib => 'foo' ) } []; }; subtest 'not found' => sub { process { note_stderr { check_lib_or_exit( lib => 'foobar') } } [ proc_event( exit => 0 ), ]; }; }; subtest 'find_lib_or_exit' => sub { subtest 'found' => sub { process { my $path = find_lib_or_exit( lib => 'foo' ) } []; }; subtest 'not found' => sub { process { note_stderr { my $path = find_lib_or_exit( lib => 'foobar') } } [ proc_event( exit => 0 ), ]; }; }; done_testing; FFI-CheckLib-0.31/t/ffi_checklib__os_cygwin.t000644 000000 000000 00000012665 14315571125 020737 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::V0 -no_srand => 1; use Test2::Plugin::FauxOS 'cygwin'; use Test2::Tools::FauxDynaLoader; use Test2::Tools::NoteStderr qw( note_stderr ); use FFI::CheckLib; @$FFI::CheckLib::system_path = ( 'corpus/cygwin/bin', 'corpus/unix/usr/lib', 'corpus/unix/lib', ); my $mock = mock_dynaloader; subtest 'find_lib (good)' => sub { my($path) = find_lib( lib => 'dinosaur' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'dinosaur' ); is $path, $path2, 'scalar context'; }; subtest 'find_lib (good) with lib and version' => sub { my($path) = find_lib( lib => 'apatosaurus' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'apatosaurus' ); is $path, $path2, 'scalar context'; }; subtest 'find_lib (good)' => sub { my($path) = find_lib( lib => 'foo' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'foo' ); is $path, $path2, 'scalar context'; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib (fail)' => sub { my @path = find_lib( lib => 'foobar' ); ok @path == 0, 'libfoobar not found'; }; subtest 'find_lib list' => sub { my @path = find_lib( lib => [ 'foo', 'bar' ] ); ok -r $path[0], "path[0] = $path[0] is readable"; ok -r $path[1], "path[1] = $path[1] is readable"; subtest foo => sub { my($foo) = grep { $_->name eq 'foo' } map { TestDLL->new($_) } @path; is $foo->name, 'foo', 'dll.name = foo'; is $foo->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest bar => sub { my($bar) = grep { $_->name eq 'bar' } map { TestDLL->new($_) } @path; is $bar->name, 'bar', 'dll.name = bar'; is $bar->version, '1.2.3', 'dll.version = 1.2.3'; }; }; subtest 'find_lib libpath' => sub { my($path) = find_lib( lib => 'foo', libpath => 'corpus/unix/custom' ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3a', 'dll.version = 1.2.3a'; }; subtest 'find_lib libpath (list)' => sub { my($path) = find_lib( lib => 'foo', libpath => ['corpus/unix/custom']); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3a', 'dll.version = 1.2.3a'; }; subtest 'find_lib symbol' => sub { my($path) = find_lib( lib => 'foo', symbol => 'foo_init' ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib symbol (bad)' => sub { my @path = find_lib( lib => 'foo', symbol => 'foo_initx' ); ok @path == 0, 'no path found'; }; subtest 'find_lib symbol (list)' => sub { my($path) = find_lib( lib => 'foo', symbol => ['foo_init', 'foo_new', 'foo_delete'] ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib symbol (list) (bad)' => sub { my @path = find_lib( lib => 'foo', symbol => ['foo_init', 'foo_new', 'foo_delete', 'bogus'] ); ok @path == 0, 'no path found'; }; subtest 'assert_lib' => sub { subtest 'found' => sub { eval { assert_lib( lib => 'foo' ) }; is $@, '', 'no exception'; }; subtest 'not found' => sub { eval { assert_lib( lib => 'foobar') }; isnt $@, '', 'exception'; }; }; subtest 'check_lib' => sub { is check_lib( lib => 'foo' ), 1, 'found'; is check_lib( lib => 'foobar'), 0, 'not found'; }; subtest 'verify bad' => sub { my @lib = find_lib( lib => 'foo', verify => sub { 0 }, ); ok @lib == 0, 'returned empty list'; @lib = find_lib( lib => 'foo', verify => [ sub { 0 } ], ); ok @lib == 0, 'returned empty list'; }; subtest 'verify' => sub { my($lib) = find_lib( lib => 'foo', verify => sub { my($name, $path) = @_; my $lib = TestDLL->new($path); $lib->version ne '1.2.3' }, ); ok -r $lib, "path = $lib is readable"; my $dll = TestDLL->new($lib); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '2.3.4', 'dll.version = 2.3.4'; }; sub p { my($path) = @_; $path =~ s{/}{\\}g if $^O eq 'MSWin32'; $path; } subtest '_cmp' => sub { my $process = sub { [ sort { FFI::CheckLib::_cmp($a,$b) } map { FFI::CheckLib::_matches($_, '/bin') } @_ ]; }; is( $process->(qw( cygfoo-1.dll cygbar-2.dll cygbaz-0.dll )), [ [ 'bar', p('/bin/cygbar-2.dll'), 2 ], [ 'baz', p('/bin/cygbaz-0.dll'), 0 ], [ 'foo', p('/bin/cygfoo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( cygbaz-0.dll cygfoo-1.dll cygbar-2.dll )), [ [ 'bar', p('/bin/cygbar-2.dll'), 2 ], [ 'baz', p('/bin/cygbaz-0.dll'), 0 ], [ 'foo', p('/bin/cygfoo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( cygbar-2.dll cygfoo-1.dll cygbaz-0.dll )), [ [ 'bar', p('/bin/cygbar-2.dll'), 2 ], [ 'baz', p('/bin/cygbaz-0.dll'), 0 ], [ 'foo', p('/bin/cygfoo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( cygfoo-2.dll cygfoo-0.dll cygfoo-1.dll )), [ [ 'foo', p('/bin/cygfoo-2.dll'), 2, ], [ 'foo', p('/bin/cygfoo-1.dll'), 1, ], [ 'foo', p('/bin/cygfoo-0.dll'), 0, ], ], 'newer version first', ); }; done_testing; FFI-CheckLib-0.31/t/ffi_checklib__os_darwin.t000644 000000 000000 00000016031 14315571125 020712 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::V0 -no_srand => 1; use Test2::Plugin::FauxOS 'darwin'; use Test2::Tools::FauxDynaLoader; use Test2::Tools::NoteStderr qw( note_stderr ); use FFI::CheckLib; @$FFI::CheckLib::system_path = ( 'corpus/darwin/usr/lib', 'corpus/darwin/lib', ); my $mock = mock_dynaloader; subtest 'find_lib (good)' => sub { my($path) = find_lib( lib => 'foo' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'foo' ); is $path, $path2, 'scalar context'; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib (fail)' => sub { my @path = find_lib( lib => 'foobar' ); ok @path == 0, 'libfoobar not found'; }; subtest 'find_lib list' => sub { my @path = find_lib( lib => [ 'foo', 'bar' ] ); ok -r $path[0], "path[0] = $path[0] is readable"; ok -r $path[1], "path[1] = $path[1] is readable"; subtest foo => sub { my($foo) = grep { $_->name eq 'foo' } map { TestDLL->new($_) } @path; is $foo->name, 'foo', 'dll.name = foo'; is $foo->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest bar => sub { my($bar) = grep { $_->name eq 'bar' } map { TestDLL->new($_) } @path; is $bar->name, 'bar', 'dll.name = bar'; is $bar->version, '1.2.3', 'dll.version = 1.2.3'; }; }; subtest 'find_lib libpath' => sub { my($path) = find_lib( lib => 'foo', libpath => 'corpus/darwin/custom' ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3a', 'dll.version = 1.2.3a'; }; subtest 'find_lib libpath (list)' => sub { my($path) = find_lib( lib => 'foo', libpath => ['corpus/darwin/custom']); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3a', 'dll.version = 1.2.3a'; }; subtest 'find_lib symbol' => sub { my($path) = find_lib( lib => 'foo', symbol => 'foo_init' ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib symbol (bad)' => sub { my @path = find_lib( lib => 'foo', symbol => 'foo_initx' ); ok @path == 0, 'no path found'; }; subtest 'find_lib symbol (list)' => sub { my($path) = find_lib( lib => 'foo', symbol => ['foo_init', 'foo_new', 'foo_delete'] ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib symbol (list) (bad)' => sub { my @path = find_lib( lib => 'foo', symbol => ['foo_init', 'foo_new', 'foo_delete', 'bogus'] ); ok @path == 0, 'no path found'; }; subtest 'assert_lib' => sub { subtest 'found' => sub { eval { assert_lib( lib => 'foo' ) }; is $@, '', 'no exception'; }; subtest 'not found' => sub { eval { assert_lib( lib => 'foobar') }; isnt $@, '', 'exception'; }; }; subtest 'check_lib' => sub { is check_lib( lib => 'foo' ), 1, 'found'; is check_lib( lib => 'foobar'), 0, 'not found'; }; subtest 'verify bad' => sub { my @lib = find_lib( lib => 'foo', verify => sub { 0 }, ); ok @lib == 0, 'returned empty list'; @lib = find_lib( lib => 'foo', verify => [ sub { 0 } ], ); ok @lib == 0, 'returned empty list'; }; subtest 'verify' => sub { my($lib) = find_lib( lib => 'foo', verify => sub { my($name, $path) = @_; my $lib = TestDLL->new($path); $lib->version ne '1.2.3' }, ); ok -r $lib, "path = $lib is readable"; my $dll = TestDLL->new($lib); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '2.3.4', 'dll.version = 2.3.4'; }; sub p { my($path) = @_; $path =~ s{/}{\\}g if $^O eq 'MSWin32'; $path; } subtest '_cmp' => sub { my $process = sub { [ sort { FFI::CheckLib::_cmp($a,$b) } map { FFI::CheckLib::_matches($_, '/lib') } @_ ]; }; is( $process->(qw( libfoo.1.2.3.dylib libbar.3.4.5.dylib libbaz.0.0.0.dylib )), [ [ 'bar', p('/lib/libbar.3.4.5.dylib'), 3,4,5 ], [ 'baz', p('/lib/libbaz.0.0.0.dylib'), 0,0,0 ], [ 'foo', p('/lib/libfoo.1.2.3.dylib'), 1,2,3 ], ], 'name first 1', ); is( $process->(qw( libbaz.0.0.0.dylib libfoo.1.2.3.dylib libbar.3.4.5.dylib )), [ [ 'bar', p('/lib/libbar.3.4.5.dylib'), 3,4,5 ], [ 'baz', p('/lib/libbaz.0.0.0.dylib'), 0,0,0 ], [ 'foo', p('/lib/libfoo.1.2.3.dylib'), 1,2,3 ], ], 'name first 2', ); is( $process->(qw( libbar.3.4.5.dylib libbaz.0.0.0.dylib libfoo.1.2.3.dylib )), [ [ 'bar', p('/lib/libbar.3.4.5.dylib'), 3,4,5 ], [ 'baz', p('/lib/libbaz.0.0.0.dylib'), 0,0,0 ], [ 'foo', p('/lib/libfoo.1.2.3.dylib'), 1,2,3 ], ], 'name first 3', ); is( $process->(qw( libfoo.1.2.3.dylib libfoo.dylib libfoo.1.2.dylib libfoo.1.dylib )), [ [ 'foo', p('/lib/libfoo.dylib'), ], [ 'foo', p('/lib/libfoo.1.dylib'), 1 ], [ 'foo', p('/lib/libfoo.1.2.dylib'), 1,2 ], [ 'foo', p('/lib/libfoo.1.2.3.dylib'), 1,2,3 ], ], 'no version before version', ); is( $process->(qw( libfoo.2.3.4.dylib libfoo.1.2.3.dylib libfoo.3.4.5.dylib )), [ [ 'foo', p('/lib/libfoo.3.4.5.dylib'), 3,4,5 ], [ 'foo', p('/lib/libfoo.2.3.4.dylib'), 2,3,4 ], [ 'foo', p('/lib/libfoo.1.2.3.dylib'), 1,2,3 ], ], 'newer version first', ); }; subtest '_darwin_extra_libraries' => sub { my $homebrew_lib_path = '/opt/homebrew/lib'; my $macports_lib_path = '/opt/local/lib'; my $mock = mock 'FFI::CheckLib'; $mock->override( _homebrew_lib_path => sub {$homebrew_lib_path}, _macports_lib_path => sub {$macports_lib_path} ); subtest 'default' => sub { local %ENV = %ENV; delete $ENV{FFI_CHECKLIB_PACKAGE}; is( [ FFI::CheckLib::_darwin_extra_paths() ], [ $homebrew_lib_path, $macports_lib_path ], 'homebrew and macports lib paths added' ); }; subtest 'none' => sub { local %ENV = %ENV; $ENV{FFI_CHECKLIB_PACKAGE} = 'NONE'; is( [ FFI::CheckLib::_darwin_extra_paths() ], [], 'None extra lib paths added' ); }; subtest 'homebrew' => sub { local %ENV = %ENV; $ENV{FFI_CHECKLIB_PACKAGE} = 'Homebrew'; is( [ FFI::CheckLib::_darwin_extra_paths() ], [ $homebrew_lib_path ], 'homebrew lib path added' ); }; subtest 'macports' => sub { local %ENV = %ENV; $ENV{FFI_CHECKLIB_PACKAGE} = 'MacPorts'; is( [ FFI::CheckLib::_darwin_extra_paths() ], [ $macports_lib_path ], 'macports lib path loaded' ); }; subtest 'macports,homebrew' => sub { local %ENV = %ENV; $ENV{FFI_CHECKLIB_PACKAGE} = 'macports,homebrew'; is( [ FFI::CheckLib::_darwin_extra_paths() ], [ $macports_lib_path, $homebrew_lib_path ], 'macports and homebrew lib paths added (order matters)' ); }; }; done_testing; FFI-CheckLib-0.31/t/ffi_checklib__os_mswin32.t000644 000000 000000 00000007315 14315571125 020735 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::V0 -no_srand => 1; use Test2::Plugin::FauxOS 'MSWin32'; use FFI::CheckLib; use Env qw( @PATH ); @$FFI::CheckLib::system_path = ( 'corpus/windows/bin', ); subtest 'find_lib (good)' => sub { my($path) = find_lib( lib => 'dinosaur' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'dinosaur' ); is $path, $path2, 'scalar context'; }; subtest 'find_lib (fail)' => sub { my @path = find_lib( lib => 'foobar' ); ok @path == 0, 'libfoobar not found'; }; subtest 'find_lib (good) with lib and version' => sub { my($path) = find_lib( lib => 'apatosaurus' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'apatosaurus' ); is $path, $path2, 'scalar context'; }; subtest 'in sync with $ENV{PATH}' => sub { local $ENV{PATH} = $ENV{PATH}; @PATH = qw( foo bar baz ); is( $FFI::CheckLib::system_path, [qw( foo bar baz )], ); }; subtest 'lib with name like libname-1-2-3.dll' => sub { my($path) = find_lib( lib => 'maiasaura' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'maiasaura' ); is $path, $path2, 'scalar context'; }; subtest 'lib with name like name-1-2-3.dll' => sub { my($path) = find_lib( lib => 'dromornis_planei' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'dromornis_planei' ); is $path, $path2, 'scalar context'; }; subtest 'lib with name like libname-1-2___.dll' => sub { my($path) = find_lib( lib => 'thylacaleo_carnifex' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'thylacaleo_carnifex' ); is $path, $path2, 'scalar context'; }; subtest 'lib with name like libname_1_2.dll' => sub { my($path) = find_lib( lib => 'brevipalatus_mcculloughi' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'brevipalatus_mcculloughi' ); is $path, $path2, 'scalar context'; }; subtest 'lib with name like libname_ext.dll' => sub { my($path) = find_lib( lib => 'apatosaurus_ajax' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'apatosaurus_ajax' ); is $path, $path2, 'scalar context'; }; sub p { my($path) = @_; $path =~ s{/}{\\}g if $^O eq 'MSWin32'; $path; } subtest '_cmp' => sub { my $process = sub { [ sort { FFI::CheckLib::_cmp($a,$b) } map { FFI::CheckLib::_matches($_, 'C:/bin') } @_ ]; }; is( $process->(qw( foo-1.dll bar-2.dll baz-0.dll )), [ [ 'bar', p('C:/bin/bar-2.dll'), 2 ], [ 'baz', p('C:/bin/baz-0.dll'), 0 ], [ 'foo', p('C:/bin/foo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( baz-0.dll foo-1.dll bar-2.dll )), [ [ 'bar', p('C:/bin/bar-2.dll'), 2 ], [ 'baz', p('C:/bin/baz-0.dll'), 0 ], [ 'foo', p('C:/bin/foo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( bar-2.dll foo-1.dll baz-0.dll )), [ [ 'bar', p('C:/bin/bar-2.dll'), 2 ], [ 'baz', p('C:/bin/baz-0.dll'), 0 ], [ 'foo', p('C:/bin/foo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( foo-2.dll foo-0.dll foo-1.dll )), [ [ 'foo', p('C:/bin/foo-2.dll'), 2, ], [ 'foo', p('C:/bin/foo-1.dll'), 1, ], [ 'foo', p('C:/bin/foo-0.dll'), 0, ], ], 'newer version first', ); }; subtest 'case insensitive' => sub { local $FFI::CheckLib::system_path = [ 'corpus/windows/bincase' ]; subtest 'no prefix' => sub { my($path) = find_lib( lib => 'foo' ); ok $path; note "path = @{[ defined $path ? $path : 'undef' ]}"; }; subtest 'with lib prefix' => sub { my($path) = find_lib( lib => 'bar' ); ok $path; note "path = @{[ defined $path ? $path : 'undef' ]}"; }; }; done_testing; FFI-CheckLib-0.31/t/ffi_checklib__os_msys.t000644 000000 000000 00000002545 14315571125 020426 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::V0 -no_srand => 1; use Test2::Plugin::FauxOS 'msys'; use FFI::CheckLib; sub p { my($path) = @_; $path =~ s{/}{\\}g if $^O eq 'MSWin32'; $path; } subtest '_cmp' => sub { my $process = sub { [ sort { FFI::CheckLib::_cmp($a,$b) } map { FFI::CheckLib::_matches($_, '/bin') } @_ ]; }; is( $process->(qw( msys-foo-1.dll msys-bar-2.dll msys-baz-0.dll )), [ [ 'bar', p('/bin/msys-bar-2.dll'), 2 ], [ 'baz', p('/bin/msys-baz-0.dll'), 0 ], [ 'foo', p('/bin/msys-foo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( msys-baz-0.dll msys-foo-1.dll msys-bar-2.dll )), [ [ 'bar', p('/bin/msys-bar-2.dll'), 2 ], [ 'baz', p('/bin/msys-baz-0.dll'), 0 ], [ 'foo', p('/bin/msys-foo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( msys-bar-2.dll msys-foo-1.dll msys-baz-0.dll )), [ [ 'bar', p('/bin/msys-bar-2.dll'), 2 ], [ 'baz', p('/bin/msys-baz-0.dll'), 0 ], [ 'foo', p('/bin/msys-foo-1.dll'), 1 ], ], 'name first 1', ); is( $process->(qw( msys-foo-2.dll msys-foo-0.dll msys-foo-1.dll )), [ [ 'foo', p('/bin/msys-foo-2.dll'), 2, ], [ 'foo', p('/bin/msys-foo-1.dll'), 1, ], [ 'foo', p('/bin/msys-foo-0.dll'), 0, ], ], 'newer version first', ); }; done_testing; FFI-CheckLib-0.31/t/ffi_checklib__os_unix.t000644 000000 000000 00000014464 14315571125 020421 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::V0 -no_srand => 1; use Test2::Plugin::FauxOS 'linux'; use Test2::Tools::FauxDynaLoader; use Test2::Tools::NoteStderr qw( note_stderr ); use FFI::CheckLib; use File::Basename qw( basename ); @$FFI::CheckLib::system_path = ( 'corpus/unix/usr/lib', 'corpus/unix/lib', ); my $mock1 = mock_dynaloader; subtest 'find_lib (good)' => sub { my($path) = find_lib( lib => 'foo' ); ok -r $path, "path = $path is readable"; my $path2 = find_lib( lib => 'foo' ); is $path, $path2, 'scalar context'; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib (fail)' => sub { my @path = find_lib( lib => 'foobar' ); ok @path == 0, 'libfoobar not found'; }; subtest 'find_lib list' => sub { my @path = find_lib( lib => [ 'foo', 'bar' ] ); ok -r $path[0], "path[0] = $path[0] is readable"; ok -r $path[1], "path[1] = $path[1] is readable"; subtest foo => sub { my($foo) = grep { $_->name eq 'foo' } map { TestDLL->new($_) } @path; is $foo->name, 'foo', 'dll.name = foo'; is $foo->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest bar => sub { my($bar) = grep { $_->name eq 'bar' } map { TestDLL->new($_) } @path; is $bar->name, 'bar', 'dll.name = bar'; is $bar->version, '1.2.3', 'dll.version = 1.2.3'; }; }; subtest 'find_lib libpath' => sub { my($path) = find_lib( lib => 'foo', libpath => 'corpus/unix/custom' ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3a', 'dll.version = 1.2.3a'; }; subtest 'find_lib libpath (list)' => sub { my($path) = find_lib( lib => 'foo', libpath => ['corpus/unix/custom']); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3a', 'dll.version = 1.2.3a'; }; subtest 'find_lib symbol' => sub { my($path) = find_lib( lib => 'foo', symbol => 'foo_init' ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib symbol (bad)' => sub { my @path = find_lib( lib => 'foo', symbol => 'foo_initx' ); ok @path == 0, 'no path found'; }; subtest 'find_lib symbol (list)' => sub { my($path) = find_lib( lib => 'foo', symbol => ['foo_init', 'foo_new', 'foo_delete'] ); ok -r $path, "path = $path is readable"; my $dll = TestDLL->new($path); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '1.2.3', 'dll.version = 1.2.3'; }; subtest 'find_lib symbol (list) (bad)' => sub { my @path = find_lib( lib => 'foo', symbol => ['foo_init', 'foo_new', 'foo_delete', 'bogus'] ); ok @path == 0, 'no path found'; }; subtest 'assert_lib' => sub { subtest 'found' => sub { eval { assert_lib( lib => 'foo' ) }; is $@, '', 'no exception'; }; subtest 'not found' => sub { eval { assert_lib( lib => 'foobar') }; isnt $@, '', 'exception'; }; }; subtest 'check_lib' => sub { is check_lib( lib => 'foo' ), 1, 'found'; is check_lib( lib => 'foobar'), 0, 'not found'; }; subtest 'verify bad' => sub { my @lib = find_lib( lib => 'foo', verify => sub { 0 }, ); ok @lib == 0, 'returned empty list'; @lib = find_lib( lib => 'foo', verify => [ sub { 0 } ], ); ok @lib == 0, 'returned empty list'; }; subtest 'verify' => sub { my($lib) = find_lib( lib => 'foo', verify => sub { my($name, $path) = @_; my $lib = TestDLL->new($path); $lib->version ne '1.2.3' }, ); ok -r $lib, "path = $lib is readable"; my $dll = TestDLL->new($lib); is $dll->name, 'foo', 'dll.name = foo'; is $dll->version, '2.3.4', 'dll.version = 2.3.4'; }; subtest 'symlink' => sub { # TODO: this test only gets run out of git, since Dist::Zilla # converts the symlinks into real files :/ skip_all 'Test requires a system with proper symlinks' unless -l 'corpus/unix/usr/lib/libxor.so' && readlink('corpus/unix/usr/lib/libxor.so'); subtest 'multiple versions of the same lib' => sub { my($lib) = find_lib( lib => 'xor', ); is(basename($lib), 'libxor.so.1.2.4'); }; subtest 'broken symlink' => sub { my($lib) = find_lib( lib => 'ganon', ); is($lib, undef); }; subtest 'infinite recurse symlink' => sub { my($lib) = find_lib( lib => 'link', ); is($lib, undef); }; }; subtest 'prefer newer' => sub { my($lib) = find_lib( lib => 'crypto', ); is($lib, T()); is(basename($lib), 'libcrypto.so.1.0.0'); note "lib = $lib"; }; sub p { my($path) = @_; $path =~ s{/}{\\}g if $^O eq 'MSWin32'; $path; } subtest '_cmp' => sub { my $process = sub { [ sort { FFI::CheckLib::_cmp($a,$b) } map { FFI::CheckLib::_matches($_, '/lib') } @_ ]; }; is( $process->(qw( libfoo.so.1.2.3 libbar.so.3.4.5 libbaz.so.0.0.0 )), [ [ 'bar', p('/lib/libbar.so.3.4.5'), 3,4,5 ], [ 'baz', p('/lib/libbaz.so.0.0.0'), 0,0,0 ], [ 'foo', p('/lib/libfoo.so.1.2.3'), 1,2,3 ], ], 'name first 1', ); is( $process->(qw( libbaz.so.0.0.0 libfoo.so.1.2.3 libbar.so.3.4.5 )), [ [ 'bar', p('/lib/libbar.so.3.4.5'), 3,4,5 ], [ 'baz', p('/lib/libbaz.so.0.0.0'), 0,0,0 ], [ 'foo', p('/lib/libfoo.so.1.2.3'), 1,2,3 ], ], 'name first 2', ); is( $process->(qw( libbar.so.3.4.5 libbaz.so.0.0.0 libfoo.so.1.2.3 )), [ [ 'bar', p('/lib/libbar.so.3.4.5'), 3,4,5 ], [ 'baz', p('/lib/libbaz.so.0.0.0'), 0,0,0 ], [ 'foo', p('/lib/libfoo.so.1.2.3'), 1,2,3 ], ], 'name first 3', ); is( $process->(qw( libfoo.so.1.2.3 libfoo.so libfoo.so.1.2 libfoo.so.1 )), [ [ 'foo', p('/lib/libfoo.so'), ], [ 'foo', p('/lib/libfoo.so.1'), 1 ], [ 'foo', p('/lib/libfoo.so.1.2'), 1,2 ], [ 'foo', p('/lib/libfoo.so.1.2.3'), 1,2,3 ], ], 'no version before version', ); is( $process->(qw( libfoo.so.2.3.4 libfoo.so.1.2.3 libfoo.so.3.4.5 )), [ [ 'foo', p('/lib/libfoo.so.3.4.5'), 3,4,5 ], [ 'foo', p('/lib/libfoo.so.2.3.4'), 2,3,4 ], [ 'foo', p('/lib/libfoo.so.1.2.3'), 1,2,3 ], ], 'newer version first', ); }; done_testing; FFI-CheckLib-0.31/t/lib/000755 000000 000000 00000000000 14315571125 014476 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/t/lib/Test2/000755 000000 000000 00000000000 14315571125 015477 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/t/lib/Test2/Plugin/000755 000000 000000 00000000000 14315571125 016735 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/t/lib/Test2/Plugin/FauxOS.pm000644 000000 000000 00000000624 14315571125 020442 0ustar00rootroot000000 000000 package Test2::Plugin::FauxOS; use strict; use warnings; use Test2::API qw/test2_add_callback_exit/; sub import { my(undef, $os) = @_; die "you must use Test2::Plugin::FauxOS prior to FFI::CheckLib" if $INC{'FFI/CheckLib.pm'}; $FFI::CheckLib::os = $os; test2_add_callback_exit(sub { my ($ctx, $real, $new) = @_; $ctx->note("faux os: $os"); $ctx->note("real os: $^O"); }); } 1; FFI-CheckLib-0.31/t/lib/Test2/Tools/000755 000000 000000 00000000000 14315571125 016577 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/t/lib/Test2/Tools/FauxDynaLoader.pm000644 000000 000000 00000002375 14315571125 022012 0ustar00rootroot000000 000000 package Test2::Tools::FauxDynaLoader; use strict; use warnings; use Test2::V0 qw( mock ); use DynaLoader; use base qw( Exporter ); our @EXPORT = qw( mock_dynaloader ); sub mock_dynaloader { my @libref = ('null'); my $mock = mock 'DynaLoader'; $mock->override(dl_load_file => sub { my($filename, $flags) = @_; return undef unless -e $filename; my $libref = scalar @libref; $libref[$libref] = TestDLL->new($filename); $libref; }); $mock->override(dl_unload_file => sub { my($libref) = @_; delete $libref[$libref]; }); $mock->override(dl_find_symbol => sub { my($libref, $symbol) = @_; my $lib = $libref[$libref]; $lib->has_symbol($symbol); }); $mock; } package TestDLL; sub new { my($class, $filename) = @_; my @list = do { my $fh; open $fh, '<', $filename; my @list = <$fh>; close $fh; @list; }; chomp @list; my $name = shift @list; my $version = shift @list; my %symbols = map { $_ => 1 } @list; bless { filename => $filename, name => $name, version => $version, symbols => \%symbols, }, $class; } sub filename { shift->{filename} } sub name { shift->{name} } sub version { shift->{version} } sub has_symbol { $_[0]->{symbols}->{$_[1]} } 1; FFI-CheckLib-0.31/t/lib/Test2/Tools/NoteStderr.pm000644 000000 000000 00000001044 14315571125 021225 0ustar00rootroot000000 000000 package Test2::Tools::NoteStderr; use strict; use warnings; use Test2::API qw( context ); use base qw( Exporter ); our @EXPORT_OK = qw( note_stderr ); BEGIN { eval q{ use Capture::Tiny qw( capture_stderr ); }; if($@) { eval q{ sub capture_stderr (&) { $_[0]->() }; }; } } sub note_stderr (&) { my($code) = @_; my($stderr, $exception) = capture_stderr { eval { $code->(); }; $@; }; my $ctx = context(); $ctx->note($stderr); $ctx->release; die $exception if $exception; return; } 1; FFI-CheckLib-0.31/xt/000755 000000 000000 00000000000 14315571125 014120 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/xt/author/000755 000000 000000 00000000000 14315571125 015422 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/xt/author/critic.t000644 000000 000000 00000000515 14315571125 017065 0ustar00rootroot000000 000000 use Test2::Require::Module 'Test2::Tools::PerlCritic'; use Test2::Require::Module 'Perl::Critic'; use Test2::Require::Module 'Perl::Critic::Freenode'; use Test2::V0; use Perl::Critic; use Test2::Tools::PerlCritic; my $critic = Perl::Critic->new( -profile => 'perlcriticrc', ); perl_critic_ok ['lib','t'], $critic; done_testing; FFI-CheckLib-0.31/xt/author/eol.t000644 000000 000000 00000000510 14315571125 016362 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::EOL' unless eval q{ use Test::EOL; 1 }; }; use Test::EOL; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_perl_files_ok(grep { -e $_ } qw( bin lib t Makefile.PL )); FFI-CheckLib-0.31/xt/author/no_tabs.t000644 000000 000000 00000000522 14315571125 017233 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::NoTabs' unless eval q{ use Test::NoTabs; 1 }; }; use Test::NoTabs; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_perl_files_ok( grep { -e $_ } qw( bin lib t Makefile.PL )); FFI-CheckLib-0.31/xt/author/pod.t000644 000000 000000 00000000472 14315571125 016374 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Pod' unless eval q{ use Test::Pod; 1 }; }; use Test::Pod; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_pod_files_ok( grep { -e $_ } qw( bin lib )); FFI-CheckLib-0.31/xt/author/pod_coverage.t000644 000000 000000 00000004001 14315571125 020237 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires 5.010 or better' unless $] >= 5.010; plan skip_all => 'test requires Test::Pod::Coverage' unless eval q{ use Test::Pod::Coverage; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML; 1; }; plan skip_all => 'test does not always work in cip check' if defined $ENV{CIPSTATIC} && $ENV{CIPSTATIC} eq 'true'; }; use Test::Pod::Coverage; use YAML qw( LoadFile ); use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; plan skip_all => 'disabled' if $config->{pod_coverage}->{skip}; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); my @private_classes; my %private_methods; push $config->{pod_coverage}->{private}->@*, 'Alien::.*::Install::Files#Inline'; foreach my $private ($config->{pod_coverage}->{private}->@*) { my($class,$method) = split /#/, $private; if(defined $class && $class ne '') { my $regex = eval 'qr{^' . $class . '$}'; if(defined $method && $method ne '') { push @private_classes, { regex => $regex, method => $method }; } else { push @private_classes, { regex => $regex, all => 1 }; } } elsif(defined $method && $method ne '') { $private_methods{$_} = 1 for split /,/, $method; } } my @classes = all_modules; plan tests => scalar @classes; foreach my $class (@classes) { SKIP: { my($is_private_class) = map { 1 } grep { $class =~ $_->{regex} && $_->{all} } @private_classes; skip "private class: $class", 1 if $is_private_class; my %methods = map {; $_ => 1 } map { split /,/, $_->{method} } grep { $class =~ $_->{regex} } @private_classes; $methods{$_} = 1 for keys %private_methods; my $also_private = eval 'qr{^' . join('|', keys %methods ) . '$}'; pod_coverage_ok $class, { also_private => [$also_private] }; }; } FFI-CheckLib-0.31/xt/author/pod_link.t000644 000000 000000 00000000705 14315571125 017410 0ustar00rootroot000000 000000 use Test2::Require::Module 'Test::Pod::LinkCheck::Lite'; use Test2::Require::EnvVar 'POD_CHECK'; use Test2::V0; use Test::Pod::LinkCheck::Lite; my @checks; if(-d 'blib/script') { push @checks, 'blib/script'; } elsif(-d 'bin') { push @checks, 'bin'; } if(-d 'blib') { push @checks, 'blib'; } else { push @checks, 'lib'; diag "checking lib instead of blib"; } Test::Pod::LinkCheck::Lite ->new ->all_pod_files_ok(@checks); done_testing; FFI-CheckLib-0.31/xt/author/pod_spelling_common.t000644 000000 000000 00000001350 14315571125 021635 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Pod::Spelling::CommonMistakes' unless eval q{ use Test::Pod::Spelling::CommonMistakes; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML qw( LoadFile ); 1 }; }; use Test::Pod::Spelling::CommonMistakes; use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; plan skip_all => 'disabled' if $config->{pod_spelling_common}->{skip}; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); # TODO: test files in bin too. all_pod_files_ok; FFI-CheckLib-0.31/xt/author/pod_spelling_system.t000644 000000 000000 00000002367 14315571125 021702 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Spelling' unless eval q{ use Test::Spelling; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML; 1; }; }; use Test::Spelling; use YAML qw( LoadFile ); use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; plan skip_all => 'disabled' if $config->{pod_spelling_system}->{skip}; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); add_stopwords($config->{pod_spelling_system}->{stopwords}->@*); add_stopwords(qw( Plicease stdout stderr stdin subref loopback username os Ollis Mojolicious plicease CPAN reinstall TODO filename filenames login callback callbacks standalone VMS hostname hostnames TCP UDP IP API MSWin32 OpenBSD FreeBSD NetBSD unencrypted WebSocket WebSockets timestamp timestamps poney BackPAN portably RedHat AIX BSD XS FFI perlish optimizations subdirectory RESTful SQLite JavaScript dir plugins munge jQuery namespace PDF PDFs usernames DBI pluggable APIs SSL JSON YAML uncommented Solaris OpenVMS URI URL CGI )); all_pod_files_spelling_ok; FFI-CheckLib-0.31/xt/author/strict.t000644 000000 000000 00000001031 14315571125 017112 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Strict' unless eval q{ use Test::Strict; 1 }; }; use Test::Strict; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); unshift @Test::Strict::MODULES_ENABLING_STRICT, 'ozo', 'Test2::Bundle::SIPS', 'Test2::V0', 'Test2::Bundle::Extended'; note "enabling strict = $_" for @Test::Strict::MODULES_ENABLING_STRICT; all_perl_files_ok( grep { -e $_ } qw( bin lib t Makefile.PL )); FFI-CheckLib-0.31/xt/author/version.t000644 000000 000000 00000001473 14315571125 017301 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; use FindBin (); BEGIN { plan skip_all => "test requires Test::Version 2.00" unless eval q{ use Test::Version 2.00 qw( version_all_ok ), { has_version => 1, filename_match => sub { $_[0] !~ m{/(ConfigData|Install/Files)\.pm$} }, }; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML; 1; }; } use YAML qw( LoadFile ); use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; if($config->{version}->{dir}) { note "using dir " . $config->{version}->{dir} } version_all_ok($config->{version}->{dir} ? ($config->{version}->{dir}) : ()); done_testing; FFI-CheckLib-0.31/xt/release/000755 000000 000000 00000000000 14315571125 015540 5ustar00rootroot000000 000000 FFI-CheckLib-0.31/xt/release/changes.t000644 000000 000000 00000001113 14315571125 017331 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::CPAN::Changes' unless eval q{ use Test::CPAN::Changes; 1 }; }; use Test::CPAN::Changes; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); do { my $old = \&Test::Builder::carp; my $new = sub { my($self, @messages) = @_; return if $messages[0] =~ /^Date ".*" is not in the recommend format/; $old->($self, @messages); }; no warnings 'redefine'; *Test::Builder::carp = $new; }; changes_file_ok; done_testing; FFI-CheckLib-0.31/xt/release/fixme.t000644 000000 000000 00000000616 14315571125 017040 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Fixme' unless eval q{ use Test::Fixme 0.14; 1 }; }; use Test::Fixme 0.07; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); run_tests( match => qr/FIXME/, where => [ grep { -e $_ } qw( bin lib t Makefile.PL Build.PL )], warn => 1, );