diff options
| author | ruki <[email protected]> | 2018-09-12 23:22:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-09-12 14:15:59 +0800 |
| commit | 6c804755e70f08edb7c83031abc739db0561b75c (patch) | |
| tree | 81658492b09f3cf723ddc9d95f42aa5756c1a715 | |
| parent | 0a8a275f8cb9a51446746f796031882dfc8381ae (diff) | |
remove required packages
| -rw-r--r-- | xmake/actions/require/info.lua | 9 | ||||
| -rw-r--r-- | xmake/actions/require/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/require/remove.lua | 70 | ||||
| -rw-r--r-- | xmake/actions/require/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 2 |
5 files changed, 82 insertions, 6 deletions
diff --git a/xmake/actions/require/info.lua b/xmake/actions/require/info.lua index 6398a240f..efb7810b5 100644 --- a/xmake/actions/require/info.lua +++ b/xmake/actions/require/info.lua @@ -49,11 +49,7 @@ function main(requires) print("The package infos:") -- list all packages - local packages = package.load_packages(requires) - if packages and #packages > 0 then - - -- get tis package - local instance = packages[#packages] + for _, instance in ipairs(package.load_packages(requires)) do -- show package name local requireinfo = instance:requireinfo() or {} @@ -102,6 +98,9 @@ function main(requires) -- show package directory cprint(" -> ${magenta}packagedir${clear}: %s", instance:directory()) + + -- end + print("") end -- leave environment diff --git a/xmake/actions/require/main.lua b/xmake/actions/require/main.lua index 0790e400c..4bcf70162 100644 --- a/xmake/actions/require/main.lua +++ b/xmake/actions/require/main.lua @@ -32,6 +32,7 @@ import("list") import("info") import("clear") import("search") +import("remove") import("install") -- @@ -82,6 +83,11 @@ function main() search(option.get("requires")) + -- remove for the installed packages + elseif option.get("remove") then + + remove(option.get("requires")) + -- show the given package info elseif option.get("info") then diff --git a/xmake/actions/require/remove.lua b/xmake/actions/require/remove.lua new file mode 100644 index 000000000..2c15db555 --- /dev/null +++ b/xmake/actions/require/remove.lua @@ -0,0 +1,70 @@ +--!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 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file remove.lua +-- + +-- imports +import("core.base.task") +import("package") +import("repository") +import("environment") + +-- show the given package info +function main(requires) + + -- no requires? + if not requires then + return + end + + -- enter environment + environment.enter() + + -- pull all repositories first if not exists + if not repository.pulled() then + task.run("repo", {update = true}) + end + + -- 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") + else + cprint("remove: %s%s not found!", requireinfo.originstr, instance:version_str() and ("/" .. instance:version_str()) or "") + end + end + + -- leave environment + environment.leave() +end + diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua index b16bdea17..8fa5e44dd 100644 --- a/xmake/actions/require/xmake.lua +++ b/xmake/actions/require/xmake.lua @@ -51,6 +51,7 @@ task("require") , { } , {nil, "info", "k", nil, "Show the given package info." } , {'s', "search", "k", nil, "Search for the given packages from repositories." } + , {nil, "remove", "k", nil, "Remove the installed packages." } , { } , {nil, "requires", "vs", nil, "The package requires.", ".e.g", diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 5806ead1e..a147bb3c2 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -248,7 +248,7 @@ end -- clear the option status and need recheck it function option:clear() - -- enable or disable this option? + -- clear config config.set(self:name(), nil) -- clear this option in cache |
