aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/cmd.lua59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index ff6abf3d..4397d43b 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -151,6 +151,18 @@ local function check_popen()
151 end 151 end
152end 152end
153 153
154local function find_project_dir()
155 local try = "."
156 for _ = 1, 10 do -- FIXME detect when root dir was hit instead
157 if exists(try .. "/.luarocks") and exists(try .. "/lua_modules") then
158 return try
159 elseif exists(try .. "/.luarocks-no-project") then
160 return nil
161 end
162 try = try .. "/.."
163 end
164end
165
154local process_tree_flags 166local process_tree_flags
155do 167do
156 local function replace_tree(flags, root, tree) 168 local function replace_tree(flags, root, tree)
@@ -159,20 +171,6 @@ do
159 path.use_tree(tree or root) 171 path.use_tree(tree or root)
160 end 172 end
161 173
162 local function find_project_dir()
163 local try = "."
164 for _ = 1, 10 do -- FIXME detect when root dir was hit instead
165 local abs = fs.absolute_name(try)
166 if fs.is_dir(abs .. "/.luarocks") and fs.is_dir(abs .. "/lua_modules") then
167 abs = abs:gsub("/.$", "")
168 return abs, abs .. "/lua_modules"
169 elseif fs.exists(abs .. "/.luarocks-no-project") then
170 return nil
171 end
172 try = try .. "/.."
173 end
174 end
175
176 local function strip_trailing_slashes() 174 local function strip_trailing_slashes()
177 if type(cfg.root_dir) == "string" then 175 if type(cfg.root_dir) == "string" then
178 cfg.root_dir = cfg.root_dir:gsub("/+$", "") 176 cfg.root_dir = cfg.root_dir:gsub("/+$", "")
@@ -185,7 +183,7 @@ do
185 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") 183 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "")
186 end 184 end
187 185
188 process_tree_flags = function(flags) 186 process_tree_flags = function(flags, project_dir)
189 187
190 if cfg.local_by_default then 188 if cfg.local_by_default then
191 flags["local"] = true 189 flags["local"] = true
@@ -219,16 +217,14 @@ do
219 "To force using the superuser's home, use --tree explicitly." 217 "To force using the superuser's home, use --tree explicitly."
220 end 218 end
221 replace_tree(flags, cfg.home_tree) 219 replace_tree(flags, cfg.home_tree)
220 elseif project_dir then
221 local project_tree = project_dir .. "/lua_modules"
222 table.insert(cfg.rocks_trees, 1, { name = "project", root = project_tree } )
223 loader.load_rocks_trees()
224 path.use_tree(project_tree)
222 else 225 else
223 local project_dir, rocks_tree = find_project_dir() 226 local trees = cfg.rocks_trees
224 if project_dir then 227 path.use_tree(trees[#trees])
225 table.insert(cfg.rocks_trees, 1, { name = "project", root = rocks_tree } )
226 loader.load_rocks_trees()
227 path.use_tree(rocks_tree)
228 else
229 local trees = cfg.rocks_trees
230 path.use_tree(trees[#trees])
231 end
232 end 228 end
233 229
234 strip_trailing_slashes() 230 strip_trailing_slashes()
@@ -414,10 +410,13 @@ function cmd.run_command(description, commands, external_namespace, ...)
414 lua_version = flags["lua-version"], 410 lua_version = flags["lua-version"],
415 } 411 }
416 end 412 end
417 elseif project_dir then
418 lua_data = find_lua_version_at(project_dir)
419 else 413 else
420 lua_data = find_lua_version_at(".") 414 if not project_dir then
415 project_dir = find_project_dir()
416 end
417 if project_dir then
418 lua_data = find_lua_version_at(project_dir)
419 end
421 end 420 end
422 421
423 -- FIXME A quick hack for the experimental Windows build 422 -- FIXME A quick hack for the experimental Windows build
@@ -441,6 +440,10 @@ function cmd.run_command(description, commands, external_namespace, ...)
441 ----------------------------------------------------------------------------- 440 -----------------------------------------------------------------------------
442 441
443 fs.init() 442 fs.init()
443
444 if project_dir then
445 project_dir = fs.absolute_name(project_dir)
446 end
444 447
445 if flags["version"] then 448 if flags["version"] then
446 util.printout(program.." "..cfg.program_version) 449 util.printout(program.." "..cfg.program_version)
@@ -464,7 +467,7 @@ function cmd.run_command(description, commands, external_namespace, ...)
464 die("Current directory does not exist. Please run LuaRocks from an existing directory.") 467 die("Current directory does not exist. Please run LuaRocks from an existing directory.")
465 end 468 end
466 469
467 ok, err = process_tree_flags(flags) 470 ok, err = process_tree_flags(flags, project_dir)
468 if not ok then 471 if not ok then
469 die(err) 472 die(err)
470 end 473 end