summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-23 22:39:57 +0800
committerruki <[email protected]>2020-12-23 22:39:57 +0800
commit50f826bb2df51dd80eb67054e446a496f2b6d15a (patch)
tree0e5f919e899f4cdbd9d555186019094ad5a5a796
parent58f26afbf964ee3a873021b972df868f23cc16c3 (diff)
improve package cache
-rw-r--r--xmake/actions/require/impl/package.lua14
-rw-r--r--xmake/core/package/package.lua45
-rw-r--r--xmake/core/project/project.lua12
3 files changed, 42 insertions, 29 deletions
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index c66f1807a..a9d536c68 100644
--- a/xmake/actions/require/impl/package.lua
+++ b/xmake/actions/require/impl/package.lua
@@ -27,6 +27,7 @@ import("core.base.scheduler")
import("core.base.tty")
import("private.async.runjobs")
import("private.utils.progress")
+import("core.cache.memcache")
import("core.cache.localcache")
import("core.project.project")
import("core.package.package", {alias = "core_package"})
@@ -36,6 +37,11 @@ import("devel.git")
import("net.fasturl")
import("repository")
+-- get memcache
+function _memcache()
+ return memcache.cache("require.impl.package")
+end
+
--
-- parse require string
--
@@ -76,7 +82,7 @@ import("repository")
function _parse_require(require_str, requires_extra, parentinfo)
-- get it from cache first
- local requires = _g._REQUIRES or {}
+ local requires = _memcache():get("requires") or {}
local required = requires[require_str]
if required then
return required.packagename, required.requireinfo
@@ -174,7 +180,7 @@ function _parse_require(require_str, requires_extra, parentinfo)
-- save this required item to cache
requires[require_str] = required
- _g._REQUIRES = requires
+ _memcache():set("requires", requires)
-- ok
return required.packagename, required.requireinfo
@@ -324,7 +330,7 @@ function _load_package(packagename, requireinfo, opt)
-- attempt to get it from cache first
opt = opt or {}
- local packages = _g._PACKAGES or {}
+ local packages = _memcache():get("packages") or {}
local package = packages[packagename]
if package then
@@ -380,7 +386,7 @@ function _load_package(packagename, requireinfo, opt)
-- save this package package to cache
packages[packagename] = package
- _g._PACKAGES = packages
+ _memcache():set("packages", packages)
return package
end
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 873cc119b..112dca95c 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -711,7 +711,7 @@ end
-- get the build hash
function _instance:buildhash()
- local buildhash = package._memcache():get2(self, "buildhash")
+ local buildhash = self._BUILDHASH
if buildhash == nil then
local str = self:plat() .. self:arch()
local configs = self:configs()
@@ -730,7 +730,7 @@ function _instance:buildhash()
str = str .. configs_str
end
buildhash = hash.uuid4(str):gsub('-', ''):lower()
- package._memcache():set2(self, "buildhash", buildhash)
+ self._BUILDHASH = buildhash
end
return buildhash
end
@@ -861,7 +861,7 @@ function _instance:fetch(opt)
opt = opt or {}
-- attempt to get it from cache
- local fetchinfo = package._memcache():get2(self, "fetchinfo")
+ local fetchinfo = self._FETCHINFO
if not opt.force and opt.external == nil and fetchinfo then
return fetchinfo
end
@@ -962,7 +962,7 @@ function _instance:fetch(opt)
end
-- save to cache
- package._memcache():set2(self, "fetchinfo", fetchinfo)
+ self._FETCHINFO = fetchinfo
-- mark as system package?
if isSys ~= nil then
@@ -973,8 +973,7 @@ end
-- exists this package?
function _instance:exists()
- local fetchinfo = package._memcache():get2(self, "fetchinfo")
- return fetchinfo ~= nil
+ return self._FETCHINFO ~= nil
end
-- fetch all local info with dependencies
@@ -1373,9 +1372,9 @@ end
function package.load_from_system(packagename)
-- get it directly from cache first
- package._PACKAGES = package._PACKAGES or {}
- if package._PACKAGES[packagename] then
- return package._PACKAGES[packagename]
+ local instance = package._memcache():get2("packages", packagename)
+ if instance then
+ return instance
end
-- get package info
@@ -1398,7 +1397,7 @@ function package.load_from_system(packagename)
end
-- make sandbox instance with the given script
- local instance, errors = sandbox.new(on_install, interp:filter())
+ instance, errors = sandbox.new(on_install, interp:filter())
if not instance then
return nil, errors
end
@@ -1413,7 +1412,7 @@ function package.load_from_system(packagename)
end
-- new an instance
- local instance = _instance.new(packagename, scopeinfo.new("package", packageinfo))
+ instance = _instance.new(packagename, scopeinfo.new("package", packageinfo))
-- mark as system or 3rd package
instance._isSys = true
@@ -1433,9 +1432,7 @@ function package.load_from_system(packagename)
end
-- save instance to the cache
- package._PACKAGES[packagename] = instance
-
- -- ok
+ package._memcache():set2("packages", instance)
return instance
end
@@ -1443,9 +1440,9 @@ end
function package.load_from_project(packagename, project)
-- get it directly from cache first
- package._PACKAGES = package._PACKAGES or {}
- if package._PACKAGES[packagename] then
- return package._PACKAGES[packagename]
+ local instance = package._memcache():get2("packages", packagename)
+ if instance then
+ return instance
end
-- load packages (with cache)
@@ -1467,8 +1464,8 @@ function package.load_from_project(packagename, project)
end
-- new an instance
- local instance = _instance.new(packagename, packageinfo)
- package._PACKAGES[packagename] = instance
+ instance = _instance.new(packagename, packageinfo)
+ package._memcache():set2("packages", instance)
return instance
end
@@ -1476,9 +1473,9 @@ end
function package.load_from_repository(packagename, repo, packagedir, packagefile)
-- get it directly from cache first
- package._PACKAGES = package._PACKAGES or {}
- if package._PACKAGES[packagename] then
- return package._PACKAGES[packagename]
+ local instance = package._memcache():get2("packages", packagename)
+ if instance then
+ return instance
end
-- load repository first for checking the xmake minimal version
@@ -1525,13 +1522,13 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile
end
-- new an instance
- local instance = _instance.new(packagename, packageinfo, path.directory(scriptpath))
+ instance = _instance.new(packagename, packageinfo, path.directory(scriptpath))
-- save repository
instance._REPO = repo
-- save instance to the cache
- package._PACKAGES[packagename] = instance
+ package._memcache():set2("packages", instance)
return instance
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 4749e19bb..28b7daddf 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -925,9 +925,19 @@ function project.clear()
opt:clear()
end
- -- clear targets and options
+ -- clear cache
+ project._INFO = nil
project._TARGETS = nil
+ project._TARGETS_LOADED = false
+ project._ORDERTARGETS = nil
project._OPTIONS = nil
+ project._REQUIRES = nil
+ project._REQUIRES_STR = nil
+ project._REQUIRES_EXTRA = nil
+ project._RULES = nil
+ project._TASKS = nil
+ project._PACKAGES = nil
+ project._POLICIES = nil
end
-- project has been loaded?