diff options
| author | ruki <[email protected]> | 2021-03-10 11:09:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-10 11:09:25 +0800 |
| commit | 548a0ad47f341bee0d757be53e478697decc39a5 (patch) | |
| tree | 3285d6cbb6a88a445624651488026a01ba26ec40 | |
| parent | aeda97353dd23f22b7d7cda78eb3d10470177d55 (diff) | |
| parent | 138a9cbec0156f31c82588314b04ecf4b1b6c847 (diff) | |
Merge pull request #1277 from xmake-io/vsxmake
improve vsxmake plugin to support `set_default(false)`
| -rw-r--r-- | xmake/core/platform/platform.lua | 48 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 31 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 26 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_solution.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 5 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/Xmake.targets | 13 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) | 1 |
7 files changed, 84 insertions, 42 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 0cdc7c1be..b9913f1b8 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -29,6 +29,7 @@ local utils = require("base/utils") local table = require("base/table") local interpreter = require("base/interpreter") local toolchain = require("tool/toolchain") +local memcache = require("cache/memcache") local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("base/global") @@ -42,6 +43,16 @@ function _instance.new(name, arch, info) return instance end +-- get memcache +function _instance:_memcache() + local cache = self._MEMCACHE + if not cache then + cache = memcache.cache("core.platform.platform." .. tostring(self)) + self._MEMCACHE = cache + end + return cache +end + -- get platform name function _instance:name() return self._NAME @@ -138,7 +149,7 @@ end -- get the toolchains function _instance:toolchains(opt) - local toolchains = self._TOOLCHAINS + local toolchains = self:_memcache():get("toolchains") if not toolchains then -- get current valid toolchains from configuration cache @@ -181,7 +192,7 @@ function _instance:toolchains(opt) table.insert(toolchains, toolchain_inst) end end - self._TOOLCHAINS = toolchains + self:_memcache():set("toolchains", toolchains) end return toolchains end @@ -345,6 +356,11 @@ function platform._apis() } end +-- get memcache +function platform._memcache() + return memcache.cache("core.platform.platform") +end + -- get platform directories function platform.directories() @@ -499,26 +515,22 @@ end -- get the all toolchains function platform.toolchains() - - -- return it directly if exists - if platform._TOOLCHAINS then - return platform._TOOLCHAINS - end - - -- get all toolchains - local toolchains = {} - local dirs = toolchain.directories() - for _, dir in ipairs(dirs) do - local dirs = os.dirs(path.join(dir, "*")) - if dirs then - for _, dir in ipairs(dirs) do - if os.isfile(path.join(dir, "xmake.lua")) then - table.insert(toolchains, path.basename(dir)) + local toolchains = self._memcache():get("toolchains") + if not toolchains then + toolchains = {} + local dirs = toolchain.directories() + for _, dir in ipairs(dirs) do + local dirs = os.dirs(path.join(dir, "*")) + if dirs then + for _, dir in ipairs(dirs) do + if os.isfile(path.join(dir, "xmake.lua")) then + table.insert(toolchains, path.basename(dir)) + end end end end + self._memcache():set("toolchains", toolchains) end - platform._TOOLCHAINS = toolchains return toolchains end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ee7e3f519..617141791 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -60,7 +60,7 @@ end function _instance:_memcache() local cache = self._MEMCACHE if not cache then - cache = memcache.cache("core.project.target." .. self:name()) + cache = memcache.cache("core.project.target." .. tostring(self)) self._MEMCACHE = cache end return cache @@ -1784,10 +1784,32 @@ end -- get the toolchains function _instance:toolchains() - local toolchains = self._TOOLCHAINS + local toolchains = self:_memcache():get("toolchains") if toolchains == nil then - toolchains = self:platform():toolchains() - self._TOOLCHAINS = toolchains + + -- load target toolchains + local target_toolchains = self:get("toolchains") + if target_toolchains then + toolchains = {} + for _, name in ipairs(table.wrap(target_toolchains)) do + local toolchain_opt = table.copy(self:extraconf("toolchains", name)) + toolchain_opt.arch = self:arch() + toolchain_opt.plat = self:plat() + local toolchain_inst, errors = toolchain.load(name, toolchain_opt) + -- attempt to load toolchain from project + if not toolchain_inst and self._PROJECT then + toolchain_inst = self._PROJECT.toolchain(name, toolchain_opt) + end + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end + else + -- load platform toolchains + toolchains = self:platform():toolchains() + end + self:_memcache():set("toolchains", toolchains) end return toolchains end @@ -1977,3 +1999,4 @@ end -- return module return target + diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 43782f2e8..24cff77f3 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -535,15 +535,16 @@ function toolchain.load(name, opt) name, packages = toolchain._parsename(name) opt.packages = opt.packages or packages - -- get cache key + -- get cache opt.plat = opt.plat or config.get("plat") or os.host() opt.arch = opt.arch or config.get("arch") or os.arch() + local cache = toolchain._memcache() local cachekey = toolchain._cachekey(name, opt) -- get it directly from cache dirst - toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} - if toolchain._TOOLCHAINS[cachekey] then - return toolchain._TOOLCHAINS[cachekey] + local instance = cache:get(cachekey) + if instance then + return instance end -- find the toolchain script path @@ -580,8 +581,8 @@ function toolchain.load(name, opt) end -- save instance to the cache - local instance = _instance.new(name, result, cachekey, opt) - toolchain._TOOLCHAINS[cachekey] = instance + instance = _instance.new(name, result, cachekey, opt) + cache:set(cachekey, instance) return instance end @@ -597,17 +598,18 @@ function toolchain.load_withinfo(name, info, opt) -- get cache key opt.plat = opt.plat or config.get("plat") or os.host() opt.arch = opt.arch or config.get("arch") or os.arch() + local cache = toolchain._memcache() local cachekey = toolchain._cachekey(name, opt) -- get it directly from cache dirst - toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} - if toolchain._TOOLCHAINS[cachekey] then - return toolchain._TOOLCHAINS[cachekey] + local instance = cache:get(cachekey) + if instance then + return instance end -- save instance to the cache - local instance = _instance.new(name, info, cachekey, opt) - toolchain._TOOLCHAINS[cachekey] = instance + instance = _instance.new(name, info, cachekey, opt) + cache:set(cachekey, instance) return instance end @@ -620,7 +622,7 @@ function toolchain.tool(toolchains, toolkind, opt) local arch = opt.arch or config.get("arch") or os.arch() -- get cache and cachekey - local cache = toolchain:_localcache() + local cache = toolchain._localcache() local cachekey = "tool_" .. (opt.cachekey or "") .. "_" .. plat .. "_" .. arch .. "_" .. toolkind local updatecache = false diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua index 8b018a5d4..c4628190f 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua @@ -52,7 +52,7 @@ function _make_projects(slnfile, vsinfo) table.insert(targets, 1, target) elseif target:is_binary() then local first_target = targets[1] - if not first_target or first_target:get("default") ~= true then + if not first_target or first_target:is_default() then table.insert(targets, 1, target) else table.insert(targets, target) diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index f2d54fdfe..396b7def3 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -136,6 +136,9 @@ function _make_targetinfo(mode, arch, target) -- save target kind targetinfo.kind = target:get("kind") + -- is default? + targetinfo.default = tostring(target:is_default()) + -- save target file targetinfo.basename = _escape(target:get("basename")) targetinfo.filename = _escape(target:get("filename")) @@ -474,7 +477,7 @@ function main(outputdir, vsinfo) table.insert(targetnames, 1, targetname) elseif target:is_binary() then local first_target = targetnames[1] and project.target(targetnames[1]) - if not first_target or first_target:get("default") ~= true then + if not first_target or first_target:is_default() then table.insert(targetnames, 1, targetname) else table.insert(targetnames, targetname) diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets index 78b6e5bca..638c7dd04 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -94,14 +94,14 @@ Text="$(XmakeProjectFile) not found at '$(XmakeProjectDirResolved)', please set XmakeProjectDir in vcxproj file" /> </Target> <Target Name="_XmakeConfig" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" Importance="High" /> + <Message Text="$xmake config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" EchoOff="true" /> + $(_XmakeExecutable) config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> </Target> <Target Name="_XmakeBuild" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" Importance="High" /> + <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" EchoOff="true" /> + $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> </Target> <Target Name="_XmakeBuildFile" DependsOnTargets="_XmakeProjCheck"> <ItemGroup> @@ -116,9 +116,9 @@ $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(XmakeTarget)" EchoOff="true" /> </Target> <Target Name="_XmakeClean" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" Importance="High" /> + <Message Text="$xmake clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> <Exec StdOutEncoding="utf-8" StdErrEncoding="utf-8" Command="$(_XmakeEnv) - $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" EchoOff="true" /> + $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> </Target> <Target Name="Show"> @@ -130,6 +130,7 @@ MSBuild Properties: XmakeBasename: $(XmakeBasename) XmakeFilename: $(XmakeFilename) XmakeKind: $(XmakeKind) + XmakeDefault: $(XmakeDefault) XmakeCudaVersion: $(XmakeCudaVersion) XmakeWindowsSdkVersion: $(XmakeWindowsSdkVersion) XmakeMfcKind: $(XmakeMfcKind) diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) index 0d6eb3dd5..4832d8e93 100644 --- a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) @@ -5,6 +5,7 @@ <XmakePlat>#plat#</XmakePlat> <XmakeArch>#arch#</XmakeArch> <XmakeKind>#kind#</XmakeKind> + <XmakeDefault>#default#</XmakeDefault> <XmakeDefines>#defines#</XmakeDefines> <XmakeLanguages>#languages#</XmakeLanguages> <XmakeSubSystem>#subsystem#</XmakeSubSystem> |
