summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-03-16 00:49:35 +0800
committerruki <[email protected]>2019-03-15 22:57:35 +0800
commit27187f0004a3e93b76431cfb78bcd0e2250263a1 (patch)
tree8891b0e086beffb44589eaefb99bc59f88da070b
parent08488b9e3a4e38e9cfe4f018d18a91f61b78e7fc (diff)
update require clean
-rw-r--r--xmake/actions/require/clean.lua87
-rw-r--r--xmake/actions/require/clear.lua40
-rw-r--r--xmake/actions/require/main.lua8
3 files changed, 91 insertions, 44 deletions
diff --git a/xmake/actions/require/clean.lua b/xmake/actions/require/clean.lua
new file mode 100644
index 000000000..cb69d85a4
--- /dev/null
+++ b/xmake/actions/require/clean.lua
@@ -0,0 +1,87 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file clean.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.cache")
+import("core.package.package")
+
+-- clean all installed package caches
+function main()
+
+ -- trace
+ print("clear all package caches ..")
+
+ -- clear cache directory
+ os.rm(package.cachedir())
+
+ -- clear require cache
+ local require_cache = cache("local.require")
+ require_cache:clear()
+ require_cache:flush()
+
+ -- trace
+ print("clear all unused packages ..")
+
+ -- clear all unused packages
+ local installdir = package.installdir()
+ for _, references_file in ipairs(os.files(path.join(installdir, "*", "*", "*", "*", "references.txt"))) do
+ local references = io.load(references_file)
+ if references then
+ local found = false
+ for projectdir, refdate in pairs(references) do
+ if os.isdir(projectdir) then
+ found = true
+ break
+ end
+ end
+ if not found then
+
+ -- get package directory
+ local packagedir = path.directory(references_file)
+ print("remove %s ..", packagedir)
+
+ -- get confirm
+ local confirm = option.get("yes")
+ if confirm == nil then
+
+ -- show tips
+ cprint("${bright color.warning}note: ${clear}no projects are using this package, remove it (pass -y to skip confirm)?")
+ cprint("please input: y (y/n)")
+
+ -- get answer
+ io.flush()
+ local answer = io.read()
+ if answer == 'y' or answer == '' then
+ confirm = true
+ end
+ end
+ if confirm then
+ os.rm(packagedir)
+ end
+ end
+ end
+ end
+end
+
diff --git a/xmake/actions/require/clear.lua b/xmake/actions/require/clear.lua
deleted file mode 100644
index ffe73ed26..000000000
--- a/xmake/actions/require/clear.lua
+++ /dev/null
@@ -1,40 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed to the Apache Software Foundation (ASF) under one
--- or more contributor license agreements. See the NOTICE file
--- distributed with this work for additional information
--- regarding copyright ownership. The ASF licenses this file
--- to you under the Apache License, Version 2.0 (the
--- "License"); you may not use this file except in compliance
--- with the License. You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
---
--- @author ruki
--- @file clear.lua
---
-
--- imports
-import("core.project.cache")
-import("core.package.package")
-
--- clear all installed package caches
-function main()
-
- -- clear cache directory
- os.rm(package.cachedir())
-
- -- clear require cache
- local require_cache = cache("local.require")
- require_cache:clear()
- require_cache:flush()
-end
-
diff --git a/xmake/actions/require/main.lua b/xmake/actions/require/main.lua
index ed42efcd5..6311434cc 100644
--- a/xmake/actions/require/main.lua
+++ b/xmake/actions/require/main.lua
@@ -30,7 +30,7 @@ import("core.project.project")
import("core.platform.platform")
import("list")
import("info")
-import("clear")
+import("clean")
import("search")
import("install")
import("uninstall")
@@ -73,10 +73,10 @@ function main()
-- load project first
_load_project()
- -- clear all installed packages cache
- if option.get("clear") then
+ -- clean all installed packages cache
+ if option.get("clean") then
- clear(option.get("global"))
+ clean(option.get("global"))
-- search for the given packages from repositories
elseif option.get("search") then