summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-01-10 23:58:01 +0800
committerruki <[email protected]>2019-01-10 17:48:06 +0800
commit89271a60c4b4e56e9801dc11241b5d67cd3b2a2b (patch)
treedea054a6d7c3cc819447708a12d33d03e69443ca
parent6d2449f9d3c5aa774de7cec9da4953ea9fefb27a (diff)
fix find_program with path env
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua37
2 files changed, 29 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c2dbfe67b..43859f86c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@
* Fix cannot call `set_optimize()` to set optimization flags when exists `add_rules("mode.release")`
* [#289](https://github.com/tboox/xmake/issues/289): Fix unarchive gzip file failed on windows
* [#296](https://github.com/tboox/xmake/issues/296): Fix `option.add_includedirs` for cuda
+* [#321](https://github.com/tboox/xmake/issues/321): Fix find program bug with $PATH envirnoment
## v2.2.3
@@ -559,6 +560,7 @@
* 修复无法通过 `set_optimize()` 设置优化选项,如果存在`add_rules("mode.release")`的情况下
* [#289](https://github.com/tboox/xmake/issues/289): 修复在windows下解压gzip文件失败
* [#296](https://github.com/tboox/xmake/issues/296): 修复`option.add_includedirs`对cuda编译不生效
+* [#321](https://github.com/tboox/xmake/issues/321): 修复PATH环境改动后查找工具不对问题
## v2.2.3
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 84e5df01d..18c9be5e3 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -79,8 +79,8 @@ function sandbox_lib_detect_find_program._check(program, opt)
return ok
end
--- find program
-function sandbox_lib_detect_find_program._find(name, pathes, opt)
+-- find program from the given pathes
+function sandbox_lib_detect_find_program._find_from_pathes(name, pathes, opt)
-- attempt to check it from the given directories
if not path.is_absolute(name) then
@@ -115,6 +115,16 @@ function sandbox_lib_detect_find_program._find(name, pathes, opt)
end
end
end
+end
+
+-- find program
+function sandbox_lib_detect_find_program._find(name, pathes, opt)
+
+ -- attempt to check it from the given directories
+ local program_path = sandbox_lib_detect_find_program._find_from_pathes(name, pathes, opt)
+ if program_path then
+ return program_path
+ end
-- attempt to check it from regists
if os.host() == "windows" then
@@ -122,7 +132,7 @@ function sandbox_lib_detect_find_program._find(name, pathes, opt)
if not program_name:endswith(".exe") then
program_name = program_name .. ".exe"
end
- local program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name)
+ program_path = winos.registry_query("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" .. program_name)
if program_path then
-- check it
program_path = program_path:trim()
@@ -146,6 +156,19 @@ function sandbox_lib_detect_find_program._find(name, pathes, opt)
end
end
+ -- attempt to check it from the some default system directories
+ local syspathes = {}
+ if os.host() ~= "windows" then
+ table.insert(syspathes, "/usr/local/bin")
+ table.insert(syspathes, "/usr/bin")
+ end
+ if #syspathes > 0 then
+ program_path = sandbox_lib_detect_find_program._find_from_pathes(name, syspathes, opt)
+ if program_path then
+ return program_path
+ end
+ end
+
-- attempt to check it directly in current environment
--
-- @note must be detected at the end, because full path is more accurate
@@ -204,15 +227,9 @@ function sandbox_lib_detect_find_program.main(name, opt)
return utils.ifelse(result, result, nil)
end
- -- add default search pathes
- local pathes = opt.pathes
- if os.host() ~= "windows" then
- pathes = table.join(table.wrap(pathes), "/usr/local/bin", "/usr/bin")
- end
-
-- find executable program
checking = utils.ifelse(coroutine_running, name, nil)
- result = sandbox_lib_detect_find_program._find(name, pathes, opt)
+ result = sandbox_lib_detect_find_program._find(name, opt.pathes, opt)
checking = nil
-- cache result