summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-10-11 22:54:45 +0800
committerruki <[email protected]>2018-10-11 11:28:34 +0800
commit2b0891928e7c36256a95a90c37677ebdc7b5687d (patch)
tree6f6da6443e5b5144af78b24f93b8ec66a4849331
parent02ba003928edb4bc2aae98ba1156013d996284cb (diff)
improve to install local package
-rw-r--r--xmake/actions/require/impl/action/install.lua23
-rw-r--r--xmake/actions/require/impl/action/prefix/install.lua34
-rw-r--r--xmake/actions/require/impl/action/prefix/uninstall.lua3
-rw-r--r--xmake/actions/require/impl/package.lua37
-rw-r--r--xmake/actions/require/main.lua14
-rw-r--r--xmake/actions/require/uninstall.lua75
-rw-r--r--xmake/actions/require/unlink.lua (renamed from xmake/actions/require/remove.lua)8
-rw-r--r--xmake/actions/require/xmake.lua3
-rw-r--r--xmake/core/package/package.lua23
-rw-r--r--xmake/core/sandbox/modules/import/core/package/package.lua9
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_package.lua41
11 files changed, 215 insertions, 55 deletions
diff --git a/xmake/actions/require/impl/action/install.lua b/xmake/actions/require/impl/action/install.lua
index b720d7bc8..42643b7ba 100644
--- a/xmake/actions/require/impl/action/install.lua
+++ b/xmake/actions/require/impl/action/install.lua
@@ -79,15 +79,26 @@ function main(package)
-- create the install task
local installtask = function ()
- -- uninstall the install directory first
+ -- uninstall it from the prefix directory first
prefix.uninstall(package)
- -- install it
- for i = 1, 3 do
- local script = scripts[i]
- if script ~= nil then
- filter.call(script, package)
+ -- build and install package to the install directory
+ local installedfile = path.join(package:installdir(), "installed.txt")
+ if not os.isfile(installedfile) then
+
+ -- clean install directory first
+ os.tryrm(package:installdir())
+
+ -- do install
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ filter.call(script, package)
+ end
end
+
+ -- mark as installed
+ io.writefile(installedfile, "")
end
-- install to the prefix directory
diff --git a/xmake/actions/require/impl/action/prefix/install.lua b/xmake/actions/require/impl/action/prefix/install.lua
index 4e0d507a0..3d6fc514f 100644
--- a/xmake/actions/require/impl/action/prefix/install.lua
+++ b/xmake/actions/require/impl/action/prefix/install.lua
@@ -23,6 +23,8 @@
--
-- imports
+import("core.base.global")
+import("core.project.config")
import("uninstall")
-- copy files to the prefix directory
@@ -63,6 +65,23 @@ function _copy_filedirs(pattern)
_copy('a', pattern)
end
+-- find the prefix info file of the previous package
+function _find_prefixfile(originpath)
+ local parentdir = path.directory(originpath)
+ while parentdir and os.isdir(parentdir) and parentdir ~= "/" do
+ local relative_path = path.relative(parentdir, path.join(global.directory(), "installed"))
+ local prefixfile_local = path.join(config.directory(), "prefix", "info", relative_path, "info.txt")
+ if os.isfile(prefixfile_local) then
+ return prefixfile_local
+ end
+ local prefixfile_global = path.join(global.directory(), "prefix", "info", relative_path, "info.txt")
+ if os.isfile(prefixfile_global) then
+ return prefixfile_global
+ end
+ parentdir = path.directory(parentdir)
+ end
+end
+
-- do link
function _do_link(sourcepath, relativepath)
@@ -77,20 +96,14 @@ function _do_link(sourcepath, relativepath)
-- trace
vprint("unlinking %s ..", relativepath)
+
-- find the prefix info file of the previous package
- local parentdir = path.directory(originpath)
- while parentdir and os.isdir(parentdir) and not os.isfile(path.join(parentdir, "prefixinfo.txt")) do
- parentdir = path.directory(parentdir)
- end
+ local prefixfile = _find_prefixfile(originpath)
-- get the prefix info
- local prefixfile = nil
local prefixinfo = nil
- if parentdir then
- prefixfile = path.join(parentdir, "prefixinfo.txt")
- if os.isfile(prefixfile) then
- prefixinfo = io.load(prefixfile)
- end
+ if prefixfile and os.isfile(prefixfile) then
+ prefixinfo = io.load(prefixfile)
end
-- remove the previous link
@@ -231,7 +244,6 @@ function main(package)
-- save the prefix info to file
local prefixinfo = package:prefixinfo()
prefixinfo.installed = _g.relative_pathes
- prefixinfo.prefixdir = _g.prefixdir
io.save(package:prefixfile(), prefixinfo)
-- register this package
diff --git a/xmake/actions/require/impl/action/prefix/uninstall.lua b/xmake/actions/require/impl/action/prefix/uninstall.lua
index 9c77cbb96..420524fd2 100644
--- a/xmake/actions/require/impl/action/prefix/uninstall.lua
+++ b/xmake/actions/require/impl/action/prefix/uninstall.lua
@@ -49,8 +49,5 @@ function main(package)
-- remove the prefix file
os.tryrm(package:prefixfile())
-
- -- remove the install directory
- os.tryrm(package:installdir())
end
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index 8bafb6041..7a5885e76 100644
--- a/xmake/actions/require/impl/package.lua
+++ b/xmake/actions/require/impl/package.lua
@@ -499,8 +499,8 @@ function install_packages(requires, opt)
return packages
end
--- remove packages
-function remove_packages(requires, opt)
+-- uninstall packages
+function uninstall_packages(requires, opt)
-- init options
opt = opt or {}
@@ -519,9 +519,36 @@ function remove_packages(requires, opt)
-- uninstall package from the prefix directory
action.prefix.uninstall(instance)
- -- remove the install files
- os.tryrm(instance:installdir())
-
+ -- remove ok
+ table.insert(packages, instance)
+ end
+
+ -- remove the installed files
+ os.tryrm(instance:installdir())
+ end
+ return packages
+end
+
+-- only unlink packages from the prefix directory
+function unlink_packages(requires, opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- do not remove dependent packages
+ opt.nodeps = true
+
+ -- clear the detect cache
+ detectcache.clear()
+
+ -- unlink all packages
+ local packages = {}
+ for _, instance in ipairs(load_packages(requires, opt)) do
+ if os.isfile(instance:prefixfile()) then
+
+ -- uninstall package from the prefix directory
+ action.prefix.uninstall(instance)
+
-- remove ok
table.insert(packages, instance)
end
diff --git a/xmake/actions/require/main.lua b/xmake/actions/require/main.lua
index 4bcf70162..2ef06b04a 100644
--- a/xmake/actions/require/main.lua
+++ b/xmake/actions/require/main.lua
@@ -32,8 +32,9 @@ import("list")
import("info")
import("clear")
import("search")
-import("remove")
import("install")
+import("uninstall")
+import("unlink")
--
-- the default repositories:
@@ -83,10 +84,15 @@ function main()
search(option.get("requires"))
- -- remove for the installed packages
- elseif option.get("remove") then
+ -- uninstall the installed packages
+ elseif option.get("uninstall") then
- remove(option.get("requires"))
+ uninstall(option.get("requires"))
+
+ -- unlink the installed packages
+ elseif option.get("unlink") then
+
+ unlink(option.get("requires"))
-- show the given package info
elseif option.get("info") then
diff --git a/xmake/actions/require/uninstall.lua b/xmake/actions/require/uninstall.lua
new file mode 100644
index 000000000..8b25146f8
--- /dev/null
+++ b/xmake/actions/require/uninstall.lua
@@ -0,0 +1,75 @@
+--!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 uninstall.lua
+--
+
+-- imports
+import("core.base.task")
+import("core.base.option")
+import("impl.package")
+import("impl.repository")
+import("impl.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
+
+ -- get extra info
+ local extra = option.get("extra")
+ local extrainfo = nil
+ if extra then
+ local tmpfile = os.tmpfile() .. ".lua"
+ io.writefile(tmpfile, "{" .. extra .. "}")
+ extrainfo = io.load(tmpfile)
+ os.tryrm(tmpfile)
+ end
+
+ -- init requires extra info
+ local requires_extra = {}
+ if extrainfo then
+ for _, require_str in ipairs(requires) do
+ requires_extra[require_str] = extrainfo
+ end
+ end
+
+ -- uninstall packages
+ local packages = package.uninstall_packages(requires, {requires_extra = requires_extra})
+ for _, instance in ipairs(packages) do
+ print("uninstall: %s%s ok!", instance:name(), instance:version_str() and ("-" .. instance:version_str()) or "")
+ end
+
+ -- leave environment
+ environment.leave()
+end
+
diff --git a/xmake/actions/require/remove.lua b/xmake/actions/require/unlink.lua
index 4ca2dc207..8aba0d8f5 100644
--- a/xmake/actions/require/remove.lua
+++ b/xmake/actions/require/unlink.lua
@@ -19,7 +19,7 @@
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
--- @file remove.lua
+-- @file unlink.lua
--
-- imports
@@ -63,10 +63,10 @@ function main(requires)
end
end
- -- remove packages
- local packages = package.remove_packages(requires, {requires_extra = requires_extra})
+ -- unlink packages
+ local packages = package.unlink_packages(requires, {requires_extra = requires_extra})
for _, instance in ipairs(packages) do
- print("remove: %s%s ok!", instance:name(), instance:version_str() and ("-" .. instance:version_str()) or "")
+ print("unlink: %s%s ok!", instance:name(), instance:version_str() and ("-" .. instance:version_str()) or "")
end
-- leave environment
diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua
index 94d4b9db0..49d523178 100644
--- a/xmake/actions/require/xmake.lua
+++ b/xmake/actions/require/xmake.lua
@@ -51,7 +51,8 @@ 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, "unlink", "k", nil, "Only unlink the installed packages." }
+ , {nil, "uninstall", "k", nil, "Uninstall the installed packages." }
, {nil, "extra", "kv", nil, "Set the extra info of packages." }
, { }
, {nil, "requires", "vs", nil, "The package requires.",
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 0f1a32b8b..fdc01169d 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -203,7 +203,7 @@ end
function _instance:installdir(...)
-- make the given install directory
- local dir = path.join(package.installdir(self:from("global"), self:debug(), self:plat(), self:arch()), self:name():sub(1, 1):lower(), self:name(), self:version_str(), ...)
+ local dir = path.join(package.installdir(self:debug(), self:plat(), self:arch()), self:name():sub(1, 1):lower(), self:name(), self:version_str(), ...)
-- ensure the install directory
if not os.isdir(dir) then
@@ -236,7 +236,7 @@ end
-- get the prefix info file
function _instance:prefixfile()
- return path.join(self:installdir(), "prefixinfo.txt")
+ return path.join(package.prefixinfodir(self:from("global"), self:debug(), self:plat(), self:arch()), self:name():sub(1, 1):lower(), self:name(), self:version_str(), "info.txt")
end
-- get prefix variables
@@ -518,9 +518,13 @@ function _instance:fetch(opt)
local system = opt.system or self:requireinfo().system
-- fetch it from the prefix directories first
+ -- and add cache key to make a distinction with finding system package
if not fetchinfo and system ~= true then
- -- add cache key to make a distinction with finding system package
- fetchinfo = self._find_package(self:name(), {prefixdirs = self:prefixdir(), system = false, cachekey = "fetch:prefix", force = opt.force})
+ fetchinfo = self._find_package(self:name(), {prefixdirs = self:prefixdir(),
+ system = false,
+ global = self:from("local") and false or nil,
+ cachekey = "fetch:prefix",
+ force = opt.force or self:from("local")})
if fetchinfo then fetchfrom = self._FROMKIND end
end
@@ -639,8 +643,8 @@ function package.cachedir()
end
-- the install directory
-function package.installdir(is_global, is_debug, plat, arch)
- return path.join(is_global and global.directory() or config.directory(), "installed", plat or os.host(), arch or os.arch(), is_debug and "debug" or "release")
+function package.installdir(is_debug, plat, arch)
+ return path.join(global.directory(), "installed", plat or os.host(), arch or os.arch(), is_debug and "debug" or "release")
end
-- get the prefix directory
@@ -648,6 +652,11 @@ function package.prefixdir(is_global, is_debug, plat, arch)
return path.join(is_global and global.directory() or config.directory(), "prefix", plat or os.host(), arch or os.arch(), is_debug and "debug" or "release")
end
+-- get the prefix info directory
+function package.prefixinfodir(is_global, is_debug, plat, arch)
+ return path.join(is_global and global.directory() or config.directory(), "prefix", "info", plat or os.host(), arch or os.arch(), is_debug and "debug" or "release")
+end
+
-- get the prefix info
function package.prefixinfo(is_global, is_debug, plat, arch)
local prefixfile = package.prefixfile(is_global, is_debug, plat, arch)
@@ -656,7 +665,7 @@ end
-- get the prefix info file
function package.prefixfile(is_global, is_debug, plat, arch)
- return path.join(package.prefixdir(is_global, is_global, plat, arch), "info.txt")
+ return path.join(package.prefixinfodir(is_global, is_global, plat, arch), "info.txt")
end
-- get environment variables
diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua
index 178467208..9d8c78324 100644
--- a/xmake/core/sandbox/modules/import/core/package/package.lua
+++ b/xmake/core/sandbox/modules/import/core/package/package.lua
@@ -36,8 +36,8 @@ function sandbox_core_package_package.cachedir()
end
-- the install directory
-function sandbox_core_package_package.installdir(is_global, is_debug, plat, arch)
- return package.installdir(is_global, is_debug, plat, arch)
+function sandbox_core_package_package.installdir(is_debug, plat, arch)
+ return package.installdir(is_debug, plat, arch)
end
-- get the prefix directory
@@ -45,6 +45,11 @@ function sandbox_core_package_package.prefixdir(is_global, is_debug, plat, arch)
return package.prefixdir(is_global, is_debug, plat, arch)
end
+-- get the prefix info directory
+function sandbox_core_package_package.prefixinfodir(is_global, is_debug, plat, arch)
+ return package.prefixinfodir(is_global, is_debug, plat, arch)
+end
+
-- load the package from the project file
function sandbox_core_package_package.load_from_project(packagename)
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
index f02204c4f..58dac1b57 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
@@ -136,22 +136,42 @@ end
-- find package from the prefix directories
function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt)
- -- get prefix directories
+ -- get the prefix directories
local prefixdirs = table.wrap(opt.prefixdirs)
local platsubdirs = path.join(config.get("plat") or os.host(), config.get("arch") or os.arch())
if #prefixdirs == 0 then
+ if opt.mode then
+ table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs, opt.mode))
+ end
table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs, "release"))
- table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, "release"))
+ table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs, "debug"))
+ if opt.global ~= false then
+ if opt.mode then
+ table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, opt.mode))
+ end
+ table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, "release"))
+ table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs, "debug"))
+ end
end
- -- find the prefix info file of package, .e.g z/zlib/1.2.11/prefixinfo.txt
+ -- find the prefix info file of package, .e.g prefix/info/z/zlib/1.2.11/info.txt
local packagedirs = {}
local packagepath = path.join(name:sub(1, 1), name, "*")
- table.insert(packagedirs, path.join(config.directory(), "installed", platsubdirs, "debug", packagepath))
- table.insert(packagedirs, path.join(config.directory(), "installed", platsubdirs, "release", packagepath))
- table.insert(packagedirs, path.join(global.directory(), "installed", platsubdirs, "debug", packagepath))
- table.insert(packagedirs, path.join(global.directory(), "installed", platsubdirs, "release", packagepath))
- local prefixfile = find_file("prefixinfo.txt", packagedirs)
+ if opt.mode then
+ table.insert(packagedirs, path.join(config.directory(), "prefix", "info", platsubdirs, opt.mode, packagepath))
+ end
+ table.insert(packagedirs, path.join(config.directory(), "prefix", "info", platsubdirs, "release", packagepath))
+ table.insert(packagedirs, path.join(config.directory(), "prefix", "info", platsubdirs, "debug", packagepath))
+
+ -- find the prefix info file from the global prefix directory
+ if opt.global ~= false then
+ if opt.mode then
+ table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, opt.mode, packagepath))
+ end
+ table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, "release", packagepath))
+ table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, "debug", packagepath))
+ end
+ local prefixfile = find_file("info.txt", packagedirs)
-- get the include and link directories
local links = {}
@@ -161,10 +181,7 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt)
if prefixinfo then
-- get prefix directory of this package
- local prefixdir = prefixinfo.prefixdir
- if not prefixdir then
- prefixdir = path.directory(path.directory(path.directory(path.directory(prefixfile)))):gsub("installed", "prefix")
- end
+ local prefixdir = path.translate(path.directory(path.directory(path.directory(path.directory(prefixfile)))):gsub("[/\\]prefix[/\\]info[/\\]", "/prefix/"))
-- get link and include directories
for _, includedir in ipairs(table.wrap(prefixinfo.includedirs)) do