diff options
| author | ruki <[email protected]> | 2016-06-09 20:27:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-06-09 20:27:48 +0800 |
| commit | cb9ce25dd0e7669189124a89bf6171190707b13e (patch) | |
| tree | 52a7953866430eb2c85eba180140c7195e26ac28 | |
| parent | 2429c51cf05dd13bc481704ad0a59e1bcef03ade (diff) | |
improve the macro plugin
| -rw-r--r-- | xmake/core/project/option.lua | 59 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 58 | ||||
| -rwxr-xr-x | xmake/plugins/macro/main.lua | 68 | ||||
| -rwxr-xr-x | xmake/plugins/macro/xmake.lua | 11 |
4 files changed, 128 insertions, 68 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index c74fc4279..dcc61c4bd 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -30,6 +30,7 @@ local path = require("base/path") local table = require("base/table") local utils = require("base/utils") local option_ = require("base/option") +local config = require("project/config") local cache = require("project/cache")("local.option") local linker = require("tool/linker") local compiler = require("tool/compiler") @@ -384,7 +385,13 @@ function option:_check_cxxtypes(cxxfile, objectfile, targetfile) end -- check option -function option:check(cfile, cxxfile, objectfile, targetfile) +function option:_check() + + -- the files + local cfile = path.join(os.tmpdir(), "__checking.c") + local cxxfile = path.join(os.tmpdir(), "__checking.cpp") + local objectfile = path.join(os.tmpdir(), "__checking.obj") + local targetfile = path.join(os.tmpdir(), "__checking.bin") -- check links if not self:_check_links(cfile, objectfile, targetfile) then return false end @@ -412,10 +419,60 @@ function option:check(cfile, cxxfile, objectfile, targetfile) end + -- remove files + os.rm(cfile) + os.rm(cxxfile) + os.rm(objectfile) + os.rm(targetfile) + -- ok return true end +-- attempt to check option +function option:check() + + -- the option name + local name = self:name() + + -- need check? + if config.get(name) == nil then + + -- enable it? + local enable = self:get("enable") + if enable ~= nil and enable then + + -- enable this option + config.set(name, true) + + -- save this option to configure + self:save() + + -- check option + elseif enable == nil and self:_check() then + + -- enable this option + config.set(name, true) + + -- save this option to configure + self:save() + else + + -- disable this option + config.set(name, false) + + -- clear this option to configure + self:clear() + end + + -- no check + elseif config.get(name) then + + -- save this option to configure directly + self:save() + end +end + -- get the option info function option:get(infoname) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index fb32e3623..2319d2a98 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -539,64 +539,12 @@ function project.check() -- enter toolchains environment environment.enter("toolchains") - - -- the source file path - local cfile = path.join(os.tmpdir(), "__checking.c") - local cxxfile = path.join(os.tmpdir(), "__checking.cpp") - - -- the object file path - local objectfile = path.join(os.tmpdir(), target.filename("__checking", "object")) - - -- the target file path - local targetfile = path.join(os.tmpdir(), target.filename("__checking", "binary")) - - -- make all options - for name, opt in pairs(options) do - - -- need check? - if config.get(name) == nil then - - -- enable it? - local enable = opt:get("enable") - if enable ~= nil and enable then - - -- enable this option - config.set(name, true) - - -- save this option to configure - opt:save() - -- check option - elseif enable == nil and opt:check(cfile, cxxfile, objectfile, targetfile) then - - -- enable this option - config.set(name, true) - - -- save this option to configure - opt:save() - else - - -- disable this option - config.set(name, false) - - -- clear this option to configure - opt:clear() - end - - -- no check - elseif config.get(name) then - - -- save this option to configure directly - opt:save() - end + -- check all options + for _, opt in pairs(options) do + opt:check() end - -- remove files - os.rm(cfile) - os.rm(cxxfile) - os.rm(objectfile) - os.rm(targetfile) - -- leave toolchains environment environment.leave("toolchains") diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua index b83b156b4..46c5e91aa 100755 --- a/xmake/plugins/macro/main.lua +++ b/xmake/plugins/macro/main.lua @@ -113,6 +113,13 @@ function _show(macroname) end end +-- clear all macros +function _clear() + + -- clear all + os.rm(path.join(config.directory(), "macros")) +end + -- delete macro function _delete(macroname) @@ -132,21 +139,61 @@ end -- import macro function _import(macrofile, macroname) - -- import it - os.cp(macrofile, _wfile(macroname)) + -- import all macros + if os.isdir(macrofile) then - -- trace - print("import macro(%s) ok!", macroname) + -- the macro directory + local macrodir = macrofile + local macrofiles = os.match(path.join(macrodir, "*.lua")) + for _, macrofile in ipairs(macrofiles) do + + -- the macro name + macroname = path.basename(macrofile) + + -- import it + os.cp(macrofile, _wfile(macroname)) + + -- trace + print("import macro(%s) ok!", macroname) + end + else + + -- import it + os.cp(macrofile, _wfile(macroname)) + + -- trace + print("import macro(%s) ok!", macroname) + end end -- export macro function _export(macrofile, macroname) - -- export it - os.cp(_rfile(macroname), macrofile) + -- export all macros + if os.isdir(macrofile) then - -- trace - print("export macro(%s) ok!", macroname) + -- the output directory + local outputdir = macrofile + + -- export all macros + for _, dir in ipairs(_directories()) do + local macrofiles = os.match(path.join(dir, "*.lua")) + for _, macrofile in ipairs(macrofiles) do + + -- export it + os.cp(macrofile, outputdir) + + -- trace + print("export macro(%s) ok!", path.basename(macrofile)) + end + end + else + -- export it + os.cp(_rfile(macroname), macrofile) + + -- trace + print("export macro(%s) ok!", macroname) + end end -- begin to record macro @@ -261,6 +308,11 @@ function main() _show(option.get("name")) + -- clear macro + elseif option.get("clear") then + + _clear() + -- delete macro elseif option.get("delete") then diff --git a/xmake/plugins/macro/xmake.lua b/xmake/plugins/macro/xmake.lua index f28c5b49f..4b6fd5ccd 100755 --- a/xmake/plugins/macro/xmake.lua +++ b/xmake/plugins/macro/xmake.lua @@ -57,13 +57,16 @@ task("macro") , {nil, "show", "k", nil, "Show the content of the given macro." } , {'l', "list", "k", nil, "List all macros." } , {'d', "delete", "k", nil, "Delete the given macro." } + , {'c', "clear", "k", nil, "Clear the all macros." } , {} - , {nil, "import", "kv", nil, "Import the given macro file." + , {nil, "import", "kv", nil, "Import the given macro file or directory." , ".e.g" - , " xmake macro --import=/xxx/macro.lua test" } - , {nil, "export", "kv", nil, "Export the given macro to file." + , " xmake macro --import=/xxx/macro.lua test" + , " xmake macro --import=/xxx/macrodir" } + , {nil, "export", "kv", nil, "Export the given macro to file or directory." , ".e.g" - , " xmake macro --export=/xxx/macro.lua test" } + , " xmake macro --export=/xxx/macro.lua test" + , " xmake macro --export=/xxx/macrodir" } , {} , {nil, "name", "v", ".", "Set the macro name." , ".e.g" |
