diff options
| author | ruki <[email protected]> | 2017-07-14 12:43:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-14 12:43:16 +0800 |
| commit | f39f4a27d43a1f63d56ae3c9f7fc34b5158e299a (patch) | |
| tree | 37d3667077443d79f9f1425d8aa9d54b42ff8599 | |
| parent | be1cbe6488d15f3f802539dacc74bc98471268f0 (diff) | |
fix has_flags when generating vs201x project
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 41 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 47 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 47 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_flags.lua | 10 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 7 |
6 files changed, 67 insertions, 92 deletions
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index b4fcacc6c..850618a57 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -44,8 +44,12 @@ sandbox_os.argv = os.argv sandbox_os.argw = os.argw sandbox_os.mtime = os.mtime sandbox_os.sleep = os.sleep +sandbox_os.raise = os.raise sandbox_os.mclock = os.mclock sandbox_os.nuldev = os.nuldev +sandbox_os.getenv = os.getenv +sandbox_os.setenv = os.setenv +sandbox_os.addenv = os.addenv sandbox_os.emptydir = os.emptydir sandbox_os.programdir = os.programdir sandbox_os.programfile = os.programfile @@ -434,43 +438,6 @@ function sandbox_os.exists(file_or_dir) return os.exists(file_or_dir) end --- raise an exception and abort the current script -function sandbox_os.raise(msg, ...) - - -- raise it - os.raise(msg, ...) -end - --- get values of the envirnoment variable -function sandbox_os.getenv(name) - - -- check - assert(name) - - -- get it - return os.getenv(name) -end - --- set values to the envirnoment variable -function sandbox_os.setenv(name, ...) - - -- check - assert(name) - - -- set it - os.setenv(name, ...) -end - --- add values to the envirnoment variable -function sandbox_os.addenv(name, ...) - - -- check - assert(name) - - -- add it - os.addenv(name, ...) -end - -- make a new uuid function sandbox_os.uuid(name) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 00d05fa6c..3be1f9749 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -208,20 +208,9 @@ function compiler:compflags(opt) -- get target local target = opt.target - -- make the key - local key = nil - for _, arg in pairs(opt) do - key = (key or "") .. tostring(arg) - end - - -- get it directly from cache dirst - if key then - self._FLAGS = self._FLAGS or {} - local flags_cached = self._FLAGS[key] - if flags_cached then - return flags_cached - end - end + -- init cache + self._COMPFLAGS = self._COMPFLAGS or {} + local cache = self._COMPFLAGS -- get target kind local targetkind = opt.targetkind @@ -233,14 +222,25 @@ function compiler:compflags(opt) local flags = {} self:_addflags_from_config(flags) - -- add flags for the target - if target then - self:_addflags_from_target(flags, target) - end - - -- add flags (named) from language + -- add flags about target if target then - self:_addflags_from_language(flags, target) + + -- get flags from cache first + local key = tostring(target) + local targetflags = cache[key] + if not targetflags then + + -- add flags for the target + targetflags = {} + self:_addflags_from_target(targetflags, target) + + -- add flags (named) from language + self:_addflags_from_language(targetflags, target) + + -- cache it + cache[key] = targetflags + end + table.join2(flags, targetflags) end -- add flags for the argument @@ -270,11 +270,6 @@ function compiler:compflags(opt) end end - -- save flags - if key then - self._FLAGS[key] = results - end - -- get it return results end diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index fa84819a7..c9c21f262 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -205,20 +205,9 @@ function linker:linkflags(opt) -- get target local target = opt.target - -- make the key - local key = nil - for _, arg in pairs(opt) do - key = (key or "") .. tostring(arg) - end - - -- get it directly from cache dirst - if key then - self._FLAGS = self._FLAGS or {} - local flags_cached = self._FLAGS[key] - if flags_cached then - return flags_cached - end - end + -- init cache + self._COMPFLAGS = self._COMPFLAGS or {} + local cache = self._COMPFLAGS -- get target kind local targetkind = opt.targetkind @@ -230,14 +219,25 @@ function linker:linkflags(opt) local flags = {} self:_addflags_from_config(flags) - -- add flags for the target + -- add flags about target if target then - self:_addflags_from_target(flags, target) - end - - -- add flags (named) from language - if target then - self:_addflags_from_language(flags, target) + + -- get flags from cache first + local key = tostring(target) + local targetflags = cache[key] + if not targetflags then + + -- add flags for the target + targetflags = {} + self:_addflags_from_target(targetflags, target) + + -- add flags (named) from language + self:_addflags_from_language(targetflags, target) + + -- cache it + cache[key] = targetflags + end + table.join2(flags, targetflags) end -- add flags for the argument @@ -272,11 +272,6 @@ function linker:linkflags(opt) end end - -- save flags - if key then - self._FLAGS[key] = results - end - -- get it return results end diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 300ab8be9..45b49e85c 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -156,8 +156,11 @@ function nf_vectorext(self, extension) , avx2 = "-arch:AVX2" } - -- make it - return maps[extension] + -- check it + local flag = maps[extension] + if flag and self:has_flags(flag) then + return flag + end end -- make the language flag diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index 1957a6b72..614049821 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -24,6 +24,7 @@ -- imports import("core.base.option") +import("core.project.config") import("lib.detect.find_tool") -- has the given flags for the current tool? @@ -74,8 +75,15 @@ function main(name, flags, opt) opt.program = tool.program opt.programver = tool.version + -- get tool arch + -- + -- some tools select arch by path environment, not be flags, .e.g cl.exe of msvc) + -- so, it will affect the cache result + -- + local arch = config.get("arch") or os.arch() + -- init cache and key - local key = tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. table.concat(flags, " ") + local key = tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. table.concat(flags, " ") .. "_" .. arch _g._RESULTS = _g._RESULTS or {} local results = _g._RESULTS diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 935914c98..43834fd6f 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -27,6 +27,7 @@ import("core.base.option") import("core.project.config") import("core.project.project") import("core.platform.platform") +import("core.platform.environment") import("core.tool.compiler") import("core.tool.linker") import("vs201x_solution") @@ -181,6 +182,9 @@ function make(outputdir, vsinfo) -- ensure to enter project directory os.cd(project.directory()) + -- enter environment (maybe check flags by calling tools) + environment.enter("toolchains") + -- save targets for targetname, target in pairs(project.targets()) do if not target:isphony() then @@ -204,6 +208,9 @@ function make(outputdir, vsinfo) _make_targetheaders(mode, arch, target, mode_idx == #vsinfo.modes and arch_idx == 2) end end + + -- leave environment + environment.leave("toolchains") end end |
