summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-11-28 22:33:34 +0800
committerruki <[email protected]>2018-11-28 09:21:28 +0800
commit6b51f7f0a60dbe3553273fa8a450f8349a51e8e5 (patch)
tree6fffd2087e1b9365ba991b5a62b735c0d0a2f69a
parentdcb7e33ca401239c3690ced264c241f10195510a (diff)
fix on_load for require
-rw-r--r--xmake/actions/require/install.lua1
-rw-r--r--xmake/core/project/project.lua13
-rw-r--r--xmake/core/project/requireinfo.lua23
3 files changed, 30 insertions, 7 deletions
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index 8217cd156..32a9014ed 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -39,6 +39,7 @@ function _register_required_package(instance, requireinfo)
requireinfo:enable(false)
else
-- add this package info
+ requireinfo:clear()
requireinfo:add(instance:fetch())
-- add all dependent packages info
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index b2e102833..241c6068f 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -524,7 +524,7 @@ function project._load_requires()
alias = extrainfo.alias
end
- -- load it from cache first
+ -- load it from cache first (@note will discard scripts in extrainfo)
local instance = requireinfo.load(alias or packagename)
if not instance then
@@ -536,6 +536,17 @@ function project._load_requires()
instance._INFO = { __requirestr = requirestr, __extrainfo = extrainfo }
end
+ -- move scripts of extrainfo (e.g. on_load ..)
+ if extrainfo then
+ for k, v in pairs(extrainfo) do
+ if type(v) == "function" then
+ instance._SCRIPTS = instance._SCRIPTS or {}
+ instance._SCRIPTS[k] = v
+ extrainfo[k] = nil
+ end
+ end
+ end
+
-- add require info
requires[alias or packagename] = instance
end
diff --git a/xmake/core/project/requireinfo.lua b/xmake/core/project/requireinfo.lua
index e5aa12b6a..f31588338 100644
--- a/xmake/core/project/requireinfo.lua
+++ b/xmake/core/project/requireinfo.lua
@@ -56,13 +56,12 @@ function requireinfo:save()
-- To ensure that the full information (version, ..) is obtained, delay loading it
if not self._LOADED then
- local extrainfo = self:extrainfo()
- if extrainfo and extrainfo.on_load then
- local ok, errors = sandbox.load(extrainfo.on_load, self)
+ local on_load = self:script("on_load")
+ if on_load then
+ local ok, errors = sandbox.load(on_load, self)
if not ok then
os.raise(errors)
end
- extrainfo.on_load = nil
end
self._LOADED = true
end
@@ -72,9 +71,16 @@ function requireinfo:save()
requireinfo._cache():flush()
end
--- clear the requireinfo status and need recheck it
+-- clear the requireinfo
function requireinfo:clear()
- requireinfo._cache():set(self:name(), nil)
+ local info = self._INFO
+ if info then
+ for k, v in pairs(info) do
+ if not k:startswith("__") then
+ info[k] = nil
+ end
+ end
+ end
end
-- dump this requireinfo
@@ -92,6 +98,11 @@ function requireinfo:name()
return self._NAME
end
+-- get the given script
+function requireinfo:script(name)
+ return self._SCRIPTS and self._SCRIPTS[name] or nil
+end
+
-- get the package version
function requireinfo:version()