summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-07-28 22:39:51 +0800
committerruki <[email protected]>2021-07-28 22:39:51 +0800
commit62d98516dcf2f7d6b5381adc429c977deba7674b (patch)
treef2cb87e702d51843853588cbad344733ba93696c
parent6ce79433b71434680d166710e403360998b8a44f (diff)
improve vala language
-rw-r--r--xmake/core/language/language.lua239
-rw-r--r--xmake/languages/vala/api.lua74
-rw-r--r--xmake/languages/vala/load.lua58
-rw-r--r--xmake/languages/vala/xmake.lua21
4 files changed, 129 insertions, 263 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua
index 4815d47db..0b38769da 100644
--- a/xmake/core/language/language.lua
+++ b/xmake/core/language/language.lua
@@ -247,11 +247,7 @@ function language._interpreter()
, "language.set_targetflags"
}
}
-
- -- save interpreter
language._INTERPRETER = interp
-
- -- ok?
return interp
end
@@ -313,11 +309,7 @@ function language.load(name)
if not instance then
return nil, errors
end
-
- -- save instance to the cache
language._LANGUAGES[name] = instance
-
- -- ok
return instance
end
@@ -347,16 +339,10 @@ function language.load_sk(sourcekind)
break
end
end
-
- -- not found?
if not result then
return nil, string.format("unknown language sourcekind: %s", sourcekind)
end
-
- -- cache this language
language._LANGUAGES_OF_SK[sourcekind] = result
-
- -- ok
return result
end
@@ -386,45 +372,37 @@ function language.load_ex(extension)
break
end
end
-
- -- not found?
if not result then
return nil, string.format("unknown language source extension: %s", extension)
end
-
- -- cache this language
language._LANGUAGES_OF_EX[extension] = result
-
- -- ok
return result
end
-- load the language apis
function language.apis()
-
- -- load all languages
- local languages, errors = language.load()
- if not languages then
- os.raise(errors)
- end
-
- -- merge apis for each language
- local apis = {values = {}, paths = {}, custom = {}, dictionary = {}}
- for name, instance in pairs(languages) do
- local instance_apis = instance:get("apis")
- if instance_apis then
- table.join2(apis.values, table.wrap(instance_apis.values))
- table.join2(apis.paths, table.wrap(instance_apis.paths))
- table.join2(apis.custom, table.wrap(instance_apis.custom))
- table.join2(apis.dictionary, table.wrap(instance_apis.dictionary))
+ local apis = language._APIS
+ if not apis then
+ local languages, errors = language.load()
+ if not languages then
+ os.raise(errors)
+ end
+ apis = {values = {}, paths = {}, custom = {}, dictionary = {}}
+ for name, instance in pairs(languages) do
+ local instance_apis = instance:get("apis")
+ if instance_apis then
+ table.join2(apis.values, table.wrap(instance_apis.values))
+ table.join2(apis.paths, table.wrap(instance_apis.paths))
+ table.join2(apis.custom, table.wrap(instance_apis.custom))
+ table.join2(apis.dictionary, table.wrap(instance_apis.dictionary))
+ end
end
+ apis.values = table.unique(apis.values)
+ apis.paths = table.unique(apis.paths)
+ apis.custom = table.unique(apis.custom)
+ language._APIS = apis
end
- apis.values = table.unique(apis.values)
- apis.paths = table.unique(apis.paths)
- apis.custom = table.unique(apis.custom)
-
- -- ok
return apis
end
@@ -443,28 +421,18 @@ end
-- }
--
function language.extensions()
-
- -- attempt to get it from cache
- if language._EXTENSIONS then
- return language._EXTENSIONS
- end
-
- -- load all languages
- local languages, errors = language.load()
- if not languages then
- os.raise(errors)
- end
-
- -- merge all for each language
- local extensions = {}
- for name, instance in pairs(languages) do
- table.join2(extensions, instance:extensions())
+ local extensions = language._EXTENSIONS
+ if not extensions then
+ local languages, errors = language.load()
+ if not languages then
+ os.raise(errors)
+ end
+ extensions = {}
+ for name, instance in pairs(languages) do
+ table.join2(extensions, instance:extensions())
+ end
+ language._EXTENSIONS = extensions
end
-
- -- cache it
- language._EXTENSIONS = extensions
-
- -- ok
return extensions
end
@@ -482,28 +450,18 @@ end
-- }
--
function language.sourcekinds()
-
- -- attempt to get it from cache
- if language._SOURCEKINDS then
- return language._SOURCEKINDS
- end
-
- -- load all languages
- local languages, errors = language.load()
- if not languages then
- os.raise(errors)
- end
-
- -- merge all for each language
- local sourcekinds = {}
- for name, instance in pairs(languages) do
- table.join2(sourcekinds, instance:sourcekinds())
+ local sourcekinds = language._SOURCEKINDS
+ if not sourcekinds then
+ local languages, errors = language.load()
+ if not languages then
+ os.raise(errors)
+ end
+ sourcekinds = {}
+ for name, instance in pairs(languages) do
+ table.join2(sourcekinds, instance:sourcekinds())
+ end
+ language._SOURCEKINDS = sourcekinds
end
-
- -- cache it
- language._SOURCEKINDS = sourcekinds
-
- -- ok
return sourcekinds
end
@@ -518,28 +476,18 @@ end
-- }
--
function language.sourceflags()
-
- -- attempt to get it from cache
- if language._SOURCEFLAGS then
- return language._SOURCEFLAGS
- end
-
- -- load all languages
- local languages, errors = language.load()
- if not languages then
- os.raise(errors)
- end
-
- -- merge all for each language
- local sourceflags = {}
- for name, instance in pairs(languages) do
- table.join2(sourceflags, instance:sourceflags())
+ local sourceflags = language._SOURCEFLAGS
+ if not sourceflags then
+ local languages, errors = language.load()
+ if not languages then
+ os.raise(errors)
+ end
+ sourceflags = {}
+ for name, instance in pairs(languages) do
+ table.join2(sourceflags, instance:sourceflags())
+ end
+ language._SOURCEFLAGS = sourceflags
end
-
- -- cache it
- language._SOURCEFLAGS = sourceflags
-
- -- ok
return sourceflags
end
@@ -560,21 +508,15 @@ function language.sourcekind_of(sourcefile)
if not sourcekind then
return nil, string.format("%s is unknown extension", extension)
end
-
- -- ok
return sourcekind
end
-- get extension of the source kind
function language.extension_of(sourcekind)
-
- -- get extension
local extension = table.wrap(language.sourcekinds()[sourcekind])[1]
if not extension then
return nil, string.format("%s is unknown source kind", sourcekind)
end
-
- -- ok
return extension
end
@@ -615,8 +557,6 @@ function language.linkerinfos_of(targetkind, sourcekinds)
end
end
end
-
- -- cache it
language._LINKERINFOS = linkerinfos
end
@@ -654,34 +594,24 @@ end
-- }
--
function language.targetkinds()
-
- -- attempt to get it from cache
- if language._TARGETKINDS then
- return language._TARGETKINDS
- end
-
- -- load all languages
- local languages, errors = language.load()
- if not languages then
- os.raise(errors)
- end
-
- -- merge all for each language
- local targetkinds = {}
- for name, instance in pairs(languages) do
- for targetkind, linkerkind in pairs(table.wrap(instance:kinds())) do
- targetkinds[targetkind] = targetkinds[targetkind] or {}
- table.insert(targetkinds[targetkind], linkerkind)
+ local targetkinds = language._TARGETKINDS
+ if not targetkinds then
+ local languages, errors = language.load()
+ if not languages then
+ os.raise(errors)
end
+ targetkinds = {}
+ for name, instance in pairs(languages) do
+ for targetkind, linkerkind in pairs(table.wrap(instance:kinds())) do
+ targetkinds[targetkind] = targetkinds[targetkind] or {}
+ table.insert(targetkinds[targetkind], linkerkind)
+ end
+ end
+ for targetkind, linkerkinds in pairs(targetkinds) do
+ targetkinds[targetkind] = table.unique(linkerkinds)
+ end
+ language._TARGETKINDS = targetkinds
end
- for targetkind, linkerkinds in pairs(targetkinds) do
- targetkinds[targetkind] = table.unique(linkerkinds)
- end
-
- -- cache it
- language._TARGETKINDS = targetkinds
-
- -- ok
return targetkinds
end
@@ -702,30 +632,19 @@ end
-- }
--
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())
+ local langkinds = language._LANGKINDS
+ if not langkinds then
+ local languages, errors = language.load()
+ if not languages then
+ os.raise(errors)
+ end
+ langkinds = {}
+ for name, instance in pairs(languages) do
+ table.join2(langkinds, instance:langkinds())
+ end
+ language._LANGKINDS = langkinds
end
-
- -- cache it
- language._LANGKINDS = langkinds
-
- -- ok
return langkinds
end
--- return module
return language
diff --git a/xmake/languages/vala/api.lua b/xmake/languages/vala/api.lua
deleted file mode 100644
index 3501a2e9d..000000000
--- a/xmake/languages/vala/api.lua
+++ /dev/null
@@ -1,74 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, TBOOX Open Source Group.
---
--- @author ruki
--- @file api.lua
---
-
--- get apis
-function apis()
-
- -- init apis
- _g.values =
- {
- -- target.add_xxx
- "target.add_links"
- , "target.add_syslinks"
- , "target.add_zcflags"
- , "target.add_ldflags"
- , "target.add_arflags"
- , "target.add_shflags"
- , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
- -- option.add_xxx
- , "option.add_links"
- , "option.add_syslinks"
- , "option.add_zcflags"
- , "option.add_ldflags"
- , "option.add_arflags"
- , "option.add_shflags"
- , "option.add_rpathdirs"
- -- package.add_xxx
- , "package.add_links"
- , "package.add_syslinks"
- , "package.add_zcflags"
- , "package.add_ldflags"
- , "package.add_arflags"
- , "package.add_shflags"
- , "package.add_rpathdirs"
- , "package.add_linkdirs"
- -- toolchain.add_xxx
- , "toolchain.add_links"
- , "toolchain.add_syslinks"
- , "toolchain.add_zcflags"
- , "toolchain.add_ldflags"
- , "toolchain.add_arflags"
- , "toolchain.add_shflags"
- , "toolchain.add_rpathdirs"
- , "toolchain.add_linkdirs"
- }
- _g.paths =
- {
- -- target.add_xxx
- "target.add_linkdirs"
- -- option.add_xxx
- , "option.add_linkdirs"
- }
-
- -- ok
- return _g
-end
-
-
diff --git a/xmake/languages/vala/load.lua b/xmake/languages/vala/load.lua
index fd547b488..fd48aab63 100644
--- a/xmake/languages/vala/load.lua
+++ b/xmake/languages/vala/load.lua
@@ -18,17 +18,57 @@
-- @file load.lua
--
--- imports
-import("api")
+function _get_apis()
+ local apis = {}
+ apis.values =
+ {
+ -- target.add_xxx
+ "target.add_links"
+ , "target.add_syslinks"
+ , "target.add_vaflags"
+ , "target.add_ldflags"
+ , "target.add_arflags"
+ , "target.add_shflags"
+ , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path
+ -- option.add_xxx
+ , "option.add_links"
+ , "option.add_syslinks"
+ , "option.add_vaflags"
+ , "option.add_ldflags"
+ , "option.add_arflags"
+ , "option.add_shflags"
+ , "option.add_rpathdirs"
+ -- package.add_xxx
+ , "package.add_links"
+ , "package.add_syslinks"
+ , "package.add_vaflags"
+ , "package.add_ldflags"
+ , "package.add_arflags"
+ , "package.add_shflags"
+ , "package.add_rpathdirs"
+ , "package.add_linkdirs"
+ -- toolchain.add_xxx
+ , "toolchain.add_links"
+ , "toolchain.add_syslinks"
+ , "toolchain.add_vaflags"
+ , "toolchain.add_ldflags"
+ , "toolchain.add_arflags"
+ , "toolchain.add_shflags"
+ , "toolchain.add_rpathdirs"
+ , "toolchain.add_linkdirs"
+ }
+ apis.paths =
+ {
+ -- target.add_xxx
+ "target.add_linkdirs"
+ -- option.add_xxx
+ , "option.add_linkdirs"
+ }
+ return apis
+end
--- load it
function main()
-
- -- init apis
- _g.apis = api.apis()
-
- -- ok
- return _g
+ return {apis = _get_apis()}
end
diff --git a/xmake/languages/vala/xmake.lua b/xmake/languages/vala/xmake.lua
index 09f6a7f6b..1639f2f16 100644
--- a/xmake/languages/vala/xmake.lua
+++ b/xmake/languages/vala/xmake.lua
@@ -18,37 +18,19 @@
-- @file xmake.lua
--
--- define language
language("vala")
-
- -- set source file kinds
set_sourcekinds {va = ".vala"}
-
- -- set source file flags
set_sourceflags {va = "vaflags"}
-
- -- set target kinds
set_targetkinds {binary = "vald", static = "vaar", shared = "vash"}
-
- -- set target flags
set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
+ set_langkinds {vala = "va"}
- -- set language kinds
- set_langkinds {vala = "va"}
-
- -- set mixing kinds
set_mixingkinds("va", "cc", "cxx", "as")
-
- -- add rules
add_rules("vala")
- -- on load
on_load("load")
-
- -- on check_main
on_check_main("check_main")
- -- set name flags
set_nameflags
{
object =
@@ -95,7 +77,6 @@ language("vala")
}
}
- -- set menu
set_menu {
config =
{