简体   繁体   English

使用ruby rake查找动态/共享和静态系统库

[英]Finding dynamic/shared and static system libraries using ruby rake

I'm trying to write a rake task that can perform a guided search on the user's system for specific system libraries. 我正在尝试编写一个rake任务,该任务可以在用户的​​系统上执行针对特定系统库的引导搜索。 The basic idea is simple enough (in semi-pseudo-code): 基本思想很简单(使用半伪代码):

def find_lib names, paths
    foreach name, path do
        return { :name => name, :path => path } if File.exists? File.join(path, name)
    end

    return false
end

find_lib ['mylib1.2', 'mylib12'], ['/usr/lib', '/usr/local/lib']

My actual implementation is a little more elegant, but this shows the basic idea. 我的实际实现更加优雅,但这显示了基本思想。 However, I would like to make this OS agnostic, which throws a few big wrenches into the gears. 但是,我想使这个操作系统不可知,这会给系统带来一些麻烦。 Each operating system has potentially different prefixes and extensions for a library. 每个操作系统对于库都可能具有不同的前缀和扩展名。 For instance, a shared library could be ".dll", ".so', or ".dylib" depending on the current system. So far, I've come up with a solution that involves building a map of prefixes/extensions based on the current operating system: 例如,根据当前系统的不同,共享库可以是“ .dll”,“。so”或“ .dylib”。到目前为止,我已经提出了一个解决方案,该方案涉及构建基于前缀/扩展名的映射。在当前操作系统上:

settings = {}
settings[:dylib_ext] = OS.windows? && ".dll"   ||
                       OS.mac?     && ".dylib" ||
                       ".so"

This works to some extent, although it only covers the dynamic library case, and also relies on an external gem "OS", which I was trying to avoid. 尽管它只涉及动态库情况,并且还依赖于我试图避免的外部gem“ OS”,但这种方法在某种程度上是可行的。

Does anyone know a better way of accomplishing such a task, or if it is a solved problem (via another gem perhaps)? 有谁知道更好的方法来完成这样的任务,或者是否已经解决了问题(也许是通过另一个宝石)? The main thing I'm concerned about is the map, which could get very cumbersome (not to mention that detecting the correct operating system is rather tedious at best, especially if you were to throw in cygwin or mingw). 我关心的主要问题是地图,地图可能非常麻烦(更不用说检测正确的操作系统充其量是乏味的,尤其是当您使用Cygwin或mingw时)。

经过一番思考,似乎我对用户当前的操作系统过于具体,而我真正想确定的始终是用户系统支持的功能...我最终使用的方法是确定可能的前缀/后缀组合的列表,并检查每个组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM