diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-05 12:25:02 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-05 14:59:21 -0300 |
| commit | fba7100c8217edec2cd41b5d8620514b274d0afd (patch) | |
| tree | b97fd3baaa0c681c011eecb97b1c693cc0a2d8b9 /src | |
| parent | daf7e7e5f5ede8c3a5a00e2edaf8246209712781 (diff) | |
| download | luarocks-fba7100c8217edec2cd41b5d8620514b274d0afd.tar.gz luarocks-fba7100c8217edec2cd41b5d8620514b274d0afd.tar.bz2 luarocks-fba7100c8217edec2cd41b5d8620514b274d0afd.zip | |
Always assume that zip and unzip are available on FreeBSD
Fixes #1022
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fs.lua | 18 | ||||
| -rw-r--r-- | src/luarocks/fs/freebsd.lua | 11 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 21 |
3 files changed, 43 insertions, 7 deletions
diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index 8122525e..849ee4d3 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua | |||
| @@ -49,12 +49,15 @@ do | |||
| 49 | end | 49 | end |
| 50 | 50 | ||
| 51 | do | 51 | do |
| 52 | local function load_fns(fs_table) | 52 | local function load_fns(fs_table, inits) |
| 53 | for name, fn in pairs(fs_table) do | 53 | for name, fn in pairs(fs_table) do |
| 54 | if not fs[name] then | 54 | if not fs[name] then |
| 55 | fs[name] = fn | 55 | fs[name] = fn |
| 56 | end | 56 | end |
| 57 | end | 57 | end |
| 58 | if fs_table.init then | ||
| 59 | table.insert(inits, fs_table.init) | ||
| 60 | end | ||
| 58 | end | 61 | end |
| 59 | 62 | ||
| 60 | function fs.init() | 63 | function fs.init() |
| @@ -67,27 +70,34 @@ do | |||
| 67 | error("cfg is not initialized, please run cfg.init() first") | 70 | error("cfg is not initialized, please run cfg.init() first") |
| 68 | end | 71 | end |
| 69 | 72 | ||
| 73 | local inits = {} | ||
| 74 | |||
| 70 | -- Load platform-specific functions | 75 | -- Load platform-specific functions |
| 71 | local loaded_platform = nil | 76 | local loaded_platform = nil |
| 72 | for platform in cfg.each_platform() do | 77 | for platform in cfg.each_platform() do |
| 73 | local ok, fs_plat = pcall(require, "luarocks.fs."..platform) | 78 | local ok, fs_plat = pcall(require, "luarocks.fs."..platform) |
| 74 | if ok and fs_plat then | 79 | if ok and fs_plat then |
| 75 | loaded_platform = platform | 80 | loaded_platform = platform |
| 76 | load_fns(fs_plat) | 81 | load_fns(fs_plat, inits) |
| 77 | break | 82 | break |
| 78 | end | 83 | end |
| 79 | end | 84 | end |
| 80 | 85 | ||
| 81 | -- Load platform-independent pure-Lua functionality | 86 | -- Load platform-independent pure-Lua functionality |
| 82 | local fs_lua = require("luarocks.fs.lua") | 87 | local fs_lua = require("luarocks.fs.lua") |
| 83 | load_fns(fs_lua) | 88 | load_fns(fs_lua, inits) |
| 84 | 89 | ||
| 85 | -- Load platform-specific fallbacks for missing Lua modules | 90 | -- Load platform-specific fallbacks for missing Lua modules |
| 86 | local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") | 91 | local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") |
| 87 | if ok and fs_plat_tools then | 92 | if ok and fs_plat_tools then |
| 88 | load_fns(fs_plat_tools) | 93 | load_fns(fs_plat_tools, inits) |
| 89 | load_fns(require("luarocks.fs.tools")) | 94 | load_fns(require("luarocks.fs.tools")) |
| 90 | end | 95 | end |
| 96 | |||
| 97 | -- Run platform-specific initializations after everything is loaded | ||
| 98 | for _, init in ipairs(inits) do | ||
| 99 | init() | ||
| 100 | end | ||
| 91 | end | 101 | end |
| 92 | end | 102 | end |
| 93 | 103 | ||
diff --git a/src/luarocks/fs/freebsd.lua b/src/luarocks/fs/freebsd.lua new file mode 100644 index 00000000..f72faa29 --- /dev/null +++ b/src/luarocks/fs/freebsd.lua | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | --- FreeBSD implementation of filesystem and platform abstractions. | ||
| 2 | local freebsd = {} | ||
| 3 | |||
| 4 | local fs = require("luarocks.fs") | ||
| 5 | |||
| 6 | function freebsd.init() | ||
| 7 | fs.set_tool_available("zip", true) | ||
| 8 | fs.set_tool_available("unzip", true) | ||
| 9 | end | ||
| 10 | |||
| 11 | return freebsd | ||
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 22bffce0..b589654f 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -99,6 +99,13 @@ function fs.execute_env(env, command, ...) | |||
| 99 | return fs.execute_string(table.concat(envstr, "\n") .. "\n" .. quote_args(command, ...)) | 99 | return fs.execute_string(table.concat(envstr, "\n") .. "\n" .. quote_args(command, ...)) |
| 100 | end | 100 | end |
| 101 | 101 | ||
| 102 | local tool_available_cache = {} | ||
| 103 | |||
| 104 | function fs_lua.set_tool_available(tool_name, value) | ||
| 105 | assert(type(value) == "boolean") | ||
| 106 | tool_available_cache[tool_name] = value | ||
| 107 | end | ||
| 108 | |||
| 102 | --- Checks if the given tool is available. | 109 | --- Checks if the given tool is available. |
| 103 | -- The tool is executed using a flag, usually just to ask its version. | 110 | -- The tool is executed using a flag, usually just to ask its version. |
| 104 | -- @param tool_cmd string: The command to be used to check the tool's presence (e.g. hg in case of Mercurial) | 111 | -- @param tool_cmd string: The command to be used to check the tool's presence (e.g. hg in case of Mercurial) |
| @@ -111,12 +118,20 @@ function fs_lua.is_tool_available(tool_cmd, tool_name, arg) | |||
| 111 | arg = arg or "--version" | 118 | arg = arg or "--version" |
| 112 | assert(type(arg) == "string") | 119 | assert(type(arg) == "string") |
| 113 | 120 | ||
| 114 | if not fs.execute_quiet(tool_cmd, arg) then | 121 | local ok |
| 122 | if tool_available_cache[tool_name] ~= nil then | ||
| 123 | ok = tool_available_cache[tool_name] | ||
| 124 | else | ||
| 125 | ok = fs.execute_quiet(tool_cmd, arg) | ||
| 126 | tool_available_cache[tool_name] = (ok == true) | ||
| 127 | end | ||
| 128 | |||
| 129 | if ok then | ||
| 130 | return true | ||
| 131 | else | ||
| 115 | local msg = "'%s' program not found. Make sure %s is installed and is available in your PATH " .. | 132 | local msg = "'%s' program not found. Make sure %s is installed and is available in your PATH " .. |
| 116 | "(or you may want to edit the 'variables.%s' value in file '%s')" | 133 | "(or you may want to edit the 'variables.%s' value in file '%s')" |
| 117 | return nil, msg:format(tool_cmd, tool_name, tool_name:upper(), cfg.config_files.nearest) | 134 | return nil, msg:format(tool_cmd, tool_name, tool_name:upper(), cfg.config_files.nearest) |
| 118 | else | ||
| 119 | return true | ||
| 120 | end | 135 | end |
| 121 | end | 136 | end |
| 122 | 137 | ||
