summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect
diff options
context:
space:
mode:
authorruki <[email protected]>2017-07-17 23:24:16 +0800
committerruki <[email protected]>2017-07-17 23:24:34 +0800
commit7cac00bb9cace801c6db9758d2a01d2711738926 (patch)
tree40831686913090534c1e2b5ddb54399aa5b6bf11 /xmake/modules/lib/detect
parent33144e73eae59ee7d934fd77673aac5a5a5cb0d1 (diff)
add add_moduledirs api and improve import
Diffstat (limited to 'xmake/modules/lib/detect')
-rw-r--r--xmake/modules/lib/detect/features.lua8
-rw-r--r--xmake/modules/lib/detect/find_tool.lua12
-rw-r--r--xmake/modules/lib/detect/find_toolname.lua12
-rw-r--r--xmake/modules/lib/detect/has_flags.lua8
4 files changed, 17 insertions, 23 deletions
diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua
index be1974a20..3992e52d5 100644
--- a/xmake/modules/lib/detect/features.lua
+++ b/xmake/modules/lib/detect/features.lua
@@ -76,11 +76,9 @@ function main(name, opt)
-- detect.tools.xxx.features(opt)?
_g._checking = ifelse(coroutine_running, key, nil)
- if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", tool.name, "features.lua")) then
- local features = import("detect.tools." .. tool.name .. ".features")
- if features then
- result = features(opt)
- end
+ local features = import("detect.tools." .. tool.name .. ".features", {try = true})
+ if features then
+ result = features(opt)
end
_g._checking = nil
diff --git a/xmake/modules/lib/detect/find_tool.lua b/xmake/modules/lib/detect/find_tool.lua
index 58289b0dc..6d74a7804 100644
--- a/xmake/modules/lib/detect/find_tool.lua
+++ b/xmake/modules/lib/detect/find_tool.lua
@@ -30,13 +30,11 @@ import("lib.detect.find_toolname")
-- find tool from modules
function _find_from_modules(name, opt)
- -- "detect.tools.find_xxx" exists?
- if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", "find_" .. name .. ".lua")) then
- local find_tool = import("detect.tools.find_" .. name)
- if find_tool then
- local program, version, toolname = find_tool(opt)
- return {name = toolname or name, program = program, version = version}
- end
+ -- attempt to import "detect.tools.find_xxx"
+ local find_tool = import("detect.tools.find_" .. name, {try = true})
+ if find_tool then
+ local program, version, toolname = find_tool(opt)
+ return {name = toolname or name, program = program, version = version}
end
end
diff --git a/xmake/modules/lib/detect/find_toolname.lua b/xmake/modules/lib/detect/find_toolname.lua
index ce3b4f1f1..d997eb879 100644
--- a/xmake/modules/lib/detect/find_toolname.lua
+++ b/xmake/modules/lib/detect/find_toolname.lua
@@ -22,14 +22,14 @@
-- @file find_toolname.lua
--
+-- imports
+import("core.sandbox.module")
+
-- find tool name from the given program
function _find(program)
- -- get tool directory
- local tooldir = path.join(os.programdir(), "modules", "detect", "tools")
-
-- attempt to find it directly first
- if os.isfile(path.join(tooldir, "find_" .. program .. ".lua")) then
+ if module.find("detect.tools.find_" .. program) then
return program
end
@@ -50,7 +50,7 @@ function _find(program)
-- find_toolname.lua exists? found
local toolname = name:gsub("[%+%-]", function (ch) return ifelse(ch == "+", "x", "_") end)
- if os.isfile(path.join(tooldir, "find_" .. toolname .. ".lua")) then
+ if module.find("detect.tools.find_" .. toolname) then
return toolname
end
@@ -65,7 +65,7 @@ function _find(program)
-- find_toolname.lua exists? found
toolname = name:gsub("%+", "x")
- if os.isfile(path.join(tooldir, "find_" .. toolname .. ".lua")) then
+ if module.find("detect.tools.find_" .. toolname) then
return toolname
end
end
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index 614049821..68069b3db 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -103,11 +103,9 @@ function main(name, flags, opt)
-- detect.tools.xxx.has_flags(flags, opt)?
_g._checking = ifelse(coroutine_running, key, nil)
- if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", tool.name, "has_flags.lua")) then
- local hasflags = import("detect.tools." .. tool.name .. ".has_flags")
- if hasflags then
- result = hasflags(flags, opt)
- end
+ local hasflags = import("detect.tools." .. tool.name .. ".has_flags", {try = true})
+ if hasflags then
+ result = hasflags(flags, opt)
else
result = try { function () os.runv(tool.program, flags); return true end }
end