aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-08-02 13:48:01 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-08-02 13:50:01 -0300
commit1ab3297faae3e57772c840d74828a9d370a6cd84 (patch)
treedfa3e5cad3e4ac1f20c77db59f951bc0b55e2e2b
parentdcaf10c26714cbc518cbf329d0fb7b71d4241494 (diff)
downloadluarocks-1ab3297faae3e57772c840d74828a9d370a6cd84.tar.gz
luarocks-1ab3297faae3e57772c840d74828a9d370a6cd84.tar.bz2
luarocks-1ab3297faae3e57772c840d74828a9d370a6cd84.zip
Fix: do not detect .luarocks/config-5.x.lua and lua_modules as modules
Running luarocks init a second time after deleting the rockspec was mis-detects .luarocks/config-5.x.lua as a module, creating an entry `["luarocks.config-5.3"] = ".luarocks/config-5.3.lua"` in `build.modules`. Same problem happened with modules under `lua_modules`. This excludes `.luarocks` and `lua_modules` from module detection. Includes a regression test. Closes #847.
-rw-r--r--spec/init_spec.lua52
-rw-r--r--src/luarocks/build/builtin.lua4
2 files changed, 54 insertions, 2 deletions
diff --git a/spec/init_spec.lua b/spec/init_spec.lua
index a4751741..95aa8ff6 100644
--- a/spec/init_spec.lua
+++ b/spec/init_spec.lua
@@ -1,9 +1,10 @@
1local test_env = require("spec.util.test_env") 1local test_env = require("spec.util.test_env")
2local run = test_env.run 2local run = test_env.run
3local testing_paths = test_env.testing_paths 3local testing_paths = test_env.testing_paths
4local get_tmp_path = test_env.get_tmp_path
5local copy_dir = test_env.copy_dir 4local copy_dir = test_env.copy_dir
6local is_win = test_env.TEST_TARGET_OS == "windows" 5local is_win = test_env.TEST_TARGET_OS == "windows"
6local write_file = test_env.write_file
7local lfs = require("lfs")
7 8
8test_env.unload_luarocks() 9test_env.unload_luarocks()
9 10
@@ -61,4 +62,53 @@ describe("Luarocks init test #integration", function()
61 assert.truthy(content:find("/lua_modules")) 62 assert.truthy(content:find("/lua_modules"))
62 end, finally) 63 end, finally)
63 end) 64 end)
65
66 it("LuaRocks init does not autodetect config or dependencies as modules of the package", function()
67 test_env.run_in_tmp(function(tmpdir)
68 local myproject = tmpdir .. "/myproject"
69 lfs.mkdir(myproject)
70 lfs.chdir(myproject)
71
72 assert(run.luarocks("init"))
73 assert.truthy(lfs.attributes(myproject .. "/.luarocks/config-" .. test_env.lua_version .. ".lua"))
74 local rockspec_filename = myproject .. "/myproject-dev-1.rockspec"
75 assert.truthy(lfs.attributes(rockspec_filename))
76
77 -- install a package locally
78 write_file("my_dependency-1.0-1.rockspec", [[
79 package = "my_dependency"
80 version = "1.0-1"
81 source = {
82 url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/my_dependency.lua"
83 }
84 build = {
85 type = "builtin",
86 modules = {
87 my_dependency = "my_dependency.lua"
88 }
89 }
90 ]], finally)
91 write_file(tmpdir .. "/my_dependency.lua", "return {}", finally)
92
93 assert.is_true(run.luarocks_bool("build --verbose my_dependency-1.0-1.rockspec"))
94 assert.truthy(lfs.attributes(myproject .. "/lua_modules/share/lua/" .. test_env.lua_version .."/my_dependency.lua"))
95
96 os.remove(rockspec_filename)
97 os.remove("my_dependency-1.0-1.rockspec")
98
99 -- re-run init
100 assert(run.luarocks("init"))
101
102 -- file is recreated
103 assert.truthy(lfs.attributes(rockspec_filename))
104
105 local fd = assert(io.open(rockspec_filename, "rb"))
106 local rockspec = assert(fd:read("*a"))
107 fd:close()
108
109 assert.no.match("my_dependency", rockspec, 1, true)
110 assert.no.match("config", rockspec, 1, true)
111
112 end, finally)
113 end)
64end) 114end)
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index 694542ba..2db6f256 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -89,7 +89,9 @@ do
89 89
90 for _, file in ipairs(fs.find()) do 90 for _, file in ipairs(fs.find()) do
91 local luamod = file:match("(.*)%.lua$") 91 local luamod = file:match("(.*)%.lua$")
92 if luamod and not luamod_blacklist[luamod] then 92 if file:match("^.luarocks") or file:match("^lua_modules") then
93 -- skip
94 elseif luamod and not luamod_blacklist[luamod] then
93 modules[path.path_to_module(file)] = prefix..file 95 modules[path.path_to_module(file)] = prefix..file
94 else 96 else
95 local cmod = file:match("(.*)%.c$") 97 local cmod = file:match("(.*)%.c$")