summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-09-19 22:44:59 +0800
committerruki <[email protected]>2018-09-19 10:29:58 +0800
commit4ee805906a0dcf442a80e0bb072c538622bd2a32 (patch)
tree0dfaa70bf639b066758f681b3c16b96ee73bbcca
parentb2609ac657e482c68cf27977174bc9080d34eee9 (diff)
remove package directory
-rw-r--r--xmake/actions/require/action/install.lua101
-rw-r--r--xmake/actions/require/info.lua6
-rw-r--r--xmake/actions/require/remove.lua6
-rw-r--r--xmake/core/package/package.lua56
-rw-r--r--xmake/core/sandbox/modules/import/core/package/package.lua10
5 files changed, 45 insertions, 134 deletions
diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua
index 9f0d7c258..9c835c194 100644
--- a/xmake/actions/require/action/install.lua
+++ b/xmake/actions/require/action/install.lua
@@ -29,89 +29,27 @@ import("build")
import("test")
import("filter")
--- generate package
-function _generate_package(package)
-
- -- the package name
- local name = package:name()
-
- -- the package directory
- local packagedir = path.join(package:directory(), name .. ".pkg")
-
- -- the linkdir
- local linkdir = path.join(packagedir, "lib", get_config("plat"), get_config("arch"))
-
- -- the includedir
- local includedir = path.join(packagedir, "include", get_config("plat"), get_config("arch"))
+-- uninstall package from the prefix directory
+function _uninstall_prefix(package)
- -- install the library files and ignore hidden files (.xxx)
- os.tryrm(linkdir)
- os.cp(package:installdir("lib"), linkdir)
+ -- remove the previous prefix files
+ local prefixdir = package:prefixdir()
+ for _, relativefile in ipairs(package:prefixlist()) do
- -- install the header files
- os.cp(package:installdir("include"), includedir)
+ -- trace
+ vprint("removing %s ..", relativefile)
- -- get links
- local links = {}
- for _, filename in ipairs(os.files(path.join(linkdir, target.filename("*", "static"))), path.filename) do
- local link = target.linkname(filename)
- if link then
- table.insert(links, link)
- end
- end
- if #links == 0 then
- for _, filename in ipairs(os.files(path.join(linkdir, target.filename("*", "shared"))), path.filename) do
- local link = target.linkname(filename)
- if link then
- table.insert(links, link)
- end
+ -- remove file
+ local prefixfile = path.absolute(relativefile, prefixdir)
+ os.tryrm(prefixfile)
+
+ -- remove it if the parent directory is empty
+ local parentdir = path.directory(prefixfile)
+ while parentdir and os.isdir(parentdir) and os.emptydir(parentdir) do
+ os.tryrm(parentdir)
+ parentdir = path.directory(parentdir)
end
end
- assert(#links > 0, "the library files not found in package %s", name)
-
- -- make xmake.lua
- local file = io.open(path.join(packagedir, "xmake.lua"), "w")
- if file then
-
- -- the xmake.lua content
- local content = [[
--- the %s package
-option("%s")
-
- -- show menu
- set_showmenu(true)
-
- -- set category
- set_category("package")
-
- -- set description
- set_description("The %s package")
-
- -- add defines to config.h if checking ok
- add_defines_h("$(prefix)_PACKAGE_HAVE_%s")
-
- -- add links for checking
- add_links("%s")
-
- -- add link directories
- add_linkdirs("lib/$(plat)/$(arch)")
-
- -- add include directories
- add_includedirs("include/$(plat)/$(arch)")
-]]
-
- -- save file
- file:writef(content, name, name, name, name:upper(), table.concat(links, "\", \""))
-
- -- exit file
- file:close()
- end
-end
-
--- uninstall package from the prefix directory
-function _uninstall_prefix(package)
-
- -- TODO
end
-- install package to the prefix directory
@@ -165,7 +103,7 @@ function _install_prefix(package)
finally
{
function ()
- -- save the prefix info to file
+ -- save the prefix list to file
io.save(package:prefixfile(), relativefiles)
end
}
@@ -233,11 +171,6 @@ function main(package)
end
end
- -- generate package(.pkg) from the install directory
- if package:kind() ~= "binary" then
- _generate_package(package)
- end
-
-- install to the prefix directory
_install_prefix(package)
diff --git a/xmake/actions/require/info.lua b/xmake/actions/require/info.lua
index 7a7db56c9..38544171b 100644
--- a/xmake/actions/require/info.lua
+++ b/xmake/actions/require/info.lua
@@ -112,12 +112,12 @@ function main(requires)
-- show cache directory
cprint(" -> ${magenta}cachedir${clear}: %s", instance:cachedir())
+ -- show prefix directory
+ cprint(" -> ${magenta}prefixdir${clear}: %s", instance:prefixdir())
+
-- show install directory
cprint(" -> ${magenta}installdir${clear}: %s", instance:installdir())
- -- show package directory
- cprint(" -> ${magenta}packagedir${clear}: %s", instance:directory())
-
-- end
print("")
end
diff --git a/xmake/actions/require/remove.lua b/xmake/actions/require/remove.lua
index 98bfa61c3..155315025 100644
--- a/xmake/actions/require/remove.lua
+++ b/xmake/actions/require/remove.lua
@@ -70,17 +70,17 @@ function main(requires)
-- remove all packages
for _, instance in ipairs(package.load_packages(requires, {nodeps = true, requires_extra = requires_extra})) do
local requireinfo = instance:requireinfo() or {}
+ --[[
if os.isdir(instance:directory()) then
- -- remove package directory
- os.rm(instance:directory())
+ -- TODO remove package directory
-- trace
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]]
end
-- leave environment
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index f6afc7845..a506a8751 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -193,12 +193,28 @@ end
-- get the prefix directory
function _instance:prefixdir(...)
- return package.prefixdir(self:from("global"), ...)
+
+ -- make the given prefix directory
+ local dir = path.join(self:from("global") and global.directory() or config.directory(), "prefix", self:debug() and "debug" or "release", config.get("plat") or os.host(), config.get("arch") or os.arch(), ...)
+
+ -- ensure the prefix directory
+ if not os.isdir(dir) then
+ os.mkdir(dir)
+ end
+ return dir
end
--- get the prefix info file
+-- get the prefix list
+function _instance:prefixlist()
+ local prefixfile = self:prefixfile()
+ if os.isfile(prefixfile) then
+ return io.load(prefixfile)
+ end
+end
+
+-- get the prefix list file
function _instance:prefixfile()
- return path.join(self:prefixdir(".info"), self:name() .. "-" .. (self:version_str() or "") .. ".txt")
+ return path.join(self:prefixdir(".list"), self:name() .. "-" .. (self:version_str() or "") .. ".txt")
end
-- get the downloaded original file
@@ -211,11 +227,6 @@ function _instance:originfile_set(filepath)
self._ORIGINFILE = filepath
end
--- get the directory of this package
-function _instance:directory()
- return path.join(package.directory(self:from("global")), self:name():sub(1, 1):lower(), self:name(), self:version_str(), self:debug() and "debug" or "release")
-end
-
-- get versions
function _instance:versions()
@@ -408,13 +419,14 @@ function _instance:fetch(opt)
-- import find_package
self._find_package = self._find_package or sandbox_module.import("lib.detect.find_package", {anonymous = true})
- -- fetch it from the package directories first
+ -- TODO fetch it from the package directories first
+ --[[
local packagedir = self:directory()
if not fetchinfo and packagedir then
-- 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
+ end]]
-- fetch it from the system directories
if not fetchinfo then
@@ -534,35 +546,11 @@ function package.apis()
}
end
--- get package directory
-function package.directory(is_global)
-
- -- get directory
- if is_global then
- return path.join(global.directory(), "packages")
- else
- return path.join(config.directory(), "packages")
- end
-end
-
-- the cache directory
function package.cachedir()
return path.join(global.directory(), "cache", "packages")
end
--- get the prefix directory
-function package.prefixdir(is_global, ...)
-
- -- make the given prefix directory
- local dir = path.join(package.directory(is_global), "prefix", config.get("plat") or os.host(), config.get("arch") or os.arch(), ...)
-
- -- ensure the prefix directory
- if not os.isdir(dir) then
- os.mkdir(dir)
- end
- return dir
-end
-
-- load the package from the system directories
function package.load_from_system(packagename)
diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua
index 0c286be72..bbcad0ec3 100644
--- a/xmake/core/sandbox/modules/import/core/package/package.lua
+++ b/xmake/core/sandbox/modules/import/core/package/package.lua
@@ -35,16 +35,6 @@ function sandbox_core_package_package.cachedir()
return package.cachedir()
end
--- get package directory
-function sandbox_core_package_package.directory(is_global)
- return package.directory(is_global)
-end
-
--- get the prefix directory
-function sandbox_core_package_package.prefixdir(is_global, ...)
- return package.prefixdir(is_global, ...)
-end
-
-- load the package from the project file
function sandbox_core_package_package.load_from_project(packagename)