summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-03 23:16:51 +0800
committerruki <[email protected]>2017-02-03 23:16:51 +0800
commitd7b0f7012c71bb59fd45d4b58ea1556380157b8f (patch)
tree340875b36f25777a2f37f8fbeb7d7187548322a0
parentcf41edd24d67f3b7de3edec43a0ab667bfb145f1 (diff)
add namedflags for archiver
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/archiver.lua4
-rw-r--r--xmake/core/tool/archiver.lua127
-rw-r--r--xmake/tools/ar.lua2
3 files changed, 102 insertions, 31 deletions
diff --git a/xmake/core/sandbox/modules/import/core/tool/archiver.lua b/xmake/core/sandbox/modules/import/core/tool/archiver.lua
index ed35580cd..1eac4bac2 100644
--- a/xmake/core/sandbox/modules/import/core/tool/archiver.lua
+++ b/xmake/core/sandbox/modules/import/core/tool/archiver.lua
@@ -34,7 +34,7 @@ local raise = require("sandbox/modules/raise")
function sandbox_core_tool_archiver.archivecmd(objectfiles, targetfile, target)
-- get the archiver instance
- local instance, errors = archiver.load()
+ local instance, errors = archiver.load(target:sourcekinds())
if not instance then
raise(errors)
end
@@ -47,7 +47,7 @@ end
function sandbox_core_tool_archiver.archive(objectfiles, targetfile, target)
-- get the archiver instance
- local instance, errors = archiver.load()
+ local instance, errors = archiver.load(target:sourcekinds())
if not instance then
raise(errors)
end
diff --git a/xmake/core/tool/archiver.lua b/xmake/core/tool/archiver.lua
index 4f6be2cb9..bfeebf87e 100644
--- a/xmake/core/tool/archiver.lua
+++ b/xmake/core/tool/archiver.lua
@@ -34,6 +34,7 @@ local string = require("base/string")
local option = require("base/option")
local config = require("project/config")
local sandbox = require("sandbox/sandbox")
+local language = require("language/language")
local platform = require("platform/platform")
local tool = require("tool/tool")
@@ -44,6 +45,13 @@ function archiver:_tool()
return self._TOOL
end
+-- get the named flags
+function archiver:_namedflags()
+
+ -- get it
+ return self._NAMEDFLAGS
+end
+
-- get the current flag name
function archiver:_flagname()
@@ -70,6 +78,9 @@ function archiver:_flags(target)
-- add flags from the target
self:_addflags_from_target(flags, target)
+ -- add flags (named) from language
+ self:_addflags_from_language(flags, target)
+
-- add flags from the platform
self:_addflags_from_platform(flags)
@@ -158,17 +169,6 @@ function archiver:_addflags_from_target(flags, target)
-- add the target flags
table.join2(flags, self:_mapflags(target:get(self:_flagname())))
-
- -- add the strip flags
- for _, strip in ipairs(table.wrap(target:get("strip"))) do
- table.join2(flags, self:strip(strip))
- end
-
- -- add the symbol flags
- local symbolfile = target:symbolfile()
- for _, symbol in ipairs(table.wrap(target:get("symbols"))) do
- table.join2(flags, self:symbol(symbol, symbolfile))
- end
end
-- add flags from the platform
@@ -185,8 +185,73 @@ function archiver:_addflags_from_archiver(flags)
table.join2(flags, self:get(self:_flagname()))
end
+-- add flags (named) from the language
+function archiver:_addflags_from_language(flags, target)
+
+ -- init getters
+ local getters =
+ {
+ config = config.get
+ , platform = platform.get
+ , target = function (name) return target:get(name) end
+ , option = function (name)
+
+ -- only for target (exclude option)
+ if target.options then
+ local results = {}
+ for _, opt in ipairs(target:options()) do
+ table.join2(results, table.wrap(opt:get(name)))
+ end
+ return results
+ end
+ end
+ }
+
+ -- get named flags for archiver
+ for _, flaginfo in ipairs(self:_namedflags()) do
+
+ -- get flag info
+ local flagscope = flaginfo[1]
+ local flagname = flaginfo[2]
+ local checkstate = flaginfo[3]
+
+ -- get getter
+ local getter = getters[flagscope]
+ assert(getter)
+
+ -- get api name of tool
+ --
+ -- .e.g
+ --
+ -- defines => define
+ -- defines_if_ok => define
+ -- ...
+ --
+ local apiname = flagname:split('_')[1]
+ if apiname:endswith("s") then
+ apiname = apiname:sub(1, #apiname - 1)
+ end
+
+ -- map named flag to real flag
+ local mapper = self:_tool()[apiname]
+ if mapper then
+
+ -- add the flags
+ for _, flagvalue in ipairs(table.wrap(getter(flagname))) do
+
+ -- map and check flag
+ local flag = mapper(flagvalue, target)
+ if flag and flag ~= "" and (not checkstate or self:check(flag)) then
+ table.join2(flags, flag)
+ end
+ end
+ end
+ end
+end
+
+
-- load the archiver
-function archiver.load()
+function archiver.load(sourcekinds)
-- get it directly from cache dirst
if archiver._INSTANCE then
@@ -201,9 +266,29 @@ function archiver.load()
if not result then
return nil, errors
end
-
- -- save tool
instance._TOOL = result
+
+ -- load the named flags of archiver
+ local namedflags = {}
+ local namedflags_exists = {}
+ for _, sourcekind in ipairs(sourcekinds) do
+
+ -- load language
+ result, errors = language.load_sk(sourcekind)
+ if not result then
+ return nil, errors
+ end
+
+ -- merge named flags
+ for _, flaginfo in ipairs(table.wrap(result:namedflags()["archiver"])) do
+ local key = flaginfo[1] .. flaginfo[2]
+ if not namedflags_exists[key] then
+ table.insert(namedflags, flaginfo)
+ namedflags_exists[key] = flaginfo
+ end
+ end
+ end
+ instance._NAMEDFLAGS = namedflags
-- init flag name
instance._FLAGNAME = "arflags"
@@ -248,20 +333,6 @@ function archiver:archivecmd(objectfiles, targetfile, target)
return self:_tool().archivecmd(table.concat(table.wrap(objectfiles), " "), targetfile, flags or "")
end
--- make the strip flag
-function archiver:strip(level)
-
- -- make it
- return self:_tool().strip(level)
-end
-
--- make the symbol flag
-function archiver:symbol(level, symbolfile)
-
- -- make it
- return self:_tool().symbol(level, symbolfile)
-end
-
-- check the given flags
function archiver:check(flags)
diff --git a/xmake/tools/ar.lua b/xmake/tools/ar.lua
index 5af3d6a47..3c9c681d0 100644
--- a/xmake/tools/ar.lua
+++ b/xmake/tools/ar.lua
@@ -61,7 +61,7 @@ function strip(level)
end
-- make the symbol flag
-function symbol(level, symbolfile)
+function symbol(level)
return ""
end