summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-18 00:45:55 +0800
committerruki <[email protected]>2022-10-18 00:45:55 +0800
commit91cb3829a4153cacd1abc96e292cfe34c6c492e7 (patch)
treeb906ff27c1857d11456a95c6770207bd26ba3153
parent24035843ac61249e110758f1e5ab9ea40b08cbfd (diff)
improve to find_package
-rw-r--r--xmake/core/package/package.lua1
-rw-r--r--xmake/modules/package/manager/xmake/find_package.lua74
2 files changed, 44 insertions, 31 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index e78034421..74e85debb 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1548,6 +1548,7 @@ function _instance:find_package(name, opt)
plat = self:plat(),
arch = self:arch(),
configs = table.join(self:configs(), opt.configs),
+ components = self:get("components"),
buildhash = self:buildhash(), -- for xmake package or 3rd package manager, e.g. go:: ..
cachekey = opt.cachekey or "fetch_package_system",
external = opt.external,
diff --git a/xmake/modules/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua
index 8ba890591..e184a5685 100644
--- a/xmake/modules/package/manager/xmake/find_package.lua
+++ b/xmake/modules/package/manager/xmake/find_package.lua
@@ -28,37 +28,11 @@ import("core.language.language")
import("lib.detect.find_file")
import("lib.detect.find_library")
--- find package from the repository (maybe only include and no links)
-function _find_package_from_repo(name, opt)
-
- -- check options
- if not opt.require_version or not opt.buildhash then
- return
- end
-
- -- find the manifest file of package, e.g. ~/.xmake/packages/z/zlib/1.1.12/ed41d5327fad3fc06fe376b4a94f62ef/manifest.txt
- local packagedirs = {}
- if opt.installdir then
- table.insert(packagedirs, opt.installdir)
- else
- table.insert(packagedirs, path.join(package.installdir(), name:lower():sub(1, 1), name:lower(), opt.require_version, opt.buildhash))
- end
- local manifest_file = find_file("manifest.txt", packagedirs)
- if not manifest_file then
- return
- end
-
- -- load manifest info
- local manifest = io.load(manifest_file)
- if not manifest then
- return
- end
-
- -- get manifest variables
- local vars = manifest.vars or {}
-
- -- get install directory of this package
- local installdir = path.directory(manifest_file)
+-- find result from vars
+function _find_result_from_vars(name, vars, opt)
+ opt = opt or {}
+ vars = vars or {}
+ local installdir = opt.installdir
-- save includedirs to result (maybe only include and no links)
local result = {}
@@ -154,6 +128,9 @@ function _find_package_from_repo(name, opt)
if result.links then
result.links = table.unique(result.links)
end
+ if result.linkdirs then
+ result.linkdirs = table.unique(result.linkdirs)
+ end
if result.libfiles then
result.libfiles = table.unique(table.join(result.libfiles, libfiles))
end
@@ -164,6 +141,40 @@ function _find_package_from_repo(name, opt)
result[name] = values
end
end
+ return result
+end
+
+-- find package from the repository (maybe only include and no links)
+function _find_package_from_repo(name, opt)
+
+ -- check options
+ if not opt.require_version or not opt.buildhash then
+ return
+ end
+
+ -- find the manifest file of package, e.g. ~/.xmake/packages/z/zlib/1.1.12/ed41d5327fad3fc06fe376b4a94f62ef/manifest.txt
+ local packagedirs = {}
+ if opt.installdir then
+ table.insert(packagedirs, opt.installdir)
+ else
+ table.insert(packagedirs, path.join(package.installdir(), name:lower():sub(1, 1), name:lower(), opt.require_version, opt.buildhash))
+ end
+ local manifest_file = find_file("manifest.txt", packagedirs)
+ if not manifest_file then
+ return
+ end
+
+ -- load manifest info
+ local manifest = io.load(manifest_file)
+ if not manifest then
+ return
+ end
+
+ -- get install directory of this package
+ local installdir = path.directory(manifest_file)
+
+ -- find result from the global vars
+ local result = _find_result_from_vars(name, manifest.vars, {installdir = installdir})
-- update the project references file
if result then
@@ -179,6 +190,7 @@ function _find_package_from_repo(name, opt)
-- get version and license
result.version = manifest.version or path.filename(path.directory(path.directory(manifest_file)))
result.license = manifest.license
+ print(result)
return result
end