diff options
| author | ruki <[email protected]> | 2016-02-14 21:27:34 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-15 19:10:27 +0800 |
| commit | 52c273079851f2b83b9c632aec8e37b7482f6a83 (patch) | |
| tree | 039d06330552a10a5b456969dc88c43aac7bd833 | |
| parent | e056e25f57d12010ad5c5db4d6abd64e3450643f (diff) | |
warning only once and deprecate set/add_ api
| -rw-r--r-- | xmake/core/base/config.lua | 5 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 44 | ||||
| -rw-r--r-- | xmake/core/base/project.lua | 6 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 34 |
4 files changed, 81 insertions, 8 deletions
diff --git a/xmake/core/base/config.lua b/xmake/core/base/config.lua index 3cea6a652..80928c091 100644 --- a/xmake/core/base/config.lua +++ b/xmake/core/base/config.lua @@ -26,6 +26,7 @@ local config = config or {} -- load modules local io = require("base/io") local os = require("base/os") +local path = require("base/path") local utils = require("base/utils") local option = require("base/option") local global = require("base/global") @@ -83,7 +84,7 @@ end function config._file() -- get it - return config.directory() .. "/xmake.conf" + return path.join(config.directory(), "xmake.conf") end -- need configure? @@ -172,7 +173,7 @@ end function config.directory() -- the directory - local dir = xmake._PROJECT_DIR .. "/.xmake" + local dir = path.join(xmake._PROJECT_DIR, ".xmake") -- create it directly first if not exists if not os.isdir(dir) then diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 61f2f0270..1da93d5a0 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -523,9 +523,9 @@ function interpreter.api_register_builtin(self, name, func) self._PUBLIC[name] = func end --- register api for set_scope() +-- register api for def_scope() -- --- interp:api_register_set_scope("scope_kind1", "scope_kind2") +-- interp:api_register_def_scope("scope_kind1", "scope_kind2") -- -- api: -- set_$(scope_kind1)("scope_name1") @@ -563,6 +563,35 @@ end -- } -- } -- +function interpreter.api_register_def_scope(self, ...) + + -- check + assert(self) + + -- define implementation + local implementation = function (self, scopes, scope_kind, scope_name) + + -- init scope for kind + local scope_for_kind = scopes[scope_kind] or {} + scopes[scope_kind] = scope_for_kind + + -- init scope for name + scope_for_kind[scope_name] = scope_for_kind[scope_name] or {} + + -- save the current scope + scopes._CURRENT = scope_for_kind[scope_name] + + -- update the current scope kind + scopes._CURRENT_KIND = scope_kind + + end + + -- register implementation + self:_api_register_xxx_scope("def", implementation, ...) +end + +-- TODO: we will remove the deprecated api in the future +-- register api for set_scope() function interpreter.api_register_set_scope(self, ...) -- check @@ -575,6 +604,11 @@ function interpreter.api_register_set_scope(self, ...) local scope_for_kind = scopes[scope_kind] or {} scopes[scope_kind] = scope_for_kind + -- warning + if not scope_name:startswith("__") then + utils.warning("please uses def_%s(\"%s\"), \"set_%s\" has been deprecated!", scope_kind, scope_name, scope_kind) + end + -- check if not scope_for_kind[scope_name] then utils.error("set_%s(\"%s\") failed, %s not found!", scope_kind, scope_name, scope_name) @@ -597,6 +631,7 @@ function interpreter.api_register_set_scope(self, ...) self:_api_register_xxx_scope("set", implementation, ...) end +-- TODO: we will remove the deprecated api in the future -- register api for add_scope() function interpreter.api_register_add_scope(self, ...) @@ -610,6 +645,11 @@ function interpreter.api_register_add_scope(self, ...) local scope_for_kind = scopes[scope_kind] or {} scopes[scope_kind] = scope_for_kind + -- warning + if not scope_name:startswith("__") then + utils.warning("please uses def_%s(\"%s\"), \"add_%s\" has been deprecated!", scope_kind, scope_name, scope_kind) + end + -- check if scope_for_kind[scope_name] then utils.error("add_%s(\"%s\") failed, %s have been defined!", scope_kind, scope_name, scope_name) diff --git a/xmake/core/base/project.lua b/xmake/core/base/project.lua index 7929c4d2c..621fc8b05 100644 --- a/xmake/core/base/project.lua +++ b/xmake/core/base/project.lua @@ -326,12 +326,14 @@ function project._interpreter() -- set root directory interp:rootdir_set(xmake._PROJECT_DIR) + -- TODO: we will remove the deprecated api in the future -- register api: set_target() and set_option() interp:api_register_set_scope("target", "option") - - -- register api: add_target() and add_option() interp:api_register_add_scope("target", "option") + -- register api: def_target() and def_option() + interp:api_register_def_scope("target", "option") + -- register api: set_script() for target interp:api_register_set_script("target", nil, "runscript" , "installscript" diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index 1ee861922..6717b6045 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -69,8 +69,38 @@ function utils.warning(msg, ...) -- check assert(msg) - -- trace - print("warning: " .. string.format(msg, ...)) + -- format message + msg = "warning: " .. string.format(msg, ...) + + -- init warnings + utils._WARNINGS = utils._WARNINGS or {} + local warnings = utils._WARNINGS + + -- the cached file path + local cachedpath = path.translate(xmake._PROJECT_DIR .. "/.xmake/warnings") + + -- load warnings from the cached file + local cachedfile = io.open(cachedpath, "r") + if cachedfile then + for line in cachedfile:lines() do + warnings[line] = true + end + end + + -- trace only once + if not warnings[msg] then + print(msg) + warnings[msg] = true + end + + -- cache warnings + cachedfile = io.open(cachedpath, "w") + if cachedfile then + for line, _ in pairs(warnings) do + cachedfile:write(line .. "\n") + end + cachedfile:close() + end end -- ifelse, a? b : c |
