From c4dbeb54523b8773c030fd23e227fcc28c84f778 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 21 Aug 2019 09:49:29 +0800 Subject: move to common file --- xmake/actions/run/main.lua | 52 ++----------- xmake/modules/private/action/run/make_runenvs.lua | 92 +++++++++++++++++++++++ xmake/plugins/project/vsxmake/getinfo.lua | 48 +++--------- 3 files changed, 108 insertions(+), 84 deletions(-) create mode 100644 xmake/modules/private/action/run/make_runenvs.lua diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua index 0ec951d41..acea817a2 100644 --- a/xmake/actions/run/main.lua +++ b/xmake/actions/run/main.lua @@ -21,43 +21,13 @@ -- imports import("core.base.option") import("core.base.task") -import("core.base.hashset") import("core.project.config") import("core.base.global") import("core.project.project") import("core.platform.platform") import("core.platform.environment") import("devel.debugger") - --- add search directories for all dependent shared libraries on windows -function _make_runpath_on_windows(target) - - local pathenv = {} - local searchdirs = hashset.new() - 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 +import("private.action.run.make_runenvs") -- run target function _do_run_target(target) @@ -77,22 +47,12 @@ function _do_run_target(target) 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 + local addrunenvs, setrunenvs = make_runenvs(target) + for name, values in pairs(addrunenvs) do + os.addenv(name, unpack(table.wrap(values))) end - - -- add search directories for all dependent shared libraries on windows - if is_plat("windows") or (is_plat("mingw") and is_host("windows")) then - os.addenv("PATH", table.unpack(_make_runpath_on_windows(target))) + for name, value in pairs(setrunenvs) do + os.setenv(name, unpack(table.wrap(value))) end -- debugging? diff --git a/xmake/modules/private/action/run/make_runenvs.lua b/xmake/modules/private/action/run/make_runenvs.lua new file mode 100644 index 000000000..c42df29b4 --- /dev/null +++ b/xmake/modules/private/action/run/make_runenvs.lua @@ -0,0 +1,92 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki, OpportunityLiu +-- @file make_runenvs.lua +-- + +-- imports +import("core.base.hashset") + +-- add search directories for all dependent shared libraries on windows +function _make_runpath_on_windows(target) + + local pathenv = {} + local searchdirs = hashset.new() + 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 + +function main(target) + + assert(target) + + local set = {} + local add = {} + + -- add run environments + local runenvs = target:get("runenvs") + if runenvs then + for name, values in pairs(runenvs) do + add[name] = table.wrap(values) + end + end + local runenv = target:get("runenv") + if runenv then + for name, value in pairs(runenv) do + set[name] = table.wrap(value) + if add[name] then + utils.warning(format("both add_runenvs and set_runenv called on environment variable \"%s\", the former one will be ignored.", name)) + add[name] = nil + end + end + end + + if is_plat("windows") or (is_plat("mingw") and is_host("windows")) then + -- get PATH table + local path = add["PATH"] or set["PATH"] + if path == nil then + path = {} + add["PATH"] = path + end + + -- add search directories for all dependent shared libraries on windows + table.append(path, table.unpack(_make_runpath_on_windows(target))) + end + + return add, set +end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index b0d24b04e..f433cb157 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -30,6 +30,7 @@ import("core.platform.environment") import("core.tool.compiler") import("core.tool.linker") import("lib.detect.find_tool") +import("private.action.run.make_runenvs") import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()}) import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) @@ -130,37 +131,6 @@ 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) @@ -207,15 +177,17 @@ function _make_targetinfo(mode, arch, target) -- save runenvs local runenvs = {} - for k, v in pairs(target:get("runenvs")) do - local defs = table.imap(table.wrap(v), function(_, v) return vformat(v) end) - runenvs[k] = format("%s;$([System.Environment]::GetEnvironmentVariable('%s'))", path.joinenv(defs), k) + local addrunenvs, setrunenvs = make_runenvs(target) + for k, v in pairs(addrunenvs) do + if k:upper() == "PATH" then + runenvs[k] = format("%s;$([System.Environment]::GetEnvironmentVariable('%s'))", _make_dirs(v), k) + else + runenvs[k] = format("%s;$([System.Environment]::GetEnvironmentVariable('%s'))", path.joinenv(v), k) + end end - for k, v in pairs(target:get("runenv")) do - local defs = table.imap(table.wrap(v), function(_, v) return vformat(v) end) - runenvs[k] = path.joinenv(defs) + for k, v in pairs(setrunenvs) do + runenvs[k] = path.joinenv(v) end - runenvs["PATH"] = _make_dirs(_make_runpath(target)) .. ";" .. (runenvs["PATH"] or "$([System.Environment]::GetEnvironmentVariable('PATH'))") local runenvstr = {} for k, v in pairs(runenvs) do table.insert(runenvstr, k .. "=" .. v) -- cgit v1.3.1 From dde0c9c001ddb75d463be78562e00463a8058cb5 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 21 Aug 2019 10:04:26 +0800 Subject: fix nev --- scripts/installer.nsi | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/installer.nsi b/scripts/installer.nsi index 1b139447e..2a843d9cf 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -285,9 +285,19 @@ Section "Add to PATH" InstallPath !macroend ${If} $NOADMIN == "false" - !insertmacro AddRegPATH ${HKLM} + ; Remove the installation path from the $PATH environment variable first + ReadRegStr $R0 ${HKLM} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" + ${WordReplace} $R0 ";$InstDir" "" "+" $R1 + + ; Write the installation path into the $PATH environment variable + WriteRegExpandStr ${HKLM} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1;$InstDir" ${Else} - !insertmacro AddRegPATH ${HKCU} + ; Remove the installation path from the $PATH environment variable first + ReadRegStr $R0 ${HKCU} "Environment" "Path" + ${WordReplace} $R0 ";$InstDir" "" "+" $R1 + + ; Write the installation path into the $PATH environment variable + WriteRegExpandStr ${HKCU} "Environment" "Path" "$R1;$InstDir" ${EndIf} SectionEnd -- cgit v1.3.1 From c6786f85771ce5eed276c8dbf6831d5944c6b1c9 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 21 Aug 2019 10:09:11 +0800 Subject: fix #540 --- scripts/installer.nsi | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/scripts/installer.nsi b/scripts/installer.nsi index 2a843d9cf..b3723a3ca 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -275,15 +275,6 @@ SectionEnd Section "Add to PATH" InstallPath - !macro AddRegPATH RootKey - ; Remove the installation path from the $PATH environment variable first - ReadRegStr $R0 ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" - ${WordReplace} $R0 ";$InstDir" "" "+" $R1 - - ; Write the installation path into the $PATH environment variable - WriteRegExpandStr ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1;$InstDir" - !macroend - ${If} $NOADMIN == "false" ; Remove the installation path from the $PATH environment variable first ReadRegStr $R0 ${HKLM} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" @@ -333,23 +324,22 @@ FunctionEnd Section "Uninstall" - !macro RemoveReg RootKey - ; Remove registry keys - DeleteRegKey ${RootKey} ${RegUninstall} - - ; Remove the installation path from the $PATH environment variable - ReadRegStr $R0 ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" - ${WordReplace} $R0 ";$InstDir" "" "+" $R1 - ; MessageBox MB_OK|MB_USERICON '$R0 - $InstDir - $R1 ' - WriteRegExpandStr ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1" - !macroend - ; Remove directories used RMDir /r "$InstDir" + + ; Clean reg ${If} $NOADMIN == "false" - !insertmacro RemoveReg ${HKLM} + DeleteRegKey ${HKLM} ${RegUninstall} + ; Remove the installation path from the $PATH environment variable + ReadRegStr $R0 ${HKLM} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" + ${WordReplace} $R0 ";$InstDir" "" "+" $R1 + WriteRegExpandStr ${HKLM} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$R1" ${Else} - !insertmacro RemoveReg ${HKCU} + DeleteRegKey ${HKCU} ${RegUninstall} + ; Remove the installation path from the $PATH environment variable + ReadRegStr $R0 ${HKCU} "Environment" "Path" + ${WordReplace} $R0 ";$InstDir" "" "+" $R1 + WriteRegExpandStr ${HKCU} "Environment" "Path" "$R1" ${EndIf} SectionEnd -- cgit v1.3.1 From 734b4f3190501de2368241ed95940a6899e7ce0b Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 21 Aug 2019 13:20:52 +0800 Subject: rename --- xmake/modules/private/action/run/make_runenvs.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xmake/modules/private/action/run/make_runenvs.lua b/xmake/modules/private/action/run/make_runenvs.lua index c42df29b4..91a6185d2 100644 --- a/xmake/modules/private/action/run/make_runenvs.lua +++ b/xmake/modules/private/action/run/make_runenvs.lua @@ -76,16 +76,16 @@ function main(target) 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 -- get PATH table - local path = add["PATH"] or set["PATH"] - if path == nil then - path = {} - add["PATH"] = path + local pathenv = add["PATH"] or set["PATH"] + local runpath = _make_runpath_on_windows(target) + if pathenv == nil then + add["PATH"] = runpath + else + table.append(pathenv, table.unpack(runpath)) end - - -- add search directories for all dependent shared libraries on windows - table.append(path, table.unpack(_make_runpath_on_windows(target))) end return add, set -- cgit v1.3.1 From db2cb167b30b6b69af1ba2d4ea35e2fa4e56eca8 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 21 Aug 2019 13:29:47 +0800 Subject: make project more portable --- xmake/plugins/project/vsxmake/getinfo.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index f433cb157..8cfe46591 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -186,7 +186,16 @@ function _make_targetinfo(mode, arch, target) end end for k, v in pairs(setrunenvs) do - runenvs[k] = path.joinenv(v) + if #v == 1 then + v = v[1] + if path.is_absolute(v) and v:startswith(project.directory()) then + runenvs[k] = _make_dirs(v) + else + runenvs[k] = v[1] + end + else + runenvs[k] = path.joinenv(v) + end end local runenvstr = {} for k, v in pairs(runenvs) do -- cgit v1.3.1 From f6b1a4866e1c73aafe6decdc6bfc1d99653f2b64 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 21 Aug 2019 13:37:22 +0800 Subject: make xmake clean --all cofigurable --- xmake/plugins/project/vsxmake/vsproj/Xmake.props | 1 + xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 5 +++-- xmake/plugins/project/vsxmake/vsproj/Xmake.xml | 6 ++++++ xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.props b/xmake/plugins/project/vsxmake/vsproj/Xmake.props index 3b4ae268e..ddec0f57d 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.props +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.props @@ -40,6 +40,7 @@ + true true false false diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets index 99583bf74..81efe2b9b 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -58,6 +58,7 @@ <_XmakeBuildFileFlags Condition="$(XmakeRebuildFile)">$(_XmakeBuildFileFlags.Trim()) -r <_XmakeCleanFlags>$(XmakeCleanFlags.Trim()) + <_XmakeCleanFlags Condition="$(XmakeCleanAll)">-a $(_XmakeCleanFlags.Trim()) <_XmakeBuildFlags>$(_XmakeBuildFlags.Trim()) <_XmakeBuildFileFlags>$(_XmakeBuildFileFlags.Trim()) @@ -109,9 +110,9 @@ $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(XmakeTarget)" EchoOff="true" /> - + + $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" EchoOff="true" /> diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.xml b/xmake/plugins/project/vsxmake/vsproj/Xmake.xml index 5e35da3ff..e1bd4b5ec 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.xml +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.xml @@ -31,6 +31,12 @@ Category="Common" Description="Enable the warnings output for build tasks." Switch="warning" /> + , and is more convenient. --> + + + -- cgit v1.3.1