diff options
| author | ruki <[email protected]> | 2017-07-14 13:35:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-14 13:35:29 +0800 |
| commit | 70716c5ed3037f2aaf79c6c19b175c0018e7309f (patch) | |
| tree | 6fba1dec356b7508f21c9c3a0519e6f424f28f41 | |
| parent | f39f4a27d43a1f63d56ae3c9f7fc34b5158e299a (diff) | |
add language kinds
| -rw-r--r-- | xmake/core/language/language.lua | 48 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/language/language.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 37 | ||||
| -rw-r--r-- | xmake/languages/asm/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/c++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/dlang/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/golang/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/msrc/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/objc++/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/rust/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/languages/swift/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gcc/features.lua | 13 |
12 files changed, 105 insertions, 22 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index dbe66b6b8..a1f2015f8 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -154,6 +154,11 @@ function _instance:mixingkinds() return self._INFO.mixingkinds end +-- get the language kinds +function _instance:langkinds() + return self._INFO.langkinds +end + -- get the name flags function _instance:nameflags() @@ -244,6 +249,7 @@ function language._interpreter() { -- language.set_xxx "language.set_nameflags" + , "language.set_langkinds" , "language.set_sourcekinds" , "language.set_sourceflags" , "language.set_targetkinds" @@ -664,5 +670,47 @@ function language.targetkinds() return targetkinds end +-- get language kinds (langkind => sourcekind) +-- +-- .e.g +-- +-- { +-- c = "cc" +-- , cxx = "cxx" +-- , m = "mm" +-- , mxx = "mxx" +-- , swift = "sc" +-- , go = "gc" +-- , as = "as" +-- , rust = "rc" +-- , d = "dc" +-- } +-- +function language.langkinds() + + -- attempt to get it from cache + if language._LANGKINDS then + return language._LANGKINDS + end + + -- load all languages + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + + -- merge all for each language + local langkinds = {} + for name, instance in pairs(languages) do + table.join2(langkinds, instance:langkinds()) + end + + -- cache it + language._LANGKINDS = langkinds + + -- ok + return langkinds +end + -- return module return language diff --git a/xmake/core/sandbox/modules/import/core/language/language.lua b/xmake/core/sandbox/modules/import/core/language/language.lua index 392f76d81..49a6abf1e 100644 --- a/xmake/core/sandbox/modules/import/core/language/language.lua +++ b/xmake/core/sandbox/modules/import/core/language/language.lua @@ -54,6 +54,11 @@ function sandbox_core_language.linkerkinds() return language.linkerkinds() end +-- get the language kinds of all languages +function sandbox_core_language.langkinds() + return language.langkinds() +end + -- load the language from the given name (c++, objc++, swift, golang, asm, ...) function sandbox_core_language.load(name) diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index 12cb8cf24..712ae3852 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -173,13 +173,17 @@ end -- get all compiler features -- --- @param sourcekind the source kind, .e.g cc, cxx, mm, mxx, sc +-- @param langkind the language kind, .e.g c, cxx, mm, mxx, swift, go, rust, d, as -- @param opt the argument options (contain all the compiler attributes of target), -- .e.g {target = ..., targetkind = "static", cxflags = "", defines = "", includedirs = "", ...} -- -- @return the features -- -function sandbox_core_tool_compiler.features(sourcekind, opt) +function sandbox_core_tool_compiler.features(langkind, opt) + + -- get sourcekind from the language kind + local sourcekind = language.langkinds()[langkind] + assert(sourcekind, "unknown language kind: " .. langkind) -- get the compiler instance local instance, errors = compiler.load(sourcekind) @@ -218,37 +222,38 @@ end -- function sandbox_core_tool_compiler.has_features(features, opt) - -- init maps for c, objc - local kinds = {c = "cc", m = "mm"} - -- import "lib.detect.has_features" sandbox_core_tool_compiler._has_features = sandbox_core_tool_compiler._has_features or import("lib.detect.has_features") if not sandbox_core_tool_compiler._has_features then return end - -- classify features by kind + -- get the language kinds + local langkinds = language.langkinds() + + -- classify features by the source kind local features_by_kind = {} for _, feature in ipairs(table.wrap(features)) do - -- get feature kind - local kind = feature:match("^(%w-)_") - assert(kind, "unknown kind for the feature: %s", feature) + -- get language kind + local langkind = feature:match("^(%w-)_") + assert(langkind, "unknown language kind for the feature: %s", feature) - -- fix kind for c, objc - kind = kinds[kind] or kind + -- get the sourcekind from the language kind + local sourcekind = langkinds[langkind] + assert(sourcekind, "unknown language kind: " .. langkind) -- add feature - features_by_kind[kind] = features_by_kind[kind] or {} - table.insert(features_by_kind[kind], feature) + features_by_kind[sourcekind] = features_by_kind[sourcekind] or {} + table.insert(features_by_kind[sourcekind], feature) end -- has features for each compiler? local results = nil - for kind, features in pairs(features_by_kind) do + for sourcekind, features in pairs(features_by_kind) do -- get the compiler instance - local instance, errors = compiler.load(kind) + local instance, errors = compiler.load(sourcekind) if not instance then raise(errors) end @@ -274,7 +279,7 @@ end -- has the given flags? -- --- @param sourcekind the source kind +-- @param sourcekind the source kind, .e.g cc, cxx, sc, gc, dc, rc, .. -- @param flags the flags -- -- @return the supported flags or nil diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua index d1b93ee42..4f729233f 100644 --- a/xmake/languages/asm/xmake.lua +++ b/xmake/languages/asm/xmake.lua @@ -37,6 +37,9 @@ language("asm") -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + -- set language kinds + set_langkinds {as = "as"} + -- set mixing kinds set_mixingkinds("as") diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index e061f06e9..43be57228 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -37,6 +37,9 @@ language("c++") -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + -- set language kinds + set_langkinds {c = "cc", cxx = "cxx"} + -- set mixing kinds set_mixingkinds("cc", "cxx", "as", "mrc") diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua index cb0ba9fe4..3052d7f65 100644 --- a/xmake/languages/dlang/xmake.lua +++ b/xmake/languages/dlang/xmake.lua @@ -37,6 +37,9 @@ language("dlang") -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + -- set language kinds + set_langkinds {d = "dc"} + -- set mixing kinds set_mixingkinds("dc", "cc", "cxx", "as") diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index 72f0faceb..5a0119f34 100644 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -37,6 +37,9 @@ language("golang") -- set target flags set_targetflags {binary = "ldflags", static = "arflags"} + -- set language kinds + set_langkinds {go = "gc"} + -- set mixing kinds set_mixingkinds("gc") diff --git a/xmake/languages/msrc/xmake.lua b/xmake/languages/msrc/xmake.lua index 9bcfcc488..e554c15a3 100644 --- a/xmake/languages/msrc/xmake.lua +++ b/xmake/languages/msrc/xmake.lua @@ -31,6 +31,9 @@ language("msrc") -- set source file flags set_sourceflags {mrc = "mrcflags"} + -- set language kinds + set_langkinds {msrc = "mrc"} + -- set mixing kinds set_mixingkinds("mrc") diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua index f1103fe63..8ba0dc135 100644 --- a/xmake/languages/objc++/xmake.lua +++ b/xmake/languages/objc++/xmake.lua @@ -37,6 +37,9 @@ language("objc++") -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + -- set language kinds + set_langkinds {m = "mm", mxx = "mxx"} + -- set mixing kinds set_mixingkinds("mm", "mxx", "cc", "cxx", "as") diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua index 0167dc5a8..5a66990a8 100644 --- a/xmake/languages/rust/xmake.lua +++ b/xmake/languages/rust/xmake.lua @@ -37,6 +37,9 @@ language("rust") -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + -- set language kinds + set_langkinds {rust = "rc"} + -- set mixing kinds set_mixingkinds("rc") diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index adbdf994b..503928555 100644 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -37,6 +37,9 @@ language("swift") -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + -- set language kinds + set_langkinds {swift = "sc"} + -- set mixing kinds set_mixingkinds("sc", "mm", "mxx", "cc", "cxx") diff --git a/xmake/modules/detect/tools/gcc/features.lua b/xmake/modules/detect/tools/gcc/features.lua index da65e87a2..09c9e857a 100644 --- a/xmake/modules/detect/tools/gcc/features.lua +++ b/xmake/modules/detect/tools/gcc/features.lua @@ -59,15 +59,16 @@ function _set_feature(feature, condition) -- init features _g.features = _g.features or {} - -- get feature kind - local kind = feature:match("^(%w-)_") - assert(kind, "unknown kind for the feature: %s", feature) + -- get language kind + local langkind = feature:match("^(%w-)_") + assert(langkind, "unknown language kind for the feature: %s", feature) - -- init maps for c, objc - local kinds = {c = "cc", m = "mm"} + -- get source kind from the language kind + local sourcekind = language.langkinds()[langkind] + assert(sourcekind, "unknown language kind: " .. langkind) -- get extension - local extension = table.wrap(language.sourcekinds()[kinds[kind] or kind])[1] + local extension = table.wrap(language.sourcekinds()[sourcekind])[1] assert(extension, "not supported kind for the feature: %s", feature) -- make snippet |
