aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/build.lua28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 5bb3c3f7..5ed2406a 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -23,24 +23,26 @@ or the name of a rock to be fetched from a repository.
23 23
24--- Install files to a given location. 24--- Install files to a given location.
25-- Takes a table where the array part is a list of filenames to be copied. 25-- Takes a table where the array part is a list of filenames to be copied.
26-- In the hash part, other keys are identifiers in Lua module format, 26-- In the hash part, other keys, if is_module_path is set, are identifiers
27-- to indicate which subdirectory the file should be copied to. For example, 27-- in Lua module format, to indicate which subdirectory the file should be
28-- install_files({["foo.bar"] = "src/bar.lua"}, "boo") will copy src/bar.lua 28-- copied to. For example, install_files({["foo.bar"] = "src/bar.lua"}, "boo")
29-- to boo/foo. 29-- will copy src/bar.lua to boo/foo.
30-- @param files table or nil: A table containing a list of files to copy in 30-- @param files table or nil: A table containing a list of files to copy in
31-- the format described above. If nil is passed, this function is a no-op. 31-- the format described above. If nil is passed, this function is a no-op.
32-- Directories should be delimited by forward slashes as in internet URLs. 32-- Directories should be delimited by forward slashes as in internet URLs.
33-- @param location string: The base directory files should be copied to. 33-- @param location string: The base directory files should be copied to.
34-- @param is_module_path boolean: True if string keys in files should be
35-- interpreted as dotted module paths.
34-- @return boolean or (nil, string): True if succeeded or 36-- @return boolean or (nil, string): True if succeeded or
35-- nil and an error message. 37-- nil and an error message.
36local function install_files(files, location) 38local function install_files(files, location, is_module_path)
37 assert(type(files) == "table" or not files) 39 assert(type(files) == "table" or not files)
38 assert(type(location) == "string") 40 assert(type(location) == "string")
39 if files then 41 if files then
40 for k, file in pairs(files) do 42 for k, file in pairs(files) do
41 local dest = location 43 local dest = location
42 if type(k) == "string" then 44 if type(k) == "string" then
43 dest = dir.path(location, path.module_to_path(k)) 45 dest = is_module_path and dir.path(location, path.module_to_path(k)) or k
44 end 46 end
45 fs.make_dir(dest) 47 fs.make_dir(dest)
46 local ok = fs.copy(dir.path(file), dest) 48 local ok = fs.copy(dir.path(file), dest)
@@ -143,14 +145,14 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode)
143 end 145 end
144 146
145 local dirs = { 147 local dirs = {
146 lua = path.lua_dir(name, version), 148 lua = { name = path.lua_dir(name, version), is_module_path = true },
147 lib = path.lib_dir(name, version), 149 lib = { name = path.lib_dir(name, version), is_module_path = true },
148 conf = path.conf_dir(name, version), 150 conf = { name = path.conf_dir(name, version), is_module_path = false },
149 bin = path.bin_dir(name, version), 151 bin = { name = path.bin_dir(name, version), is_module_path = false },
150 } 152 }
151 153
152 for _, d in pairs(dirs) do 154 for _, d in pairs(dirs) do
153 fs.make_dir(d) 155 fs.make_dir(d.name)
154 end 156 end
155 local rollback = util.schedule_function(function() 157 local rollback = util.schedule_function(function()
156 fs.delete(path.install_dir(name, version)) 158 fs.delete(path.install_dir(name, version))
@@ -188,7 +190,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode)
188 190
189 if build.install then 191 if build.install then
190 for id, install_dir in pairs(dirs) do 192 for id, install_dir in pairs(dirs) do
191 ok, err = install_files(build.install[id], install_dir) 193 ok, err = install_files(build.install[id], install_dir.name, install_dir.is_module_path)
192 if not ok then 194 if not ok then
193 return nil, err 195 return nil, err
194 end 196 end
@@ -206,7 +208,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode)
206 end 208 end
207 209
208 for _, d in pairs(dirs) do 210 for _, d in pairs(dirs) do
209 fs.remove_dir_if_empty(d) 211 fs.remove_dir_if_empty(d.name)
210 end 212 end
211 213
212 fs.pop_dir() 214 fs.pop_dir()