如何检查 Perl 中是否存在二进制依赖项?
我自愿维护一个停滞的 CPAN 包 (GnuPG),我想改进安装文件,以便在找不到 gpg
二进制文件(GnuPG 是其包装器)时它们可以正常退出。 在从其他包中寻找灵感之后,我想出了将其添加到 Makefile.PL 中:
my @paths = grep { -x "$_/gpg" } split /:/, $ENV{PATH}, $ENV{PGP_PATH};
unless ( scalar @paths ) {
print <<EOD;
I can't find the gpg binary on your system. If it's not installed in your usual PATH, set $ENV{PGP_PATH} to include where it can be found and try installing again.
EOD
exit(0);
}
WriteMakefile(
'NAME' => 'GnuPG',
'VERSION_FROM' => 'GnuPG.pm',
'EXE_FILES' => [ gpgmailtunl ],
'LICENSE' => 'GPL',
'LIBS' => [ @paths ],
);
这看起来合理吗?
Having volunteered to maintain a stagnant CPAN package (GnuPG) I'd like improve the install files such that they exit gracefully if the gpg
binary (which GnuPG is a wrapper for) cannot be found. After a bit of seeking inspiration from other packages, I've come up with adding this to Makefile.PL:
my @paths = grep { -x "$_/gpg" } split /:/, $ENV{PATH}, $ENV{PGP_PATH};
unless ( scalar @paths ) {
print <<EOD;
I can't find the gpg binary on your system. If it's not installed in your usual PATH, set $ENV{PGP_PATH} to include where it can be found and try installing again.
EOD
exit(0);
}
WriteMakefile(
'NAME' => 'GnuPG',
'VERSION_FROM' => 'GnuPG.pm',
'EXE_FILES' => [ gpgmailtunl ],
'LICENSE' => 'GPL',
'LIBS' => [ @paths ],
);
Does that look sane?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用的是 Module::Install 或该系列的一部分,则可以使用 do
See Module: :Install::External 了解详细信息。
没有充分的理由重新发明轮子。
If you're using Module::Install or part of that family, you can use do
See Module::Install::External for details.
No good reason to reinvent the wheel.
一般概念很好 - 如果您需要工作的内容不存在,则不要创建 makefile。 CPAN 测试人员有关于失败时以零状态退出的规则(这让我很恼火,但没关系;我讨厌以成功状态失败!)。
问题:您是否记录了安装时找到 PGP 的位置,以便如果其他人在其路径上没有该位置的情况下使用 Perl 模块,该模块仍然可以运行?
对于 DBD::Informix,我有严格的依赖关系,没有它模块就无法编译; 因此,Makefile.PL 本身就是一个主要产品。 它还尝试处理超过 15 年的软件版本; 这也使其生活变得复杂。 如果先决条件(某些 Perl 模块;某些非 Perl 软件)不可用,则不会安装。
The general concept is fine - if what you need to work is not present, don't create the makefile. The CPAN Testers have rules about exiting with a zero status on failure (which annoys me a lot, but never mind; I hate failing with a success status!).
Question: do you keep a record of where PGP was found at install time, so that if somebody else uses the Perl module without the location on their path, the module can still run?
For DBD::Informix, I have rigid dependencies without which the module cannot be compiled; the Makefile.PL is a major production in its own right because of that. It also tries to handle versions of the software covering over 15 years; that complicates its life, too. If the pre-requisites (some Perl modules; some non-Perl software) is not available, it won't install.
只打印警告不是更有意义吗? 安装本身是否需要 gpg?
代码本身对我来说看起来不错。 但也许有一个内置的“哪个”功能。 :)。
Wouldn't it make more sense to just print a warning? Is gpg necessary for the installation itself?
The code itself looks fine by me. But perhaps there's a built-in 'which' functionality. :).
为了获得更高的准确性,您应该查看 File::Which 或至少使用 File: :规格->路径()。
For better accuracy you should look at File::Which or at least use File::Spec->path().
File::这将是一个跨平台解决方案。 您需要将其捆绑到 inc/ 目录中或要求使用configure_requires 安装它。 对于 EU::MM 可以使用
Module::Install 来完成也是一个很好的解决方案,但是每次发布新版本的 Module::Install 时您都需要发布新版本的发行版,并且更改很重要。
File::Which would be a crossplatform solution. You will need to either bundle it into inc/ directory or require it to be installed with configure_requires. For EU::MM it can be done with
Module::Install is also a good solution, but you will need to release new version of distribution each time new version of Module::Install is released and changes are important.