diff options
| author | ruki <[email protected]> | 2016-04-23 13:37:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-04-23 13:37:36 +0800 |
| commit | 31e930871e159dc022ddd1f7a326fcc120e2fb00 (patch) | |
| tree | 7004c115c96e7ed73bde20cb99c09bc0c6356df1 | |
| parent | 6f8d1fe8d6451d403e6c2ec72b630bb500b10b4d (diff) | |
load and get entry for platform
| -rw-r--r-- | xmake/core/platform/platform.lua | 81 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 1 |
2 files changed, 76 insertions, 6 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index ee16dc4d3..c17509558 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -30,9 +30,24 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local interpreter = require("base/interpreter") +local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("project/global") +-- new an instance +function _instance.new(name, info) + + -- new an instance + local instance = table.inherit(_instance) + + -- save name and info + instance._NAME = name + instance._INFO = info + + -- ok + return instance +end + -- get the platform os function _instance:os() @@ -61,6 +76,31 @@ function _instance:archs() return self._INFO.archs end +-- get the platform configure +function _instance:get(name) + + -- the info + local info = self._INFO + + -- load it first + if self._g == nil and info.load ~= nil then + + -- load it + local ok, errors = sandbox.load(info.load) + if not ok then + raise(errors) + end + + -- save _g + self._g = getfenv(info.load)._g + end + + -- get it + if self._g ~= nil then + return self._g[name] + end +end + -- the directories of platform function platform._directories() @@ -142,7 +182,6 @@ function platform.load(plat) -- load platform local results, errors = platform._interpreter():load(scriptpath, "platform", true, false) if not results and os.isfile(scriptpath) then - -- failed return nil, errors end @@ -152,11 +191,10 @@ function platform.load(plat) end -- new an instance - local instance = table.inherit(_instance) - - -- save name and info - instance._NAME = plat - instance._INFO = results[plat] + local instance, errors = _instance.new(plat, results[plat]) + if not instance then + return nil, errors + end -- save instance to the cache platform._PLATFORMS[plat] = instance @@ -179,6 +217,16 @@ function platform.os(plat) return instance:os() end +-- get the given platform configure +function platform.get(name) + + -- get the current platform configure + local instance = platform.load() + if instance then + return instance:get(name) + end +end + -- get the platform archs function platform.archs(plat) @@ -223,5 +271,26 @@ function platform.plats() return plats end +-- get the given tool +function platform.tool(name) + + -- get tools + local tools = platform.get("tools") + if tools then + return tools[name] + end +end + +-- get the given format +function platform.format(kind) + + -- get formats + local formats = platform.get("formats") + if formats then + return formats[kind] + end +end + + -- return module return platform diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index c4da87b05..2d7fcbbaf 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -59,6 +59,7 @@ function sandbox._traceback(errors) -- get debug info local info = debug.getinfo(level, "Sln") + table.dump(info) -- end? if not info then |
