summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-17 13:05:20 +0800
committerruki <[email protected]>2017-05-17 13:05:20 +0800
commit5b5b05522da5ea1834e14de2bc5b9029c53bd422 (patch)
tree7584c339be4514f5990e3629deecb0458b9b0949
parentcfb1dd7f7b3ece03825c686651c2f88ac65b33d5 (diff)
use which to find program
-rw-r--r--xmake/core/base/os.lua17
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua15
-rw-r--r--xmake/core/sandbox/modules/os.lua19
3 files changed, 34 insertions, 17 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index c78d41c67..8f3e32ecb 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -589,7 +589,7 @@ function os.isexec(filepath)
-- check permission
-- is *.exe for windows?
- if xmake._HOST == "windows" and not filepath:find("%.exe") then
+ if os.host() == "windows" and not filepath:find("%.exe") then
filepath = filepath .. ".exe"
end
@@ -597,6 +597,21 @@ function os.isexec(filepath)
return os.isfile(filepath)
end
+-- get the system host
+function os.host()
+ return xmake._HOST
+end
+
+-- get the system architecture
+function os.arch()
+ return xmake._ARCH
+end
+
+-- get the system null device
+function os.nuldev()
+ return xmake._NULDEV
+end
+
-- get version info
function os.versioninfo()
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index 0c811a8de..5eaadfe9f 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -80,7 +80,6 @@ function sandbox_lib_detect_find_program._find(name, dirs, check)
-- the program path
local program_path = path.join(dir, name)
if os.isexec(program_path) then
-
-- check it
if sandbox_lib_detect_find_program._check(program_path, check) then
return program_path
@@ -88,6 +87,20 @@ function sandbox_lib_detect_find_program._find(name, dirs, check)
end
end
end
+
+ -- attempt to check it use `which program` command
+ if os.host() ~= "windows" then
+ local ok, program_path = os.iorunv("which", {name})
+ if ok and program_path then
+ -- check it
+ program_path = program_path:trim()
+ if os.isexec(program_path) then
+ if sandbox_lib_detect_find_program._check(program_path, check) then
+ return program_path
+ end
+ end
+ end
+ end
end
-- find program
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index b2a41aa31..04fac619d 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -34,13 +34,17 @@ local vformat = require("sandbox/modules/vformat")
local sandbox_os = sandbox_os or {}
-- inherit some builtin interfaces
+sandbox_os.host = os.host
+sandbox_os.arch = os.arch
sandbox_os.exit = os.exit
sandbox_os.date = os.date
sandbox_os.time = os.time
sandbox_os.argv = os.argv
sandbox_os.argw = os.argw
sandbox_os.mtime = os.mtime
+sandbox_os.sleep = os.sleep
sandbox_os.mclock = os.mclock
+sandbox_os.nuldev = os.nuldev
sandbox_os.emptydir = os.emptydir
-- copy file or directory
@@ -395,21 +399,6 @@ function sandbox_os.raise(msg, ...)
os.raise(msg, ...)
end
--- get the system host
-function sandbox_os.host()
- return xmake._HOST
-end
-
--- get the system architecture
-function sandbox_os.arch()
- return xmake._ARCH
-end
-
--- get the system null device
-function sandbox_os.nuldev()
- return xmake._NULDEV
-end
-
-- get the envirnoment variables
function sandbox_os.getenv(name)