diff options
author | Hisham <hisham@gobolinux.org> | 2016-10-06 11:51:31 -0300 |
---|---|---|
committer | Hisham <hisham@gobolinux.org> | 2016-10-06 11:51:31 -0300 |
commit | 67a7d4faee164903769d001abbebd1073ad87e01 (patch) | |
tree | a0286bed898166a47987065c0396ef656cf0c638 /src | |
parent | 5f3b2b79bbba5de0a571188c08b42a213aac772f (diff) | |
download | luarocks-67a7d4faee164903769d001abbebd1073ad87e01.tar.gz luarocks-67a7d4faee164903769d001abbebd1073ad87e01.tar.bz2 luarocks-67a7d4faee164903769d001abbebd1073ad87e01.zip |
Make the workaround for older LuaRocks versions more robust.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/loader.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 06a0cfda..874bc10c 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua | |||
@@ -23,8 +23,25 @@ local deps = require("luarocks.deps") | |||
23 | local util = require("luarocks.util") | 23 | local util = require("luarocks.util") |
24 | 24 | ||
25 | -- Workaround for wrappers produced by older versions of LuaRocks | 25 | -- Workaround for wrappers produced by older versions of LuaRocks |
26 | local temporary_global = false | ||
26 | if luarocks then | 27 | if luarocks then |
28 | -- The site_config.lua file generated by old versions uses module(), | ||
29 | -- so it produces a global `luarocks` table. Since we have the table, | ||
30 | -- add the `loader` field to make the old wrappers happy. | ||
27 | luarocks.loader = loader | 31 | luarocks.loader = loader |
32 | else | ||
33 | -- When a new version is installed on top of an old version, | ||
34 | -- site_config.lua may be replaced, and then it no longer creates | ||
35 | -- a global. | ||
36 | -- Detect when being called via -lluarocks.loader; this is | ||
37 | -- most likely a wrapper. | ||
38 | local info = debug.getinfo(2, "nS") | ||
39 | if info.what == "C" and not info.name then | ||
40 | luarocks = { loader = loader } | ||
41 | temporary_global = true | ||
42 | -- For the other half of this hack, | ||
43 | -- see the next use of `temporary_global` below. | ||
44 | end | ||
28 | end | 45 | end |
29 | 46 | ||
30 | loader.context = {} | 47 | loader.context = {} |
@@ -60,6 +77,13 @@ function loader.add_context(name, version) | |||
60 | -- assert(type(name) == "string") | 77 | -- assert(type(name) == "string") |
61 | -- assert(type(version) == "string") | 78 | -- assert(type(version) == "string") |
62 | 79 | ||
80 | if temporary_global then | ||
81 | -- The first thing a wrapper does is to call add_context. | ||
82 | -- From here on, it's safe to clean the global environment. | ||
83 | luarocks = nil | ||
84 | temporary_global = false | ||
85 | end | ||
86 | |||
63 | if loader.context[name] then | 87 | if loader.context[name] then |
64 | return | 88 | return |
65 | end | 89 | end |