diff options
| author | ruki <[email protected]> | 2017-01-22 08:51:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-01-22 08:51:21 +0800 |
| commit | 43c75eaea996ac463f1fd6cdf042216b37c92dba (patch) | |
| tree | 3be1110a8a4528f3e10c1ad9e12be717329e71cb | |
| parent | af019e8ea85c8f6a4025ce6d63b1d7d57c92a699 (diff) | |
move sourcekind of file to language
| -rw-r--r-- | xmake/core/language/language.lua | 22 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 9 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 19 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/language/language.lua | 13 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 13 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 29 |
6 files changed, 56 insertions, 49 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index 99a24deea..82d9182a9 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -419,5 +419,27 @@ function language.sourcekinds() return sourcekinds end +-- get source kind of the source file name +function language.sourcekind_of(sourcefile) + + -- get the source file extension + local extension = path.extension(sourcefile) + if not extension then + return nil, string.format("%s has not extension", sourcefile) + end + + -- get extensions + local extensions = language.extensions() + + -- get source kind from extension + local sourcekind = extensions[extension:lower()] + if not sourcekind then + return nil, string.format("%s is unknown extension", extension) + end + + -- ok + return sourcekind +end + -- return module return language diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 8440781aa..900fb953c 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -37,6 +37,7 @@ local cache = require("project/cache")("local.option") local linker = require("tool/linker") local compiler = require("tool/compiler") local sandbox = require("sandbox/sandbox") +local language = require("language/language") -- check link function option:_check_link(sourcefile, objectfile, targetfile) @@ -45,7 +46,7 @@ function option:_check_link(sourcefile, objectfile, targetfile) assert(sourcefile and objectfile and targetfile) -- update source kinds - self._SOURCEKINDS = compiler.kind_of_file(sourcefile) + self._SOURCEKINDS = language.sourcekind_of(sourcefile) -- load the linker instance local instance = linker.load("binary") @@ -84,7 +85,7 @@ function option:_check_include(include, srcpath, objpath) srcfile:close() -- load the compiler instance - local instance = compiler.load(compiler.kind_of_file(srcpath)) + local instance = compiler.load(language.sourcekind_of(srcpath)) if not instance then return false end @@ -106,7 +107,7 @@ function option:_check_function(checkcode, srcpath, objpath) end -- load the compiler instance - local instance = compiler.load(compiler.kind_of_file(srcpath)) + local instance = compiler.load(language.sourcekind_of(srcpath)) if not instance then return false end @@ -154,7 +155,7 @@ function option:_check_typedef(typedef, srcpath, objpath) end -- load the compiler instance - local instance = compiler.load(compiler.kind_of_file(srcpath)) + local instance = compiler.load(language.sourcekind_of(srcpath)) if not instance then return false end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index aa17ceefb..ef66558e4 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -35,6 +35,7 @@ local config = require("project/config") local linker = require("tool/linker") local compiler = require("tool/compiler") local platform = require("platform/platform") +local language = require("language/language") -- get the filename from the given name and kind function target.filename(name, kind) @@ -425,25 +426,25 @@ function target:sourcekinds() return self._SOURCEKINDS end - -- make kinds - local kinds = {} + -- make source kinds + local sourcekinds = {} for _, sourcefile in pairs(self:sourcefiles()) do - -- get kind - local kind = compiler.kind_of_file(sourcefile) - if kind then - table.insert(kinds, kind) + -- get source kind + local sourcekind = language.sourcekind_of(sourcefile) + if sourcekind then + table.insert(sourcekinds, sourcekind) end end -- remove repeat - kinds = table.unique(kinds) + sourcekinds = table.unique(sourcekinds) -- cache it - self._SOURCEKINDS = kinds + self._SOURCEKINDS = sourcekinds -- ok? - return kinds + return sourcekinds end diff --git a/xmake/core/sandbox/modules/import/core/language/language.lua b/xmake/core/sandbox/modules/import/core/language/language.lua index a87a6c9a0..749119838 100644 --- a/xmake/core/sandbox/modules/import/core/language/language.lua +++ b/xmake/core/sandbox/modules/import/core/language/language.lua @@ -82,5 +82,18 @@ function sandbox_core_language.load_ex(extension) return instance end +-- get source kind of the source file name +function sandbox_core_language.sourcekind_of(sourcefile) + + -- get it + local sourcekind, errors = language.sourcekind_of(sourcefile) + if not sourcekind then + raise(errors) + end + + -- ok + return sourcekind +end + -- return module return sandbox_core_language diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index 8d3b21e62..6dc7f6faf 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -27,14 +27,16 @@ local sandbox_core_tool_compiler = sandbox_core_tool_compiler or {} -- load modules local platform = require("platform/platform") +local language = require("language/language") local compiler = require("tool/compiler") local raise = require("sandbox/modules/raise") +local assert = require("sandbox/modules/assert") -- make command for compiling source file function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target) -- get the compiler instance - local instance, errors = compiler.load(compiler.kind_of_file(sourcefile)) + local instance, errors = compiler.load(assert(language.sourcekind_of(sourcefile))) if not instance then raise(errors) end @@ -47,7 +49,7 @@ end function sandbox_core_tool_compiler.compflags(sourcefile, target) -- get the compiler instance - local instance, errors = compiler.load(compiler.kind_of_file(sourcefile)) + local instance, errors = compiler.load(assert(language.sourcekind_of(sourcefile))) if not instance then raise(errors) end @@ -60,7 +62,7 @@ end function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, target) -- get the compiler instance - local instance, errors = compiler.load(compiler.kind_of_file(sourcefile)) + local instance, errors = compiler.load(assert(language.sourcekind_of(sourcefile))) if not instance then raise(errors) end @@ -72,10 +74,5 @@ function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, end end --- get kind of the compiling source file -function sandbox_core_tool_compiler.kind_of_file(sourcefile) - return compiler.kind_of_file(sourcefile) -end - -- return module return sandbox_core_tool_compiler diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 50d22c988..ae0aaedd2 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -35,6 +35,7 @@ local option = require("base/option") local tool = require("tool/tool") local config = require("project/config") local sandbox = require("sandbox/sandbox") +local language = require("language/language") local platform = require("platform/platform") -- get the current tool @@ -233,34 +234,6 @@ function compiler:_addflags_from_compiler(flags, kind) end end --- get the compiler kind of the source file -function compiler.kind_of_file(sourcefile) - - -- get the source file type - local filetype = path.extension(sourcefile) - if not filetype then - return nil - end - - -- the kinds - local kinds = - { - [".c"] = "cc" - , [".cc"] = "cxx" - , [".cpp"] = "cxx" - , [".cxx"] = "cxx" - , [".m"] = "mm" - , [".mm"] = "mxx" - , [".s"] = "as" - , [".asm"] = "as" - , [".go"] = "go" - , [".swift"] = "sc" - } - - -- get kind - return kinds[filetype:lower()] -end - -- get the current kind function compiler:kind() |
