summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-18 00:53:25 +0800
committerruki <[email protected]>2022-10-18 00:53:25 +0800
commit16e25c578ff2227f8f88e894ed3711944fe49f44 (patch)
tree09c0e7c2a6391cc79e7a18edf400bff1478d0767
parent91cb3829a4153cacd1abc96e292cfe34c6c492e7 (diff)
improve to find_package
-rw-r--r--xmake/modules/package/manager/xmake/find_package.lua92
1 files changed, 54 insertions, 38 deletions
diff --git a/xmake/modules/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua
index e184a5685..44668d503 100644
--- a/xmake/modules/package/manager/xmake/find_package.lua
+++ b/xmake/modules/package/manager/xmake/find_package.lua
@@ -28,11 +28,37 @@ import("core.language.language")
import("lib.detect.find_file")
import("lib.detect.find_library")
--- find result from vars
-function _find_result_from_vars(name, vars, opt)
- opt = opt or {}
- vars = vars or {}
- local installdir = opt.installdir
+-- 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)
-- save includedirs to result (maybe only include and no links)
local result = {}
@@ -50,8 +76,21 @@ function _find_result_from_vars(name, vars, opt)
-- get links and link directories
local links = {}
local linkdirs = {}
+ local components = opt.components
if vars.links then
table.join2(links, vars.links)
+ elseif components and manifest.components then
+ -- get links from components
+ local vars = manifest.components.vars
+ if vars then
+ for _, component_name in ipairs(components) do
+ local component_vars = vars[component_name]
+ if component_vars and component_vars.links then
+ table.join2(links, component_vars.links)
+ end
+ end
+ end
+ links = table.reverse_unique(links)
else
-- we scan links automatically
local found = false
@@ -126,7 +165,7 @@ function _find_result_from_vars(name, vars, opt)
end
end
if result.links then
- result.links = table.unique(result.links)
+ result.links = table.reverse_unique(result.links)
end
if result.linkdirs then
result.linkdirs = table.unique(result.linkdirs)
@@ -141,41 +180,18 @@ function _find_result_from_vars(name, vars, 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
+ -- save components
+ if result and components and manifest.components then
+ local vars = manifest.components.vars
+ if vars then
+ for _, component_name in ipairs(components) do
+ result.components = result.components or {}
+ result.components[component_name] = vars[component_name]
+ end
+ end
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
local projectdir = os.projectdir()