summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-08-20 15:56:56 +0800
committerOpportunityLiu <[email protected]>2019-08-20 15:56:56 +0800
commit58d8987b3030d211c468283b67ef31a937596128 (patch)
tree0c1133c5ef0607911f3739a6a963e0a74c09b510
parenta0d6bcacb190ce0538ded1c15336b6abdafbb7c2 (diff)
add vsxmake support
-rw-r--r--xmake/actions/run/main.lua117
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua33
2 files changed, 97 insertions, 53 deletions
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 358b28fbe..a3c1d5702 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -29,70 +29,81 @@ import("core.platform.platform")
import("core.platform.environment")
import("devel.debugger")
--- run target
-function _do_run_target(target)
- if target:targetkind() == "binary" then
-
- -- get the run directory of target
- local rundir = target:rundir()
+-- add search directories for all dependent shared libraries on windows
+function _make_runpath(target)
- -- get the absolute target file path
- local targetfile = path.absolute(target:targetfile())
+ if not (is_plat("windows") or (is_plat("mingw") and is_host("windows"))) then
+ return {}
+ end
- -- enter the run directory
- local oldir = os.cd(rundir)
+ local searchdirs = hashset.new()
+ local pathenv = {}
- -- add run environments
- local runenvs = target:get("runenvs")
- if runenvs then
- for name, values in pairs(runenvs) do
- os.addenv(name, unpack(table.wrap(values)))
- end
+ local function insert(dir)
+ if not path.is_absolute(dir) then
+ dir = path.absolute(dir, os.projectdir())
end
- local runenv = target:get("runenv")
- if runenv then
- for name, value in pairs(runenv) do
- os.setenv(name, unpack(table.wrap(value)))
- end
+ if searchdirs:insert(dir) then
+ table.insert(pathenv, dir)
end
+ end
- -- add search directories for all dependent shared libraries on windows
- if is_plat("windows") or (is_plat("mingw") and is_host("windows")) then
- local searchdirs = hashset.new()
- local pathenv = {}
- for _, linkdir in ipairs(target:get("linkdirs")) do
- if not path.is_absolute(linkdir) then
- linkdir = path.absolute(linkdir, os.projectdir())
- end
- if searchdirs:insert(linkdir) then
- table.insert(pathenv, linkdir)
- end
- end
- for _, dep in ipairs(target:orderdeps()) do
- if dep:targetkind() == "shared" then
- local depdir = dep:targetdir()
- if not path.is_absolute(depdir) then
- depdir = path.absolute(depdir, os.projectdir())
- end
- if searchdirs:insert(depdir) then
- table.insert(pathenv, depdir)
- end
- end
- end
- pathenv = table.reverse(pathenv)
- os.addenv("PATH", table.unpack(pathenv))
+ for _, linkdir in ipairs(target:get("linkdirs")) do
+ insert(linkdir)
+ end
+ for _, opt in ipairs(target:orderopts()) do
+ for _, linkdir in ipairs(opt:get("linkdirs")) do
+ insert(linkdir)
end
+ end
+ for _, dep in ipairs(target:orderdeps()) do
+ if dep:targetkind() == "shared" then
+ insert(dep:targetdir())
+ end
+ end
+ return pathenv
+end
+
+-- run target
+function _do_run_target(target)
+ if target:targetkind() ~= "binary" then
+ return
+ end
+
+ -- get the run directory of target
+ local rundir = target:rundir()
+
+ -- get the absolute target file path
+ local targetfile = path.absolute(target:targetfile())
- -- debugging?
- if option.get("debug") then
- debugger.run(targetfile, option.get("arguments"))
- else
- os.execv(targetfile, option.get("arguments"))
+ -- enter the run directory
+ local oldir = os.cd(rundir)
+
+ -- add run environments
+ local runenvs = target:get("runenvs")
+ if runenvs then
+ for name, values in pairs(runenvs) do
+ os.addenv(name, unpack(table.wrap(values)))
+ end
+ end
+ local runenv = target:get("runenv")
+ if runenv then
+ for name, value in pairs(runenv) do
+ os.setenv(name, unpack(table.wrap(value)))
end
+ end
- -- restore the previous directory
- os.cd(oldir)
+ os.addenv("PATH", table.unpack(_make_runpath(target)))
+
+ -- debugging?
+ if option.get("debug") then
+ debugger.run(targetfile, option.get("arguments"))
+ else
+ os.execv(targetfile, option.get("arguments"))
end
+
+ -- restore the previous directory
+ os.cd(oldir)
end
-- run target
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index 53200dd2c..0508ebbd8 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -21,6 +21,7 @@
-- imports
import("core.base.option")
import("core.base.semver")
+import("core.base.hashset")
import("core.project.config")
import("core.project.cache")
import("core.project.project")
@@ -129,6 +130,37 @@ function _get_values(target, name)
return table.unique(values)
end
+-- add search directories for all dependent shared libraries on windows
+function _make_runpath(target)
+
+ local searchdirs = hashset.new()
+ local pathenv = {}
+
+ local function insert(dir)
+ if not path.is_absolute(dir) then
+ dir = path.absolute(dir, os.projectdir())
+ end
+ if searchdirs:insert(dir) then
+ table.insert(pathenv, dir)
+ end
+ end
+
+ for _, linkdir in ipairs(target:get("linkdirs")) do
+ insert(linkdir)
+ end
+ for _, opt in ipairs(target:orderopts()) do
+ for _, linkdir in ipairs(opt:get("linkdirs")) do
+ insert(linkdir)
+ end
+ end
+ for _, dep in ipairs(target:orderdeps()) do
+ if dep:targetkind() == "shared" then
+ insert(dep:targetdir())
+ end
+ end
+ return pathenv
+end
+
-- make target info
function _make_targetinfo(mode, arch, target)
@@ -183,6 +215,7 @@ function _make_targetinfo(mode, arch, target)
local defs = table.imap(table.wrap(v), function(_, v) return vformat(v) end)
runenvs[k] = path.joinenv(defs)
end
+ runenvs["PATH"] = path.joinenv(_make_runpath(target)) .. ";" .. (runenvs["PATH"] or "$([System.Environment]::GetEnvironmentVariable('PATH'))")
local runenvstr = {}
for k, v in pairs(runenvs) do
table.insert(runenvstr, k .. "=" .. v)