diff options
| author | ruki <[email protected]> | 2020-10-24 00:53:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-10-24 00:53:07 +0800 |
| commit | a83ee200a7c905f123b780881b4067b58aa305e3 (patch) | |
| tree | 3bd02b3810f525b2a70dd024b8f864d11a6ce32c | |
| parent | 1d192142d27973332edae50e0b1c4a37080ea65f (diff) | |
improve fetch packages
| -rw-r--r-- | xmake/actions/require/fetch.lua | 18 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 27 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/linker.lua | 21 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 18 |
4 files changed, 71 insertions, 13 deletions
diff --git a/xmake/actions/require/fetch.lua b/xmake/actions/require/fetch.lua index da4157226..9f0eee70a 100644 --- a/xmake/actions/require/fetch.lua +++ b/xmake/actions/require/fetch.lua @@ -23,6 +23,8 @@ import("core.base.option") import("core.base.hashset") import("core.project.project") import("core.package.package", {alias = "core_package"}) +import("core.tool.linker") +import("core.tool.compiler") import("impl.package") import("impl.repository") import("impl.utils.get_requires") @@ -62,12 +64,8 @@ function main(requires_raw) local flags = {} if fetchmodes:has("cflags") then for _, fetchinfo in ipairs(fetchinfos) do - for _, includedir in ipairs(fetchinfo.includedirs) do - table.insert(flags, "-I" .. os.args(includedir)) - end - for _, define in ipairs(fetchinfo.defines) do - table.insert(flags, "-D" .. define) - end + table.join2(flags, compiler.map_flags("cxx", "define", fetchinfo.defines)) + table.join2(flags, compiler.map_flags("cxx", "includedir", fetchinfo.includedirs)) for _, cflag in ipairs(fetchinfo.cflags) do table.insert(flags, cflag) end @@ -81,12 +79,8 @@ function main(requires_raw) end if fetchmodes:has("ldflags") then for _, fetchinfo in ipairs(fetchinfos) do - for _, linkdir in ipairs(fetchinfo.linkdirs) do - table.insert(flags, "-L" .. os.args(linkdir)) - end - for _, link in ipairs(fetchinfo.links) do - table.insert(flags, "-l" .. link) - end + table.join2(flags, linker.map_flags("binary", {"cxx"}, "linkdir", fetchinfo.linkdirs)) + table.join2(flags, linker.map_flags("binary", {"cxx"}, "link", fetchinfo.links)) for _, ldflag in ipairs(fetchinfo.ldflags) do table.insert(flags, ldflags) end diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index ef7bb4371..238d10756 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -289,7 +289,7 @@ end -- -- @param langkind the language kind, e.g. c, cxx, mm, mxx, swift, go, rust, d, as -- @param flags the flags --- @param options the options +-- @param opt the options -- -- @return the supported flags or nil -- @@ -309,5 +309,30 @@ function sandbox_core_tool_compiler.has_flags(langkind, flags, opt) return instance:has_flags(flags) end +-- map flags from name and values +-- +-- @param langkind the language kind, e.g. c, cxx, mm, mxx, swift, go, rust, d, as +-- @param name the name, e.g. includedirs, defines, links +-- @param values the values +-- @param opt the options +-- +-- @return flags or nil +-- +function sandbox_core_tool_compiler.map_flags(langkind, name, values, opt) + + -- init options + opt = opt or {} + + -- get sourcekind from the language kind + local sourcekind = language.langkinds()[langkind] + assert(sourcekind, "unknown language kind: " .. langkind) + + -- get the compiler instance + local instance = sandbox_core_tool_compiler.load(sourcekind, opt) + + -- map flags + return instance:map_flags(name, values, opt) +end + -- return module return sandbox_core_tool_compiler diff --git a/xmake/core/sandbox/modules/import/core/tool/linker.lua b/xmake/core/sandbox/modules/import/core/tool/linker.lua index 4bd612e64..8cf7cc6ab 100644 --- a/xmake/core/sandbox/modules/import/core/tool/linker.lua +++ b/xmake/core/sandbox/modules/import/core/tool/linker.lua @@ -113,5 +113,26 @@ function sandbox_core_tool_linker.has_flags(targetkind, sourcekinds, flags, opt) return instance:has_flags(flags) end +-- map flags from name and values +-- +-- @param targetkind the target kind +-- @param sourcekinds the source kinds +-- @param values the values +-- @param opt the options +-- +-- @return flags or nil +-- +function sandbox_core_tool_linker.map_flags(targetkind, sourcekinds, name, values, opt) + + -- init options + opt = opt or {} + + -- get the linker instance + local instance = sandbox_core_tool_linker.load(targetkind, sourcekinds, opt) + + -- map flags + return instance:map_flags(name, values, opt) +end + -- return module return sandbox_core_tool_linker diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 72c8e1932..6ebff1861 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -407,6 +407,24 @@ function builder:has_flags(flags, flagkind) return self:_tool():has_flags(flags, flagkind) end +-- map flags from name and values, e.g. linkdirs, links, defines +function builder:map_flags(name, values, opt) + local flags = {} + local mapper = self:_tool()["nf_" .. name] + if mapper then + opt = opt or {} + for _, value in ipairs(table.wrap(values)) do + local flag = mapper(self:_tool(), value, opt.target, opt.targetkind) + if flag and flag ~= "" and (not opt.check or self:has_flags(flag)) then + table.join2(flags, flag) + end + end + end + if #flags > 0 then + return flags + end +end + -- get the format of the given target kind function builder:format(targetkind) local formats = self:get("formats") |
