From 0478f29fc3621404ffe311e35831c078f8e219a6 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 12 Jul 2019 12:28:10 +0800 Subject: use sep pdb file --- xmake/modules/core/tools/cl.lua | 57 +++++++++++++++++++-------------------- xmake/modules/core/tools/nvcc.lua | 53 +++++++++++++++--------------------- 2 files changed, 49 insertions(+), 61 deletions(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 7709165d1..f8153f0e0 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -87,33 +87,13 @@ end -- make the symbol flag function nf_symbol(self, level, target) - -- debug? generate *.pdb file - local flags = nil - if level == "debug" then - local symbolfile = nil - if target and target.symbolfile then - symbolfile = target:symbolfile() - end - if symbolfile then - - -- ensure the object directory - local symboldir = path.directory(symbolfile) - if not os.isdir(symboldir) then - os.mkdir(symboldir) - end - - -- check and add symbol output file - flags = "-Zi -Fd" .. target:symbolfile() - if self:has_flags({"-Zi", "-FS", "-Fd" .. os.tmpfile() .. ".pdb"}, "cxflags") then - flags = "-FS " .. flags - end - else - flags = "-Zi" - end - end + -- the maps + local maps = + { + debug = "-Zi" + } - -- none - return flags + return maps[level] end -- make the warning flag @@ -341,8 +321,8 @@ end -- make the complie arguments list for the precompiled header function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags) - -- remove "-Yuxxx.h" and "-Fpxxx.pch" local pchflags = {} + -- remove "-Yuxxx.h" and "-Fpxxx.pch" for _, flag in ipairs(flags) do if not flag:find("-Yu", 1, true) and not flag:find("-Fp", 1, true) then table.insert(pchflags, flag) @@ -363,14 +343,33 @@ end -- make the complie arguments list function _compargv1(self, sourcefile, objectfile, flags) + local compflags = flags + + -- check if we need -Fd flags + local need_pdb = false + local has_pdb = false + for _, flag in ipairs(flags) do + if flag:find("-ZI", 1, true) or flag:find("-Zi", 1, true) then + need_pdb = true + end + if flag:find("-Fd", 1, true) then + has_pdb = true + end + end + + -- add pdb output + if need_pdb and not has_pdb then + compflags = table.join(flags, "-Fd" .. objectfile .. ".pdb") + end + -- precompiled header? local extension = path.extension(sourcefile) if (extension:startswith(".h") or extension == ".inl") then - return _compargv1_pch(self, sourcefile, objectfile, flags) + return _compargv1_pch(self, sourcefile, objectfile, compflags) end -- make complie arguments list - return self:program(), table.join("-c", flags, "-Fo" .. objectfile, sourcefile) + return self:program(), table.join("-c", compflags, "-Fo" .. objectfile, sourcefile) end -- complie the source file diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 24032b08e..59d87412e 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -59,38 +59,13 @@ end -- make the symbol flag function nf_symbol(self, level, target) - -- debug? generate *.pdb file - local flags = nil - if level == "debug" then - flags = "-g -G" - if is_plat("windows") then - local host_flags = nil - local symbolfile = nil - if target and target.symbolfile then - symbolfile = target:symbolfile() - end - if symbolfile then - - -- ensure the object directory - local symboldir = path.directory(symbolfile) - if not os.isdir(symboldir) then - os.mkdir(symboldir) - end - - -- check and add symbol output file - host_flags = "-Zi -Fd" .. target:symbolfile() - if self:has_flags({'-Xcompiler "-Zi -FS -Fd' .. os.tmpfile() .. '.pdb"'}, "cuflags") then - host_flags = "-FS " .. host_flags - end - else - host_flags = "-Zi" - end - flags = flags .. ' -Xcompiler "' .. host_flags .. '"' - end - end + -- the maps + local maps = + { + debug = "-g -G" + } - -- none - return flags + return maps[level] end -- make the warning flag @@ -285,10 +260,24 @@ function _compargv1(self, sourcefile, objectfile, flags) -- make argv local argv = table.join("-c", flags, "-o", objectfile, sourcefile) + -- insert -Fd flags + if is_plat("windows") then + local need_pdb = false + for _, flag in ipairs(flags) do + if flag:find("-g", 1, true) then + need_pdb = true + end + end + if need_pdb then + table.insert(argv, "-Xcompiler") + table.insert(argv, "-Fd" .. objectfile .. ".pdb") + end + end + -- uses cache? local program = self:program() if ccache then - + -- parse the filename and arguments, .e.g "xcrun -sdk macosx clang" if not os.isexec(program) then argv = table.join(program:split("%s"), argv) -- cgit v1.3.1 From 97a44ac26e00bf98062cfb99ef203f960d8f6408 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 12 Jul 2019 13:20:53 +0800 Subject: fix --- xmake/modules/core/tools/cl.lua | 52 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index f8153f0e0..e0b6e3f57 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -262,7 +262,7 @@ function _include_note(self, line) -- -- TODO zh-tw, zh-hk, jp, ... -- - _g.notes = _g.notes or + _g.notes = _g.notes or { "Note: including file: " , "注意: 包含文件: " @@ -270,7 +270,7 @@ function _include_note(self, line) -- contain notes? for idx, note in ipairs(_g.notes) do - + -- dump line bytes --[[ print(line) @@ -318,6 +318,31 @@ function _include_deps(self, outdata) return results end +-- add if we need -Fd flags +function _patch_pdbflags(objectfile, flags) + + local compflags = flags + + -- check if we need -Fd flags + local need_pdb = false + local has_pdb = false + for _, flag in ipairs(flags) do + if flag:find("-ZI", 1, true) or flag:find("-Zi", 1, true) or flag:find("/ZI", 1, true) or flag:find("/Zi", 1, true) then + need_pdb = true + end + if flag:find("-Fd", 1, true) or flag:find("/Fd", 1, true) then + has_pdb = true + end + end + + -- add pdb output + if need_pdb and not has_pdb then + compflags = table.join(flags, "-Fd" .. objectfile .. ".pdb") + end + + return compflags +end + -- make the complie arguments list for the precompiled header function _compargv1_pch(self, pcheaderfile, pcoutputfile, flags) @@ -343,33 +368,16 @@ end -- make the complie arguments list function _compargv1(self, sourcefile, objectfile, flags) - local compflags = flags - - -- check if we need -Fd flags - local need_pdb = false - local has_pdb = false - for _, flag in ipairs(flags) do - if flag:find("-ZI", 1, true) or flag:find("-Zi", 1, true) then - need_pdb = true - end - if flag:find("-Fd", 1, true) then - has_pdb = true - end - end - - -- add pdb output - if need_pdb and not has_pdb then - compflags = table.join(flags, "-Fd" .. objectfile .. ".pdb") - end + flags = _patch_pdbflags(objectfile, flags) -- precompiled header? local extension = path.extension(sourcefile) if (extension:startswith(".h") or extension == ".inl") then - return _compargv1_pch(self, sourcefile, objectfile, compflags) + return _compargv1_pch(self, sourcefile, objectfile, flags) end -- make complie arguments list - return self:program(), table.join("-c", compflags, "-Fo" .. objectfile, sourcefile) + return self:program(), table.join("-c", flags, "-Fo" .. objectfile, sourcefile) end -- complie the source file -- cgit v1.3.1 From 741274711841086019bdafc3eacab0345eea789f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 12 Jul 2019 14:05:28 +0800 Subject: use hashset --- xmake/modules/core/tools/cl.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index e0b6e3f57..abb3b4841 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.hashset") import("core.project.project") import("core.language.language") @@ -323,11 +324,14 @@ function _patch_pdbflags(objectfile, flags) local compflags = flags + local _pdbflags = _g._pdbflags or hashset.of("-ZI", "-Zi", "/ZI", "/Zi") + _g._pdbflags = _pdbflags + -- check if we need -Fd flags local need_pdb = false local has_pdb = false for _, flag in ipairs(flags) do - if flag:find("-ZI", 1, true) or flag:find("-Zi", 1, true) or flag:find("/ZI", 1, true) or flag:find("/Zi", 1, true) then + if _pdbflags:has(flag) then need_pdb = true end if flag:find("-Fd", 1, true) or flag:find("/Fd", 1, true) then -- cgit v1.3.1 From a6fbe448d1c1f39d424217189677ba7bababf65f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 12 Jul 2019 14:07:07 +0800 Subject: add hashset --- xmake/core/base/hashset.lua | 98 ++++++++++++++++++++++ .../sandbox/modules/import/core/base/hashset.lua | 36 ++++++++ 2 files changed, 134 insertions(+) create mode 100644 xmake/core/base/hashset.lua create mode 100644 xmake/core/sandbox/modules/import/core/base/hashset.lua diff --git a/xmake/core/base/hashset.lua b/xmake/core/base/hashset.lua new file mode 100644 index 000000000..7ec5bd4a0 --- /dev/null +++ b/xmake/core/base/hashset.lua @@ -0,0 +1,98 @@ +--!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 OpportunityLiu +-- @file hashset.lua +-- + +-- define module +local hashset = hashset or {} +local hashset_impl = hashset.__index or {} + +-- load modules +local table = require("base/table") + +-- representaion for nil key +hashset._NIL = setmetatable({}, {__tostring = function() return "nil" end }) + +function hashset._to_key(key) + if key == nil then + key = hashset._NIL + end + return key +end + +-- make a new hashset +function hashset.new() + return setmetatable({ _DATA = {} }, hashset) +end + +-- construct from list of items +function hashset.of(...) + local result = hashset.new() + local data = table.pack(...) + for i = 1, data.n do + result._DATA[hashset._to_key(data[i])] = true + end + return result +end + +-- construct from an array +function hashset.from(array) + assert(array) + return hashset.of(table.unpack(array)) +end + +-- check value is in hashset +function hashset_impl:has(value) + value = hashset._to_key(value) + return self._DATA[value] or false +end + +-- insert value to hashset, returns false if value has already in the hashset +function hashset_impl:insert(value) + value = hashset._to_key(value) + local result = self._DATA[value] or false + if not result then + self._DATA[value] = true + end + return result +end + +-- remove value from hashset, returns false if value is not in the hashset +function hashset_impl:remove(value) + value = hashset._to_key(value) + local result = self._DATA[value] or false + if result then + self._DATA[value] = nil + end + return result +end + +-- convert hashset to an array, nil in the set will be ignored +function hashset_impl:to_array() + local result = {} + for k,_ in pairs(self._DATA) do + if k ~= hashset._NIL then + table.insert(result, k) + end + end + return result +end + +-- return module +hashset.__index = hashset_impl +return hashset diff --git a/xmake/core/sandbox/modules/import/core/base/hashset.lua b/xmake/core/sandbox/modules/import/core/base/hashset.lua new file mode 100644 index 000000000..81c833f57 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/base/hashset.lua @@ -0,0 +1,36 @@ +--!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 OpportunityLiu +-- @file hashset.lua +-- + +-- load modules +local hashset = require("base/hashset") + + +-- define module +local sandbox_hashset = sandbox_hashset or {} + +-- inherit some builtin interfaces +sandbox_hashset.new = hashset.new +sandbox_hashset.of = hashset.of +sandbox_hashset.from = hashset.from + +-- return module +return sandbox_hashset + + -- cgit v1.3.1 From 14fb0573a09d6bd1bd64ea16890ee7220c7f8244 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 12 Jul 2019 14:19:13 +0800 Subject: add break --- xmake/modules/core/tools/cl.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index abb3b4841..7d4fda764 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -337,6 +337,9 @@ function _patch_pdbflags(objectfile, flags) if flag:find("-Fd", 1, true) or flag:find("/Fd", 1, true) then has_pdb = true end + if need_pdb and has_pdb then + break + end end -- add pdb output -- cgit v1.3.1 From 887d8d84223de495f0442baa9ae143c382747285 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 12 Jul 2019 14:45:40 +0800 Subject: add break --- xmake/modules/core/tools/nvcc.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 59d87412e..274d72a54 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -266,6 +266,7 @@ function _compargv1(self, sourcefile, objectfile, flags) for _, flag in ipairs(flags) do if flag:find("-g", 1, true) then need_pdb = true + break end end if need_pdb then @@ -281,7 +282,7 @@ function _compargv1(self, sourcefile, objectfile, flags) -- parse the filename and arguments, .e.g "xcrun -sdk macosx clang" if not os.isexec(program) then argv = table.join(program:split("%s"), argv) - else + else table.insert(argv, 1, program) end return ccache, argv -- cgit v1.3.1