diff options
| author | ruki <[email protected]> | 2019-08-21 14:25:05 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-08-21 14:25:05 +0800 |
| commit | bb8580531e75a4ebd190126c442b61fe319044e3 (patch) | |
| tree | d34c7d0935b6b9b95b0aad18eec09d04b6d54fec | |
| parent | 2c891f5a18aec7d47d3458ef39b9294d7f3b4d59 (diff) | |
| parent | f6b1a4866e1c73aafe6decdc6bfc1d99653f2b64 (diff) | |
Merge pull request #543 from OpportunityLiu/dev
improve runenvs
| -rw-r--r-- | scripts/installer.nsi | 42 | ||||
| -rw-r--r-- | xmake/actions/run/main.lua | 52 | ||||
| -rw-r--r-- | xmake/modules/private/action/run/make_runenvs.lua | 92 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 57 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/Xmake.props | 1 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 5 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/Xmake.xml | 6 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props | 3 |
8 files changed, 151 insertions, 107 deletions
diff --git a/scripts/installer.nsi b/scripts/installer.nsi index 1b139447e..b3723a3ca 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -275,19 +275,20 @@ SectionEnd Section "Add to PATH" InstallPath - !macro AddRegPATH RootKey + ${If} $NOADMIN == "false" ; Remove the installation path from the $PATH environment variable first - ReadRegStr $R0 ${RootKey} "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" + ReadRegStr $R0 ${HKLM} "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" - !insertmacro AddRegPATH ${HKLM} + 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 @@ -323,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 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..91a6185d2 --- /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 + + -- 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 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 + end + + return add, set +end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index b0d24b04e..8cfe46591 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,26 @@ 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 + 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 - 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) 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 @@ </PropertyGroup> <PropertyGroup Label="XmakeFlagsFallback"> + <XmakeCleanAll Condition="'$(XmakeCleanAll)' == ''">true</XmakeCleanAll> <XmakeWarning Condition="'$(XmakeWarning)' == ''">true</XmakeWarning> <XmakeVerbose Condition="'$(XmakeVerbose)' == ''">false</XmakeVerbose> <XmakeDiagnosis Condition="'$(XmakeDiagnosis)' == ''">false</XmakeDiagnosis> 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</_XmakeBuildFileFlags> <_XmakeCleanFlags>$(XmakeCleanFlags.Trim())</_XmakeCleanFlags> + <_XmakeCleanFlags Condition="$(XmakeCleanAll)">-a $(_XmakeCleanFlags.Trim())</_XmakeCleanFlags> <_XmakeBuildFlags>$(_XmakeBuildFlags.Trim())</_XmakeBuildFlags> <_XmakeBuildFileFlags>$(_XmakeBuildFileFlags.Trim())</_XmakeBuildFileFlags> @@ -109,9 +110,9 @@ $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(XmakeTarget)" EchoOff="true" /> </Target> <Target Name="_XmakeClean" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake clean $(_XmakeCommonFlags) -a $(_XmakeCleanFlags) $(XmakeTarget)" Importance="High" /> + <Message Text="$xmake clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" Importance="High" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) clean $(_XmakeCommonFlags) -a $(_XmakeCleanFlags) $(XmakeTarget)" EchoOff="true" /> + $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" EchoOff="true" /> </Target> <Target Name="Show"> 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 @@ -32,6 +32,12 @@ Description="Enable the warnings output for build tasks." Switch="warning" /> <BoolProperty + Name="XmakeCleanAll" + DisplayName="Clean all" + Category="Common" + Description="Clean all auto-generated files by xmake for clean tasks." + Switch="all" /> + <BoolProperty Name="XmakeRebuildFile" DisplayName="Force rebuild selected files" Category="Common" diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props b/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props index eaff91446..52b055455 100644 --- a/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props +++ b/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props @@ -25,6 +25,9 @@ For -w, -v and -D, use <XmakeWarning>, <XmakeVerbose> and <XmakeDiagnosis> is more convenient. --> + <!-- Set -a for "xmake clean" --> + <!-- <XmakeCleanAll Condition="'$(XmakeCleanAll)' == ''">true</XmakeWarning> --> + <!-- Set -w for "xmake build" --> <!-- <XmakeWarning Condition="'$(XmakeWarning)' == ''">true</XmakeWarning> --> |
