打包一个 Perl 应用程序,以便它可以在 Perl 的默认前缀之外工作
我正在使用 Module::Build (尽管我在构建环境上很灵活)来打包我正在编写的一些 Perl 软件,供我工作的内部使用。它包括一些脚本和一些辅助模块。我的计划是这样你可以在构建过程中指定任何你想要的前缀(即 perl 默认 @INC
之外的东西),并且构建的脚本应该仍然能够找到它们的帮助程序模块没有任何问题。
我想这样做是因为我想使用“Encap”在内部分发该软件,这是一个打包工具,默认情况下不能安装 /usr/local 之外的任何内容,并且位于我们的 RedHat 上。默认情况下,perl 不会在 /usr/local/lib 中搜索模块。
这让我有可能告诉用户每次想要运行应用程序时手动将 PERL5LIB 设置为 /usr/local/lib,或者对构建系统进行一些智能操作来获得它指定 --prefix
后,修改每个脚本的 use lib
行。
现在,我只是在每个脚本中手动设置 use lib
直接指向 /usr/local/lib ,但我不太喜欢这种解决方案。主要是因为测试过程:我想在测试期间覆盖 @INC
,以便它首先使用我的工作目录作为 perl 模块,但是在构建后,应该从 @ 中删除工作目录INC
并替换为用户指定的前缀。但也因为我希望这个软件可以安装到任意位置(例如 NFS 上的某个小岛,有自己的 bin/ 和 lib/ 目录)并且仍然可以正常工作。
问题:
Module::Build 是否允许我在构建步骤期间摆弄脚本的 use lib
行?我注意到 MakeMaker 有一个 pm_filter 选项,允许您指定搜索和替换,可以在构建时任意修改 .pm 文件,但这仅适用于 .pm 文件,不适用于脚本。 Module::Build 应该更灵活,但我淹没在文档中试图找出你在哪里指定它。
I'm using Module::Build (although I'm flexible on build environments) to package up some perl software I'm writing for internal use where I work. It includes a handful of scripts, and some helper modules. My plan is to make it so you can specify a prefix of whatever you want (ie. something outside of perl's default @INC
) during the build process and the built scripts should still be able to find their helper modules without any problems.
I want to do this because I want to distribute this software internally with "Encap", which is a packaging tool that by default can not install anything outside of /usr/local, and being on RedHat, our perl does not search /usr/local/lib for modules by default.
This leaves me with the prospect of either telling the user to manually set PERL5LIB
to /usr/local/lib every time they want to run the app, or to do something intelligent with the build system to have it fiddle with each script's use lib
line after a --prefix
is specified.
Right now I'm just setting use lib
to point straight to /usr/local/lib manually in each of my scripts, but I'm not really liking that as a solution. Chiefly because of the testing process: I want to override @INC
during testing so that it uses my working directory first for perl modules, but upon being built, the working directory should be removed from @INC
and replaced with the user's specified prefix. But also because I would like this software to be installed to arbitrary locations (such as its own little island somewhere on NFS with its own bin/ and lib/ dirs) and still work without issue.
The question:
Can Module::Build allow me to fiddle with my scripts' use lib
lines during build steps? I notice MakeMaker has a pm_filter option that lets you specify a search-and-replace that can arbitrarily modify your .pm files as they're being built, but that only works with .pm files, not scripts. Module::Build is supposed to be more flexible but I'm drowning in the documentation trying to figure out where you'd specify that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)