diff options
| author | ruki <[email protected]> | 2018-09-12 23:47:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-09-12 16:46:30 +0800 |
| commit | d5bbf65a46f53058816081631fafc015bce83ba3 (patch) | |
| tree | 423fb3cdb60159e2e99b2b42bf4ffe588088f0c5 | |
| parent | 6c804755e70f08edb7c83031abc739db0561b75c (diff) | |
clear cache when removing package
| -rw-r--r-- | xmake/actions/require/action/install.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/require/package.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/require/remove.lua | 14 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 18 |
4 files changed, 22 insertions, 16 deletions
diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua index 620327f89..a270b538c 100644 --- a/xmake/actions/require/action/install.lua +++ b/xmake/actions/require/action/install.lua @@ -195,7 +195,7 @@ function main(package) end -- fetch package and force to flush the cache - assert(package:fetch(true), "fetch %s failed!", tipname) + assert(package:fetch({force = true}), "fetch %s failed!", tipname) -- trace cprint("${green}ok") diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua index b95b7bcc4..752c85622 100644 --- a/xmake/actions/require/package.lua +++ b/xmake/actions/require/package.lua @@ -37,11 +37,11 @@ import("repository") -- -- parse require string -- +-- add_requires("zlib") -- add_requires("tbox >=1.5.1", "zlib >=1.2.11") -- add_requires("zlib master") -- add_requires("xmake-repo@tbox >=1.5.1") --- add_requires("https://github.com/tboox/[email protected] >=1.5.1") --- add_requires("tbox >=1.5.1 <1.6.0", {optional = true, alias = "tbox"}) +-- add_requires("aaa_bbb_ccc >=1.5.1 <1.6.0", {optional = true, alias = "mypkg"}) -- function _parse_require(require_str, requires_extra, parentinfo) diff --git a/xmake/actions/require/remove.lua b/xmake/actions/require/remove.lua index 2c15db555..fe02d45ad 100644 --- a/xmake/actions/require/remove.lua +++ b/xmake/actions/require/remove.lua @@ -27,6 +27,7 @@ import("core.base.task") import("package") import("repository") import("environment") +import("lib.detect.cache") -- show the given package info function main(requires) @@ -44,22 +45,21 @@ function main(requires) task.run("repo", {update = true}) end + -- clear the detect cache + cache.clear() + -- remove all packages for _, instance in ipairs(package.load_packages(requires)) do - - -- this package has been installed? local requireinfo = instance:requireinfo() or {} if os.isdir(instance:directory()) then - + -- remove package directory os.rm(instance:directory()) - -- force to re-fetch package and flush lib.detect.find_package cache - local fetchinfo, fetchfrom = instance:fetch(true) - -- trace - cprint("remove: %s%s %s!", requireinfo.originstr, instance:version_str() and ("/" .. instance:version_str()) or "", (fetchinfo and fetchfrom ~= "system") and "failed" or "ok") + cprint("remove: %s%s ok!", requireinfo.originstr, instance:version_str() and ("/" .. instance:version_str()) or "") else + -- trace cprint("remove: %s%s not found!", requireinfo.originstr, instance:version_str() and ("/" .. instance:version_str()) or "") end end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 5888bff80..532cc1e23 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -311,14 +311,19 @@ end -- fetch package info from the local packages -- +-- @param opt the fetch option, .e.g {force = true, system = false} +-- -- @return {packageinfo}, fetchfrom (.e.g local/global/system) -- -function _instance:fetch(force) +function _instance:fetch(opt) + + -- init options + opt = opt or {} -- attempt to get it from cache local fetchfrom = self._FETCHFROM local fetchinfo = self._FETCHINFO - if not force and fetchinfo then + if not opt.force and fetchinfo then return fetchinfo, fetchfrom end @@ -331,7 +336,7 @@ function _instance:fetch(force) self._find_tool = self._find_tool or sandbox_module.import("lib.detect.find_tool", {anonymous = true}) -- fetch it from the system directories - fetchinfo = self._find_tool(self:name(), {force = force}) + fetchinfo = self._find_tool(self:name(), {force = opt.force}) if fetchinfo then fetchfrom = "system" -- ignore self:requireinfo().system end @@ -343,18 +348,19 @@ function _instance:fetch(force) -- fetch it from the package directories first local packagedir = self:directory() if not fetchinfo and packagedir then - fetchinfo = self._find_package(self:name(), {packagedirs = packagedir, system = false, cachekey = "package:fetch", force = force}) + -- add cache key to make a distinction with finding system package + fetchinfo = self._find_package(self:name(), {packagedirs = packagedir, system = false, cachekey = "package:fetch", force = opt.force}) if fetchinfo then fetchfrom = self._FROMKIND end end -- fetch it from the system directories if not fetchinfo then - local system = self:requireinfo().system + local system = opt.system or self:requireinfo().system if system == nil then -- find system package by default system = true end if system then - fetchinfo = self._find_package(self:name(), {force = force}) + fetchinfo = self._find_package(self:name(), {force = opt.force}) if fetchinfo then fetchfrom = "system" end end end |
