summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-09-19 23:52:44 +0800
committerruki <[email protected]>2018-09-19 17:16:24 +0800
commitbc71d4f29362e0af30fb7446d1d71059acf4ba5b (patch)
tree18bc8051dfe2fffb0bd7e1491774911fc075016e
parentec49cc61a1b0c14319c63457e4d46ec7134afa8a (diff)
improve find_package for system
-rw-r--r--xmake/actions/require/package.lua17
-rw-r--r--xmake/core/package/package.lua19
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_package.lua24
3 files changed, 28 insertions, 32 deletions
diff --git a/xmake/actions/require/package.lua b/xmake/actions/require/package.lua
index 438f42219..3b579bd3b 100644
--- a/xmake/actions/require/package.lua
+++ b/xmake/actions/require/package.lua
@@ -45,6 +45,11 @@ import("repository")
-- add_requires("aaa_bbb_ccc >=1.5.1 <1.6.0", {optional = true, alias = "mypkg", debug = true})
-- add_requires("tbox", {config = {coroutine = true, abc = "xxx"}})
--
+-- {system = nil/true/false}:
+-- nil: get local or system packages
+-- true: only get system package
+-- false: only get local packages
+--
function _parse_require(require_str, requires_extra, parentinfo)
-- get it from cache first
@@ -423,15 +428,6 @@ function install_packages(requires, opt)
-- load packages
local packages = load_packages(requires, opt)
- --[[
- -- add path environment for fetch binary packages
- local pathes = os.getenv("PATH")
- for _, package in ipairs(packages) do
- if package:kind() == "binary" and package:supported() then
- os.addenv("PATH", package:installdir("bin"))
- end
- end]]
-
-- fetch packages (with system) from local first
if not option.get("force") then
process.runjobs(function (index)
@@ -513,9 +509,6 @@ function install_packages(requires, opt)
action.install(package)
end
- -- restore path environment
--- os.setenv("PATH", pathes)
-
-- ok
return packages
end
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 918db45b3..a07bfb375 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -425,23 +425,22 @@ function _instance:fetch(opt)
-- import find_package
self._find_package = self._find_package or sandbox_module.import("lib.detect.find_package", {anonymous = true})
+ -- nil: find local or system packages
+ -- true: only find system package
+ -- false: only find local packages
+ local system = opt.system or self:requireinfo().system
+
-- fetch it from the prefix directories first
- if not fetchinfo then
+ 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 = "package:fetch", force = opt.force})
if fetchinfo then fetchfrom = self._FROMKIND end
end
-- fetch it from the system directories
- if not fetchinfo then
- local system = opt.system or self:requireinfo().system
- if system == nil then -- find system package by default
- system = true
- end
- if system then
- fetchinfo = self._find_package(self:name(), {force = opt.force})
- if fetchinfo then fetchfrom = "system" end
- end
+ if not fetchinfo and system ~= false then
+ fetchinfo = self._find_package(self:name(), {force = opt.force, system = true})
+ if fetchinfo then fetchfrom = "system" end
end
end
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 089f65132..b0e87e302 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
@@ -334,21 +334,30 @@ function sandbox_lib_detect_find_package._find_from_systemdirs(name, opt)
end
-- find package
+--
+-- opt.system:
+-- nil: find local or system packages
+-- true: only find system package
+-- false: only find local packages
+--
function sandbox_lib_detect_find_package._find(name, opt)
-- init find scripts
local findscripts = {}
- -- find package from the prefix directories
- table.insert(findscripts, sandbox_lib_detect_find_package._find_from_prefixdirs)
+ -- we cannot find it if only find system packages
+ if opt.system ~= true then
+ -- find package from the prefix directories
+ table.insert(findscripts, sandbox_lib_detect_find_package._find_from_prefixdirs)
+ end
-- find package from the package directories
if opt.packagedirs then
table.insert(findscripts, sandbox_lib_detect_find_package._find_from_packagedirs)
end
- -- find system package
- if opt.system then
+ -- find system package if be not disabled
+ if opt.system ~= false then
-- find package from modules
table.insert(findscripts, sandbox_lib_detect_find_package._find_from_modules)
@@ -410,11 +419,6 @@ function sandbox_lib_detect_find_package.main(name, opt)
opt.arch = opt.arch or config.get("arch") or os.arch()
opt.mode = opt.mode or config.get("mode")
- -- enable system package by default
- if opt.system == nil then
- opt.system = true
- end
-
-- init cache key
local key = "find_package_" .. opt.plat .. "_" .. opt.arch
if opt.cachekey then
@@ -432,7 +436,7 @@ function sandbox_lib_detect_find_package.main(name, opt)
result = sandbox_lib_detect_find_package._find(name, opt)
-- cache result
- cacheinfo[name] = utils.ifelse(result, result, false)
+ cacheinfo[name] = result and result or false
cache.save(key, cacheinfo)
-- trace