summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-07 09:59:13 +0800
committerruki <[email protected]>2017-02-07 09:59:13 +0800
commit03165a0481bad23d0dacd2e2afbe1703cc1b3bfe (patch)
tree56c8234956c3a0cd9dd02fda7d01c4fa4486a4fa
parent072f97eb86fd3626fb70325e17e028bf90766dc2 (diff)
remove repeat load implementaion for linker
-rw-r--r--xmake/core/tool/archiver.lua47
-rw-r--r--xmake/core/tool/builder.lua64
-rw-r--r--xmake/core/tool/linker.lua60
3 files changed, 68 insertions, 103 deletions
diff --git a/xmake/core/tool/archiver.lua b/xmake/core/tool/archiver.lua
index 8936f3e8e..dcc630261 100644
--- a/xmake/core/tool/archiver.lua
+++ b/xmake/core/tool/archiver.lua
@@ -92,51 +92,8 @@ end
-- load the archiver
function archiver.load(sourcekinds)
- -- get it directly from cache dirst
- if archiver._INSTANCE then
- return archiver._INSTANCE
- end
-
- -- new instance
- local instance = table.inherit(archiver, builder)
-
- -- load the archiver tool from the source file type
- local result, errors = tool.load("ar")
- if not result then
- return nil, errors
- end
- instance._TOOL = result
-
- -- load the name flags of archiver
- local nameflags = {}
- local nameflags_exists = {}
- for _, sourcekind in ipairs(sourcekinds) do
-
- -- load language
- result, errors = language.load_sk(sourcekind)
- if not result then
- return nil, errors
- end
-
- -- merge name flags
- for _, flaginfo in ipairs(table.wrap(result:nameflags()["archiver"])) do
- local key = flaginfo[1] .. flaginfo[2]
- if not nameflags_exists[key] then
- table.insert(nameflags, flaginfo)
- nameflags_exists[key] = flaginfo
- end
- end
- end
- instance._NAMEFLAGS = nameflags
-
- -- init flag kinds
- instance._FLAGKINDS = {"arflags"}
-
- -- save this instance
- archiver._INSTANCE = instance
-
- -- ok
- return instance
+ -- load linker
+ return builder.load_linker(archiver, "archiver", "static", sourcekinds)
end
-- archive the library file
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index c0a75dac8..fe0af6af9 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -260,5 +260,69 @@ function builder:check(flags)
return ok
end
+-- load the linker from the given target kind
+function builder.load_linker(linker, linkername, targetkind, sourcekinds)
+
+ -- check
+ assert(sourcekinds)
+
+ -- wrap sourcekinds first
+ sourcekinds = table.wrap(sourcekinds)
+
+ -- get the linker info
+ local linkerinfo, errors = language.linkerinfo_of(targetkind, sourcekinds)
+ if not linkerinfo then
+ return nil, errors
+ end
+
+ -- get it directly from cache dirst
+ builder._INSTANCES = builder._INSTANCES or {}
+ if builder._INSTANCES[linkerinfo.kind] then
+ return builder._INSTANCES[linkerinfo.kind]
+ end
+
+ -- new instance
+ local instance = table.inherit(linker, builder)
+
+ -- load the linker tool from the source file type
+ local result, errors = tool.load(linkerinfo.kind)
+ if not result then
+ return nil, errors
+ end
+ instance._TOOL = result
+
+ -- load the name flags of archiver
+ local nameflags = {}
+ local nameflags_exists = {}
+ for _, sourcekind in ipairs(sourcekinds) do
+
+ -- load language
+ result, errors = language.load_sk(sourcekind)
+ if not result then
+ return nil, errors
+ end
+
+ -- merge name flags
+ for _, flaginfo in ipairs(table.wrap(result:nameflags()[linkername])) do
+ local key = flaginfo[1] .. flaginfo[2]
+ if not nameflags_exists[key] then
+ table.insert(nameflags, flaginfo)
+ nameflags_exists[key] = flaginfo
+ end
+ end
+ end
+ instance._NAMEFLAGS = nameflags
+
+ -- init flag kinds
+ instance._FLAGKINDS = {linkerinfo.flag}
+
+ -- save this instance
+ builder._INSTANCES[linkerinfo.kind] = instance
+
+ -- ok
+ return instance
+end
+
+
-- return module
return builder
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 0f71123c6..3419fec04 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -72,64 +72,8 @@ end
-- load the linker from the given target kind
function linker.load(targetkind, sourcekinds)
- -- check
- assert(sourcekinds)
-
- -- wrap sourcekinds first
- sourcekinds = table.wrap(sourcekinds)
-
- -- get the linker info
- local linkerinfo, errors = language.linkerinfo_of(targetkind, sourcekinds)
- if not linkerinfo then
- return nil, errors
- end
-
- -- get it directly from cache dirst
- linker._INSTANCES = linker._INSTANCES or {}
- if linker._INSTANCES[linkerinfo.kind] then
- return linker._INSTANCES[linkerinfo.kind]
- end
-
- -- new instance
- local instance = table.inherit(linker, builder)
-
- -- load the linker tool from the source file type
- local result, errors = tool.load(linkerinfo.kind)
- if not result then
- return nil, errors
- end
- instance._TOOL = result
-
- -- load the name flags of archiver
- local nameflags = {}
- local nameflags_exists = {}
- for _, sourcekind in ipairs(sourcekinds) do
-
- -- load language
- result, errors = language.load_sk(sourcekind)
- if not result then
- return nil, errors
- end
-
- -- merge name flags
- for _, flaginfo in ipairs(table.wrap(result:nameflags()["linker"])) do
- local key = flaginfo[1] .. flaginfo[2]
- if not nameflags_exists[key] then
- table.insert(nameflags, flaginfo)
- nameflags_exists[key] = flaginfo
- end
- end
- end
- instance._NAMEFLAGS = nameflags
-
- -- init flag kinds
- instance._FLAGKINDS = {linkerinfo.flag}
-
- -- save this instance
- linker._INSTANCES[linkerinfo.kind] = instance
-
- -- ok
- return instance
+ -- load linker
+ return builder.load_linker(linker, "linker", targetkind, sourcekinds)
end
-- link the target file