summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-03-12 00:43:33 +0800
committerruki <[email protected]>2019-03-11 22:21:19 +0800
commit08162f29172031440607bba5bf0e759a3c0ba447 (patch)
treece83056998171f3b496b77972dc2675243d4c3a1
parent6e4c9f31810a9b5053b2d0b72056fd5552bcd8b4 (diff)
improve find xmake packages
-rw-r--r--xmake/core/package/package.lua57
-rw-r--r--xmake/modules/package/manager/xmake/find_package.lua87
2 files changed, 73 insertions, 71 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index f213cb234..111f39560 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -260,6 +260,8 @@ function _instance:manifest_save()
manifest.arch = self:arch()
manifest.mode = self:mode()
manifest.configs = self:configs()
+ manifest.envs = self:envs()
+ manifest.vars = self:vars()
local repo = self:repo()
if repo then
manifest.repo = {}
@@ -275,29 +277,54 @@ function _instance:manifest_save()
end
end
--- get prefix variables
+-- get the exported variables
+function _instance:vars()
+ local vars = self._VARS
+ if not vars then
+ vars = {}
+ self._VARS = vars
+ end
+ return vars
+end
+
+-- get the given variable
function _instance:getvar(name)
- -- TODO
+ return self:vars()[name]
end
--- set prefix variables
+-- set the given variable
function _instance:setvar(name, ...)
+ self:vars()[name] = {...}
end
--- add prefix variables
+-- add the given variable
function _instance:addvar(name, ...)
+ self:vars()[name] = table.join(self:vars()[name] or {}, ...)
+end
+
+-- get the exported environments
+function _instance:envs()
+ local envs = self._ENVS
+ if not envs then
+ envs = {}
+ self._ENVS = envs
+ end
+ return envs
end
--- get environment variables
+-- get the given environment variable
function _instance:getenv(name)
+ return self:envs()[name]
end
--- set environment variables
+-- set the given environment variable
function _instance:setenv(name, ...)
+ self:envs()[name] = {...}
end
--- add values to environment variable
+-- add the given environment variable
function _instance:addenv(name, ...)
+ self:envs()[name] = table.join(self:envs()[name] or {}, ...)
end
-- get user private data
@@ -565,8 +592,7 @@ function _instance:fetch(opt)
-- only fetch it from the xmake repository first
if not fetchinfo and system ~= true and not self:is3rd() then
- fetchinfo = self._find_package("xmake::" .. self:name(), {mode = self:mode(),
- version = require_ver,
+ fetchinfo = self._find_package("xmake::" .. self:name(), {version = self:version_str(),
cachekey = "fetch_package_xmake",
buildhash = self:buildhash(),
force = opt.force})
@@ -697,19 +723,6 @@ function package.installdir()
return path.join(global.directory(), "packages")
end
--- get environment variables
-function package.getenv(is_global, mode, plat, arch, name)
- -- TODO
-end
-
--- add values to environment variable
-function package.addenv(is_global, mode, plat, arch, name, values)
-end
-
--- remove values to environment variable
-function package.delenv(is_global, mode, plat, arch, name, values)
-end
-
-- load the package from the system directories
function package.load_from_system(packagename)
diff --git a/xmake/modules/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua
index a3e907539..915552257 100644
--- a/xmake/modules/package/manager/xmake/find_package.lua
+++ b/xmake/modules/package/manager/xmake/find_package.lua
@@ -27,6 +27,7 @@ import("core.base.global")
import("core.project.config")
import("core.project.option")
import("core.project.target")
+import("core.package.package")
import("core.language.language")
import("lib.detect.find_file")
import("lib.detect.find_library")
@@ -34,86 +35,76 @@ import("lib.detect.find_library")
-- find package from the repository (maybe only include and no links)
function _find_package_from_repo(name, opt)
- -- get build mode, e.g. debug_f7821231
- local mode = table.concat({opt.mode or "release", opt.buildhash}, '_')
-
- -- 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
- table.insert(prefixdirs, path.join(opt.islocal and config.directory() or global.directory(), "prefix", platsubdirs, mode))
- end
-
- -- find the prefix info file of package, .e.g prefix/info/z/zlib/1.2.11/info.txt
+ -- find the manifest file of package, .e.g ~/.xmake/packages/z/zlib/1.1.12/ed41d5327fad3fc06fe376b4a94f62ef/manifest.txt
local packagedirs = {}
- local packagepath = path.join(name:sub(1, 1), name, "*")
- table.insert(packagedirs, path.join(opt.islocal and config.directory() or global.directory(), "prefix", "info", platsubdirs, mode, packagepath))
- local prefixfile = find_file("info.txt", packagedirs)
- if not prefixfile then
+ table.insert(packagedirs, path.join(package.installdir(), name:sub(1, 1), name, opt.version or "*", opt.buildhash))
+ local manifest_file = find_file("manifest.txt", packagedirs)
+ if not manifest_file then
return
end
- -- load prefix info
- local prefixinfo = io.load(prefixfile)
- if not prefixinfo then
+ -- load manifest info
+ local manifest = io.load(manifest_file)
+ if not manifest then
return
end
- -- get prefix directory of this package
- local prefixdir = path.translate(path.directory(path.directory(path.directory(path.directory(prefixfile)))):gsub("[/\\]prefix[/\\]info[/\\]", "/prefix/"))
+ -- get manifest variables
+ local vars = manifest.vars or {}
+
+ -- get install directory of this package
+ local installdir = path.directory(manifest_file)
-- save includedirs to result (maybe only include and no links)
local result = {}
local includedirs = {}
- for _, includedir in ipairs(prefixinfo.includedirs) do
- table.insert(includedirs, path.join(prefixdir, includedir))
+ for _, includedir in ipairs(vars.includedirs) do
+ table.insert(includedirs, path.join(installdir, includedir))
end
if #includedirs == 0 then
- table.insert(includedirs, path.join(prefixdir, "include"))
+ table.insert(includedirs, path.join(installdir, "include"))
end
result.includedirs = table.unique(includedirs)
-- get links and link directories
local links = {}
local linkdirs = {}
- for _, linkdir in ipairs(prefixinfo.linkdirs) do
- table.insert(linkdirs, path.join(prefixdir, linkdir))
+ for _, linkdir in ipairs(vars.linkdirs) do
+ table.insert(linkdirs, path.join(installdir, linkdir))
end
- if prefixinfo.links then
- table.join2(links, prefixinfo.links)
+ if vars.links then
+ table.join2(links, vars.links)
end
- if prefixinfo.installed and (not prefixinfo.linkdirs or not prefixinfo.links) then
+ if not vars.linkdirs or not vars.links then
local found = false
- for _, line in ipairs(prefixinfo.installed) do
- line = line:trim()
- if line:endswith(".lib") or line:endswith(".a") then
+ for _, file in ipairs(os.files(path.join(installdir, "lib", "*"))) do
+ if file:endswith(".lib") or file:endswith(".a") then
found = true
- if not prefixinfo.linkdirs then
- table.insert(linkdirs, path.join(prefixdir, path.directory(line)))
+ if not vars.linkdirs then
+ table.insert(linkdirs, path.directory(file))
end
- if not prefixinfo.links then
- table.insert(links, target.linkname(path.filename(line)))
+ if not vars.links then
+ table.insert(links, target.linkname(path.filename(file)))
end
end
end
if not found then
- for _, line in ipairs(prefixinfo.installed) do
- line = line:trim()
- if line:endswith(".so") or line:endswith(".dylib") then
- if not prefixinfo.linkdirs then
- table.insert(linkdirs, path.join(prefixdir, path.directory(line)))
+ for _, file in ipairs(os.files(path.join(installdir, "lib", "*"))) do
+ if file:endswith(".so") or file:endswith(".dylib") then
+ if not vars.linkdirs then
+ table.insert(linkdirs, path.directory(file))
end
- if not prefixinfo.links then
- table.insert(links, target.linkname(path.filename(line)))
+ if not vars.links then
+ table.insert(links, target.linkname(path.filename(file)))
end
end
end
end
end
- -- add root include and link directories
+ -- add root link directories
if #linkdirs == 0 then
- table.insert(linkdirs, path.join(prefixdir, "lib"))
+ table.insert(linkdirs, path.join(installdir, "lib"))
end
-- uses name as links directly .e.g libname.a
@@ -135,16 +126,14 @@ function _find_package_from_repo(name, opt)
end
-- inherit the other prefix variables
- for name, values in pairs(prefixinfo) do
- if name ~= "links" and name ~= "linkdirs" and name ~= "includedirs" and name ~= "installed" and name ~= "prefixdir" then
+ for name, values in pairs(vars) do
+ if name ~= "links" and name ~= "linkdirs" and name ~= "includedirs" then
result[name] = values
end
end
-- get version
- result.version = path.filename(path.directory(prefixfile))
-
- -- ok
+ result.version = manifest.version or path.filename(path.directory(path.directory(manifest_file)))
return result
end