summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-10-20 22:47:24 +0800
committerruki <[email protected]>2017-10-20 10:44:24 +0800
commit365ce94fe03a3d5330bfd3f76b1e703afff73da8 (patch)
tree6570299cde02e228f2bd853d10596736e61757a7
parent10bb94a674e52aee141ebec8badca5595bd5c409 (diff)
fix current directory when running target
-rw-r--r--CHANGELOG.md8
-rw-r--r--tests/projects/requires/xmake.lua2
-rw-r--r--xmake/actions/run/main.lua13
3 files changed, 20 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8cdc35ede..4396db45e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@
* Add `XMAKE_LOGFILE` environment variable to dump the output info to file
* Support tinyc compiler
+### Bugs fixed
+
+* [#145](https://github.com/tboox/xmake/issues/145): Fix the current directory when running target
+
## v2.1.7
### New features
@@ -382,6 +386,10 @@
* 添加`XMAKE_LOGFILE`环境变量,启用输出到日志文件
* 添加对tinyc编译器的支持
+### Bugs修复
+
+* [#145](https://github.com/tboox/xmake/issues/145): 修复运行target的当前目录环境
+
## v2.1.7
### 新特性
diff --git a/tests/projects/requires/xmake.lua b/tests/projects/requires/xmake.lua
index a5747c1c1..9b2acfc4a 100644
--- a/tests/projects/requires/xmake.lua
+++ b/tests/projects/requires/xmake.lua
@@ -1,7 +1,7 @@
-- define package
package("mbedtls")
set_urls("https://github.com/ARMmbed/mbedtls.git")
- add_deps("https://github.com/glennrp/libpng.git@libpng >=1.6.28", {optional = true})
+ add_deps("https://github.com/glennrp/libpng.git@libpng >=1.6.28")
package_end()
-- group packages
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index e80072347..bd69d72f9 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -37,16 +37,25 @@ function _on_run_target(target)
-- get kind
if target:targetkind() == "binary" then
+ -- get the absolute target file path
+ local targetfile = path.absolute(target:targetfile())
+
+ -- enter the target directory
+ local oldir = os.cd(path.directory(target:targetfile()))
+
-- debugging?
if option.get("debug") then
-- debug it
- debugger.run(target:targetfile(), option.get("arguments"))
+ debugger.run(targetfile, option.get("arguments"))
else
-- run it
- os.execv(target:targetfile(), option.get("arguments"))
+ os.execv(targetfile, option.get("arguments"))
end
+
+ -- restore the previous directory
+ os.cd(oldir)
end
end