diff options
| author | ruki <[email protected]> | 2019-02-03 12:20:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-02-03 12:20:55 +0800 |
| commit | 2c7a2ff446fd7ad85922a2990d6452627133c8c3 (patch) | |
| tree | e1502c769f9e1aa590e37b571d453a6123e9cc53 | |
| parent | e35595f73271cb14363c027694183dec3a32e910 (diff) | |
improve deprecated tips
| -rw-r--r-- | xmake/core/base/deprecated.lua | 16 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 22 | ||||
| -rw-r--r-- | xmake/core/project/deprecated/project.lua | 83 |
3 files changed, 88 insertions, 33 deletions
diff --git a/xmake/core/base/deprecated.lua b/xmake/core/base/deprecated.lua index 89702a89a..657d48f86 100644 --- a/xmake/core/base/deprecated.lua +++ b/xmake/core/base/deprecated.lua @@ -48,32 +48,26 @@ end -- dump all deprecated entries function deprecated.dump() - -- the entries - deprecated._ENTRIES = deprecated._ENTRIES or {} - - -- dump all + -- dump one or more .. local index = 0 + deprecated._ENTRIES = deprecated._ENTRIES or {} for old, new in pairs(deprecated._ENTRIES) do - -- trace newline + -- trace if index == 0 then print("") end - - -- trace if new then utils.cprint("${bright color.warning}deprecated: ${clear}please uses %s instead of %s", new, old) else utils.cprint("${bright color.warning}deprecated: ${clear}please remove %s", old) end - -- too much? - if index > 6 and not option.get("verbose") then + -- show more? + if not option.get("verbose") then utils.cprint("${bright color.warning}deprecated: ${clear}add -v for getting more ..") break end - - -- update index index = index + 1 end end diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 544c2dd5e..4cf4dc307 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -396,6 +396,28 @@ function interpreter:_api_within_scope(scope_kind, apiname) end end +-- set api function within scope +function interpreter:_api_within_scope_set(scope_kind, apiname, apifunc) + + -- the private + local priv = self._PRIVATE + assert(priv) + + -- the scopes + local scopes = priv._SCOPES + assert(scopes) + + -- get scope api + if scope_kind and priv._APIS then + + -- get api function + local api_scope = priv._APIS[scope_kind] + if api_scope then + api_scope[apiname] = apifunc + end + end +end + -- clear results function interpreter:_clear() diff --git a/xmake/core/project/deprecated/project.lua b/xmake/core/project/deprecated/project.lua index 4c1c5e349..a7df6594c 100644 --- a/xmake/core/project/deprecated/project.lua +++ b/xmake/core/project/deprecated/project.lua @@ -101,54 +101,91 @@ function deprecated_project._api_add_packages(interp, ...) return deprecated_project._api_add_pkgs(interp, ...) end --- set_enable for option -function deprecated_project._api_option_set_enable(interp) +-- add_csnippet/add_cxxsnippet for option +function deprecated_project._api_option_add_cxsnippet(interp, apiname) -- get api function - local apifunc = interp:_api_within_scope("option", "set_default") + local apifunc = interp:_api_within_scope("option", apiname) assert(apifunc) -- register api - interp:api_register_builtin("set_enable", function (value) + interp:_api_within_scope_set("option", apiname, function (...) -- deprecated - deprecated.add("set_default(%s)", "set_enable(%s)", tostring(value)) + deprecated.add(apiname .. "s(...)", apiname .. "(...)") -- dispatch it - apifunc(value) + apifunc(...) end) end --- add_csnippet/add_cxxsnippet for option -function deprecated_project._api_option_add_cxsnippet(interp, apiname) +-- add_headers for target +function deprecated_project._api_target_add_headers(interp) -- get api function - local apifunc = interp:_api_within_scope("option", apiname .. 's') + local apifunc = interp:_api_within_scope("target", "add_headers") assert(apifunc) -- register api - interp:api_register_builtin(apiname, function (...) + interp:_api_within_scope_set("target", "add_headers", function (value, ...) -- deprecated - deprecated.add(apiname .. "s(...)", apiname .. "(...)") - + deprecated.add("add_headerfiles(%s)", "add_headers(%s)", tostring(value)) + -- dispatch it - apifunc(...) + apifunc(value, ...) end) end --- add_headers for target -function deprecated_project._api_target_add_headers(interp) + +-- add_defines_h for target +function deprecated_project._api_target_add_defines_h(interp) -- get api function - local apifunc = interp:_api_within_scope("target", "add_headers") + local apifunc = interp:_api_within_scope("target", "add_defines_h") assert(apifunc) -- register api - interp:api_register_builtin("add_headers", function (value, ...) + interp:_api_within_scope_set("target", "add_defines_h", function (value, ...) -- deprecated - deprecated.add("add_headerfiles(%s)", "add_headers(%s)", tostring(value)) + deprecated.add("add_configfiles() and set_configvar(%s)", "add_defines_h(%s)", tostring(value)) + + -- dispatch it + apifunc(value, ...) + end) +end + +-- add_defines_h for option +function deprecated_project._api_option_add_defines_h(interp) + + -- get api function + local apifunc = interp:_api_within_scope("option", "add_defines_h") + assert(apifunc) + + -- register api + interp:_api_within_scope_set("option", "add_defines_h", function (value, ...) + + -- deprecated + deprecated.add("add_configfiles() and set_configvar(%s)", "add_defines_h(%s)", tostring(value)) + + -- dispatch it + apifunc(value, ...) + end) +end + +-- set_config_header for target +function deprecated_project._api_target_set_config_header(interp) + + -- get api function + local apifunc = interp:_api_within_scope("target", "set_config_header") + assert(apifunc) + + -- register api + interp:_api_within_scope_set("target", "set_config_header", function (value, ...) + + -- deprecated + deprecated.add("add_configfiles(%s.in)", "set_config_header(%s)", tostring(value)) -- dispatch it apifunc(value, ...) @@ -163,7 +200,7 @@ function deprecated_project._api_target_set_headerdir(interp) assert(apifunc) -- register api - interp:api_register_builtin("set_headerdir", function (value, ...) + interp:_api_within_scope_set("target", "set_headerdir", function (value, ...) -- deprecated deprecated.add(false, "set_headerdir(%s)", tostring(value)) @@ -207,9 +244,6 @@ function deprecated_project.api_register(interp) -- register api: is_option() to root interp:api_register(nil, "is_option", deprecated_project._api_is_option) - -- register api: set_enable() to option - deprecated_project._api_option_set_enable(interp) - -- register api: add_csnippet/add_cxxsnippet() to option deprecated_project._api_option_add_cxsnippet(interp, "add_csnippet") deprecated_project._api_option_add_cxsnippet(interp, "add_cxxsnippet") @@ -217,6 +251,11 @@ function deprecated_project.api_register(interp) -- register api: add_headers() to target deprecated_project._api_target_add_headers(interp) + -- register api: add_defines_h()/set_config_header() to option/target + deprecated_project._api_option_add_defines_h(interp) + deprecated_project._api_target_add_defines_h(interp) + deprecated_project._api_target_set_config_header(interp) + -- register api: set_headerdir() to target deprecated_project._api_target_set_headerdir(interp) end |
