aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2011-08-14 14:50:10 -0300
committerHisham Muhammad <hisham@gobolinux.org>2011-08-14 14:50:10 -0300
commit4724492df402089b0529c3ef7cb4fd240cbb5ed0 (patch)
tree156108d0960653cc06cc1b7a5683c2e56072b66a
parent09636127a571086e6e864f0bb9b162cbdd7c8a51 (diff)
downloadluarocks-4724492df402089b0529c3ef7cb4fd240cbb5ed0.tar.gz
luarocks-4724492df402089b0529c3ef7cb4fd240cbb5ed0.tar.bz2
luarocks-4724492df402089b0529c3ef7cb4fd240cbb5ed0.zip
Abstract all external commands so they can be overriden via config.lua
-rw-r--r--src/luarocks/add.lua6
-rw-r--r--src/luarocks/cache.lua4
-rw-r--r--src/luarocks/cfg.lua50
-rw-r--r--src/luarocks/fetch/cvs.lua2
-rw-r--r--src/luarocks/fetch/git.lua5
-rw-r--r--src/luarocks/fetch/sscm.lua5
-rw-r--r--src/luarocks/fetch/svn.lua3
-rw-r--r--src/luarocks/fs/unix/tools.lua73
-rw-r--r--src/luarocks/fs/win32/tools.lua57
9 files changed, 121 insertions, 84 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua
index 92b5ac4b..6edfea35 100644
--- a/src/luarocks/add.lua
+++ b/src/luarocks/add.lua
@@ -81,12 +81,12 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server)
81 local cmd 81 local cmd
82 if protocol == "rsync" then 82 if protocol == "rsync" then
83 local srv, path = server_path:match("([^/]+)(/.+)") 83 local srv, path = server_path:match("([^/]+)(/.+)")
84 cmd = "rsync --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" 84 cmd = cfg.variables.RSYNC.." --exclude=.git -Oavz -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/"
85 elseif upload_server and upload_server.sftp then 85 elseif upload_server and upload_server.sftp then
86 local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") 86 local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$")
87 cmd = "scp manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 87 cmd = cfg.variables.SCP.." manifest index.html "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2
88 else 88 else
89 cmd = "curl "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url 89 cmd = cfg.variables.CURL.." "..login_info.." -T '{manifest,index.html,"..table.concat(files, ",").."}' "..login_url
90 end 90 end
91 91
92 util.printout(cmd) 92 util.printout(cmd)
diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua
index 692d3346..21185c10 100644
--- a/src/luarocks/cache.lua
+++ b/src/luarocks/cache.lua
@@ -71,12 +71,12 @@ function refresh_local_cache(server, url, user, password)
71 local ok = false 71 local ok = false
72 if protocol == "rsync" then 72 if protocol == "rsync" then
73 local srv, path = server_path:match("([^/]+)(/.+)") 73 local srv, path = server_path:match("([^/]+)(/.+)")
74 ok = fs.execute("rsync -avz -e ssh "..user.."@"..srv..":"..path.."/ "..local_cache.."/") 74 ok = fs.execute(cfg.variables.RSYNC.." -avz -e ssh "..user.."@"..srv..":"..path.."/ "..local_cache.."/")
75 else 75 else
76 local login_info = "" 76 local login_info = ""
77 if user then login_info = " --user="..user end 77 if user then login_info = " --user="..user end
78 if password then login_info = login_info .. " --password="..password end 78 if password then login_info = login_info .. " --password="..password end
79 ok = fs.execute("wget --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info) 79 ok = fs.execute(cfg.variables.WGET.." --no-cache -q -m -np -nd "..protocol.."://"..server_path..login_info)
80 end 80 end
81 if not ok then 81 if not ok then
82 return nil, "Failed downloading cache." 82 return nil, "Failed downloading cache."
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index ace0dbf1..1abe39cb 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -145,7 +145,47 @@ local defaults = {
145 downloader = config.LUAROCKS_DOWNLOADER or "wget", 145 downloader = config.LUAROCKS_DOWNLOADER or "wget",
146 md5checker = config.LUAROCKS_MD5CHECKER or "md5sum", 146 md5checker = config.LUAROCKS_MD5CHECKER or "md5sum",
147 147
148 variables = {}, 148 variables = {
149 MAKE = "make",
150 CC = "cc",
151 LD = "ld",
152
153 CVS = "cvs",
154 GIT = "git",
155 SSCM = "sscm",
156 SVN = "svn",
157
158 RSYNC = "rsync",
159 WGET = "wget",
160 SCP = "scp",
161 CURL = "curl",
162
163 PWD = "pwd",
164 MKDIR = "mkdir",
165 RMDIR = "rmdir",
166 CP = "cp",
167 LS = "ls",
168 RM = "rm",
169 FIND = "find",
170 TEST = "test",
171 CHMOD = "chmod",
172 PATCH = "patch",
173
174 ZIP = "zip",
175 UNZIP = "unzip",
176 GUNZIP = "gunzip",
177 BUNZIP2 = "bunzip2",
178 TAR = "tar",
179
180 MD5SUM = "md5sum",
181 OPENSSL = "openssl",
182 MD5 = "md5",
183 STAT = "stat",
184
185 SEVENZ = "7z",
186
187 STATFLAG = "-c '%a'",
188 },
149 189
150 external_deps_subdirs = { 190 external_deps_subdirs = {
151 bin = "bin", 191 bin = "bin",
@@ -241,9 +281,6 @@ if detected.unix then
241 defaults.variables.CFLAGS = "-O2" 281 defaults.variables.CFLAGS = "-O2"
242 defaults.cmake_generator = "Unix Makefiles" 282 defaults.cmake_generator = "Unix Makefiles"
243 defaults.platforms = { "unix" } 283 defaults.platforms = { "unix" }
244 defaults.variables.MAKE = "make"
245 defaults.variables.CC = "cc"
246 defaults.variables.LD = "ld"
247 defaults.variables.LIBFLAG = "-shared" 284 defaults.variables.LIBFLAG = "-shared"
248 defaults.external_deps_patterns = { 285 defaults.external_deps_patterns = {
249 bin = { "?" }, 286 bin = { "?" },
@@ -282,6 +319,10 @@ if detected.macosx then
282 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" 319 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load"
283end 320end
284 321
322if detected.bsd then
323 defaults.variables.STATFLAG = "-f '%A'"
324end
325
285if detected.linux then 326if detected.linux then
286 defaults.arch = "linux-"..proc 327 defaults.arch = "linux-"..proc
287 defaults.platforms = {"unix", "linux"} 328 defaults.platforms = {"unix", "linux"}
@@ -302,6 +343,7 @@ end
302if detected.openbsd then 343if detected.openbsd then
303 defaults.arch = "openbsd-"..proc 344 defaults.arch = "openbsd-"..proc
304 defaults.platforms = {"unix", "bsd", "openbsd"} 345 defaults.platforms = {"unix", "bsd", "openbsd"}
346 defaults.variables.STATFLAG = "-f '%Op'"
305end 347end
306 348
307-- Expose some more values detected by LuaRocks for use by rockspec authors. 349-- Expose some more values detected by LuaRocks for use by rockspec authors.
diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua
index c2957c09..a622cdcb 100644
--- a/src/luarocks/fetch/cvs.lua
+++ b/src/luarocks/fetch/cvs.lua
@@ -19,7 +19,7 @@ function get_sources(rockspec, extract, dest_dir)
19 19
20 local name_version = rockspec.name .. "-" .. rockspec.version 20 local name_version = rockspec.name .. "-" .. rockspec.version
21 local module = rockspec.source.module or dir.base_name(rockspec.source.url) 21 local module = rockspec.source.module or dir.base_name(rockspec.source.url)
22 local command = {"cvs", "-d"..rockspec.source.pathname, "export", module} 22 local command = {rockspec.variables.CVS, "-d"..rockspec.source.pathname, "export", module}
23 if rockspec.source.tag then 23 if rockspec.source.tag then
24 table.insert(command, 4, "-r") 24 table.insert(command, 4, "-r")
25 table.insert(command, 5, rockspec.source.tag) 25 table.insert(command, 5, rockspec.source.tag)
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index a3b763d6..7db74c26 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -17,15 +17,16 @@ function get_sources(rockspec, extract, dest_dir)
17 assert(type(rockspec) == "table") 17 assert(type(rockspec) == "table")
18 assert(type(dest_dir) == "string" or not dest_dir) 18 assert(type(dest_dir) == "string" or not dest_dir)
19 19
20 local git_cmd = rockspec.variables.GIT
20 local name_version = rockspec.name .. "-" .. rockspec.version 21 local name_version = rockspec.name .. "-" .. rockspec.version
21 local module = dir.base_name(rockspec.source.url) 22 local module = dir.base_name(rockspec.source.url)
22 -- Strip off .git from base name if present 23 -- Strip off .git from base name if present
23 module = module:gsub("%.git$", "") 24 module = module:gsub("%.git$", "")
24 local command = {"git", "clone", "--depth=1", rockspec.source.url, module} 25 local command = {git_cmd, "clone", "--depth=1", rockspec.source.url, module}
25 local checkout_command 26 local checkout_command
26 local tag_or_branch = rockspec.source.tag or rockspec.source.branch 27 local tag_or_branch = rockspec.source.tag or rockspec.source.branch
27 if tag_or_branch then 28 if tag_or_branch then
28 checkout_command = {"git", "checkout", tag_or_branch} 29 checkout_command = {git_cmd, "checkout", tag_or_branch}
29 end 30 end
30 local store_dir 31 local store_dir
31 if not dest_dir then 32 if not dest_dir then
diff --git a/src/luarocks/fetch/sscm.lua b/src/luarocks/fetch/sscm.lua
index 539014c2..e52e8019 100644
--- a/src/luarocks/fetch/sscm.lua
+++ b/src/luarocks/fetch/sscm.lua
@@ -16,6 +16,7 @@ function get_sources(rockspec, extract, dest_dir)
16 assert(type(rockspec) == "table") 16 assert(type(rockspec) == "table")
17 assert(type(dest_dir) == "string" or not dest_dir) 17 assert(type(dest_dir) == "string" or not dest_dir)
18 18
19 local sscm_cmd = rockspec.variables.SSCM
19 local module = rockspec.source.module or dir.base_name(rockspec.source.url) 20 local module = rockspec.source.module or dir.base_name(rockspec.source.url)
20 local branch, repository = string.match(rockspec.source.pathname, "^([^/]*)/(.*)") 21 local branch, repository = string.match(rockspec.source.pathname, "^([^/]*)/(.*)")
21 if not branch or not repository then 22 if not branch or not repository then
@@ -23,7 +24,7 @@ function get_sources(rockspec, extract, dest_dir)
23 end 24 end
24 -- Search for working directory. 25 -- Search for working directory.
25 local working_dir 26 local working_dir
26 local tmp = io.popen(string.format([[sscm property "/" -d -b%s -p%s]], branch, repository)) 27 local tmp = io.popen(string.format(sscm_cmd..[[ property "/" -d -b%s -p%s]], branch, repository))
27 for line in tmp:lines() do 28 for line in tmp:lines() do
28 --%c because a chr(13) comes in the end. 29 --%c because a chr(13) comes in the end.
29 working_dir = string.match(line, "Working directory:[%s]*(.*)%c$") 30 working_dir = string.match(line, "Working directory:[%s]*(.*)%c$")
@@ -33,7 +34,7 @@ function get_sources(rockspec, extract, dest_dir)
33 if not working_dir then 34 if not working_dir then
34 return nil, "Error retrieving working directory from SSCM." 35 return nil, "Error retrieving working directory from SSCM."
35 end 36 end
36 if not fs.execute([["sscm"]], "get", "*", "-e" , "-r", "-b"..branch, "-p"..repository, "-tmodify", "-wreplace") then 37 if not fs.execute(sscm_cmd, "get", "*", "-e" , "-r", "-b"..branch, "-p"..repository, "-tmodify", "-wreplace") then
37 return nil, "Failed fetching files from SSCM." 38 return nil, "Failed fetching files from SSCM."
38 end 39 end
39 -- FIXME: This function does not honor the dest_dir parameter. 40 -- FIXME: This function does not honor the dest_dir parameter.
diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua
index 01ea6ba9..9d00ce5b 100644
--- a/src/luarocks/fetch/svn.lua
+++ b/src/luarocks/fetch/svn.lua
@@ -17,10 +17,11 @@ function get_sources(rockspec, extract, dest_dir)
17 assert(type(rockspec) == "table") 17 assert(type(rockspec) == "table")
18 assert(type(dest_dir) == "string" or not dest_dir) 18 assert(type(dest_dir) == "string" or not dest_dir)
19 19
20 local svn_cmd = rockspec.variables.SVN
20 local name_version = rockspec.name .. "-" .. rockspec.version 21 local name_version = rockspec.name .. "-" .. rockspec.version
21 local module = rockspec.source.module or dir.base_name(rockspec.source.url) 22 local module = rockspec.source.module or dir.base_name(rockspec.source.url)
22 local url = rockspec.source.url:gsub("^svn://", "") 23 local url = rockspec.source.url:gsub("^svn://", "")
23 local command = {"svn", "checkout", url, module} 24 local command = {svn_cmd, "checkout", url, module}
24 if rockspec.source.tag then 25 if rockspec.source.tag then
25 table.insert(command, 5, "-r") 26 table.insert(command, 5, "-r")
26 table.insert(command, 6, rockspec.source.tag) 27 table.insert(command, 6, rockspec.source.tag)
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 9cd4ca1c..d1722f4b 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -8,6 +8,8 @@ local cfg = require("luarocks.cfg")
8 8
9local dir_stack = {} 9local dir_stack = {}
10 10
11local vars = cfg.variables
12
11--- Run the given command. 13--- Run the given command.
12-- The command is executed in the current directory in the dir stack. 14-- The command is executed in the current directory in the dir stack.
13-- @param cmd string: No quoting/escaping is applied to the command. 15-- @param cmd string: No quoting/escaping is applied to the command.
@@ -26,7 +28,7 @@ end
26-- Uses the module's internal dir stack. 28-- Uses the module's internal dir stack.
27-- @return string: the absolute pathname of the current directory. 29-- @return string: the absolute pathname of the current directory.
28function current_dir() 30function current_dir()
29 local pipe = io.popen("pwd") 31 local pipe = io.popen(vars.PWD)
30 local current = pipe:read("*l") 32 local current = pipe:read("*l")
31 pipe:close() 33 pipe:close()
32 for _, d in ipairs(dir_stack) do 34 for _, d in ipairs(dir_stack) do
@@ -65,7 +67,7 @@ end
65-- @return boolean: true on success, false on failure. 67-- @return boolean: true on success, false on failure.
66function make_dir(d) 68function make_dir(d)
67 assert(d) 69 assert(d)
68 return fs.execute("mkdir -p", d) 70 return fs.execute(vars.MKDIR.." -p", d)
69end 71end
70 72
71--- Remove a directory if it is empty. 73--- Remove a directory if it is empty.
@@ -74,7 +76,7 @@ end
74-- @param dir string: pathname of directory to remove. 76-- @param dir string: pathname of directory to remove.
75function remove_dir_if_empty(d) 77function remove_dir_if_empty(d)
76 assert(d) 78 assert(d)
77 fs.execute_string("rmdir "..fs.Q(d).." 1> /dev/null 2> /dev/null") 79 fs.execute_string(vars.RMDIR.." "..fs.Q(d).." 1> /dev/null 2> /dev/null")
78end 80end
79 81
80--- Remove a directory if it is empty. 82--- Remove a directory if it is empty.
@@ -83,7 +85,7 @@ end
83-- @param dir string: pathname of directory to remove. 85-- @param dir string: pathname of directory to remove.
84function remove_dir_tree_if_empty(d) 86function remove_dir_tree_if_empty(d)
85 assert(d) 87 assert(d)
86 fs.execute_string("rmdir -p "..fs.Q(d).." 1> /dev/null 2> /dev/null") 88 fs.execute_string(vars.RMDIR.." -p "..fs.Q(d).." 1> /dev/null 2> /dev/null")
87end 89end
88 90
89--- Copy a file. 91--- Copy a file.
@@ -93,7 +95,7 @@ end
93-- plus an error message. 95-- plus an error message.
94function copy(src, dest) 96function copy(src, dest)
95 assert(src and dest) 97 assert(src and dest)
96 if fs.execute("cp", src, dest) then 98 if fs.execute(vars.CP, src, dest) then
97 return true 99 return true
98 else 100 else
99 return false, "Failed copying "..src.." to "..dest 101 return false, "Failed copying "..src.." to "..dest
@@ -107,7 +109,7 @@ end
107-- plus an error message. 109-- plus an error message.
108function copy_contents(src, dest) 110function copy_contents(src, dest)
109 assert(src and dest) 111 assert(src and dest)
110 if fs.execute_string("cp -pPR "..fs.Q(src).."/* "..fs.Q(dest).." 1> /dev/null 2>/dev/null") then 112 if fs.execute_string(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest).." 1> /dev/null 2>/dev/null") then
111 return true 113 return true
112 else 114 else
113 return false, "Failed copying "..src.." to "..dest 115 return false, "Failed copying "..src.." to "..dest
@@ -120,7 +122,7 @@ end
120function delete(arg) 122function delete(arg)
121 assert(arg) 123 assert(arg)
122 assert(arg:sub(1,1) == "/") 124 assert(arg:sub(1,1) == "/")
123 return fs.execute_string("rm -rf " .. fs.Q(arg) .. " 1> /dev/null 2>/dev/null") 125 return fs.execute_string(vars.RM.." -rf " .. fs.Q(arg) .. " 1> /dev/null 2>/dev/null")
124end 126end
125 127
126--- List the contents of a directory. 128--- List the contents of a directory.
@@ -137,7 +139,7 @@ function list_dir(at)
137 return {} 139 return {}
138 end 140 end
139 local result = {} 141 local result = {}
140 local pipe = io.popen("cd "..fs.Q(at).." && ls") 142 local pipe = io.popen("cd "..fs.Q(at).." && "..vars.LS)
141 for file in pipe:lines() do 143 for file in pipe:lines() do
142 table.insert(result, file) 144 table.insert(result, file)
143 end 145 end
@@ -159,7 +161,7 @@ function find(at)
159 return {} 161 return {}
160 end 162 end
161 local result = {} 163 local result = {}
162 local pipe = io.popen("cd "..fs.Q(at).." && find * 2>/dev/null") 164 local pipe = io.popen("cd "..fs.Q(at).." && "..vars.FIND.." * 2>/dev/null")
163 for file in pipe:lines() do 165 for file in pipe:lines() do
164 table.insert(result, file) 166 table.insert(result, file)
165 end 167 end
@@ -173,7 +175,7 @@ end
173-- additional arguments. 175-- additional arguments.
174-- @return boolean: true on success, false on failure. 176-- @return boolean: true on success, false on failure.
175function zip(zipfile, ...) 177function zip(zipfile, ...)
176 return fs.execute("zip -r", zipfile, ...) 178 return fs.execute(vars.ZIP.." -r", zipfile, ...)
177end 179end
178 180
179--- Uncompress files from a .zip archive. 181--- Uncompress files from a .zip archive.
@@ -181,7 +183,7 @@ end
181-- @return boolean: true on success, false on failure. 183-- @return boolean: true on success, false on failure.
182function unzip(zipfile) 184function unzip(zipfile)
183 assert(zipfile) 185 assert(zipfile)
184 return fs.execute("unzip", zipfile) 186 return fs.execute(vars.UNZIP, zipfile)
185end 187end
186 188
187--- Test for existance of a file. 189--- Test for existance of a file.
@@ -189,7 +191,7 @@ end
189-- @return boolean: true if file exists, false otherwise. 191-- @return boolean: true if file exists, false otherwise.
190function exists(file) 192function exists(file)
191 assert(file) 193 assert(file)
192 return fs.execute("test -r", file) 194 return fs.execute(vars.TEST, "-r", file)
193end 195end
194 196
195--- Test is file/dir is writable. 197--- Test is file/dir is writable.
@@ -197,7 +199,7 @@ end
197-- @return boolean: true if file exists, false otherwise. 199-- @return boolean: true if file exists, false otherwise.
198function is_writable(file) 200function is_writable(file)
199 assert(file) 201 assert(file)
200 return fs.execute("test -w", file) 202 return fs.execute(vars.TEST, "-w", file)
201end 203end
202 204
203--- Test is pathname is a directory. 205--- Test is pathname is a directory.
@@ -205,7 +207,7 @@ end
205-- @return boolean: true if it is a directory, false otherwise. 207-- @return boolean: true if it is a directory, false otherwise.
206function is_dir(file) 208function is_dir(file)
207 assert(file) 209 assert(file)
208 return fs.execute("test -d", file) 210 return fs.execute(vars.TEST, "-d", file)
209end 211end
210 212
211--- Test is pathname is a regular file. 213--- Test is pathname is a regular file.
@@ -213,7 +215,7 @@ end
213-- @return boolean: true if it is a regular file, false otherwise. 215-- @return boolean: true if it is a regular file, false otherwise.
214function is_file(file) 216function is_file(file)
215 assert(file) 217 assert(file)
216 return fs.execute("test -f", file) 218 return fs.execute(vars.TEST, "-f", file)
217end 219end
218 220
219--- Download a remote file. 221--- Download a remote file.
@@ -228,7 +230,7 @@ function download(url, filename)
228 assert(type(filename) == "string" or not filename) 230 assert(type(filename) == "string" or not filename)
229 231
230 if cfg.downloader == "wget" then 232 if cfg.downloader == "wget" then
231 local wget_cmd = "wget --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue " 233 local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue "
232 if filename then 234 if filename then
233 return fs.execute(wget_cmd.." --output-document ", filename, url) 235 return fs.execute(wget_cmd.." --output-document ", filename, url)
234 else 236 else
@@ -236,13 +238,13 @@ function download(url, filename)
236 end 238 end
237 elseif cfg.downloader == "curl" then 239 elseif cfg.downloader == "curl" then
238 filename = filename or dir.base_name(url) 240 filename = filename or dir.base_name(url)
239 return fs.execute_string("curl -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename)) 241 return fs.execute_string(vars.CURL.." -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> /dev/null 1> "..fs.Q(filename))
240 end 242 end
241end 243end
242 244
243function chmod(pathname, mode) 245function chmod(pathname, mode)
244 if mode then 246 if mode then
245 return fs.execute("chmod "..mode, pathname) 247 return fs.execute(vars.CHMOD, mode, pathname)
246 else 248 else
247 return false 249 return false
248 end 250 end
@@ -251,7 +253,7 @@ end
251--- Apply a patch. 253--- Apply a patch.
252-- @param patchname string: The filename of the patch. 254-- @param patchname string: The filename of the patch.
253function apply_patch(patchname) 255function apply_patch(patchname)
254 return fs.execute("patch -p1 -f -i ", patchname) 256 return fs.execute(vars.PATCH.." -p1 -f -i ", patchname)
255end 257end
256 258
257--- Unpack an archive. 259--- Unpack an archive.
@@ -265,12 +267,12 @@ function unpack_archive(archive)
265 local ok 267 local ok
266 if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then 268 if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then
267 -- ok = fs.execute("tar zxvpf ", archive) 269 -- ok = fs.execute("tar zxvpf ", archive)
268 ok = fs.execute_string("gunzip -c "..archive.."|tar -xf -") 270 ok = fs.execute_string(vars.GUNZIP.." -c "..archive.."|"..vars.TAR.." -xf -")
269 elseif archive:match("%.tar%.bz2$") then 271 elseif archive:match("%.tar%.bz2$") then
270 -- ok = fs.execute("tar jxvpf ", archive) 272 -- ok = fs.execute("tar jxvpf ", archive)
271 ok = fs.execute_string("bunzip2 -c "..archive.."|tar -xf -") 273 ok = fs.execute_string(vars.BUNZIP2.." -c "..archive.."|tar -xf -")
272 elseif archive:match("%.zip$") then 274 elseif archive:match("%.zip$") then
273 ok = fs.execute("unzip ", archive) 275 ok = fs.execute(vars.UNZIP, archive)
274 elseif archive:match("%.lua$") or archive:match("%.c$") then 276 elseif archive:match("%.lua$") or archive:match("%.c$") then
275 -- Ignore .lua and .c files; they don't need to be extracted. 277 -- Ignore .lua and .c files; they don't need to be extracted.
276 return true 278 return true
@@ -285,18 +287,18 @@ function unpack_archive(archive)
285end 287end
286 288
287local md5_cmd = { 289local md5_cmd = {
288 md5sum = "md5sum ", 290 md5sum = vars.MD5SUM,
289 openssl = "openssl md5 ", 291 openssl = vars.OPENSSL.." md5",
290 md5 = "md5 ", 292 md5 = vars.MD5,
291} 293}
292 294
293--- Get the MD5 checksum for a file. 295--- Get the MD5 checksum for a file.
294-- @param file string: The file to be computed. 296-- @param file string: The file to be computed.
295-- @return string: The MD5 checksum 297-- @return string: The MD5 checksum
296function get_md5(file) 298function get_md5(file)
297 local cmd = md5_cmd[cfg.md5checker] 299 local cmd = md5_cmd[cfg.md5checker]
298 if not cmd then return nil end 300 if not cmd then return nil end
299 local pipe = io.popen(cmd..fs.absolute_name(file)) 301 local pipe = io.popen(cmd.." "..fs.absolute_name(file))
300 local computed = pipe:read("*a") 302 local computed = pipe:read("*a")
301 pipe:close() 303 pipe:close()
302 if not computed then return nil end 304 if not computed then return nil end
@@ -304,21 +306,8 @@ function get_md5(file)
304end 306end
305 307
306function get_permissions(filename) 308function get_permissions(filename)
307 local ret 309 local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename))
308 310 local ret = pipe:read("*l")
309 local flag
310 if cfg.is_platform("bsd") then
311 if cfg.is_platform("openbsd") then
312 flag = "-f '%Op'"
313 else
314 flag = "-f '%A'"
315 end
316 else
317 flag = "-c '%a'"
318 end
319
320 local pipe = io.popen("stat "..flag.." "..fs.Q(filename))
321 ret = pipe:read("*l")
322 pipe:close() 311 pipe:close()
323 return ret 312 return ret
324end 313end
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index a3b7cdd0..5b7634cf 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -10,6 +10,8 @@ local dir = require("luarocks.dir")
10 10
11local dir_stack = {} 11local dir_stack = {}
12 12
13local vars = cfg.variables
14
13--- Strip the last extension of a filename. 15--- Strip the last extension of a filename.
14-- Example: "foo.tar.gz" becomes "foo.tar". 16-- Example: "foo.tar.gz" becomes "foo.tar".
15-- If filename has no dots, returns it unchanged. 17-- If filename has no dots, returns it unchanged.
@@ -43,7 +45,7 @@ end
43-- Uses the module's internal dir stack. 45-- Uses the module's internal dir stack.
44-- @return string: the absolute pathname of the current directory. 46-- @return string: the absolute pathname of the current directory.
45function current_dir() 47function current_dir()
46 local pipe = io.popen("pwd") 48 local pipe = io.popen(vars.PWD)
47 local current = pipe:read("*l") 49 local current = pipe:read("*l")
48 pipe:close() 50 pipe:close()
49 for _, d in ipairs(dir_stack) do 51 for _, d in ipairs(dir_stack) do
@@ -57,22 +59,22 @@ end
57-- @return boolean: true if it is a regular file, false otherwise. 59-- @return boolean: true if it is a regular file, false otherwise.
58function is_file(file) 60function is_file(file)
59 assert(file) 61 assert(file)
60 return fs.execute("test -f", file) 62 return fs.execute(vars.TEST.." -f", file)
61end 63end
62 64
63local md5_cmd = { 65local md5_cmd = {
64 md5sum = "md5sum ", 66 md5sum = vars.MD5SUM,
65 openssl = "openssl md5 ", 67 openssl = vars.OPENSSL.." md5",
66 md5 = "md5 ", 68 md5 = vars.MD5,
67} 69}
68 70
69--- Get the MD5 checksum for a file. 71--- Get the MD5 checksum for a file.
70-- @param file string: The file to be computed. 72-- @param file string: The file to be computed.
71-- @return string: The MD5 checksum 73-- @return string: The MD5 checksum
72function get_md5(file) 74function get_md5(file)
73 local cmd = md5_cmd[cfg.md5checker] 75 local cmd = md5_cmd[cfg.md5checker]
74 if not cmd then return nil end 76 if not cmd then return nil end
75 local pipe = io.popen(cmd..fs.absolute_name(file)) 77 local pipe = io.popen(cmd.." "..fs.absolute_name(file))
76 local computed = pipe:read("*a") 78 local computed = pipe:read("*a")
77 pipe:close() 79 pipe:close()
78 if not computed then return nil end 80 if not computed then return nil end
@@ -120,7 +122,7 @@ end
120-- @return boolean: true if it is a regular file, false otherwise. 122-- @return boolean: true if it is a regular file, false otherwise.
121function is_dir(file) 123function is_dir(file)
122 assert(file) 124 assert(file)
123 return fs.execute("test -d " .. fs.Q(file) .. " 2>NUL 1>NUL") 125 return fs.execute(vars.TEST.." -d " .. fs.Q(file) .. " 2>NUL 1>NUL")
124end 126end
125 127
126--- Create a directory if it does not already exist. 128--- Create a directory if it does not already exist.
@@ -130,7 +132,7 @@ end
130-- @return boolean: true on success, false on failure. 132-- @return boolean: true on success, false on failure.
131function make_dir(d) 133function make_dir(d)
132 assert(d) 134 assert(d)
133 fs.execute("mkdir "..fs.Q(d).." 1> NUL 2> NUL") 135 fs.execute(vars.MKDIR.." "..fs.Q(d).." 1> NUL 2> NUL")
134 return 1 136 return 1
135end 137end
136 138
@@ -140,7 +142,7 @@ end
140-- @param d string: pathname of directory to remove. 142-- @param d string: pathname of directory to remove.
141function remove_dir_if_empty(d) 143function remove_dir_if_empty(d)
142 assert(d) 144 assert(d)
143 fs.execute_string("rmdir "..fs.Q(d).." 1> NUL 2> NUL") 145 fs.execute_string(vars.RMDIR.." "..fs.Q(d).." 1> NUL 2> NUL")
144end 146end
145 147
146--- Remove a directory if it is empty. 148--- Remove a directory if it is empty.
@@ -149,7 +151,7 @@ end
149-- @param dir string: pathname of directory to remove. 151-- @param dir string: pathname of directory to remove.
150function remove_dir_tree_if_empty(d) 152function remove_dir_tree_if_empty(d)
151 assert(d) 153 assert(d)
152 fs.execute_string("rmdir "..fs.Q(d).." 1> NUL 2> NUL") 154 fs.execute_string(vars.RMDIR.." "..fs.Q(d).." 1> NUL 2> NUL")
153end 155end
154 156
155--- Copy a file. 157--- Copy a file.
@@ -160,7 +162,7 @@ end
160function copy(src, dest) 162function copy(src, dest)
161 assert(src and dest) 163 assert(src and dest)
162 if dest:match("[/\\]$") then dest = dest:sub(1, -2) end 164 if dest:match("[/\\]$") then dest = dest:sub(1, -2) end
163 if fs.execute("cp", src, dest) then 165 if fs.execute(vars.CP, src, dest) then
164 return true 166 return true
165 else 167 else
166 return false, "Failed copying "..src.." to "..dest 168 return false, "Failed copying "..src.." to "..dest
@@ -174,7 +176,7 @@ end
174-- plus an error message. 176-- plus an error message.
175function copy_contents(src, dest) 177function copy_contents(src, dest)
176 assert(src and dest) 178 assert(src and dest)
177 if fs.execute_string("cp -a "..src.."\\*.* "..fs.Q(dest).." 1> NUL 2> NUL") then 179 if fs.execute_string(vars.CP.." -a "..src.."\\*.* "..fs.Q(dest).." 1> NUL 2> NUL") then
178 return true 180 return true
179 else 181 else
180 return false, "Failed copying "..src.." to "..dest 182 return false, "Failed copying "..src.." to "..dest
@@ -188,8 +190,8 @@ end
188function delete(arg) 190function delete(arg)
189 assert(arg) 191 assert(arg)
190 assert(arg:match("^[\a-zA-Z]?:?[\\/]")) 192 assert(arg:match("^[\a-zA-Z]?:?[\\/]"))
191 fs.execute("chmod a+rw -R ", arg) 193 fs.execute(vars.CHMOD.." a+rw -R ", arg)
192 return fs.execute_string("rm -rf " .. fs.Q(arg) .. " 1> NUL 2> NUL") 194 return fs.execute_string(vars.RM.." -rf " .. fs.Q(arg) .. " 1> NUL 2> NUL")
193end 195end
194 196
195--- List the contents of a directory. 197--- List the contents of a directory.
@@ -206,7 +208,7 @@ function list_dir(at)
206 return {} 208 return {}
207 end 209 end
208 local result = {} 210 local result = {}
209 local pipe = io.popen(command_at(at, "ls")) 211 local pipe = io.popen(command_at(at, vars.LS))
210 for file in pipe:lines() do 212 for file in pipe:lines() do
211 table.insert(result, file) 213 table.insert(result, file)
212 end 214 end
@@ -229,7 +231,7 @@ function find(at)
229 return {} 231 return {}
230 end 232 end
231 local result = {} 233 local result = {}
232 local pipe = io.popen(command_at(at, "find 2> NUL")) 234 local pipe = io.popen(command_at(at, vars.FIND.." 2> NUL"))
233 for file in pipe:lines() do 235 for file in pipe:lines() do
234 -- Windows find is a bit different 236 -- Windows find is a bit different
235 local first_two = file:sub(1,2) 237 local first_two = file:sub(1,2)
@@ -253,7 +255,7 @@ function download(url, filename)
253 assert(type(filename) == "string" or not filename) 255 assert(type(filename) == "string" or not filename)
254 256
255 if cfg.downloader == "wget" then 257 if cfg.downloader == "wget" then
256 local wget_cmd = "wget --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue " 258 local wget_cmd = vars.WGET.." --no-check-certificate --no-cache --user-agent="..cfg.user_agent.." --quiet --continue "
257 if filename then 259 if filename then
258 return fs.execute(wget_cmd.." --output-document ", filename, url) 260 return fs.execute(wget_cmd.." --output-document ", filename, url)
259 else 261 else
@@ -261,7 +263,7 @@ function download(url, filename)
261 end 263 end
262 elseif cfg.downloader == "curl" then 264 elseif cfg.downloader == "curl" then
263 filename = filename or dir.base_name(url) 265 filename = filename or dir.base_name(url)
264 return fs.execute_string("curl -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename)) 266 return fs.execute_string(vars.CURL.." -L --user-agent "..cfg.user_agent.." "..fs.Q(url).." 2> NUL 1> "..fs.Q(filename))
265 end 267 end
266end 268end
267 269
@@ -272,7 +274,7 @@ end
272-- additional arguments. 274-- additional arguments.
273-- @return boolean: true on success, false on failure. 275-- @return boolean: true on success, false on failure.
274function zip(zipfile, ...) 276function zip(zipfile, ...)
275 return fs.execute("7z a -tzip", zipfile, ...) 277 return fs.execute(vars.SEVENZ.." a -tzip", zipfile, ...)
276end 278end
277 279
278--- Uncompress files from a .zip archive. 280--- Uncompress files from a .zip archive.
@@ -280,14 +282,14 @@ end
280-- @return boolean: true on success, false on failure. 282-- @return boolean: true on success, false on failure.
281function unzip(zipfile) 283function unzip(zipfile)
282 assert(zipfile) 284 assert(zipfile)
283 return fs.execute("7z x", zipfile) 285 return fs.execute(vars.SEVENZ.." x", zipfile)
284end 286end
285 287
286--- Uncompress gzip file. 288--- Uncompress gzip file.
287-- @param archive string: Filename of archive. 289-- @param archive string: Filename of archive.
288-- @return boolean : success status 290-- @return boolean : success status
289local function gunzip(archive) 291local function gunzip(archive)
290 return fs.execute("7z x", archive) 292 return fs.execute(vars.SEVENZ.." x", archive)
291end 293end
292 294
293--- Unpack an archive. 295--- Unpack an archive.
@@ -299,23 +301,24 @@ function unpack_archive(archive)
299 assert(type(archive) == "string") 301 assert(type(archive) == "string")
300 302
301 local ok 303 local ok
304 local sevenzx = vars.SEVENZ.." x"
302 if archive:match("%.tar%.gz$") then 305 if archive:match("%.tar%.gz$") then
303 ok = gunzip(archive) 306 ok = gunzip(archive)
304 if ok then 307 if ok then
305 ok = fs.execute("7z x", strip_extension(archive)) 308 ok = fs.execute(sevenzx, strip_extension(archive))
306 end 309 end
307 elseif archive:match("%.tgz$") then 310 elseif archive:match("%.tgz$") then
308 ok = gunzip(archive) 311 ok = gunzip(archive)
309 if ok then 312 if ok then
310 ok = fs.execute("7z x ", strip_extension(archive)..".tar") 313 ok = fs.execute(sevenzx, strip_extension(archive)..".tar")
311 end 314 end
312 elseif archive:match("%.tar%.bz2$") then 315 elseif archive:match("%.tar%.bz2$") then
313 ok = fs.execute("7z x ", archive) 316 ok = fs.execute(sevenzx, archive)
314 if ok then 317 if ok then
315 ok = fs.execute("7z x ", strip_extension(archive)) 318 ok = fs.execute(sevenzx, strip_extension(archive))
316 end 319 end
317 elseif archive:match("%.zip$") then 320 elseif archive:match("%.zip$") then
318 ok = fs.execute("7z x ", archive) 321 ok = fs.execute(sevenzx, archive)
319 elseif archive:match("%.lua$") or archive:match("%.c$") then 322 elseif archive:match("%.lua$") or archive:match("%.c$") then
320 -- Ignore .lua and .c files; they don't need to be extracted. 323 -- Ignore .lua and .c files; they don't need to be extracted.
321 return true 324 return true